Commit 8eb04d6805621db14280659932a0957fb241604b
1 parent
c4933976
🔧 简化 errorCode 模块的 VO
Showing
12 changed files
with
72 additions
and
239 deletions
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/ErrorCodeController.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.errorcode; |
| 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; |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 5 | 7 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 6 | 8 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 7 | -import cn.iocoder.yudao.module.system.convert.errorcode.ErrorCodeConvert; | |
| 8 | 9 | import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.*; |
| 9 | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; |
| 10 | 11 | import cn.iocoder.yudao.module.system.service.errorcode.ErrorCodeService; |
| ... | ... | @@ -36,14 +37,14 @@ public class ErrorCodeController { |
| 36 | 37 | @PostMapping("/create") |
| 37 | 38 | @Operation(summary = "创建错误码") |
| 38 | 39 | @PreAuthorize("@ss.hasPermission('system:error-code:create')") |
| 39 | - public CommonResult<Long> createErrorCode(@Valid @RequestBody ErrorCodeCreateReqVO createReqVO) { | |
| 40 | + public CommonResult<Long> createErrorCode(@Valid @RequestBody ErrorCodeSaveReqVO createReqVO) { | |
| 40 | 41 | return success(errorCodeService.createErrorCode(createReqVO)); |
| 41 | 42 | } |
| 42 | 43 | |
| 43 | 44 | @PutMapping("/update") |
| 44 | 45 | @Operation(summary = "更新错误码") |
| 45 | 46 | @PreAuthorize("@ss.hasPermission('system:error-code:update')") |
| 46 | - public CommonResult<Boolean> updateErrorCode(@Valid @RequestBody ErrorCodeUpdateReqVO updateReqVO) { | |
| 47 | + public CommonResult<Boolean> updateErrorCode(@Valid @RequestBody ErrorCodeSaveReqVO updateReqVO) { | |
| 47 | 48 | errorCodeService.updateErrorCode(updateReqVO); |
| 48 | 49 | return success(true); |
| 49 | 50 | } |
| ... | ... | @@ -63,7 +64,7 @@ public class ErrorCodeController { |
| 63 | 64 | @PreAuthorize("@ss.hasPermission('system:error-code:query')") |
| 64 | 65 | public CommonResult<ErrorCodeRespVO> getErrorCode(@RequestParam("id") Long id) { |
| 65 | 66 | ErrorCodeDO errorCode = errorCodeService.getErrorCode(id); |
| 66 | - return success(ErrorCodeConvert.INSTANCE.convert(errorCode)); | |
| 67 | + return success(BeanUtils.toBean(errorCode, ErrorCodeRespVO.class)); | |
| 67 | 68 | } |
| 68 | 69 | |
| 69 | 70 | @GetMapping("/page") |
| ... | ... | @@ -71,19 +72,20 @@ public class ErrorCodeController { |
| 71 | 72 | @PreAuthorize("@ss.hasPermission('system:error-code:query')") |
| 72 | 73 | public CommonResult<PageResult<ErrorCodeRespVO>> getErrorCodePage(@Valid ErrorCodePageReqVO pageVO) { |
| 73 | 74 | PageResult<ErrorCodeDO> pageResult = errorCodeService.getErrorCodePage(pageVO); |
| 74 | - return success(ErrorCodeConvert.INSTANCE.convertPage(pageResult)); | |
| 75 | + return success(BeanUtils.toBean(pageResult, ErrorCodeRespVO.class)); | |
| 75 | 76 | } |
| 76 | 77 | |
| 77 | 78 | @GetMapping("/export-excel") |
| 78 | 79 | @Operation(summary = "导出错误码 Excel") |
| 79 | 80 | @PreAuthorize("@ss.hasPermission('system:error-code:export')") |
| 80 | 81 | @OperateLog(type = EXPORT) |
| 81 | - public void exportErrorCodeExcel(@Valid ErrorCodeExportReqVO exportReqVO, | |
| 82 | + public void exportErrorCodeExcel(@Valid ErrorCodePageReqVO exportReqVO, | |
| 82 | 83 | HttpServletResponse response) throws IOException { |
| 83 | - List<ErrorCodeDO> list = errorCodeService.getErrorCodeList(exportReqVO); | |
| 84 | + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 85 | + List<ErrorCodeDO> list = errorCodeService.getErrorCodePage(exportReqVO).getList(); | |
| 84 | 86 | // 导出 Excel |
| 85 | - List<ErrorCodeExcelVO> datas = ErrorCodeConvert.INSTANCE.convertList02(list); | |
| 86 | - ExcelUtils.write(response, "错误码.xls", "数据", ErrorCodeExcelVO.class, datas); | |
| 87 | + ExcelUtils.write(response, "错误码.xls", "数据", ErrorCodeRespVO.class, | |
| 88 | + BeanUtils.toBean(list, ErrorCodeRespVO.class)); | |
| 87 | 89 | } |
| 88 | 90 | |
| 89 | 91 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.errorcode.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 | -@Schema(description = "管理后台 - 错误码创建 Request VO") | |
| 9 | -@Data | |
| 10 | -@EqualsAndHashCode(callSuper = true) | |
| 11 | -@ToString(callSuper = true) | |
| 12 | -public class ErrorCodeCreateReqVO extends ErrorCodeBaseVO { | |
| 13 | - | |
| 14 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeExcelVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.errorcode.vo; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | -import com.alibaba.excel.annotation.ExcelProperty; | |
| 6 | -import lombok.Data; | |
| 7 | - | |
| 8 | -import java.time.LocalDateTime; | |
| 9 | - | |
| 10 | -/** | |
| 11 | - * 错误码 Excel VO | |
| 12 | - * | |
| 13 | - * @author 芋道源码 | |
| 14 | - */ | |
| 15 | -@Data | |
| 16 | -public class ErrorCodeExcelVO { | |
| 17 | - | |
| 18 | - @ExcelProperty("错误码编号") | |
| 19 | - private Long id; | |
| 20 | - | |
| 21 | - @ExcelProperty(value = "错误码类型", converter = DictConvert.class) | |
| 22 | - @DictFormat("inf_error_code_type") // TODO 芋艿:得思考下杂解决枚举值 | |
| 23 | - private Integer type; | |
| 24 | - | |
| 25 | - @ExcelProperty("应用名") | |
| 26 | - private String applicationName; | |
| 27 | - | |
| 28 | - @ExcelProperty("错误码编码") | |
| 29 | - private Integer code; | |
| 30 | - | |
| 31 | - @ExcelProperty("错误码错误提示") | |
| 32 | - private String message; | |
| 33 | - | |
| 34 | - @ExcelProperty("备注") | |
| 35 | - private String memo; | |
| 36 | - | |
| 37 | - @ExcelProperty("创建时间") | |
| 38 | - private LocalDateTime createTime; | |
| 39 | - | |
| 40 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeExportReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.errorcode.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 = "管理后台 - 错误码 Excel 导出 Request VO,参数和 InfErrorCodePageReqVO 是一致的") | |
| 12 | -@Data | |
| 13 | -public class ErrorCodeExportReqVO { | |
| 14 | - | |
| 15 | - @Schema(description = "错误码类型", example = "1") | |
| 16 | - private Integer type; | |
| 17 | - | |
| 18 | - @Schema(description = "应用名", example = "dashboard") | |
| 19 | - private String applicationName; | |
| 20 | - | |
| 21 | - @Schema(description = "错误码编码", example = "1234") | |
| 22 | - private Integer code; | |
| 23 | - | |
| 24 | - @Schema(description = "错误码错误提示", example = "帅气") | |
| 25 | - private String message; | |
| 26 | - | |
| 27 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 28 | - @Schema(description = "创建时间") | |
| 29 | - private LocalDateTime[] createTime; | |
| 30 | - | |
| 31 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.errorcode.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.system.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 | -import lombok.ToString; | |
| 7 | 10 | |
| 11 | +import javax.validation.constraints.NotNull; | |
| 8 | 12 | import java.time.LocalDateTime; |
| 9 | 13 | |
| 10 | 14 | @Schema(description = "管理后台 - 错误码 Response VO") |
| 11 | 15 | @Data |
| 12 | -@EqualsAndHashCode(callSuper = true) | |
| 13 | -@ToString(callSuper = true) | |
| 14 | -public class ErrorCodeRespVO extends ErrorCodeBaseVO { | |
| 16 | +@ExcelIgnoreUnannotated | |
| 17 | +public class ErrorCodeRespVO { | |
| 15 | 18 | |
| 16 | 19 | @Schema(description = "错误码编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 20 | + @ExcelProperty("错误码编号") | |
| 17 | 21 | private Long id; |
| 18 | 22 | |
| 19 | 23 | @Schema(description = "错误码类型,参见 ErrorCodeTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 24 | + @ExcelProperty(value = "错误码类型", converter = DictConvert.class) | |
| 25 | + @DictFormat(DictTypeConstants.ERROR_CODE_TYPE) | |
| 20 | 26 | private Integer type; |
| 21 | 27 | |
| 28 | + @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard") | |
| 29 | + @NotNull(message = "应用名不能为空") | |
| 30 | + @ExcelProperty("应用名") | |
| 31 | + private String applicationName; | |
| 32 | + | |
| 33 | + @Schema(description = "错误码编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1234") | |
| 34 | + @NotNull(message = "错误码编码不能为空") | |
| 35 | + @ExcelProperty("错误码编码") | |
| 36 | + private Integer code; | |
| 37 | + | |
| 38 | + @Schema(description = "错误码错误提示", requiredMode = Schema.RequiredMode.REQUIRED, example = "帅气") | |
| 39 | + @NotNull(message = "错误码错误提示不能为空") | |
| 40 | + @ExcelProperty("错误码错误提示") | |
| 41 | + private String message; | |
| 42 | + | |
| 43 | + @Schema(description = "备注", example = "哈哈哈") | |
| 44 | + @ExcelProperty("备注") | |
| 45 | + private String memo; | |
| 46 | + | |
| 22 | 47 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 48 | + @ExcelProperty("创建时间") | |
| 23 | 49 | private LocalDateTime createTime; |
| 24 | 50 | |
| 25 | 51 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeBaseVO.java renamed to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeSaveReqVO.java
| ... | ... | @@ -5,12 +5,12 @@ import lombok.Data; |
| 5 | 5 | |
| 6 | 6 | import javax.validation.constraints.NotNull; |
| 7 | 7 | |
| 8 | -/** | |
| 9 | -* 错误码 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 10 | -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 11 | -*/ | |
| 8 | +@Schema(description = "管理后台 - 错误码创建/修改 Request VO") | |
| 12 | 9 | @Data |
| 13 | -public class ErrorCodeBaseVO { | |
| 10 | +public class ErrorCodeSaveReqVO { | |
| 11 | + | |
| 12 | + @Schema(description = "错误码编号", example = "1024") | |
| 13 | + private Long id; | |
| 14 | 14 | |
| 15 | 15 | @Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard") |
| 16 | 16 | @NotNull(message = "应用名不能为空") | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/errorcode/vo/ErrorCodeUpdateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.errorcode.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 ErrorCodeUpdateReqVO extends ErrorCodeBaseVO { | |
| 15 | - | |
| 16 | - @Schema(description = "错误码编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 17 | - @NotNull(message = "错误码编号不能为空") | |
| 18 | - private Long id; | |
| 19 | - | |
| 20 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/errorcode/ErrorCodeConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.system.convert.errorcode; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; | |
| 5 | -import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; | |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeCreateReqVO; | |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeExcelVO; | |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeRespVO; | |
| 9 | -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeUpdateReqVO; | |
| 10 | -import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; | |
| 11 | -import org.mapstruct.Mapper; | |
| 12 | -import org.mapstruct.factory.Mappers; | |
| 13 | - | |
| 14 | -import java.util.List; | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * 错误码 Convert | |
| 18 | - * | |
| 19 | - * @author 芋道源码 | |
| 20 | - */ | |
| 21 | -@Mapper | |
| 22 | -public interface ErrorCodeConvert { | |
| 23 | - | |
| 24 | - ErrorCodeConvert INSTANCE = Mappers.getMapper(ErrorCodeConvert.class); | |
| 25 | - | |
| 26 | - ErrorCodeDO convert(ErrorCodeCreateReqVO bean); | |
| 27 | - | |
| 28 | - ErrorCodeDO convert(ErrorCodeUpdateReqVO bean); | |
| 29 | - | |
| 30 | - ErrorCodeRespVO convert(ErrorCodeDO bean); | |
| 31 | - | |
| 32 | - List<ErrorCodeRespVO> convertList(List<ErrorCodeDO> list); | |
| 33 | - | |
| 34 | - PageResult<ErrorCodeRespVO> convertPage(PageResult<ErrorCodeDO> page); | |
| 35 | - | |
| 36 | - List<ErrorCodeExcelVO> convertList02(List<ErrorCodeDO> list); | |
| 37 | - | |
| 38 | - ErrorCodeDO convert(ErrorCodeAutoGenerateReqDTO bean); | |
| 39 | - | |
| 40 | - List<ErrorCodeRespDTO> convertList03(List<ErrorCodeDO> list); | |
| 41 | - | |
| 42 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/errorcode/ErrorCodeMapper.java
| ... | ... | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.dal.mysql.errorcode; |
| 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.system.controller.admin.errorcode.vo.ErrorCodeExportReqVO; | |
| 7 | 6 | import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; |
| 8 | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; |
| 9 | 8 | import org.apache.ibatis.annotations.Mapper; |
| ... | ... | @@ -25,16 +24,6 @@ public interface ErrorCodeMapper extends BaseMapperX<ErrorCodeDO> { |
| 25 | 24 | .orderByDesc(ErrorCodeDO::getCode)); |
| 26 | 25 | } |
| 27 | 26 | |
| 28 | - default List<ErrorCodeDO> selectList(ErrorCodeExportReqVO reqVO) { | |
| 29 | - return selectList(new LambdaQueryWrapperX<ErrorCodeDO>() | |
| 30 | - .eqIfPresent(ErrorCodeDO::getType, reqVO.getType()) | |
| 31 | - .likeIfPresent(ErrorCodeDO::getApplicationName, reqVO.getApplicationName()) | |
| 32 | - .eqIfPresent(ErrorCodeDO::getCode, reqVO.getCode()) | |
| 33 | - .likeIfPresent(ErrorCodeDO::getMessage, reqVO.getMessage()) | |
| 34 | - .betweenIfPresent(ErrorCodeDO::getCreateTime, reqVO.getCreateTime()) | |
| 35 | - .orderByDesc(ErrorCodeDO::getCode)); | |
| 36 | - } | |
| 37 | - | |
| 38 | 27 | default List<ErrorCodeDO> selectListByCodes(Collection<Integer> codes) { |
| 39 | 28 | return selectList(ErrorCodeDO::getCode, codes); |
| 40 | 29 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeService.java
| ... | ... | @@ -3,10 +3,8 @@ package cn.iocoder.yudao.module.system.service.errorcode; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; |
| 5 | 5 | import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeCreateReqVO; | |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeExportReqVO; | |
| 8 | 6 | import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; |
| 9 | -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeUpdateReqVO; | |
| 7 | +import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeSaveReqVO; | |
| 10 | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; |
| 11 | 9 | |
| 12 | 10 | import javax.validation.Valid; |
| ... | ... | @@ -44,14 +42,14 @@ public interface ErrorCodeService { |
| 44 | 42 | * @param createReqVO 创建信息 |
| 45 | 43 | * @return 编号 |
| 46 | 44 | */ |
| 47 | - Long createErrorCode(@Valid ErrorCodeCreateReqVO createReqVO); | |
| 45 | + Long createErrorCode(@Valid ErrorCodeSaveReqVO createReqVO); | |
| 48 | 46 | |
| 49 | 47 | /** |
| 50 | 48 | * 更新错误码 |
| 51 | 49 | * |
| 52 | 50 | * @param updateReqVO 更新信息 |
| 53 | 51 | */ |
| 54 | - void updateErrorCode(@Valid ErrorCodeUpdateReqVO updateReqVO); | |
| 52 | + void updateErrorCode(@Valid ErrorCodeSaveReqVO updateReqVO); | |
| 55 | 53 | |
| 56 | 54 | /** |
| 57 | 55 | * 删除错误码 |
| ... | ... | @@ -76,12 +74,4 @@ public interface ErrorCodeService { |
| 76 | 74 | */ |
| 77 | 75 | PageResult<ErrorCodeDO> getErrorCodePage(ErrorCodePageReqVO pageReqVO); |
| 78 | 76 | |
| 79 | - /** | |
| 80 | - * 获得错误码列表, 用于 Excel 导出 | |
| 81 | - * | |
| 82 | - * @param exportReqVO 查询条件 | |
| 83 | - * @return 错误码列表 | |
| 84 | - */ | |
| 85 | - List<ErrorCodeDO> getErrorCodeList(ErrorCodeExportReqVO exportReqVO); | |
| 86 | - | |
| 87 | 77 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceImpl.java
| ... | ... | @@ -2,13 +2,11 @@ package cn.iocoder.yudao.module.system.service.errorcode; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 5 | 6 | import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; |
| 6 | 7 | import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeCreateReqVO; | |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeExportReqVO; | |
| 9 | 8 | import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; |
| 10 | -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeUpdateReqVO; | |
| 11 | -import cn.iocoder.yudao.module.system.convert.errorcode.ErrorCodeConvert; | |
| 9 | +import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeSaveReqVO; | |
| 12 | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; |
| 13 | 11 | import cn.iocoder.yudao.module.system.dal.mysql.errorcode.ErrorCodeMapper; |
| 14 | 12 | import cn.iocoder.yudao.module.system.enums.errorcode.ErrorCodeTypeEnum; |
| ... | ... | @@ -43,12 +41,12 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { |
| 43 | 41 | private ErrorCodeMapper errorCodeMapper; |
| 44 | 42 | |
| 45 | 43 | @Override |
| 46 | - public Long createErrorCode(ErrorCodeCreateReqVO createReqVO) { | |
| 44 | + public Long createErrorCode(ErrorCodeSaveReqVO createReqVO) { | |
| 47 | 45 | // 校验 code 重复 |
| 48 | 46 | validateCodeDuplicate(createReqVO.getCode(), null); |
| 49 | 47 | |
| 50 | 48 | // 插入 |
| 51 | - ErrorCodeDO errorCode = ErrorCodeConvert.INSTANCE.convert(createReqVO) | |
| 49 | + ErrorCodeDO errorCode = BeanUtils.toBean(createReqVO, ErrorCodeDO.class) | |
| 52 | 50 | .setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()); |
| 53 | 51 | errorCodeMapper.insert(errorCode); |
| 54 | 52 | // 返回 |
| ... | ... | @@ -56,14 +54,14 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { |
| 56 | 54 | } |
| 57 | 55 | |
| 58 | 56 | @Override |
| 59 | - public void updateErrorCode(ErrorCodeUpdateReqVO updateReqVO) { | |
| 57 | + public void updateErrorCode(ErrorCodeSaveReqVO updateReqVO) { | |
| 60 | 58 | // 校验存在 |
| 61 | 59 | validateErrorCodeExists(updateReqVO.getId()); |
| 62 | 60 | // 校验 code 重复 |
| 63 | 61 | validateCodeDuplicate(updateReqVO.getCode(), updateReqVO.getId()); |
| 64 | 62 | |
| 65 | 63 | // 更新 |
| 66 | - ErrorCodeDO updateObj = ErrorCodeConvert.INSTANCE.convert(updateReqVO) | |
| 64 | + ErrorCodeDO updateObj = BeanUtils.toBean(updateReqVO, ErrorCodeDO.class) | |
| 67 | 65 | .setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()); |
| 68 | 66 | errorCodeMapper.updateById(updateObj); |
| 69 | 67 | } |
| ... | ... | @@ -117,11 +115,6 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { |
| 117 | 115 | } |
| 118 | 116 | |
| 119 | 117 | @Override |
| 120 | - public List<ErrorCodeDO> getErrorCodeList(ErrorCodeExportReqVO exportReqVO) { | |
| 121 | - return errorCodeMapper.selectList(exportReqVO); | |
| 122 | - } | |
| 123 | - | |
| 124 | - @Override | |
| 125 | 118 | @Transactional |
| 126 | 119 | public void autoGenerateErrorCodes(List<ErrorCodeAutoGenerateReqDTO> autoGenerateDTOs) { |
| 127 | 120 | if (CollUtil.isEmpty(autoGenerateDTOs)) { |
| ... | ... | @@ -134,40 +127,40 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { |
| 134 | 127 | |
| 135 | 128 | // 遍历 autoGenerateBOs 数组,逐个插入或更新。考虑到每次量级不大,就不走批量了 |
| 136 | 129 | autoGenerateDTOs.forEach(autoGenerateDTO -> { |
| 137 | - ErrorCodeDO errorCodeDO = errorCodeDOMap.get(autoGenerateDTO.getCode()); | |
| 130 | + ErrorCodeDO errorCode = errorCodeDOMap.get(autoGenerateDTO.getCode()); | |
| 138 | 131 | // 不存在,则进行新增 |
| 139 | - if (errorCodeDO == null) { | |
| 140 | - errorCodeDO = ErrorCodeConvert.INSTANCE.convert(autoGenerateDTO) | |
| 132 | + if (errorCode == null) { | |
| 133 | + errorCode = BeanUtils.toBean(autoGenerateDTO, ErrorCodeDO.class) | |
| 141 | 134 | .setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); |
| 142 | - errorCodeMapper.insert(errorCodeDO); | |
| 135 | + errorCodeMapper.insert(errorCode); | |
| 143 | 136 | return; |
| 144 | 137 | } |
| 145 | 138 | // 存在,则进行更新。更新有三个前置条件: |
| 146 | 139 | // 条件 1. 只更新自动生成的错误码,即 Type 为 ErrorCodeTypeEnum.AUTO_GENERATION |
| 147 | - if (!ErrorCodeTypeEnum.AUTO_GENERATION.getType().equals(errorCodeDO.getType())) { | |
| 140 | + if (!ErrorCodeTypeEnum.AUTO_GENERATION.getType().equals(errorCode.getType())) { | |
| 148 | 141 | return; |
| 149 | 142 | } |
| 150 | 143 | // 条件 2. 分组 applicationName 必须匹配,避免存在错误码冲突的情况 |
| 151 | - if (!autoGenerateDTO.getApplicationName().equals(errorCodeDO.getApplicationName())) { | |
| 144 | + if (!autoGenerateDTO.getApplicationName().equals(errorCode.getApplicationName())) { | |
| 152 | 145 | log.error("[autoGenerateErrorCodes][自动创建({}/{}) 错误码失败,数据库中已经存在({}/{})]", |
| 153 | 146 | autoGenerateDTO.getCode(), autoGenerateDTO.getApplicationName(), |
| 154 | - errorCodeDO.getCode(), errorCodeDO.getApplicationName()); | |
| 147 | + errorCode.getCode(), errorCode.getApplicationName()); | |
| 155 | 148 | return; |
| 156 | 149 | } |
| 157 | 150 | // 条件 3. 错误提示语存在差异 |
| 158 | - if (autoGenerateDTO.getMessage().equals(errorCodeDO.getMessage())) { | |
| 151 | + if (autoGenerateDTO.getMessage().equals(errorCode.getMessage())) { | |
| 159 | 152 | return; |
| 160 | 153 | } |
| 161 | 154 | // 最终匹配,进行更新 |
| 162 | - errorCodeMapper.updateById(new ErrorCodeDO().setId(errorCodeDO.getId()).setMessage(autoGenerateDTO.getMessage())); | |
| 155 | + errorCodeMapper.updateById(new ErrorCodeDO().setId(errorCode.getId()).setMessage(autoGenerateDTO.getMessage())); | |
| 163 | 156 | }); |
| 164 | 157 | } |
| 165 | 158 | |
| 166 | 159 | @Override |
| 167 | 160 | public List<ErrorCodeRespDTO> getErrorCodeList(String applicationName, LocalDateTime minUpdateTime) { |
| 168 | - List<ErrorCodeDO> errorCodeDOs = errorCodeMapper.selectListByApplicationNameAndUpdateTimeGt( | |
| 161 | + List<ErrorCodeDO> list = errorCodeMapper.selectListByApplicationNameAndUpdateTimeGt( | |
| 169 | 162 | applicationName, minUpdateTime); |
| 170 | - return ErrorCodeConvert.INSTANCE.convertList03(errorCodeDOs); | |
| 163 | + return BeanUtils.toBean(list, ErrorCodeRespDTO.class); | |
| 171 | 164 | } |
| 172 | 165 | |
| 173 | 166 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java
| ... | ... | @@ -5,10 +5,8 @@ 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.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; |
| 7 | 7 | import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeCreateReqVO; | |
| 9 | -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeExportReqVO; | |
| 10 | 8 | import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; |
| 11 | -import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeUpdateReqVO; | |
| 9 | +import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeSaveReqVO; | |
| 12 | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.errorcode.ErrorCodeDO; |
| 13 | 11 | import cn.iocoder.yudao.module.system.dal.mysql.errorcode.ErrorCodeMapper; |
| 14 | 12 | import cn.iocoder.yudao.module.system.enums.errorcode.ErrorCodeTypeEnum; |
| ... | ... | @@ -44,7 +42,8 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { |
| 44 | 42 | @Test |
| 45 | 43 | public void testCreateErrorCode_success() { |
| 46 | 44 | // 准备参数 |
| 47 | - ErrorCodeCreateReqVO reqVO = randomPojo(ErrorCodeCreateReqVO.class); | |
| 45 | + ErrorCodeSaveReqVO reqVO = randomPojo(ErrorCodeSaveReqVO.class) | |
| 46 | + .setId(null); // 防止 id 被赋值 | |
| 48 | 47 | |
| 49 | 48 | // 调用 |
| 50 | 49 | Long errorCodeId = errorCodeService.createErrorCode(reqVO); |
| ... | ... | @@ -52,7 +51,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { |
| 52 | 51 | assertNotNull(errorCodeId); |
| 53 | 52 | // 校验记录的属性是否正确 |
| 54 | 53 | ErrorCodeDO errorCode = errorCodeMapper.selectById(errorCodeId); |
| 55 | - assertPojoEquals(reqVO, errorCode); | |
| 54 | + assertPojoEquals(reqVO, errorCode, "id"); | |
| 56 | 55 | assertEquals(ErrorCodeTypeEnum.MANUAL_OPERATION.getType(), errorCode.getType()); |
| 57 | 56 | } |
| 58 | 57 | |
| ... | ... | @@ -62,7 +61,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { |
| 62 | 61 | ErrorCodeDO dbErrorCode = randomErrorCodeDO(); |
| 63 | 62 | errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据 |
| 64 | 63 | // 准备参数 |
| 65 | - ErrorCodeUpdateReqVO reqVO = randomPojo(ErrorCodeUpdateReqVO.class, o -> { | |
| 64 | + ErrorCodeSaveReqVO reqVO = randomPojo(ErrorCodeSaveReqVO.class, o -> { | |
| 66 | 65 | o.setId(dbErrorCode.getId()); // 设置更新的 ID |
| 67 | 66 | }); |
| 68 | 67 | |
| ... | ... | @@ -134,25 +133,6 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { |
| 134 | 133 | } |
| 135 | 134 | |
| 136 | 135 | @Test |
| 137 | - public void testGetErrorCodeList_export() { | |
| 138 | - // mock 数据 | |
| 139 | - ErrorCodeDO dbErrorCode = initGetErrorCodePage(); | |
| 140 | - // 准备参数 | |
| 141 | - ErrorCodeExportReqVO reqVO = new ErrorCodeExportReqVO(); | |
| 142 | - reqVO.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); | |
| 143 | - reqVO.setApplicationName("tu"); | |
| 144 | - reqVO.setCode(1); | |
| 145 | - reqVO.setMessage("ma"); | |
| 146 | - reqVO.setCreateTime(buildBetweenTime(2020, 11, 1, 2020, 11, 30)); | |
| 147 | - | |
| 148 | - // 调用 | |
| 149 | - List<ErrorCodeDO> list = errorCodeService.getErrorCodeList(reqVO); | |
| 150 | - // 断言 | |
| 151 | - assertEquals(1, list.size()); | |
| 152 | - assertPojoEquals(dbErrorCode, list.get(0)); | |
| 153 | - } | |
| 154 | - | |
| 155 | - @Test | |
| 156 | 136 | public void testValidateCodeDuplicate_codeDuplicateForCreate() { |
| 157 | 137 | // 准备参数 |
| 158 | 138 | Integer code = randomInteger(); | ... | ... |