1.优化目录结构
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
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.config.FunctionConfigHolder;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("config")
|
||||
public class FunctionConfigController {
|
||||
|
||||
@Autowired
|
||||
private FunctionConfigMapper configMapper;
|
||||
|
||||
// 获取所有配置
|
||||
@GetMapping("getAllConfig")
|
||||
public ResponseData<Object> getAllConfig() {
|
||||
return ResponseData.success(FunctionConfigHolder.CONFIGS);
|
||||
}
|
||||
|
||||
// 更新配置项内容
|
||||
@PostMapping("updateConfigValue")
|
||||
public ResponseData<Object> 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<Object> 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<Object> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user