1.调整 controller 位置

2.添加日志拦截
This commit is contained in:
2025-08-07 21:17:47 +08:00
parent ff29da493e
commit 5caa4b6580
12 changed files with 91 additions and 23 deletions

View File

@@ -1,67 +0,0 @@
package vvpkassistant.FunctionConfig.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vvpkassistant.Data.ResponseData;
import vvpkassistant.Data.ResponseInfo;
import vvpkassistant.FunctionConfig.mapper.FunctionConfigMapper;
import vvpkassistant.FunctionConfig.model.FunctionConfigModel;
import vvpkassistant.FunctionConfig.service.FunctionConfigService;
import vvpkassistant.common.ErrorCode;
import vvpkassistant.config.FunctionConfigHolder;
import vvpkassistant.exception.BusinessException;
import javax.annotation.Resource;
@RestController
@RequestMapping("config")
public class FunctionConfigController {
@Autowired
private FunctionConfigMapper configMapper;
@Resource
private FunctionConfigService functionConfigService;
// 获取所有配置
@GetMapping("getAllConfig")
public ResponseData<Object> getAllConfig() {
return ResponseData.success(FunctionConfigHolder.CONFIGS);
}
// 更新配置项内容
@PostMapping("updateConfigValue")
public ResponseData<Object> updateConfigValue(@RequestBody FunctionConfigModel model) {
// 1. 更新数据库
functionConfigService.updateById(model);
// 2. 更新内存
FunctionConfigHolder.CONFIGS.removeIf(c -> model.getFunctionName().equals(c.getFunctionName()));
FunctionConfigHolder.CONFIGS.add(model);
return ResponseData.success("");
}
@PostMapping("add")
public ResponseData<Object> addNewConfig(@RequestBody FunctionConfigModel newModel) {
String name = newModel.getFunctionName();
boolean isDuplicate = FunctionConfigHolder.CONFIGS.stream()
.anyMatch(config -> name.equals(config.getFunctionName()));
if (isDuplicate) {
throw new BusinessException(ErrorCode.CONFIG_NAME_DUPLICATE);
}else {
functionConfigService.save(newModel);
FunctionConfigHolder.CONFIGS.add(newModel);
return ResponseData.success("");
}
}
@PostMapping("deleteConfigById")
public ResponseData<Object> deleteConfigById(@RequestBody FunctionConfigModel model) {
if (functionConfigService.removeById(model)) {
FunctionConfigHolder.CONFIGS.removeIf(c -> model.getId().equals(c.getId()));
return ResponseData.success("");
}else {
throw new BusinessException(ErrorCode.DELETE_FAILED);
}
}
}