Commit 645e6f3cc8ff97b911a0b25763f6248f9b96c06a
1 parent
42dc4b61
🔧 简化 config 模块的 VO
Showing
12 changed files
with
87 additions
and
245 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/ConfigController.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.controller.admin.config; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 6 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 6 | 7 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| ... | ... | @@ -38,15 +39,15 @@ public class ConfigController { |
| 38 | 39 | @PostMapping("/create") |
| 39 | 40 | @Operation(summary = "创建参数配置") |
| 40 | 41 | @PreAuthorize("@ss.hasPermission('infra:config:create')") |
| 41 | - public CommonResult<Long> createConfig(@Valid @RequestBody ConfigCreateReqVO reqVO) { | |
| 42 | - return success(configService.createConfig(reqVO)); | |
| 42 | + public CommonResult<Long> createConfig(@Valid @RequestBody ConfigSaveReqVO createReqVO) { | |
| 43 | + return success(configService.createConfig(createReqVO)); | |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | 46 | @PutMapping("/update") |
| 46 | 47 | @Operation(summary = "修改参数配置") |
| 47 | 48 | @PreAuthorize("@ss.hasPermission('infra:config:update')") |
| 48 | - public CommonResult<Boolean> updateConfig(@Valid @RequestBody ConfigUpdateReqVO reqVO) { | |
| 49 | - configService.updateConfig(reqVO); | |
| 49 | + public CommonResult<Boolean> updateConfig(@Valid @RequestBody ConfigSaveReqVO updateReqVO) { | |
| 50 | + configService.updateConfig(updateReqVO); | |
| 50 | 51 | return success(true); |
| 51 | 52 | } |
| 52 | 53 | |
| ... | ... | @@ -84,8 +85,8 @@ public class ConfigController { |
| 84 | 85 | @GetMapping("/page") |
| 85 | 86 | @Operation(summary = "获取参数配置分页") |
| 86 | 87 | @PreAuthorize("@ss.hasPermission('infra:config:query')") |
| 87 | - public CommonResult<PageResult<ConfigRespVO>> getConfigPage(@Valid ConfigPageReqVO reqVO) { | |
| 88 | - PageResult<ConfigDO> page = configService.getConfigPage(reqVO); | |
| 88 | + public CommonResult<PageResult<ConfigRespVO>> getConfigPage(@Valid ConfigPageReqVO pageReqVO) { | |
| 89 | + PageResult<ConfigDO> page = configService.getConfigPage(pageReqVO); | |
| 89 | 90 | return success(ConfigConvert.INSTANCE.convertPage(page)); |
| 90 | 91 | } |
| 91 | 92 | |
| ... | ... | @@ -93,13 +94,13 @@ public class ConfigController { |
| 93 | 94 | @Operation(summary = "导出参数配置") |
| 94 | 95 | @PreAuthorize("@ss.hasPermission('infra:config:export')") |
| 95 | 96 | @OperateLog(type = EXPORT) |
| 96 | - public void exportConfig(@Valid ConfigExportReqVO reqVO, | |
| 97 | + public void exportConfig(@Valid ConfigPageReqVO exportReqVO, | |
| 97 | 98 | HttpServletResponse response) throws IOException { |
| 98 | - List<ConfigDO> list = configService.getConfigList(reqVO); | |
| 99 | - // 拼接数据 | |
| 100 | - List<ConfigExcelVO> datas = ConfigConvert.INSTANCE.convertList(list); | |
| 99 | + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 100 | + List<ConfigDO> list = configService.getConfigPage(exportReqVO).getList(); | |
| 101 | 101 | // 输出 |
| 102 | - ExcelUtils.write(response, "参数配置.xls", "数据", ConfigExcelVO.class, datas); | |
| 102 | + ExcelUtils.write(response, "参数配置.xls", "数据", ConfigRespVO.class, | |
| 103 | + ConfigConvert.INSTANCE.convertList(list)); | |
| 103 | 104 | } |
| 104 | 105 | |
| 105 | 106 | } | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.infra.controller.admin.config.vo; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | - | |
| 7 | -import javax.validation.constraints.NotBlank; | |
| 8 | -import javax.validation.constraints.Size; | |
| 9 | - | |
| 10 | -@Schema(description = "管理后台 - 参数配置创建 Request VO") | |
| 11 | -@Data | |
| 12 | -@EqualsAndHashCode(callSuper = true) | |
| 13 | -public class ConfigCreateReqVO extends ConfigBaseVO { | |
| 14 | - | |
| 15 | - @Schema(description = "参数键名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yunai.db.username") | |
| 16 | - @NotBlank(message = "参数键名长度不能为空") | |
| 17 | - @Size(max = 100, message = "参数键名长度不能超过100个字符") | |
| 18 | - private String key; | |
| 19 | - | |
| 20 | -} |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigExcelVO.java deleted
| 1 | -package cn.iocoder.yudao.module.infra.controller.admin.config.vo; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | -import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; | |
| 6 | -import com.alibaba.excel.annotation.ExcelProperty; | |
| 7 | -import lombok.Data; | |
| 8 | - | |
| 9 | -import java.time.LocalDateTime; | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * 参数配置 Excel 导出响应 VO | |
| 13 | - */ | |
| 14 | -@Data | |
| 15 | -public class ConfigExcelVO { | |
| 16 | - | |
| 17 | - @ExcelProperty("参数配置序号") | |
| 18 | - private Long id; | |
| 19 | - | |
| 20 | - @ExcelProperty("参数键名") | |
| 21 | - private String configKey; | |
| 22 | - | |
| 23 | - @ExcelProperty("参数分类") | |
| 24 | - private String category; | |
| 25 | - | |
| 26 | - @ExcelProperty("参数名称") | |
| 27 | - private String name; | |
| 28 | - | |
| 29 | - @ExcelProperty("参数键值") | |
| 30 | - private String value; | |
| 31 | - | |
| 32 | - @ExcelProperty(value = "参数类型", converter = DictConvert.class) | |
| 33 | - @DictFormat(DictTypeConstants.CONFIG_TYPE) | |
| 34 | - private Integer type; | |
| 35 | - | |
| 36 | - @ExcelProperty(value = "是否可见", converter = DictConvert.class) | |
| 37 | - @DictFormat(DictTypeConstants.BOOLEAN_STRING) | |
| 38 | - private Boolean visible; | |
| 39 | - | |
| 40 | - @ExcelProperty("备注") | |
| 41 | - private String remark; | |
| 42 | - | |
| 43 | - @ExcelProperty("创建时间") | |
| 44 | - private LocalDateTime createTime; | |
| 45 | - | |
| 46 | -} |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigExportReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.infra.controller.admin.config.vo; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import org.springframework.format.annotation.DateTimeFormat; | |
| 6 | - | |
| 7 | -import java.time.LocalDateTime; | |
| 8 | - | |
| 9 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 10 | - | |
| 11 | -@Schema(description = "管理后台 - 参数配置导出 Request VO") | |
| 12 | -@Data | |
| 13 | -public class ConfigExportReqVO { | |
| 14 | - | |
| 15 | - @Schema(description = "参数名称", example = "模糊匹配") | |
| 16 | - private String name; | |
| 17 | - | |
| 18 | - @Schema(description = "参数键名,模糊匹配", example = "yunai.db.username") | |
| 19 | - private String key; | |
| 20 | - | |
| 21 | - @Schema(description = "参数类型,参见 SysConfigTypeEnum 枚举", example = "1") | |
| 22 | - private Integer type; | |
| 23 | - | |
| 24 | - @Schema(description = "创建时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]") | |
| 25 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 26 | - private LocalDateTime[] createTime; | |
| 27 | - | |
| 28 | -} |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.controller.admin.config.vo; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | +import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; | |
| 6 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 7 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 3 | 8 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 9 | import lombok.Data; |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | 10 | |
| 7 | -import javax.validation.constraints.NotBlank; | |
| 8 | -import javax.validation.constraints.Size; | |
| 9 | 11 | import java.time.LocalDateTime; |
| 10 | 12 | |
| 11 | 13 | @Schema(description = "管理后台 - 参数配置信息 Response VO") |
| 12 | 14 | @Data |
| 13 | -@EqualsAndHashCode(callSuper = true) | |
| 14 | -public class ConfigRespVO extends ConfigBaseVO { | |
| 15 | +@ExcelIgnoreUnannotated | |
| 16 | +public class ConfigRespVO { | |
| 15 | 17 | |
| 16 | 18 | @Schema(description = "参数配置序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 19 | + @ExcelProperty("参数配置序号") | |
| 17 | 20 | private Long id; |
| 18 | 21 | |
| 22 | + @Schema(description = "参数分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "biz") | |
| 23 | + @ExcelProperty("参数分类") | |
| 24 | + private String category; | |
| 25 | + | |
| 26 | + @Schema(description = "参数名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "数据库名") | |
| 27 | + @ExcelProperty("参数名称") | |
| 28 | + private String name; | |
| 29 | + | |
| 19 | 30 | @Schema(description = "参数键名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yunai.db.username") |
| 20 | - @NotBlank(message = "参数键名长度不能为空") | |
| 21 | - @Size(max = 100, message = "参数键名长度不能超过100个字符") | |
| 31 | + @ExcelProperty("参数键名") | |
| 22 | 32 | private String key; |
| 23 | 33 | |
| 34 | + @Schema(description = "参数键值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 35 | + @ExcelProperty("参数键值") | |
| 36 | + private String value; | |
| 37 | + | |
| 24 | 38 | @Schema(description = "参数类型,参见 SysConfigTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 39 | + @ExcelProperty(value = "参数类型", converter = DictConvert.class) | |
| 40 | + @DictFormat(DictTypeConstants.CONFIG_TYPE) | |
| 25 | 41 | private Integer type; |
| 26 | 42 | |
| 43 | + @Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 44 | + @ExcelProperty(value = "是否可见", converter = DictConvert.class) | |
| 45 | + @DictFormat(DictTypeConstants.BOOLEAN_STRING) | |
| 46 | + private Boolean visible; | |
| 47 | + | |
| 48 | + @Schema(description = "备注", example = "备注一下很帅气!") | |
| 49 | + @ExcelProperty("备注") | |
| 50 | + private String remark; | |
| 51 | + | |
| 27 | 52 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") |
| 53 | + @ExcelProperty("创建时间") | |
| 28 | 54 | private LocalDateTime createTime; |
| 29 | 55 | |
| 30 | 56 | } | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigBaseVO.java renamed to yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigSaveReqVO.java
| ... | ... | @@ -8,26 +8,31 @@ import javax.validation.constraints.NotEmpty; |
| 8 | 8 | import javax.validation.constraints.NotNull; |
| 9 | 9 | import javax.validation.constraints.Size; |
| 10 | 10 | |
| 11 | -/** | |
| 12 | - * 参数配置 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 13 | - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 14 | - */ | |
| 11 | +@Schema(description = "管理后台 - 参数配置创建/修改 Request VO") | |
| 15 | 12 | @Data |
| 16 | -public class ConfigBaseVO { | |
| 13 | +public class ConfigSaveReqVO { | |
| 14 | + | |
| 15 | + @Schema(description = "参数配置序号", example = "1024") | |
| 16 | + private Long id; | |
| 17 | 17 | |
| 18 | 18 | @Schema(description = "参数分组", requiredMode = Schema.RequiredMode.REQUIRED, example = "biz") |
| 19 | 19 | @NotEmpty(message = "参数分组不能为空") |
| 20 | - @Size(max = 50, message = "参数名称不能超过50个字符") | |
| 20 | + @Size(max = 50, message = "参数名称不能超过 50 个字符") | |
| 21 | 21 | private String category; |
| 22 | 22 | |
| 23 | 23 | @Schema(description = "参数名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "数据库名") |
| 24 | 24 | @NotBlank(message = "参数名称不能为空") |
| 25 | - @Size(max = 100, message = "参数名称不能超过100个字符") | |
| 25 | + @Size(max = 100, message = "参数名称不能超过 100 个字符") | |
| 26 | 26 | private String name; |
| 27 | 27 | |
| 28 | + @Schema(description = "参数键名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yunai.db.username") | |
| 29 | + @NotBlank(message = "参数键名长度不能为空") | |
| 30 | + @Size(max = 100, message = "参数键名长度不能超过 100 个字符") | |
| 31 | + private String key; | |
| 32 | + | |
| 28 | 33 | @Schema(description = "参数键值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 29 | 34 | @NotBlank(message = "参数键值不能为空") |
| 30 | - @Size(max = 500, message = "参数键值长度不能超过500个字符") | |
| 35 | + @Size(max = 500, message = "参数键值长度不能超过 500 个字符") | |
| 31 | 36 | private String value; |
| 32 | 37 | |
| 33 | 38 | @Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/vo/ConfigUpdateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.infra.controller.admin.config.vo; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | -import lombok.ToString; | |
| 7 | - | |
| 8 | -import javax.validation.constraints.NotNull; | |
| 9 | - | |
| 10 | -@Schema(description = "管理后台 - 参数配置创建 Request VO") | |
| 11 | -@Data | |
| 12 | -@EqualsAndHashCode(callSuper = true) | |
| 13 | -@ToString(callSuper = true) | |
| 14 | -public class ConfigUpdateReqVO extends ConfigBaseVO { | |
| 15 | - | |
| 16 | - @Schema(description = "参数配置序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 17 | - @NotNull(message = "参数配置编号不能为空") | |
| 18 | - private Long id; | |
| 19 | - | |
| 20 | -} |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/config/ConfigConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.convert.config; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; | |
| 5 | -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExcelVO; | |
| 6 | 4 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigRespVO; |
| 7 | -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; | |
| 8 | 6 | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; |
| 9 | 7 | import org.mapstruct.Mapper; |
| 10 | 8 | import org.mapstruct.Mapping; |
| ... | ... | @@ -19,15 +17,12 @@ public interface ConfigConvert { |
| 19 | 17 | |
| 20 | 18 | PageResult<ConfigRespVO> convertPage(PageResult<ConfigDO> page); |
| 21 | 19 | |
| 20 | + List<ConfigRespVO> convertList(List<ConfigDO> list); | |
| 21 | + | |
| 22 | 22 | @Mapping(source = "configKey", target = "key") |
| 23 | 23 | ConfigRespVO convert(ConfigDO bean); |
| 24 | 24 | |
| 25 | 25 | @Mapping(source = "key", target = "configKey") |
| 26 | - ConfigDO convert(ConfigCreateReqVO bean); | |
| 27 | - | |
| 28 | - ConfigDO convert(ConfigUpdateReqVO bean); | |
| 29 | - | |
| 30 | - @Mapping(source = "configKey", target = "key") | |
| 31 | - List<ConfigExcelVO> convertList(List<ConfigDO> list); | |
| 26 | + ConfigDO convert(ConfigSaveReqVO bean); | |
| 32 | 27 | |
| 33 | 28 | } | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/config/ConfigMapper.java
| ... | ... | @@ -3,13 +3,10 @@ package cn.iocoder.yudao.module.infra.dal.mysql.config; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExportReqVO; | |
| 7 | 6 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; |
| 8 | 7 | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; |
| 9 | 8 | import org.apache.ibatis.annotations.Mapper; |
| 10 | 9 | |
| 11 | -import java.util.List; | |
| 12 | - | |
| 13 | 10 | @Mapper |
| 14 | 11 | public interface ConfigMapper extends BaseMapperX<ConfigDO> { |
| 15 | 12 | |
| ... | ... | @@ -25,12 +22,4 @@ public interface ConfigMapper extends BaseMapperX<ConfigDO> { |
| 25 | 22 | .betweenIfPresent(ConfigDO::getCreateTime, reqVO.getCreateTime())); |
| 26 | 23 | } |
| 27 | 24 | |
| 28 | - default List<ConfigDO> selectList(ConfigExportReqVO reqVO) { | |
| 29 | - return selectList(new LambdaQueryWrapperX<ConfigDO>() | |
| 30 | - .likeIfPresent(ConfigDO::getName, reqVO.getName()) | |
| 31 | - .likeIfPresent(ConfigDO::getConfigKey, reqVO.getKey()) | |
| 32 | - .eqIfPresent(ConfigDO::getType, reqVO.getType()) | |
| 33 | - .betweenIfPresent(ConfigDO::getCreateTime, reqVO.getCreateTime())); | |
| 34 | - } | |
| 35 | - | |
| 36 | 25 | } | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigService.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.service.config; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; | |
| 5 | -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExportReqVO; | |
| 6 | 4 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; |
| 7 | -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; | |
| 8 | 6 | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; |
| 9 | 7 | |
| 10 | 8 | import javax.validation.Valid; |
| 11 | -import java.util.List; | |
| 12 | 9 | |
| 13 | 10 | /** |
| 14 | 11 | * 参数配置 Service 接口 |
| ... | ... | @@ -20,17 +17,17 @@ public interface ConfigService { |
| 20 | 17 | /** |
| 21 | 18 | * 创建参数配置 |
| 22 | 19 | * |
| 23 | - * @param reqVO 创建信息 | |
| 20 | + * @param createReqVO 创建信息 | |
| 24 | 21 | * @return 配置编号 |
| 25 | 22 | */ |
| 26 | - Long createConfig(@Valid ConfigCreateReqVO reqVO); | |
| 23 | + Long createConfig(@Valid ConfigSaveReqVO createReqVO); | |
| 27 | 24 | |
| 28 | 25 | /** |
| 29 | 26 | * 更新参数配置 |
| 30 | 27 | * |
| 31 | - * @param reqVO 更新信息 | |
| 28 | + * @param updateReqVO 更新信息 | |
| 32 | 29 | */ |
| 33 | - void updateConfig(@Valid ConfigUpdateReqVO reqVO); | |
| 30 | + void updateConfig(@Valid ConfigSaveReqVO updateReqVO); | |
| 34 | 31 | |
| 35 | 32 | /** |
| 36 | 33 | * 删除参数配置 |
| ... | ... | @@ -63,13 +60,4 @@ public interface ConfigService { |
| 63 | 60 | */ |
| 64 | 61 | PageResult<ConfigDO> getConfigPage(@Valid ConfigPageReqVO reqVO); |
| 65 | 62 | |
| 66 | - /** | |
| 67 | - * 获得参数配置列表 | |
| 68 | - * | |
| 69 | - * @param reqVO 列表 | |
| 70 | - * @return 列表 | |
| 71 | - */ | |
| 72 | - List<ConfigDO> getConfigList(@Valid ConfigExportReqVO reqVO); | |
| 73 | - | |
| 74 | - | |
| 75 | 63 | } | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.service.config; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.util.StrUtil; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; | |
| 6 | -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExportReqVO; | |
| 7 | 4 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; |
| 8 | -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; | |
| 9 | 6 | import cn.iocoder.yudao.module.infra.convert.config.ConfigConvert; |
| 10 | 7 | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; |
| 11 | 8 | import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper; |
| ... | ... | @@ -16,7 +13,6 @@ import org.springframework.stereotype.Service; |
| 16 | 13 | import org.springframework.validation.annotation.Validated; |
| 17 | 14 | |
| 18 | 15 | import javax.annotation.Resource; |
| 19 | -import java.util.List; | |
| 20 | 16 | |
| 21 | 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 22 | 18 | import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; |
| ... | ... | @@ -33,22 +29,26 @@ public class ConfigServiceImpl implements ConfigService { |
| 33 | 29 | private ConfigMapper configMapper; |
| 34 | 30 | |
| 35 | 31 | @Override |
| 36 | - public Long createConfig(ConfigCreateReqVO reqVO) { | |
| 37 | - // 校验正确性 | |
| 38 | - validateConfigForCreateOrUpdate(null, reqVO.getKey()); | |
| 32 | + public Long createConfig(ConfigSaveReqVO createReqVO) { | |
| 33 | + // 校验参数配置 key 的唯一性 | |
| 34 | + validateConfigKeyUnique(null, createReqVO.getKey()); | |
| 35 | + | |
| 39 | 36 | // 插入参数配置 |
| 40 | - ConfigDO config = ConfigConvert.INSTANCE.convert(reqVO); | |
| 37 | + ConfigDO config = ConfigConvert.INSTANCE.convert(createReqVO); | |
| 41 | 38 | config.setType(ConfigTypeEnum.CUSTOM.getType()); |
| 42 | 39 | configMapper.insert(config); |
| 43 | 40 | return config.getId(); |
| 44 | 41 | } |
| 45 | 42 | |
| 46 | 43 | @Override |
| 47 | - public void updateConfig(ConfigUpdateReqVO reqVO) { | |
| 48 | - // 校验正确性 | |
| 49 | - validateConfigForCreateOrUpdate(reqVO.getId(), null); // 不允许更新 key | |
| 44 | + public void updateConfig(ConfigSaveReqVO updateReqVO) { | |
| 45 | + // 校验自己存在 | |
| 46 | + validateConfigExists(updateReqVO.getId()); | |
| 47 | + // 校验参数配置 key 的唯一性 | |
| 48 | + validateConfigKeyUnique(updateReqVO.getId(), updateReqVO.getKey()); | |
| 49 | + | |
| 50 | 50 | // 更新参数配置 |
| 51 | - ConfigDO updateObj = ConfigConvert.INSTANCE.convert(reqVO); | |
| 51 | + ConfigDO updateObj = ConfigConvert.INSTANCE.convert(updateReqVO); | |
| 52 | 52 | configMapper.updateById(updateObj); |
| 53 | 53 | } |
| 54 | 54 | |
| ... | ... | @@ -75,22 +75,8 @@ public class ConfigServiceImpl implements ConfigService { |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | @Override |
| 78 | - public PageResult<ConfigDO> getConfigPage(ConfigPageReqVO reqVO) { | |
| 79 | - return configMapper.selectPage(reqVO); | |
| 80 | - } | |
| 81 | - | |
| 82 | - @Override | |
| 83 | - public List<ConfigDO> getConfigList(ConfigExportReqVO reqVO) { | |
| 84 | - return configMapper.selectList(reqVO); | |
| 85 | - } | |
| 86 | - | |
| 87 | - private void validateConfigForCreateOrUpdate(Long id, String key) { | |
| 88 | - // 校验自己存在 | |
| 89 | - validateConfigExists(id); | |
| 90 | - // 校验参数配置 key 的唯一性 | |
| 91 | - if (StrUtil.isNotEmpty(key)) { | |
| 92 | - validateConfigKeyUnique(id, key); | |
| 93 | - } | |
| 78 | + public PageResult<ConfigDO> getConfigPage(ConfigPageReqVO pageReqVO) { | |
| 79 | + return configMapper.selectPage(pageReqVO); | |
| 94 | 80 | } |
| 95 | 81 | |
| 96 | 82 | @VisibleForTesting | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImplTest.java
| ... | ... | @@ -4,10 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 5 | 5 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 6 | 6 | import cn.iocoder.yudao.framework.test.core.util.RandomUtils; |
| 7 | -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; | |
| 8 | -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigExportReqVO; | |
| 9 | 7 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; |
| 10 | -import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqVO; | |
| 8 | +import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; | |
| 11 | 9 | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; |
| 12 | 10 | import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper; |
| 13 | 11 | import cn.iocoder.yudao.module.infra.enums.config.ConfigTypeEnum; |
| ... | ... | @@ -15,7 +13,6 @@ import org.junit.jupiter.api.Test; |
| 15 | 13 | import org.springframework.context.annotation.Import; |
| 16 | 14 | |
| 17 | 15 | import javax.annotation.Resource; |
| 18 | -import java.util.List; | |
| 19 | 16 | import java.util.function.Consumer; |
| 20 | 17 | |
| 21 | 18 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| ... | ... | @@ -40,7 +37,8 @@ public class ConfigServiceImplTest extends BaseDbUnitTest { |
| 40 | 37 | @Test |
| 41 | 38 | public void testCreateConfig_success() { |
| 42 | 39 | // 准备参数 |
| 43 | - ConfigCreateReqVO reqVO = randomPojo(ConfigCreateReqVO.class); | |
| 40 | + ConfigSaveReqVO reqVO = randomPojo(ConfigSaveReqVO.class) | |
| 41 | + .setId(null); // 防止 id 被赋值,导致唯一性校验失败 | |
| 44 | 42 | |
| 45 | 43 | // 调用 |
| 46 | 44 | Long configId = configService.createConfig(reqVO); |
| ... | ... | @@ -48,7 +46,7 @@ public class ConfigServiceImplTest extends BaseDbUnitTest { |
| 48 | 46 | assertNotNull(configId); |
| 49 | 47 | // 校验记录的属性是否正确 |
| 50 | 48 | ConfigDO config = configMapper.selectById(configId); |
| 51 | - assertPojoEquals(reqVO, config); | |
| 49 | + assertPojoEquals(reqVO, config, "id"); | |
| 52 | 50 | assertEquals(ConfigTypeEnum.CUSTOM.getType(), config.getType()); |
| 53 | 51 | } |
| 54 | 52 | |
| ... | ... | @@ -58,7 +56,7 @@ public class ConfigServiceImplTest extends BaseDbUnitTest { |
| 58 | 56 | ConfigDO dbConfig = randomConfigDO(); |
| 59 | 57 | configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据 |
| 60 | 58 | // 准备参数 |
| 61 | - ConfigUpdateReqVO reqVO = randomPojo(ConfigUpdateReqVO.class, o -> { | |
| 59 | + ConfigSaveReqVO reqVO = randomPojo(ConfigSaveReqVO.class, o -> { | |
| 62 | 60 | o.setId(dbConfig.getId()); // 设置更新的 ID |
| 63 | 61 | }); |
| 64 | 62 | |
| ... | ... | @@ -179,38 +177,6 @@ public class ConfigServiceImplTest extends BaseDbUnitTest { |
| 179 | 177 | } |
| 180 | 178 | |
| 181 | 179 | @Test |
| 182 | - public void testGetConfigList() { | |
| 183 | - // mock 数据 | |
| 184 | - ConfigDO dbConfig = randomConfigDO(o -> { // 等会查询到 | |
| 185 | - o.setName("芋艿"); | |
| 186 | - o.setConfigKey("yunai"); | |
| 187 | - o.setType(ConfigTypeEnum.SYSTEM.getType()); | |
| 188 | - o.setCreateTime(buildTime(2021, 2, 1)); | |
| 189 | - }); | |
| 190 | - configMapper.insert(dbConfig); | |
| 191 | - // 测试 name 不匹配 | |
| 192 | - configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setName("土豆"))); | |
| 193 | - // 测试 key 不匹配 | |
| 194 | - configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou"))); | |
| 195 | - // 测试 type 不匹配 | |
| 196 | - configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType()))); | |
| 197 | - // 测试 createTime 不匹配 | |
| 198 | - configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | |
| 199 | - // 准备参数 | |
| 200 | - ConfigExportReqVO reqVO = new ConfigExportReqVO(); | |
| 201 | - reqVO.setName("艿"); | |
| 202 | - reqVO.setKey("nai"); | |
| 203 | - reqVO.setType(ConfigTypeEnum.SYSTEM.getType()); | |
| 204 | - reqVO.setCreateTime(buildBetweenTime(2021, 1, 15, 2021, 2, 15)); | |
| 205 | - | |
| 206 | - // 调用 | |
| 207 | - List<ConfigDO> list = configService.getConfigList(reqVO); | |
| 208 | - // 断言 | |
| 209 | - assertEquals(1, list.size()); | |
| 210 | - assertPojoEquals(dbConfig, list.get(0)); | |
| 211 | - } | |
| 212 | - | |
| 213 | - @Test | |
| 214 | 180 | public void testGetConfig() { |
| 215 | 181 | // mock 数据 |
| 216 | 182 | ConfigDO dbConfig = randomConfigDO(); | ... | ... |