mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-17 20:45:06 +08:00
完成参数配置
This commit is contained in:
@ -1,8 +1,26 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.config;
|
||||
|
||||
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.*;
|
||||
import cn.iocoder.dashboard.modules.system.convert.config.SysConfigConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
|
||||
import cn.iocoder.dashboard.modules.system.service.config.SysConfigService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_SENSITIVE;
|
||||
|
||||
@Api(tags = "参数配置")
|
||||
@RestController
|
||||
@ -24,4 +42,78 @@ public class SysConfigController {
|
||||
//
|
||||
// }
|
||||
|
||||
@Resource
|
||||
private SysConfigService configService;
|
||||
|
||||
@ApiOperation("获取参数配置分页")
|
||||
@GetMapping("/page")
|
||||
// @PreAuthorize("@ss.hasPermi('system:config:list')")
|
||||
public CommonResult<PageResult<SysConfigRespVO>> getConfigPage(@Validated SysConfigPageReqVO reqVO) {
|
||||
PageResult<SysConfigDO> page = configService.getConfigPage(reqVO);
|
||||
return success(SysConfigConvert.INSTANCE.convertPage(page));
|
||||
}
|
||||
|
||||
@ApiOperation("导出参数配置")
|
||||
@GetMapping("/export")
|
||||
// @Log(title = "参数管理", businessType = BusinessType.EXPORT)
|
||||
// @PreAuthorize("@ss.hasPermi('system:config:export')")
|
||||
public void exportSysConfig(HttpServletResponse response, @Validated SysConfigExportReqVO reqVO) throws IOException {
|
||||
List<SysConfigDO> list = configService.getConfigList(reqVO);
|
||||
// 拼接数据
|
||||
List<SysConfigExcelVO> excelDataList = SysConfigConvert.INSTANCE.convertList(list);
|
||||
// 输出
|
||||
ExcelUtils.write(response, "参数配置.xls", "配置列表",
|
||||
SysConfigExcelVO.class, excelDataList);
|
||||
}
|
||||
|
||||
@ApiOperation("获得参数配置")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@GetMapping(value = "/get")
|
||||
// @PreAuthorize("@ss.hasPermi('system:config:query')")
|
||||
public CommonResult<SysConfigRespVO> getConfig(@RequestParam("id") Long id) {
|
||||
return success(SysConfigConvert.INSTANCE.convert(configService.getConfig(id)));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据参数键名查询参数值", notes = "敏感配置,不允许返回给前端")
|
||||
@ApiImplicitParam(name = "key", value = "参数键", required = true, example = "yunai.biz.username", dataTypeClass = String.class)
|
||||
@GetMapping(value = "/get-value-by-key")
|
||||
public CommonResult<String> getConfigKey(@RequestParam("key") String key) {
|
||||
SysConfigDO config = configService.getConfigByKey(key);
|
||||
if (config == null) {
|
||||
return null;
|
||||
}
|
||||
if (config.getSensitive()) {
|
||||
throw ServiceExceptionUtil.exception(CONFIG_GET_VALUE_ERROR_IF_SENSITIVE);
|
||||
}
|
||||
return success(config.getValue());
|
||||
}
|
||||
|
||||
@ApiOperation("新增参数配置")
|
||||
@PostMapping("/create")
|
||||
// @PreAuthorize("@ss.hasPermi('system:config:add')")
|
||||
// @Log(title = "参数管理", businessType = BusinessType.INSERT)
|
||||
// @RepeatSubmit
|
||||
public CommonResult<Long> createConfig(@Validated @RequestBody SysConfigCreateReqVO reqVO) {
|
||||
return success(configService.createConfig(reqVO));
|
||||
}
|
||||
|
||||
@ApiOperation("修改参数配置")
|
||||
@PutMapping("/update")
|
||||
// @PreAuthorize("@ss.hasPermi('system:config:edit')")
|
||||
// @Log(title = "参数管理", businessType = BusinessType.UPDATE)
|
||||
public CommonResult<Boolean> edit(@Validated @RequestBody SysConfigUpdateReqVO reqVO) {
|
||||
configService.updateConfig(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ApiOperation("删除参数配置")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@DeleteMapping("/delete")
|
||||
// @PreAuthorize("@ss.hasPermi('system:config:remove')")
|
||||
// @Log(title = "参数管理", businessType = BusinessType.DELETE)
|
||||
public CommonResult<Boolean> deleteConfig(@RequestParam("id") Long id) {
|
||||
configService.deleteConfig(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
@ -29,11 +30,8 @@ public class SysConfigBaseVO {
|
||||
@Size(max = 500, message = "参数键值长度不能超过500个字符")
|
||||
private String value;
|
||||
|
||||
@ApiModelProperty(value = "参数类型", required = true, example = "1", notes = "参见 SysConfigTypeEnum 枚举")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "是否敏感", required = true, example = "true")
|
||||
@NotBlank(message = "是否敏感不能为空")
|
||||
@NotNull(message = "是否敏感不能为空")
|
||||
private Boolean sensitive;
|
||||
|
||||
@ApiModelProperty(value = "备注", example = "备注一下很帅气!")
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.config.vo;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptBaseVO;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
@ -12,7 +11,7 @@ import javax.validation.constraints.Size;
|
||||
@ApiModel("参数配置创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysConfigCreateReqVO extends SysDeptBaseVO {
|
||||
public class SysConfigCreateReqVO extends SysConfigBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "参数键名", required = true, example = "yunai.db.username")
|
||||
@NotBlank(message = "参数键名长度不能为空")
|
||||
|
@ -1,5 +1,8 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.config.vo;
|
||||
|
||||
import cn.iocoder.dashboard.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.dashboard.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.dashboard.modules.system.enums.dict.SysDictTypeEnum;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@ -26,10 +29,12 @@ public class SysConfigExcelVO {
|
||||
@ExcelProperty("参数键值")
|
||||
private String value;
|
||||
|
||||
@ExcelProperty("参数类型")
|
||||
private String type;
|
||||
@ExcelProperty(value = "参数类型", converter = DictConvert.class)
|
||||
@DictFormat(SysDictTypeEnum.SYS_CONFIG_TYPE)
|
||||
private Integer type;
|
||||
|
||||
@ExcelProperty("是否敏感")
|
||||
@ExcelProperty(value = "是否敏感", converter = DictConvert.class)
|
||||
@DictFormat(SysDictTypeEnum.SYS_BOOLEAN_STRING)
|
||||
private Boolean sensitive;
|
||||
|
||||
@ExcelProperty("备注")
|
||||
|
@ -0,0 +1,33 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.config.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel("参数配置导出 Request VO")
|
||||
@Data
|
||||
public class SysConfigExportReqVO {
|
||||
|
||||
@ApiModelProperty(value = "参数名称", example = "模糊匹配")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "参数键名", example = "yunai.db.username", notes = "模糊匹配")
|
||||
private String key;
|
||||
|
||||
@ApiModelProperty(value = "参数类型", example = "1", notes = "参见 SysConfigTypeEnum 枚举")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "开始时间", example = "2020-10-24")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date beginTime;
|
||||
|
||||
@ApiModelProperty(value = "结束时间", example = "2020-10-24")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date endTime;
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.config.vo;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel("参数配置分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysConfigPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "参数名称", example = "模糊匹配")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "参数键名", example = "yunai.db.username", notes = "模糊匹配")
|
||||
private String key;
|
||||
|
||||
@ApiModelProperty(value = "参数类型", example = "1", notes = "参见 SysConfigTypeEnum 枚举")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "开始时间", example = "2020-10-24")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date beginTime;
|
||||
|
||||
@ApiModelProperty(value = "结束时间", example = "2020-10-24")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date endTime;
|
||||
|
||||
}
|
@ -22,6 +22,9 @@ public class SysConfigRespVO extends SysConfigBaseVO {
|
||||
@Size(max = 100, message = "参数键名长度不能超过100个字符")
|
||||
private String key;
|
||||
|
||||
@ApiModelProperty(value = "参数类型", required = true, example = "1", notes = "参见 SysConfigTypeEnum 枚举")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
|
||||
private Date createTime;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.config.vo;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptBaseVO;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
@ -11,7 +10,7 @@ import javax.validation.constraints.NotNull;
|
||||
@ApiModel("参数配置创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysConfigUpdateReqVO extends SysDeptBaseVO {
|
||||
public class SysConfigUpdateReqVO extends SysConfigBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "参数配置序号", required = true, example = "1024")
|
||||
@NotNull(message = "参数配置编号不能为空")
|
||||
|
@ -0,0 +1,29 @@
|
||||
package cn.iocoder.dashboard.modules.system.convert.config;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExcelVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysConfigConvert {
|
||||
|
||||
SysConfigConvert INSTANCE = Mappers.getMapper(SysConfigConvert.class);
|
||||
|
||||
PageResult<SysConfigRespVO> convertPage(PageResult<SysConfigDO> page);
|
||||
|
||||
SysConfigRespVO convert(SysConfigDO bean);
|
||||
|
||||
SysConfigDO convert(SysConfigCreateReqVO bean);
|
||||
|
||||
SysConfigDO convert(SysConfigUpdateReqVO bean);
|
||||
|
||||
List<SysConfigExcelVO> convertList(List<SysConfigDO> list);
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.config;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysConfigMapper extends BaseMapperX<SysConfigDO> {
|
||||
|
||||
default PageResult<SysConfigDO> selectPage(SysConfigPageReqVO reqVO) {
|
||||
return selectPage(reqVO,
|
||||
new QueryWrapperX<SysConfigDO>().likeIfPresent("name", reqVO.getName())
|
||||
.likeIfPresent("`key`", reqVO.getKey())
|
||||
.eqIfPresent("`type`", reqVO.getType())
|
||||
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
|
||||
}
|
||||
|
||||
default SysConfigDO selectByKey(String key) {
|
||||
return selectOne(new QueryWrapper<SysConfigDO>().eq("`key`", key));
|
||||
}
|
||||
|
||||
default List<SysConfigDO> selectList(SysConfigExportReqVO reqVO) {
|
||||
return selectList(new QueryWrapperX<SysConfigDO>().likeIfPresent("name", reqVO.getName())
|
||||
.likeIfPresent("`key`", reqVO.getKey())
|
||||
.eqIfPresent("`type`", reqVO.getType())
|
||||
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,11 @@ package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config;
|
||||
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.dashboard.modules.system.enums.config.SysConfigTypeEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* 参数配置表
|
||||
@ -10,6 +14,9 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
* @author ruoyi
|
||||
*/
|
||||
@TableName("sys_config")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SysConfigDO extends BaseDO {
|
||||
|
||||
/**
|
||||
@ -19,6 +26,7 @@ public class SysConfigDO extends BaseDO {
|
||||
/**
|
||||
* 参数分组
|
||||
*/
|
||||
@TableField("`group`")
|
||||
private String group;
|
||||
/**
|
||||
* 参数名称
|
||||
@ -27,6 +35,7 @@ public class SysConfigDO extends BaseDO {
|
||||
/**
|
||||
* 参数键名
|
||||
*/
|
||||
@TableField("`key`")
|
||||
private String key;
|
||||
/**
|
||||
* 参数键值
|
||||
@ -37,12 +46,14 @@ public class SysConfigDO extends BaseDO {
|
||||
*
|
||||
* 枚举 {@link SysConfigTypeEnum}
|
||||
*/
|
||||
private String type;
|
||||
@TableField("`type`")
|
||||
private Integer type;
|
||||
/**
|
||||
* 是否敏感
|
||||
*
|
||||
* 对于敏感配置,需要管理权限才能查看
|
||||
*/
|
||||
@TableField("`sensitive`")
|
||||
private Boolean sensitive;
|
||||
/**
|
||||
* 备注
|
||||
|
@ -74,4 +74,10 @@ public interface SysErrorCodeConstants {
|
||||
|
||||
// ========== 文件 1002009000 ==========
|
||||
ErrorCode FILE_PATH_EXISTS = new ErrorCode(1002009001, "文件路径已经存在");
|
||||
|
||||
// ========== 参数配置 1002010000 ==========
|
||||
ErrorCode CONFIG_NOT_FOUND = new ErrorCode(1002010001, "参数配置不存在");
|
||||
ErrorCode CONFIG_NAME_DUPLICATE = new ErrorCode(1002010002, "参数配置 key 重复");
|
||||
ErrorCode CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE = new ErrorCode(1002010003, "不能删除类型为系统内置的参数配置");
|
||||
ErrorCode CONFIG_GET_VALUE_ERROR_IF_SENSITIVE = new ErrorCode(1002010004, "不允许获取敏感配置到前端");
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ public enum SysDictTypeEnum {
|
||||
SYS_COMMON_STATUS("sys_common_status"), // 系统状态
|
||||
SYS_OPERATE_TYPE("sys_operate_type"), // 操作类型
|
||||
SYS_LOGIN_RESULT("sys_login_result"), // 登陆结果
|
||||
SYS_CONFIG_TYPE("sys_config_type"), // 参数配置类型
|
||||
SYS_BOOLEAN_STRING("sys_boolean_string"), // Boolean 是否类型
|
||||
;
|
||||
|
||||
|
||||
|
@ -0,0 +1,71 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.config;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 参数配置 Service 接口
|
||||
*/
|
||||
public interface SysConfigService {
|
||||
|
||||
/**
|
||||
* 获得参数配置分页列表
|
||||
*
|
||||
* @param reqVO 分页条件
|
||||
* @return 分页列表
|
||||
*/
|
||||
PageResult<SysConfigDO> getConfigPage(SysConfigPageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得参数配置列表
|
||||
*
|
||||
* @param reqVO 列表
|
||||
* @return 列表
|
||||
*/
|
||||
List<SysConfigDO> getConfigList(SysConfigExportReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得参数配置
|
||||
*
|
||||
* @param id 配置编号
|
||||
* @return 参数配置
|
||||
*/
|
||||
SysConfigDO getConfig(Long id);
|
||||
|
||||
/**
|
||||
* 根据参数键,获得参数配置
|
||||
*
|
||||
* @param key 配置键
|
||||
* @return 参数配置
|
||||
*/
|
||||
SysConfigDO getConfigByKey(String key);
|
||||
|
||||
/**
|
||||
* 创建参数配置
|
||||
*
|
||||
* @param reqVO 创建信息
|
||||
* @return 配置编号
|
||||
*/
|
||||
Long createConfig(SysConfigCreateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 更新参数配置
|
||||
*
|
||||
* @param reqVO 更新信息
|
||||
*/
|
||||
void updateConfig(SysConfigUpdateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 删除参数配置
|
||||
*
|
||||
* @param id 配置编号
|
||||
*/
|
||||
void deleteConfig(Long id);
|
||||
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.config.impl;
|
||||
|
||||
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.convert.config.SysConfigConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.config.SysConfigMapper;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
|
||||
import cn.iocoder.dashboard.modules.system.enums.config.SysConfigTypeEnum;
|
||||
import cn.iocoder.dashboard.modules.system.service.config.SysConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 参数配置 Service 实现类
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SysConfigServiceImpl implements SysConfigService {
|
||||
|
||||
@Resource
|
||||
private SysConfigMapper configMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<SysConfigDO> getConfigPage(SysConfigPageReqVO reqVO) {
|
||||
return configMapper.selectPage(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysConfigDO> getConfigList(SysConfigExportReqVO reqVO) {
|
||||
return configMapper.selectList(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysConfigDO getConfig(Long id) {
|
||||
return configMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysConfigDO getConfigByKey(String key) {
|
||||
return configMapper.selectByKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createConfig(SysConfigCreateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(null, reqVO.getKey());
|
||||
// 插入参数配置
|
||||
SysConfigDO config = SysConfigConvert.INSTANCE.convert(reqVO);
|
||||
config.setType(SysConfigTypeEnum.CUSTOM.getType());
|
||||
configMapper.insert(config);
|
||||
return config.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConfig(SysConfigUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(reqVO.getId(), null); // 不允许更新 key
|
||||
// 更新参数配置
|
||||
SysConfigDO updateObj = SysConfigConvert.INSTANCE.convert(reqVO);
|
||||
configMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteConfig(Long id) {
|
||||
// 校验配置存在
|
||||
SysConfigDO config = checkConfigExists(id);
|
||||
// 内置配置,不允许删除
|
||||
if (SysConfigTypeEnum.SYSTEM.getType().equals(config.getType())) {
|
||||
throw ServiceExceptionUtil.exception(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
|
||||
}
|
||||
// 删除
|
||||
configMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void checkCreateOrUpdate(Long id, String key) {
|
||||
// 校验自己存在
|
||||
checkConfigExists(id);
|
||||
// 校验参数配置 key 的唯一性
|
||||
checkConfigKeyUnique(id, key);
|
||||
}
|
||||
|
||||
private SysConfigDO checkConfigExists(Long id) {
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
SysConfigDO config = configMapper.selectById(id);
|
||||
if (config == null) {
|
||||
throw ServiceExceptionUtil.exception(CONFIG_NOT_FOUND);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
private void checkConfigKeyUnique(Long id, String key) {
|
||||
SysConfigDO config = configMapper.selectByKey(key);
|
||||
if (config == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的参数配置
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(CONFIG_NAME_DUPLICATE);
|
||||
}
|
||||
if (!config.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(CONFIG_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user