1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package com.vincent.rsf.openApi.controller.platform;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vincent.rsf.openApi.entity.app.ApiMap;
import com.vincent.rsf.openApi.entity.dto.CommonResponse;
import com.vincent.rsf.openApi.service.ApiMapService;
import com.vincent.rsf.openApi.utils.ParamsMapUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * ApiMap管理Controller
 * 
 * @author vincent
 * @since 2026-01-04
 */
@RestController
@RequestMapping("/api/map")
@Api(tags = "字段映射管理")
public class ApiMapController {
 
    @Autowired
    private ApiMapService apiMapService;
 
 
    @ApiOperation("分页查询字段映射列表")
    @GetMapping("/page")
    public CommonResponse page(@RequestParam(defaultValue = "1") Integer current,
                                @RequestParam(defaultValue = "10") Integer size,
                                @RequestParam(required = false) String appId,
                                @RequestParam(required = false) String funcId) {
        LambdaQueryWrapper<ApiMap> wrapper = new LambdaQueryWrapper<>();
        if (appId != null && !appId.isEmpty()) {
            wrapper.eq(ApiMap::getAppId, appId);
        }
        if (funcId != null && !funcId.isEmpty()) {
            wrapper.eq(ApiMap::getFuncId, funcId);
        }
        Page<ApiMap> page = apiMapService.page(new Page<>(current, size), wrapper);
        return CommonResponse.ok().setData(page);
    }
 
    @ApiOperation("查询所有字段映射")
    @GetMapping("/list")
    public CommonResponse list(@RequestParam(required = false) String appId,
                                @RequestParam(required = false) String funcId) {
        LambdaQueryWrapper<ApiMap> wrapper = new LambdaQueryWrapper<>();
        if (appId != null && !appId.isEmpty()) {
            wrapper.eq(ApiMap::getAppId, appId);
        }
        if (funcId != null && !funcId.isEmpty()) {
            wrapper.eq(ApiMap::getFuncId, funcId);
        }
        List<ApiMap> list = apiMapService.list(wrapper);
        return CommonResponse.ok().setData(list);
    }
 
    @ApiOperation("根据ID查询字段映射")
    @GetMapping("/{id}")
    public CommonResponse getById(@PathVariable Integer id) {
        ApiMap map = apiMapService.getById(id);
        return CommonResponse.ok().setData(map);
    }
 
    @ApiOperation("新增字段映射")
    @PostMapping
    public CommonResponse save(@RequestBody ApiMap map) {
        boolean result = apiMapService.save(map);
        if (result) {
            apiMapService.refreshCache();
            return CommonResponse.ok().setMsg("新增成功");
        }
        return CommonResponse.error("新增失败");
    }
 
    @ApiOperation("批量新增字段映射")
    @PostMapping("/batch")
    public CommonResponse saveBatch(@RequestBody List<ApiMap> maps) {
        boolean result = apiMapService.saveBatch(maps);
        if (result) {
            apiMapService.refreshCache();
            return CommonResponse.ok().setMsg("批量新增成功");
        }
        return CommonResponse.error("批量新增失败");
    }
 
    @ApiOperation("更新字段映射")
    @PutMapping
    public CommonResponse update(@RequestBody ApiMap map) {
        boolean result = apiMapService.updateById(map);
        if (result) {
            apiMapService.refreshCache();
            return CommonResponse.ok().setMsg("更新成功");
        }
        return CommonResponse.error("更新失败");
    }
 
    @ApiOperation("删除字段映射")
    @DeleteMapping("/{id}")
    public CommonResponse delete(@PathVariable Integer id) {
        boolean result = apiMapService.removeById(id);
        if (result) {
            apiMapService.refreshCache();
            return CommonResponse.ok().setMsg("删除成功");
        }
        return CommonResponse.error("删除失败");
    }
 
    @ApiOperation("批量删除字段映射")
    @DeleteMapping("/batch")
    public CommonResponse deleteBatch(@RequestBody List<Integer> ids) {
        boolean result = apiMapService.removeByIds(ids);
        if (result) {
            apiMapService.refreshCache();
            return CommonResponse.ok().setMsg("批量删除成功");
        }
        return CommonResponse.error("批量删除失败");
    }
 
    @ApiOperation("刷新映射缓存")
    @PostMapping("/refresh")
    public CommonResponse refresh() {
        apiMapService.refreshCache();
        return CommonResponse.ok().setMsg("缓存刷新成功");
    }
 
//    @ApiOperation("刷新所有缓存")
//    @PostMapping("/refresh/all")
//    public CommonResponse refreshAll() {
//        new ParamsMapUtils().refreshAll();
//        return CommonResponse.ok().setMsg("所有缓存刷新成功");
//    }
}