package vvpkassistant.FunctionConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import vvpkassistant.Data.ResponseData; import vvpkassistant.Data.ResponseInfo; @RestController @RequestMapping("config") public class FunctionConfigController { @Autowired private FunctionConfigMapper configMapper; // 获取所有配置 @GetMapping("getAllConfig") public ResponseData getAllConfig() { return ResponseData.success(FunctionConfigHolder.CONFIGS); } // 更新配置项内容 @PostMapping("updateConfigValue") public ResponseData updateConfigValue(@RequestBody FunctionConfigModel model) { // 1. 更新数据库 configMapper.updateById(model); // 2. 更新内存 FunctionConfigHolder.CONFIGS.removeIf(c -> model.getFunctionName().equals(c.getFunctionName())); FunctionConfigHolder.CONFIGS.add(model); return ResponseData.success(""); } @PostMapping("add") public ResponseData addNewConfig(@RequestBody FunctionConfigModel newModel) { String name = newModel.getFunctionName(); boolean isDuplicate = FunctionConfigHolder.CONFIGS.stream() .anyMatch(config -> name.equals(config.getFunctionName())); if (isDuplicate) { return ResponseData.error(ResponseInfo.ERROR,"配置名称重复"); }else { configMapper.insert(newModel); FunctionConfigHolder.CONFIGS.add(newModel); return ResponseData.success(""); } } @PostMapping("deleteConfigById") public ResponseData deleteConfigById(@RequestBody FunctionConfigModel model) { int i = configMapper.deleteById(model); if (i == 1) { FunctionConfigHolder.CONFIGS.removeIf(c -> model.getId().equals(c.getId())); return ResponseData.success(""); }else { return ResponseData.error(ResponseInfo.ERROR,null); } } }