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("所有缓存刷新成功");
|
// }
|
}
|