系统配置
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
package org.xyzh.system.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.xyzh.api.system.config.SysConfigService;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
import org.xyzh.common.core.page.PageRequest;
|
||||
import org.xyzh.common.dto.system.TbSysConfig;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @description 系统配置管理控制器
|
||||
* @filename ConfigController.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-11-18
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/config")
|
||||
public class ConfigController {
|
||||
|
||||
@Autowired
|
||||
private SysConfigService sysConfigService;
|
||||
|
||||
/**
|
||||
* @description 获取所有配置项(前端配置视图使用)
|
||||
* @return ResultDomain<TbSysConfig> 配置项列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public ResultDomain<TbSysConfig> getAllConfigs() {
|
||||
return sysConfigService.getAllConfigs();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 根据分组获取配置项
|
||||
* @param groupKey 分组键
|
||||
* @return ResultDomain<TbSysConfig> 配置项列表
|
||||
*/
|
||||
@GetMapping("/group/{groupKey}")
|
||||
public ResultDomain<TbSysConfig> getConfigsByGroup(@PathVariable String groupKey) {
|
||||
return sysConfigService.getConfigsByGroup(groupKey);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description 保存配置项(批量保存)
|
||||
* @param configs 配置项列表
|
||||
* @return ResultDomain<Boolean> 保存结果
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
public ResultDomain<Boolean> saveConfigs(@RequestBody List<Map<String, String>> configs) {
|
||||
return sysConfigService.batchSaveConfigs(configs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 创建单个配置项
|
||||
* @param config 配置项
|
||||
* @return ResultDomain<Boolean> 创建结果
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
public ResultDomain<Boolean> createConfig(@RequestBody TbSysConfig config) {
|
||||
return sysConfigService.createConfig(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 更新单个配置项
|
||||
* @param config 配置项
|
||||
* @return ResultDomain<Boolean> 更新结果
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public ResultDomain<Boolean> updateConfig(@RequestBody TbSysConfig config) {
|
||||
return sysConfigService.updateConfig(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 删除配置项
|
||||
* @param id 配置ID
|
||||
* @return ResultDomain<Boolean> 删除结果
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public ResultDomain<Boolean> deleteConfig(@PathVariable String id) {
|
||||
return sysConfigService.deleteConfig(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 分页查询配置项
|
||||
* @param pageRequest 分页请求
|
||||
* @return ResultDomain<TbSysConfig> 配置项分页列表
|
||||
*/
|
||||
@PostMapping("/page")
|
||||
public ResultDomain<TbSysConfig> getConfigPage(@RequestBody PageRequest<TbSysConfig> pageRequest) {
|
||||
return sysConfigService.getConfigPage(pageRequest.getFilter(), pageRequest.getPageParam());
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 根据ID获取配置项详情
|
||||
* @param id 配置ID
|
||||
* @return ResultDomain<TbSysConfig> 配置项详情
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public ResultDomain<TbSysConfig> getConfigById(@PathVariable String id) {
|
||||
return sysConfigService.getConfigById(id);
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,16 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.xyzh.api.system.config.SysConfigService;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.core.page.PageDomain;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
import org.xyzh.common.dto.system.TbSysConfig;
|
||||
import org.xyzh.system.mapper.SysConfigMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @description 系统配置服务实现
|
||||
* @author AI Assistant
|
||||
@@ -205,4 +212,163 @@ public class SysConfigServiceImpl implements SysConfigService {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 配置管理接口实现 ====================
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysConfig> getAllConfigs() {
|
||||
ResultDomain<TbSysConfig> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
List<TbSysConfig> configs = sysConfigMapper.selectAllSysConfig();
|
||||
resultDomain.success("查询成功", configs);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("获取所有配置失败", e);
|
||||
resultDomain.fail("获取配置失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysConfig> getConfigsByGroup(String groupKey) {
|
||||
ResultDomain<TbSysConfig> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
List<TbSysConfig> configs = sysConfigMapper.selectSysConfigByGroup(groupKey);
|
||||
resultDomain.success("查询成功", configs);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("根据分组获取配置失败: {}", groupKey, e);
|
||||
resultDomain.fail("获取配置失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Boolean> batchSaveConfigs(List<Map<String, String>> configs) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
for (Map<String, String> configMap : configs) {
|
||||
String configKey = configMap.get("configKey");
|
||||
String configValue = configMap.get("configValue");
|
||||
|
||||
TbSysConfig existingConfig = sysConfigMapper.selectSysConfigByKey(configKey);
|
||||
if (existingConfig != null) {
|
||||
existingConfig.setConfigValue(configValue);
|
||||
sysConfigMapper.updateSysConfig(existingConfig);
|
||||
} else {
|
||||
logger.warn("配置项不存在,跳过: {}", configKey);
|
||||
}
|
||||
}
|
||||
resultDomain.success("保存成功", true);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("批量保存配置失败", e);
|
||||
resultDomain.fail("保存配置失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Boolean> createConfig(TbSysConfig config) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
TbSysConfig existingConfig = sysConfigMapper.selectSysConfigByKey(config.getConfigKey());
|
||||
if (existingConfig != null) {
|
||||
resultDomain.fail("配置键已存在: " + config.getConfigKey());
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
if (config.getID() == null || config.getID().isEmpty()) {
|
||||
config.setID(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
int result = sysConfigMapper.insertSysConfig(config);
|
||||
if (result > 0) {
|
||||
resultDomain.success("创建成功", true);
|
||||
return resultDomain;
|
||||
} else {
|
||||
resultDomain.fail("创建配置失败");
|
||||
return resultDomain;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("创建配置失败", e);
|
||||
resultDomain.fail("创建配置失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Boolean> updateConfig(TbSysConfig config) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
int result = sysConfigMapper.updateSysConfig(config);
|
||||
if (result > 0) {
|
||||
resultDomain.success("更新成功", true);
|
||||
return resultDomain;
|
||||
} else {
|
||||
resultDomain.fail("更新配置失败");
|
||||
return resultDomain;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("更新配置失败", e);
|
||||
resultDomain.fail("更新配置失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Boolean> deleteConfig(String id) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
int result = sysConfigMapper.deleteSysConfig(id);
|
||||
if (result > 0) {
|
||||
resultDomain.success("删除成功", true);
|
||||
return resultDomain;
|
||||
} else {
|
||||
resultDomain.fail("删除配置失败");
|
||||
return resultDomain;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("删除配置失败: {}", id, e);
|
||||
resultDomain.fail("删除配置失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysConfig> getConfigPage(TbSysConfig filter, PageParam pageParam) {
|
||||
ResultDomain<TbSysConfig> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
int total = sysConfigMapper.countSelectSysConfig(filter);
|
||||
List<TbSysConfig> configs = sysConfigMapper.selectSysConfigPage(filter, pageParam);
|
||||
pageParam.setTotalElements(total);
|
||||
pageParam.setTotalPages((int) Math.ceil((double) total / pageParam.getPageSize()));
|
||||
PageDomain<TbSysConfig> pageDomain = new PageDomain<>(pageParam,configs);
|
||||
resultDomain.success("查询成功", pageDomain);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("分页查询配置失败", e);
|
||||
resultDomain.fail("查询配置失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysConfig> getConfigById(String id) {
|
||||
ResultDomain<TbSysConfig> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
TbSysConfig config = sysConfigMapper.selectSysConfigById(id);
|
||||
if (config != null) {
|
||||
resultDomain.success("查询成功", config);
|
||||
return resultDomain;
|
||||
} else {
|
||||
resultDomain.fail("配置不存在");
|
||||
return resultDomain;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("根据ID获取配置失败: {}", id, e);
|
||||
resultDomain.fail("获取配置失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,20 @@
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.system.TbSysConfig">
|
||||
<id column="id" property="ID" />
|
||||
<result column="config_key" property="configKey" />
|
||||
<result column="config_name" property="configName" />
|
||||
<result column="config_value" property="configValue" />
|
||||
<result column="config_type" property="configType" />
|
||||
<result column="render_type" property="renderType" />
|
||||
<result column="config_group" property="configGroup" />
|
||||
<result column="description" property="description" />
|
||||
<result column="placeholder" property="placeholder" />
|
||||
<result column="remark" property="remark" />
|
||||
<result column="rows" property="rows" />
|
||||
<result column="min_value" property="minValue" />
|
||||
<result column="max_value" property="maxValue" />
|
||||
<result column="unit" property="unit" />
|
||||
<result column="options" property="options" />
|
||||
<result column="order_num" property="orderNum" />
|
||||
<result column="is_system" property="isSystem" />
|
||||
<result column="creator" property="creator" />
|
||||
<result column="updater" property="updater" />
|
||||
@@ -21,7 +31,8 @@
|
||||
|
||||
<!-- 字段列表 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, config_key, config_value, config_type, config_group, description,
|
||||
id, config_key, config_name, config_value, config_type, render_type, config_group,
|
||||
description, placeholder, remark, `rows`, min_value, max_value, unit, `options`, order_num,
|
||||
is_system, creator, updater, create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
@@ -47,22 +58,35 @@
|
||||
<!-- 插入系统配置 -->
|
||||
<insert id="insertSysConfig" parameterType="org.xyzh.common.dto.system.TbSysConfig">
|
||||
INSERT INTO tb_sys_config (
|
||||
id, config_key, config_value, config_type, config_group, description,
|
||||
id, config_key, config_name, config_value, config_type, render_type, config_group,
|
||||
description, placeholder, remark, `rows`, min_value, max_value, unit, `options`, order_num,
|
||||
is_system, creator, create_time
|
||||
) VALUES (
|
||||
#{config.ID}, #{config.configKey}, #{config.configValue}, #{config.configType},
|
||||
#{config.configGroup}, #{config.description}, #{config.isSystem},
|
||||
#{config.creator}, NOW()
|
||||
#{config.ID}, #{config.configKey}, #{config.configName}, #{config.configValue},
|
||||
#{config.configType}, #{config.renderType}, #{config.configGroup}, #{config.description},
|
||||
#{config.placeholder}, #{config.remark}, #{config.rows}, #{config.minValue},
|
||||
#{config.maxValue}, #{config.unit}, #{config.options}, #{config.orderNum},
|
||||
#{config.isSystem}, #{config.creator}, NOW()
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 更新系统配置 -->
|
||||
<update id="updateSysConfig" parameterType="org.xyzh.common.dto.system.TbSysConfig">
|
||||
UPDATE tb_sys_config
|
||||
SET config_value = #{config.configValue},
|
||||
SET config_name = #{config.configName},
|
||||
config_value = #{config.configValue},
|
||||
config_type = #{config.configType},
|
||||
render_type = #{config.renderType},
|
||||
config_group = #{config.configGroup},
|
||||
description = #{config.description},
|
||||
placeholder = #{config.placeholder},
|
||||
remark = #{config.remark},
|
||||
`rows` = #{config.rows},
|
||||
min_value = #{config.minValue},
|
||||
max_value = #{config.maxValue},
|
||||
unit = #{config.unit},
|
||||
`options` = #{config.options},
|
||||
order_num = #{config.orderNum},
|
||||
is_system = #{config.isSystem},
|
||||
updater = #{config.updater},
|
||||
update_time = NOW()
|
||||
@@ -100,7 +124,7 @@
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM tb_sys_config
|
||||
WHERE deleted = 0
|
||||
ORDER BY config_group, config_key
|
||||
ORDER BY config_group, order_num, config_key
|
||||
</select>
|
||||
|
||||
<!-- 根据分组查询 -->
|
||||
@@ -109,7 +133,7 @@
|
||||
FROM tb_sys_config
|
||||
WHERE config_group = #{configGroup}
|
||||
AND deleted = 0
|
||||
ORDER BY config_key
|
||||
ORDER BY order_num, config_key
|
||||
</select>
|
||||
|
||||
<!-- 查询系统配置列表 -->
|
||||
@@ -117,7 +141,7 @@
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM tb_sys_config
|
||||
<include refid="Base_Where_Clause" />
|
||||
ORDER BY config_group, config_key
|
||||
ORDER BY config_group, order_num, config_key
|
||||
</select>
|
||||
|
||||
<!-- 分页查询 -->
|
||||
@@ -125,7 +149,7 @@
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM tb_sys_config
|
||||
<include refid="Base_Where_Clause" />
|
||||
ORDER BY config_group, config_key
|
||||
ORDER BY config_group, order_num, config_key
|
||||
LIMIT #{pageParam.offset}, #{pageParam.pageSize}
|
||||
</select>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user