Files
todo-backend/src/main/java/com/example/building/controller/SystemConfigController.java

58 lines
1.7 KiB
Java

package com.example.building.controller;
import com.example.building.common.Result;
import com.example.building.entity.SystemConfig;
import com.example.building.mapper.SystemConfigMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 系统配置控制器
*/
@RestController
@RequestMapping("/api/v1/system-config")
public class SystemConfigController {
@Autowired
private SystemConfigMapper systemConfigMapper;
/**
* 获取所有配置
*/
@GetMapping
public Result<Map<String, String>> getAllConfig() {
List<SystemConfig> configs = systemConfigMapper.selectList(null);
Map<String, String> result = new HashMap<>();
for (SystemConfig config : configs) {
result.put(config.getConfigKey(), config.getConfigValue());
}
return Result.success(result);
}
/**
* 更新配置
*/
@PutMapping
public Result<Void> updateConfig(@RequestBody SystemConfig config) {
// 检查是否存在
SystemConfig existing = systemConfigMapper.selectOne(
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<SystemConfig>()
.eq(SystemConfig::getConfigKey, config.getConfigKey())
);
if (existing != null) {
existing.setConfigValue(config.getConfigValue());
existing.setRemark(config.getRemark());
systemConfigMapper.updateById(existing);
} else {
config.setConfigId(java.util.UUID.randomUUID().toString());
systemConfigMapper.insert(config);
}
return Result.success();
}
}