mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-28 16:58:43 +08:00 
			
		
		
		
	🔧 简化 config 模块的 VO
This commit is contained in:
		| @@ -1,6 +1,7 @@ | |||||||
| package cn.iocoder.yudao.module.infra.controller.admin.config; | package cn.iocoder.yudao.module.infra.controller.admin.config; | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||||
|  | import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||||
| import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||||||
| import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||||||
| @@ -38,15 +39,15 @@ public class ConfigController { | |||||||
|     @PostMapping("/create") |     @PostMapping("/create") | ||||||
|     @Operation(summary = "创建参数配置") |     @Operation(summary = "创建参数配置") | ||||||
|     @PreAuthorize("@ss.hasPermission('infra:config:create')") |     @PreAuthorize("@ss.hasPermission('infra:config:create')") | ||||||
|     public CommonResult<Long> createConfig(@Valid @RequestBody ConfigCreateReqVO reqVO) { |     public CommonResult<Long> createConfig(@Valid @RequestBody ConfigSaveReqVO createReqVO) { | ||||||
|         return success(configService.createConfig(reqVO)); |         return success(configService.createConfig(createReqVO)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @PutMapping("/update") |     @PutMapping("/update") | ||||||
|     @Operation(summary = "修改参数配置") |     @Operation(summary = "修改参数配置") | ||||||
|     @PreAuthorize("@ss.hasPermission('infra:config:update')") |     @PreAuthorize("@ss.hasPermission('infra:config:update')") | ||||||
|     public CommonResult<Boolean> updateConfig(@Valid @RequestBody ConfigUpdateReqVO reqVO) { |     public CommonResult<Boolean> updateConfig(@Valid @RequestBody ConfigSaveReqVO updateReqVO) { | ||||||
|         configService.updateConfig(reqVO); |         configService.updateConfig(updateReqVO); | ||||||
|         return success(true); |         return success(true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -84,8 +85,8 @@ public class ConfigController { | |||||||
|     @GetMapping("/page") |     @GetMapping("/page") | ||||||
|     @Operation(summary = "获取参数配置分页") |     @Operation(summary = "获取参数配置分页") | ||||||
|     @PreAuthorize("@ss.hasPermission('infra:config:query')") |     @PreAuthorize("@ss.hasPermission('infra:config:query')") | ||||||
|     public CommonResult<PageResult<ConfigRespVO>> getConfigPage(@Valid ConfigPageReqVO reqVO) { |     public CommonResult<PageResult<ConfigRespVO>> getConfigPage(@Valid ConfigPageReqVO pageReqVO) { | ||||||
|         PageResult<ConfigDO> page = configService.getConfigPage(reqVO); |         PageResult<ConfigDO> page = configService.getConfigPage(pageReqVO); | ||||||
|         return success(ConfigConvert.INSTANCE.convertPage(page)); |         return success(ConfigConvert.INSTANCE.convertPage(page)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -93,13 +94,13 @@ public class ConfigController { | |||||||
|     @Operation(summary = "导出参数配置") |     @Operation(summary = "导出参数配置") | ||||||
|     @PreAuthorize("@ss.hasPermission('infra:config:export')") |     @PreAuthorize("@ss.hasPermission('infra:config:export')") | ||||||
|     @OperateLog(type = EXPORT) |     @OperateLog(type = EXPORT) | ||||||
|     public void exportConfig(@Valid ConfigExportReqVO reqVO, |     public void exportConfig(@Valid ConfigPageReqVO exportReqVO, | ||||||
|                              HttpServletResponse response) throws IOException { |                              HttpServletResponse response) throws IOException { | ||||||
|         List<ConfigDO> list = configService.getConfigList(reqVO); |         exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | ||||||
|         // 拼接数据 |         List<ConfigDO> list = configService.getConfigPage(exportReqVO).getList(); | ||||||
|         List<ConfigExcelVO> datas = ConfigConvert.INSTANCE.convertList(list); |  | ||||||
|         // 输出 |         // 输出 | ||||||
|         ExcelUtils.write(response, "参数配置.xls", "数据", ConfigExcelVO.class, datas); |         ExcelUtils.write(response, "参数配置.xls", "数据", ConfigRespVO.class, | ||||||
|  |                 ConfigConvert.INSTANCE.convertList(list)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,20 +0,0 @@ | |||||||
| package cn.iocoder.yudao.module.infra.controller.admin.config.vo; |  | ||||||
|  |  | ||||||
| import io.swagger.v3.oas.annotations.media.Schema; |  | ||||||
| import lombok.Data; |  | ||||||
| import lombok.EqualsAndHashCode; |  | ||||||
|  |  | ||||||
| import javax.validation.constraints.NotBlank; |  | ||||||
| import javax.validation.constraints.Size; |  | ||||||
|  |  | ||||||
| @Schema(description = "管理后台 - 参数配置创建 Request VO") |  | ||||||
| @Data |  | ||||||
| @EqualsAndHashCode(callSuper = true) |  | ||||||
| public class ConfigCreateReqVO extends ConfigBaseVO { |  | ||||||
|  |  | ||||||
|     @Schema(description = "参数键名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yunai.db.username") |  | ||||||
|     @NotBlank(message = "参数键名长度不能为空") |  | ||||||
|     @Size(max = 100, message = "参数键名长度不能超过100个字符") |  | ||||||
|     private String key; |  | ||||||
|  |  | ||||||
| } |  | ||||||
| @@ -1,46 +0,0 @@ | |||||||
| package cn.iocoder.yudao.module.infra.controller.admin.config.vo; |  | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; |  | ||||||
| import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; |  | ||||||
| import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; |  | ||||||
| import com.alibaba.excel.annotation.ExcelProperty; |  | ||||||
| import lombok.Data; |  | ||||||
|  |  | ||||||
| import java.time.LocalDateTime; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * 参数配置 Excel 导出响应 VO |  | ||||||
|  */ |  | ||||||
| @Data |  | ||||||
| public class ConfigExcelVO { |  | ||||||
|  |  | ||||||
|     @ExcelProperty("参数配置序号") |  | ||||||
|     private Long id; |  | ||||||
|  |  | ||||||
|     @ExcelProperty("参数键名") |  | ||||||
|     private String configKey; |  | ||||||
|  |  | ||||||
|     @ExcelProperty("参数分类") |  | ||||||
|     private String category; |  | ||||||
|  |  | ||||||
|     @ExcelProperty("参数名称") |  | ||||||
|     private String name; |  | ||||||
|  |  | ||||||
|     @ExcelProperty("参数键值") |  | ||||||
|     private String value; |  | ||||||
|  |  | ||||||
|     @ExcelProperty(value = "参数类型", converter = DictConvert.class) |  | ||||||
|     @DictFormat(DictTypeConstants.CONFIG_TYPE) |  | ||||||
|     private Integer type; |  | ||||||
|  |  | ||||||
|     @ExcelProperty(value = "是否可见", converter = DictConvert.class) |  | ||||||
|     @DictFormat(DictTypeConstants.BOOLEAN_STRING) |  | ||||||
|     private Boolean visible; |  | ||||||
|  |  | ||||||
|     @ExcelProperty("备注") |  | ||||||
|     private String remark; |  | ||||||
|  |  | ||||||
|     @ExcelProperty("创建时间") |  | ||||||
|     private LocalDateTime createTime; |  | ||||||
|  |  | ||||||
| } |  | ||||||
| @@ -1,28 +0,0 @@ | |||||||
| package cn.iocoder.yudao.module.infra.controller.admin.config.vo; |  | ||||||
|  |  | ||||||
| import io.swagger.v3.oas.annotations.media.Schema; |  | ||||||
| import lombok.Data; |  | ||||||
| import org.springframework.format.annotation.DateTimeFormat; |  | ||||||
|  |  | ||||||
| import java.time.LocalDateTime; |  | ||||||
|  |  | ||||||
| import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |  | ||||||
|  |  | ||||||
| @Schema(description = "管理后台 - 参数配置导出 Request VO") |  | ||||||
| @Data |  | ||||||
| public class ConfigExportReqVO { |  | ||||||
|  |  | ||||||
|     @Schema(description = "参数名称", example = "模糊匹配") |  | ||||||
|     private String name; |  | ||||||
|  |  | ||||||
|     @Schema(description = "参数键名,模糊匹配", example = "yunai.db.username") |  | ||||||
|     private String key; |  | ||||||
|  |  | ||||||
|     @Schema(description = "参数类型,参见 SysConfigTypeEnum 枚举", example = "1") |  | ||||||
|     private Integer type; |  | ||||||
|  |  | ||||||
|     @Schema(description = "创建时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]") |  | ||||||
|     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |  | ||||||
|     private LocalDateTime[] createTime; |  | ||||||
|  |  | ||||||
| } |  | ||||||
| @@ -1,30 +1,56 @@ | |||||||
| package cn.iocoder.yudao.module.infra.controller.admin.config.vo; | package cn.iocoder.yudao.module.infra.controller.admin.config.vo; | ||||||
|  |  | ||||||
|  | import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | ||||||
|  | import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | ||||||
|  | import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; | ||||||
|  | import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | ||||||
|  | import com.alibaba.excel.annotation.ExcelProperty; | ||||||
| import io.swagger.v3.oas.annotations.media.Schema; | import io.swagger.v3.oas.annotations.media.Schema; | ||||||
| import lombok.Data; | import lombok.Data; | ||||||
| import lombok.EqualsAndHashCode; |  | ||||||
|  |  | ||||||
| import javax.validation.constraints.NotBlank; |  | ||||||
| import javax.validation.constraints.Size; |  | ||||||
| import java.time.LocalDateTime; | import java.time.LocalDateTime; | ||||||
|  |  | ||||||
| @Schema(description = "管理后台 - 参数配置信息 Response VO") | @Schema(description = "管理后台 - 参数配置信息 Response VO") | ||||||
| @Data | @Data | ||||||
| @EqualsAndHashCode(callSuper = true) | @ExcelIgnoreUnannotated | ||||||
| public class ConfigRespVO extends ConfigBaseVO { | public class ConfigRespVO { | ||||||
|  |  | ||||||
|     @Schema(description = "参数配置序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |     @Schema(description = "参数配置序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||||||
|  |     @ExcelProperty("参数配置序号") | ||||||
|     private Long id; |     private Long id; | ||||||
|  |  | ||||||
|  |     @Schema(description = "参数分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "biz") | ||||||
|  |     @ExcelProperty("参数分类") | ||||||
|  |     private String category; | ||||||
|  |  | ||||||
|  |     @Schema(description = "参数名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "数据库名") | ||||||
|  |     @ExcelProperty("参数名称") | ||||||
|  |     private String name; | ||||||
|  |  | ||||||
|     @Schema(description = "参数键名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yunai.db.username") |     @Schema(description = "参数键名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yunai.db.username") | ||||||
|     @NotBlank(message = "参数键名长度不能为空") |     @ExcelProperty("参数键名") | ||||||
|     @Size(max = 100, message = "参数键名长度不能超过100个字符") |  | ||||||
|     private String key; |     private String key; | ||||||
|  |  | ||||||
|  |     @Schema(description = "参数键值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||||||
|  |     @ExcelProperty("参数键值") | ||||||
|  |     private String value; | ||||||
|  |  | ||||||
|     @Schema(description = "参数类型,参见 SysConfigTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |     @Schema(description = "参数类型,参见 SysConfigTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||||||
|  |     @ExcelProperty(value = "参数类型", converter = DictConvert.class) | ||||||
|  |     @DictFormat(DictTypeConstants.CONFIG_TYPE) | ||||||
|     private Integer type; |     private Integer type; | ||||||
|  |  | ||||||
|  |     @Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | ||||||
|  |     @ExcelProperty(value = "是否可见", converter = DictConvert.class) | ||||||
|  |     @DictFormat(DictTypeConstants.BOOLEAN_STRING) | ||||||
|  |     private Boolean visible; | ||||||
|  |  | ||||||
|  |     @Schema(description = "备注", example = "备注一下很帅气!") | ||||||
|  |     @ExcelProperty("备注") | ||||||
|  |     private String remark; | ||||||
|  |  | ||||||
|     @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") |     @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") | ||||||
|  |     @ExcelProperty("创建时间") | ||||||
|     private LocalDateTime createTime; |     private LocalDateTime createTime; | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -8,12 +8,12 @@ import javax.validation.constraints.NotEmpty; | |||||||
| import javax.validation.constraints.NotNull; | import javax.validation.constraints.NotNull; | ||||||
| import javax.validation.constraints.Size; | import javax.validation.constraints.Size; | ||||||
| 
 | 
 | ||||||
| /** | @Schema(description = "管理后台 - 参数配置创建/修改 Request VO") | ||||||
|  * 参数配置 Base VO,提供给添加、修改、详细的子 VO 使用 |  | ||||||
|  * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 |  | ||||||
|  */ |  | ||||||
| @Data | @Data | ||||||
| public class ConfigBaseVO { | public class ConfigSaveReqVO { | ||||||
|  | 
 | ||||||
|  |     @Schema(description = "参数配置序号", example = "1024") | ||||||
|  |     private Long id; | ||||||
| 
 | 
 | ||||||
|     @Schema(description = "参数分组", requiredMode = Schema.RequiredMode.REQUIRED, example = "biz") |     @Schema(description = "参数分组", requiredMode = Schema.RequiredMode.REQUIRED, example = "biz") | ||||||
|     @NotEmpty(message = "参数分组不能为空") |     @NotEmpty(message = "参数分组不能为空") | ||||||
| @@ -25,6 +25,11 @@ public class ConfigBaseVO { | |||||||
|     @Size(max = 100, message = "参数名称不能超过 100 个字符") |     @Size(max = 100, message = "参数名称不能超过 100 个字符") | ||||||
|     private String name; |     private String name; | ||||||
| 
 | 
 | ||||||
|  |     @Schema(description = "参数键名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yunai.db.username") | ||||||
|  |     @NotBlank(message = "参数键名长度不能为空") | ||||||
|  |     @Size(max = 100, message = "参数键名长度不能超过 100 个字符") | ||||||
|  |     private String key; | ||||||
|  | 
 | ||||||
|     @Schema(description = "参数键值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |     @Schema(description = "参数键值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||||||
|     @NotBlank(message = "参数键值不能为空") |     @NotBlank(message = "参数键值不能为空") | ||||||
|     @Size(max = 500, message = "参数键值长度不能超过 500 个字符") |     @Size(max = 500, message = "参数键值长度不能超过 500 个字符") | ||||||
| @@ -1,20 +0,0 @@ | |||||||
| package cn.iocoder.yudao.module.infra.controller.admin.config.vo; |  | ||||||
|  |  | ||||||
| import io.swagger.v3.oas.annotations.media.Schema; |  | ||||||
| import lombok.Data; |  | ||||||
| import lombok.EqualsAndHashCode; |  | ||||||
| import lombok.ToString; |  | ||||||
|  |  | ||||||
| import javax.validation.constraints.NotNull; |  | ||||||
|  |  | ||||||
| @Schema(description = "管理后台 - 参数配置创建 Request VO") |  | ||||||
| @Data |  | ||||||
| @EqualsAndHashCode(callSuper = true) |  | ||||||
| @ToString(callSuper = true) |  | ||||||
| public class ConfigUpdateReqVO extends ConfigBaseVO { |  | ||||||
|  |  | ||||||
|     @Schema(description = "参数配置序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |  | ||||||
|     @NotNull(message = "参数配置编号不能为空") |  | ||||||
|     private Long id; |  | ||||||
|  |  | ||||||
| } |  | ||||||
| @@ -1,10 +1,8 @@ | |||||||
| package cn.iocoder.yudao.module.infra.convert.config; | package cn.iocoder.yudao.module.infra.convert.config; | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; |  | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExcelVO; |  | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigRespVO; | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigRespVO; | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqVO; | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; | ||||||
| import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; | ||||||
| import org.mapstruct.Mapper; | import org.mapstruct.Mapper; | ||||||
| import org.mapstruct.Mapping; | import org.mapstruct.Mapping; | ||||||
| @@ -19,15 +17,12 @@ public interface ConfigConvert { | |||||||
|  |  | ||||||
|     PageResult<ConfigRespVO> convertPage(PageResult<ConfigDO> page); |     PageResult<ConfigRespVO> convertPage(PageResult<ConfigDO> page); | ||||||
|  |  | ||||||
|  |     List<ConfigRespVO> convertList(List<ConfigDO> list); | ||||||
|  |  | ||||||
|     @Mapping(source = "configKey", target = "key") |     @Mapping(source = "configKey", target = "key") | ||||||
|     ConfigRespVO convert(ConfigDO bean); |     ConfigRespVO convert(ConfigDO bean); | ||||||
|  |  | ||||||
|     @Mapping(source = "key", target = "configKey") |     @Mapping(source = "key", target = "configKey") | ||||||
|     ConfigDO convert(ConfigCreateReqVO bean); |     ConfigDO convert(ConfigSaveReqVO bean); | ||||||
|  |  | ||||||
|     ConfigDO convert(ConfigUpdateReqVO bean); |  | ||||||
|  |  | ||||||
|     @Mapping(source = "configKey", target = "key") |  | ||||||
|     List<ConfigExcelVO> convertList(List<ConfigDO> list); |  | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -3,13 +3,10 @@ package cn.iocoder.yudao.module.infra.dal.mysql.config; | |||||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||||
| import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||||||
| import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExportReqVO; |  | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; | ||||||
| import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; | ||||||
| import org.apache.ibatis.annotations.Mapper; | import org.apache.ibatis.annotations.Mapper; | ||||||
|  |  | ||||||
| import java.util.List; |  | ||||||
|  |  | ||||||
| @Mapper | @Mapper | ||||||
| public interface ConfigMapper extends BaseMapperX<ConfigDO> { | public interface ConfigMapper extends BaseMapperX<ConfigDO> { | ||||||
|  |  | ||||||
| @@ -25,12 +22,4 @@ public interface ConfigMapper extends BaseMapperX<ConfigDO> { | |||||||
|                 .betweenIfPresent(ConfigDO::getCreateTime, reqVO.getCreateTime())); |                 .betweenIfPresent(ConfigDO::getCreateTime, reqVO.getCreateTime())); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     default List<ConfigDO> selectList(ConfigExportReqVO reqVO) { |  | ||||||
|         return selectList(new LambdaQueryWrapperX<ConfigDO>() |  | ||||||
|                 .likeIfPresent(ConfigDO::getName, reqVO.getName()) |  | ||||||
|                 .likeIfPresent(ConfigDO::getConfigKey, reqVO.getKey()) |  | ||||||
|                 .eqIfPresent(ConfigDO::getType, reqVO.getType()) |  | ||||||
|                 .betweenIfPresent(ConfigDO::getCreateTime, reqVO.getCreateTime())); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,14 +1,11 @@ | |||||||
| package cn.iocoder.yudao.module.infra.service.config; | package cn.iocoder.yudao.module.infra.service.config; | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; |  | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExportReqVO; |  | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqVO; | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; | ||||||
| import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; | ||||||
|  |  | ||||||
| import javax.validation.Valid; | import javax.validation.Valid; | ||||||
| import java.util.List; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * 参数配置 Service 接口 |  * 参数配置 Service 接口 | ||||||
| @@ -20,17 +17,17 @@ public interface ConfigService { | |||||||
|     /** |     /** | ||||||
|      * 创建参数配置 |      * 创建参数配置 | ||||||
|      * |      * | ||||||
|      * @param reqVO 创建信息 |      * @param createReqVO 创建信息 | ||||||
|      * @return 配置编号 |      * @return 配置编号 | ||||||
|      */ |      */ | ||||||
|     Long createConfig(@Valid ConfigCreateReqVO reqVO); |     Long createConfig(@Valid ConfigSaveReqVO createReqVO); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 更新参数配置 |      * 更新参数配置 | ||||||
|      * |      * | ||||||
|      * @param reqVO 更新信息 |      * @param updateReqVO 更新信息 | ||||||
|      */ |      */ | ||||||
|     void updateConfig(@Valid ConfigUpdateReqVO reqVO); |     void updateConfig(@Valid ConfigSaveReqVO updateReqVO); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 删除参数配置 |      * 删除参数配置 | ||||||
| @@ -63,13 +60,4 @@ public interface ConfigService { | |||||||
|      */ |      */ | ||||||
|     PageResult<ConfigDO> getConfigPage(@Valid ConfigPageReqVO reqVO); |     PageResult<ConfigDO> getConfigPage(@Valid ConfigPageReqVO reqVO); | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 获得参数配置列表 |  | ||||||
|      * |  | ||||||
|      * @param reqVO 列表 |  | ||||||
|      * @return 列表 |  | ||||||
|      */ |  | ||||||
|     List<ConfigDO> getConfigList(@Valid ConfigExportReqVO reqVO); |  | ||||||
|  |  | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,11 +1,8 @@ | |||||||
| package cn.iocoder.yudao.module.infra.service.config; | package cn.iocoder.yudao.module.infra.service.config; | ||||||
|  |  | ||||||
| import cn.hutool.core.util.StrUtil; |  | ||||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; |  | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExportReqVO; |  | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqVO; | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; | ||||||
| import cn.iocoder.yudao.module.infra.convert.config.ConfigConvert; | import cn.iocoder.yudao.module.infra.convert.config.ConfigConvert; | ||||||
| import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; | ||||||
| import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper; | import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper; | ||||||
| @@ -16,7 +13,6 @@ import org.springframework.stereotype.Service; | |||||||
| import org.springframework.validation.annotation.Validated; | import org.springframework.validation.annotation.Validated; | ||||||
|  |  | ||||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||||
| import java.util.List; |  | ||||||
|  |  | ||||||
| import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||||||
| import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | ||||||
| @@ -33,22 +29,26 @@ public class ConfigServiceImpl implements ConfigService { | |||||||
|     private ConfigMapper configMapper; |     private ConfigMapper configMapper; | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public Long createConfig(ConfigCreateReqVO reqVO) { |     public Long createConfig(ConfigSaveReqVO createReqVO) { | ||||||
|         // 校验正确性 |         // 校验参数配置 key 的唯一性 | ||||||
|         validateConfigForCreateOrUpdate(null, reqVO.getKey()); |         validateConfigKeyUnique(null, createReqVO.getKey()); | ||||||
|  |  | ||||||
|         // 插入参数配置 |         // 插入参数配置 | ||||||
|         ConfigDO config = ConfigConvert.INSTANCE.convert(reqVO); |         ConfigDO config = ConfigConvert.INSTANCE.convert(createReqVO); | ||||||
|         config.setType(ConfigTypeEnum.CUSTOM.getType()); |         config.setType(ConfigTypeEnum.CUSTOM.getType()); | ||||||
|         configMapper.insert(config); |         configMapper.insert(config); | ||||||
|         return config.getId(); |         return config.getId(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public void updateConfig(ConfigUpdateReqVO reqVO) { |     public void updateConfig(ConfigSaveReqVO updateReqVO) { | ||||||
|         // 校验正确性 |         // 校验自己存在 | ||||||
|         validateConfigForCreateOrUpdate(reqVO.getId(), null); // 不允许更新 key |         validateConfigExists(updateReqVO.getId()); | ||||||
|  |         // 校验参数配置 key 的唯一性 | ||||||
|  |         validateConfigKeyUnique(updateReqVO.getId(), updateReqVO.getKey()); | ||||||
|  |  | ||||||
|         // 更新参数配置 |         // 更新参数配置 | ||||||
|         ConfigDO updateObj = ConfigConvert.INSTANCE.convert(reqVO); |         ConfigDO updateObj = ConfigConvert.INSTANCE.convert(updateReqVO); | ||||||
|         configMapper.updateById(updateObj); |         configMapper.updateById(updateObj); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -75,22 +75,8 @@ public class ConfigServiceImpl implements ConfigService { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public PageResult<ConfigDO> getConfigPage(ConfigPageReqVO reqVO) { |     public PageResult<ConfigDO> getConfigPage(ConfigPageReqVO pageReqVO) { | ||||||
|         return configMapper.selectPage(reqVO); |         return configMapper.selectPage(pageReqVO); | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public List<ConfigDO> getConfigList(ConfigExportReqVO reqVO) { |  | ||||||
|         return configMapper.selectList(reqVO); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private void validateConfigForCreateOrUpdate(Long id, String key) { |  | ||||||
|         // 校验自己存在 |  | ||||||
|         validateConfigExists(id); |  | ||||||
|         // 校验参数配置 key 的唯一性 |  | ||||||
|         if (StrUtil.isNotEmpty(key)) { |  | ||||||
|             validateConfigKeyUnique(id, key); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @VisibleForTesting |     @VisibleForTesting | ||||||
|   | |||||||
| @@ -4,10 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | |||||||
| import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | ||||||
| import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | ||||||
| import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; |  | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExportReqVO; |  | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqVO; | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; | ||||||
| import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; | ||||||
| import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper; | import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper; | ||||||
| import cn.iocoder.yudao.module.infra.enums.config.ConfigTypeEnum; | import cn.iocoder.yudao.module.infra.enums.config.ConfigTypeEnum; | ||||||
| @@ -15,7 +13,6 @@ import org.junit.jupiter.api.Test; | |||||||
| import org.springframework.context.annotation.Import; | import org.springframework.context.annotation.Import; | ||||||
|  |  | ||||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||||
| import java.util.List; |  | ||||||
| import java.util.function.Consumer; | import java.util.function.Consumer; | ||||||
|  |  | ||||||
| import static cn.hutool.core.util.RandomUtil.randomEle; | import static cn.hutool.core.util.RandomUtil.randomEle; | ||||||
| @@ -40,7 +37,8 @@ public class ConfigServiceImplTest extends BaseDbUnitTest { | |||||||
|     @Test |     @Test | ||||||
|     public void testCreateConfig_success() { |     public void testCreateConfig_success() { | ||||||
|         // 准备参数 |         // 准备参数 | ||||||
|         ConfigCreateReqVO reqVO = randomPojo(ConfigCreateReqVO.class); |         ConfigSaveReqVO reqVO = randomPojo(ConfigSaveReqVO.class) | ||||||
|  |                 .setId(null); // 防止 id 被赋值,导致唯一性校验失败 | ||||||
|  |  | ||||||
|         // 调用 |         // 调用 | ||||||
|         Long configId = configService.createConfig(reqVO); |         Long configId = configService.createConfig(reqVO); | ||||||
| @@ -48,7 +46,7 @@ public class ConfigServiceImplTest extends BaseDbUnitTest { | |||||||
|         assertNotNull(configId); |         assertNotNull(configId); | ||||||
|         // 校验记录的属性是否正确 |         // 校验记录的属性是否正确 | ||||||
|         ConfigDO config = configMapper.selectById(configId); |         ConfigDO config = configMapper.selectById(configId); | ||||||
|         assertPojoEquals(reqVO, config); |         assertPojoEquals(reqVO, config, "id"); | ||||||
|         assertEquals(ConfigTypeEnum.CUSTOM.getType(), config.getType()); |         assertEquals(ConfigTypeEnum.CUSTOM.getType(), config.getType()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -58,7 +56,7 @@ public class ConfigServiceImplTest extends BaseDbUnitTest { | |||||||
|         ConfigDO dbConfig = randomConfigDO(); |         ConfigDO dbConfig = randomConfigDO(); | ||||||
|         configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据 |         configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据 | ||||||
|         // 准备参数 |         // 准备参数 | ||||||
|         ConfigUpdateReqVO reqVO = randomPojo(ConfigUpdateReqVO.class, o -> { |         ConfigSaveReqVO reqVO = randomPojo(ConfigSaveReqVO.class, o -> { | ||||||
|             o.setId(dbConfig.getId()); // 设置更新的 ID |             o.setId(dbConfig.getId()); // 设置更新的 ID | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
| @@ -178,38 +176,6 @@ public class ConfigServiceImplTest extends BaseDbUnitTest { | |||||||
|         assertPojoEquals(dbConfig, pageResult.getList().get(0)); |         assertPojoEquals(dbConfig, pageResult.getList().get(0)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void testGetConfigList() { |  | ||||||
|         // mock 数据 |  | ||||||
|         ConfigDO dbConfig = randomConfigDO(o -> { // 等会查询到 |  | ||||||
|             o.setName("芋艿"); |  | ||||||
|             o.setConfigKey("yunai"); |  | ||||||
|             o.setType(ConfigTypeEnum.SYSTEM.getType()); |  | ||||||
|             o.setCreateTime(buildTime(2021, 2, 1)); |  | ||||||
|         }); |  | ||||||
|         configMapper.insert(dbConfig); |  | ||||||
|         // 测试 name 不匹配 |  | ||||||
|         configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setName("土豆"))); |  | ||||||
|         // 测试 key 不匹配 |  | ||||||
|         configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou"))); |  | ||||||
|         // 测试 type 不匹配 |  | ||||||
|         configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType()))); |  | ||||||
|         // 测试 createTime 不匹配 |  | ||||||
|         configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); |  | ||||||
|         // 准备参数 |  | ||||||
|         ConfigExportReqVO reqVO = new ConfigExportReqVO(); |  | ||||||
|         reqVO.setName("艿"); |  | ||||||
|         reqVO.setKey("nai"); |  | ||||||
|         reqVO.setType(ConfigTypeEnum.SYSTEM.getType()); |  | ||||||
|         reqVO.setCreateTime(buildBetweenTime(2021, 1, 15, 2021, 2, 15)); |  | ||||||
|  |  | ||||||
|         // 调用 |  | ||||||
|         List<ConfigDO> list = configService.getConfigList(reqVO); |  | ||||||
|         // 断言 |  | ||||||
|         assertEquals(1, list.size()); |  | ||||||
|         assertPojoEquals(dbConfig, list.get(0)); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Test |     @Test | ||||||
|     public void testGetConfig() { |     public void testGetConfig() { | ||||||
|         // mock 数据 |         // mock 数据 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV