Commit e973a4368f4807f582134db5ac5de7c0c6de343b
1 parent
c6ef8b3a
refactor(error-code): 移除错误码BO
Showing
13 changed files
with
75 additions
and
296 deletions
src/main/java/cn/iocoder/dashboard/framework/errorcode/config/ErrorCodeProperties.java
| 1 | 1 | package cn.iocoder.dashboard.framework.errorcode.config; |
| 2 | 2 | |
| 3 | +import lombok.Getter; | |
| 4 | +import lombok.Setter; | |
| 3 | 5 | import org.springframework.boot.context.properties.ConfigurationProperties; |
| 4 | 6 | import org.springframework.validation.annotation.Validated; |
| 5 | 7 | |
| 6 | 8 | import javax.validation.constraints.NotNull; |
| 7 | 9 | |
| 8 | -@ConfigurationProperties("ruoyi.error-code") | |
| 10 | +@ConfigurationProperties("yudao.error-code") | |
| 9 | 11 | @Validated |
| 12 | +@Getter | |
| 13 | +@Setter | |
| 10 | 14 | public class ErrorCodeProperties { |
| 11 | 15 | |
| 12 | 16 | /** |
| 13 | 17 | * 应用分组 |
| 14 | 18 | */ |
| 15 | - @NotNull(message = "应用分组不能为空,请设置 ruoyi.error-code.group 配置项,推荐直接使用 spring. application.name 配置项") | |
| 19 | + @NotNull(message = "应用分组不能为空,请设置 yudao.error-code.group 配置项,推荐直接使用 spring.application.name 配置项") | |
| 16 | 20 | private String group; |
| 17 | 21 | /** |
| 18 | 22 | * 错误码枚举类 |
| 19 | 23 | */ |
| 20 | 24 | private String constantsClass; |
| 21 | - | |
| 22 | - public String getGroup() { | |
| 23 | - return group; | |
| 24 | - } | |
| 25 | - | |
| 26 | - public ErrorCodeProperties setGroup(String group) { | |
| 27 | - this.group = group; | |
| 28 | - return this; | |
| 29 | - } | |
| 30 | - | |
| 31 | - public String getConstantsClass() { | |
| 32 | - return constantsClass; | |
| 33 | - } | |
| 34 | - | |
| 35 | - public ErrorCodeProperties setConstantsClass(String constantsClass) { | |
| 36 | - this.constantsClass = constantsClass; | |
| 37 | - return this; | |
| 38 | - } | |
| 39 | 25 | } |
| 40 | 26 | \ No newline at end of file | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/errorcode/core/ErrorCodeAutoGenerator.java
| ... | ... | @@ -3,10 +3,8 @@ package cn.iocoder.dashboard.framework.errorcode.core; |
| 3 | 3 | import cn.iocoder.dashboard.common.exception.ErrorCode; |
| 4 | 4 | import cn.iocoder.dashboard.common.pojo.CommonResult; |
| 5 | 5 | import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodeAutoGenerateDTO; |
| 6 | -import cn.iocoder.dashboard.modules.system.convert.errorcode.ErrorCodeConvert; | |
| 7 | 6 | import cn.iocoder.dashboard.modules.system.service.errorcode.ErrorCodeService; |
| 8 | -import org.slf4j.Logger; | |
| 9 | -import org.slf4j.LoggerFactory; | |
| 7 | +import lombok.extern.slf4j.Slf4j; | |
| 10 | 8 | import org.springframework.boot.context.event.ApplicationReadyEvent; |
| 11 | 9 | import org.springframework.context.event.EventListener; |
| 12 | 10 | import org.springframework.scheduling.annotation.Async; |
| ... | ... | @@ -17,10 +15,9 @@ import java.util.ArrayList; |
| 17 | 15 | import java.util.Arrays; |
| 18 | 16 | import java.util.List; |
| 19 | 17 | |
| 18 | +@Slf4j | |
| 20 | 19 | public class ErrorCodeAutoGenerator { |
| 21 | 20 | |
| 22 | - private Logger logger = LoggerFactory.getLogger(ErrorCodeAutoGenerator.class); | |
| 23 | - | |
| 24 | 21 | /** |
| 25 | 22 | * 应用分组 |
| 26 | 23 | */ |
| ... | ... | @@ -47,18 +44,18 @@ public class ErrorCodeAutoGenerator { |
| 47 | 44 | public void execute() { |
| 48 | 45 | // 校验 errorCodeConstantsClass 参数 |
| 49 | 46 | if (!StringUtils.hasText(errorCodeConstantsClass)) { |
| 50 | - logger.info("[execute][未配置 ruoyi.error-code.constants-class 配置项,不进行自动写入到 system-service 服务]"); | |
| 47 | + log.info("[execute][未配置 yudao.error-code.constants-class 配置项,不进行自动写入到当前服务中]"); | |
| 51 | 48 | return; |
| 52 | 49 | } |
| 53 | 50 | Class errorCodeConstantsClazz; |
| 54 | 51 | try { |
| 55 | 52 | errorCodeConstantsClazz = Class.forName(errorCodeConstantsClass); |
| 56 | 53 | } catch (ClassNotFoundException e) { |
| 57 | - logger.error("[execute][配置的 ({}) 找不到对应的类]", errorCodeConstantsClass); | |
| 54 | + log.error("[execute][配置的 ({}) 找不到对应的类]", errorCodeConstantsClass); | |
| 58 | 55 | return; |
| 59 | 56 | } |
| 60 | 57 | // 写入 system-service 服务 |
| 61 | - logger.info("[execute][自动将 ({}) 类的错误码,准备写入到 system-service 服务]", errorCodeConstantsClass); | |
| 58 | + log.info("[execute][自动将 ({}) 类的错误码,准备写入到当前服务]", errorCodeConstantsClass); | |
| 62 | 59 | List<ErrorCodeAutoGenerateDTO> autoGenerateDTOs = new ArrayList<>(); |
| 63 | 60 | Arrays.stream(errorCodeConstantsClazz.getFields()).forEach(field -> { |
| 64 | 61 | if (field.getType() != ErrorCode.class) { |
| ... | ... | @@ -73,11 +70,11 @@ public class ErrorCodeAutoGenerator { |
| 73 | 70 | throw new RuntimeException(e); |
| 74 | 71 | } |
| 75 | 72 | }); |
| 76 | - CommonResult<Boolean> autoGenerateErrorCodesResult = errorCodeService.autoGenerateErrorCodes1(ErrorCodeConvert.INSTANCE.convertList03(autoGenerateDTOs)); | |
| 73 | + CommonResult<Boolean> autoGenerateErrorCodesResult = errorCodeService.autoGenerateErrorCodes1(autoGenerateDTOs); | |
| 77 | 74 | if (autoGenerateErrorCodesResult.isSuccess()) { |
| 78 | - logger.info("[execute][自动将 ({}) 类的错误码,成功写入到 system-service 服务]", errorCodeConstantsClass); | |
| 75 | + log.info("[execute][自动将 ({}) 类的错误码,成功写入到当前服务]", errorCodeConstantsClass); | |
| 79 | 76 | } else { |
| 80 | - logger.error("[execute][自动将 ({}) 类的错误码,失败写入到 system-service 服务,原因为 ({}/{})]", errorCodeConstantsClass, | |
| 77 | + log.error("[execute][自动将 ({}) 类的错误码,失败写入到当前服务,原因为 ({}/{})]", errorCodeConstantsClass, | |
| 81 | 78 | autoGenerateErrorCodesResult.getCode(), autoGenerateErrorCodesResult.getMsg()); |
| 82 | 79 | } |
| 83 | 80 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/errorcode/core/ErrorCodeRemoteLoader.java
| ... | ... | @@ -5,10 +5,8 @@ import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil; |
| 5 | 5 | import cn.iocoder.dashboard.common.pojo.CommonResult; |
| 6 | 6 | import cn.iocoder.dashboard.modules.system.controller.errorcode.vo.ErrorCodeVO; |
| 7 | 7 | import cn.iocoder.dashboard.modules.system.service.errorcode.ErrorCodeService; |
| 8 | -import cn.iocoder.dashboard.modules.system.service.errorcode.bo.ErrorCodeBO; | |
| 9 | 8 | import cn.iocoder.dashboard.util.date.DateUtils; |
| 10 | -import org.slf4j.Logger; | |
| 11 | -import org.slf4j.LoggerFactory; | |
| 9 | +import lombok.extern.slf4j.Slf4j; | |
| 12 | 10 | import org.springframework.boot.context.event.ApplicationReadyEvent; |
| 13 | 11 | import org.springframework.context.event.EventListener; |
| 14 | 12 | import org.springframework.scheduling.annotation.Scheduled; |
| ... | ... | @@ -17,12 +15,11 @@ import javax.annotation.Resource; |
| 17 | 15 | import java.util.Date; |
| 18 | 16 | import java.util.List; |
| 19 | 17 | |
| 18 | +@Slf4j | |
| 20 | 19 | public class ErrorCodeRemoteLoader { |
| 21 | 20 | |
| 22 | 21 | private static final int REFRESH_ERROR_CODE_PERIOD = 60 * 1000; |
| 23 | 22 | |
| 24 | - private Logger logger = LoggerFactory.getLogger(ErrorCodeRemoteLoader.class); | |
| 25 | - | |
| 26 | 23 | /** |
| 27 | 24 | * 应用分组 |
| 28 | 25 | */ |
| ... | ... | @@ -42,7 +39,7 @@ public class ErrorCodeRemoteLoader { |
| 42 | 39 | // 从 ErrorCodeRpc 全量加载 ErrorCode 错误码 |
| 43 | 40 | CommonResult<List<ErrorCodeVO>> listErrorCodesResult = errorCodeService.listErrorCodes1(group, null); |
| 44 | 41 | listErrorCodesResult.checkError(); |
| 45 | - logger.info("[loadErrorCodes][从 group({}) 全量加载到 {} 个 ErrorCode 错误码]", group, listErrorCodesResult.getData().size()); | |
| 42 | + log.info("[loadErrorCodes][从 group({}) 全量加载到 {} 个 ErrorCode 错误码]", group, listErrorCodesResult.getData().size()); | |
| 46 | 43 | // 写入到 ServiceExceptionUtil 到 |
| 47 | 44 | listErrorCodesResult.getData().forEach(errorCodeVO -> { |
| 48 | 45 | ServiceExceptionUtil.put(errorCodeVO.getCode(), errorCodeVO.getMessage()); |
| ... | ... | @@ -60,7 +57,7 @@ public class ErrorCodeRemoteLoader { |
| 60 | 57 | if (CollUtil.isEmpty(listErrorCodesResult.getData())) { |
| 61 | 58 | return; |
| 62 | 59 | } |
| 63 | - logger.info("[refreshErrorCodes][从 group({}) 增量加载到 {} 个 ErrorCode 错误码]", group, listErrorCodesResult.getData().size()); | |
| 60 | + log.info("[refreshErrorCodes][从 group({}) 增量加载到 {} 个 ErrorCode 错误码]", group, listErrorCodesResult.getData().size()); | |
| 64 | 61 | // 写入到 ServiceExceptionUtil 到 |
| 65 | 62 | listErrorCodesResult.getData().forEach(errorCodeVO -> { |
| 66 | 63 | ServiceExceptionUtil.put(errorCodeVO.getCode(), errorCodeVO.getMessage()); | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/errorcode/ErrorCodeController.java
| ... | ... | @@ -7,9 +7,7 @@ import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodeCre |
| 7 | 7 | import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodePageDTO; |
| 8 | 8 | import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodeUpdateDTO; |
| 9 | 9 | import cn.iocoder.dashboard.modules.system.controller.errorcode.vo.ErrorCodeVO; |
| 10 | -import cn.iocoder.dashboard.modules.system.convert.errorcode.ErrorCodeConvert; | |
| 11 | 10 | import cn.iocoder.dashboard.modules.system.service.errorcode.ErrorCodeService; |
| 12 | -import cn.iocoder.dashboard.modules.system.service.errorcode.bo.ErrorCodeBO; | |
| 13 | 11 | import io.swagger.annotations.Api; |
| 14 | 12 | import io.swagger.annotations.ApiOperation; |
| 15 | 13 | import org.springframework.beans.propertyeditors.CustomDateEditor; |
| ... | ... | @@ -44,7 +42,7 @@ public class ErrorCodeController { |
| 44 | 42 | @ApiOperation("获取指定分组下的状态码") |
| 45 | 43 | @GetMapping("/list-group") |
| 46 | 44 | public CommonResult<List<ErrorCodeVO>> listErrorCodes(@NotNull(message = "错误码分组不能为空") String group, Date minUpdateTime) { |
| 47 | - return success(ErrorCodeConvert.INSTANCE.convertList02(errorCodeService.listErrorCodes(group, minUpdateTime))); | |
| 45 | + return success(errorCodeService.listErrorCodes(group, minUpdateTime)); | |
| 48 | 46 | } |
| 49 | 47 | |
| 50 | 48 | /** |
| ... | ... | @@ -55,7 +53,7 @@ public class ErrorCodeController { |
| 55 | 53 | @ApiOperation("自动生成错误码") |
| 56 | 54 | @PostMapping("/generate") |
| 57 | 55 | public CommonResult<Boolean> autoGenerateErrorCodes(@RequestBody List<ErrorCodeAutoGenerateDTO> autoGenerateDTOs) { |
| 58 | - errorCodeService.autoGenerateErrorCodes(ErrorCodeConvert.INSTANCE.convertList03(autoGenerateDTOs)); | |
| 56 | + errorCodeService.autoGenerateErrorCodes(autoGenerateDTOs); | |
| 59 | 57 | return success(Boolean.TRUE); |
| 60 | 58 | } |
| 61 | 59 | |
| ... | ... | @@ -69,7 +67,7 @@ public class ErrorCodeController { |
| 69 | 67 | @ApiOperation("创建错误码") |
| 70 | 68 | @PostMapping("/create") |
| 71 | 69 | public CommonResult<Integer> createErrorCode(@RequestBody ErrorCodeCreateDTO createDTO) { |
| 72 | - return success(errorCodeService.createErrorCode(ErrorCodeConvert.INSTANCE.convert(createDTO)).getId()); | |
| 70 | + return success(errorCodeService.createErrorCode(createDTO).getId()); | |
| 73 | 71 | } |
| 74 | 72 | |
| 75 | 73 | /** |
| ... | ... | @@ -80,7 +78,7 @@ public class ErrorCodeController { |
| 80 | 78 | @ApiOperation("更新错误码") |
| 81 | 79 | @PatchMapping("/update") |
| 82 | 80 | public CommonResult<Boolean> updateErrorCode(@RequestBody ErrorCodeUpdateDTO updateDTO) { |
| 83 | - errorCodeService.updateErrorCode(ErrorCodeConvert.INSTANCE.convert(updateDTO)); | |
| 81 | + errorCodeService.updateErrorCode(updateDTO); | |
| 84 | 82 | return success(Boolean.TRUE); |
| 85 | 83 | } |
| 86 | 84 | |
| ... | ... | @@ -105,7 +103,7 @@ public class ErrorCodeController { |
| 105 | 103 | @ApiOperation("获取错误码") |
| 106 | 104 | @GetMapping("/query") |
| 107 | 105 | public CommonResult<ErrorCodeVO> getErrorCode(Integer errorCodeId) { |
| 108 | - return success(ErrorCodeConvert.INSTANCE.convert(errorCodeService.getErrorCode(errorCodeId))); | |
| 106 | + return success(errorCodeService.getErrorCode(errorCodeId)); | |
| 109 | 107 | } |
| 110 | 108 | |
| 111 | 109 | /** |
| ... | ... | @@ -117,7 +115,7 @@ public class ErrorCodeController { |
| 117 | 115 | @ApiOperation("获取错误码列表") |
| 118 | 116 | @GetMapping("/query-ids") |
| 119 | 117 | public CommonResult<List<ErrorCodeVO>> listErrorCodes(@RequestBody List<Integer> errorCodeIds) { |
| 120 | - return success(ErrorCodeConvert.INSTANCE.convertList02(errorCodeService.listErrorCodes(errorCodeIds))); | |
| 118 | + return success(errorCodeService.listErrorCodes(errorCodeIds)); | |
| 121 | 119 | } |
| 122 | 120 | |
| 123 | 121 | /** |
| ... | ... | @@ -129,8 +127,7 @@ public class ErrorCodeController { |
| 129 | 127 | @ApiOperation("获取错误码分页列表") |
| 130 | 128 | @GetMapping("/page") |
| 131 | 129 | public CommonResult<PageResult<ErrorCodeVO>> pageErrorCode(ErrorCodePageDTO pageDTO) { |
| 132 | - final PageResult<ErrorCodeBO> pageResult = errorCodeService.pageErrorCode(ErrorCodeConvert.INSTANCE.convert(pageDTO)); | |
| 133 | - return success(ErrorCodeConvert.INSTANCE.convertPage(pageResult)); | |
| 130 | + return success(errorCodeService.pageErrorCode(pageDTO)); | |
| 134 | 131 | } |
| 135 | 132 | |
| 136 | 133 | @InitBinder | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/convert/errorcode/ErrorCodeConvert.java
| ... | ... | @@ -3,47 +3,37 @@ package cn.iocoder.dashboard.modules.system.convert.errorcode; |
| 3 | 3 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodeAutoGenerateDTO; |
| 5 | 5 | import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodeCreateDTO; |
| 6 | -import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodePageDTO; | |
| 7 | 6 | import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodeUpdateDTO; |
| 8 | 7 | import cn.iocoder.dashboard.modules.system.controller.errorcode.vo.ErrorCodeVO; |
| 9 | 8 | import cn.iocoder.dashboard.modules.system.dal.dataobject.errorcode.ErrorCodeDO; |
| 10 | -import cn.iocoder.dashboard.modules.system.service.errorcode.bo.*; | |
| 11 | 9 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| 12 | 10 | import org.mapstruct.Mapper; |
| 13 | 11 | import org.mapstruct.Mapping; |
| 12 | +import org.mapstruct.ReportingPolicy; | |
| 14 | 13 | import org.mapstruct.factory.Mappers; |
| 15 | 14 | |
| 16 | 15 | import java.util.List; |
| 17 | 16 | |
| 18 | -@Mapper | |
| 17 | +/** | |
| 18 | + * @author dylan | |
| 19 | + */ | |
| 20 | +@Mapper(unmappedSourcePolicy = ReportingPolicy.IGNORE) | |
| 19 | 21 | public interface ErrorCodeConvert { |
| 20 | 22 | |
| 21 | 23 | ErrorCodeConvert INSTANCE = Mappers.getMapper(ErrorCodeConvert.class); |
| 22 | 24 | |
| 23 | - ErrorCodeDO convert(ErrorCodeCreateBO bean); | |
| 25 | + ErrorCodeVO convert (ErrorCodeDO bean); | |
| 24 | 26 | |
| 25 | - ErrorCodeBO convert(ErrorCodeDO bean); | |
| 26 | - | |
| 27 | - List<ErrorCodeBO> convertList(List<ErrorCodeDO> list); | |
| 27 | + List<ErrorCodeVO> convertList(List<ErrorCodeDO> list); | |
| 28 | 28 | |
| 29 | 29 | @Mapping(source = "records", target = "list") |
| 30 | - PageResult<ErrorCodeBO> convertPage(IPage<ErrorCodeDO> page); | |
| 31 | - | |
| 32 | - ErrorCodeDO convert(ErrorCodeUpdateBO bean); | |
| 33 | - | |
| 34 | - ErrorCodeCreateBO convert(ErrorCodeCreateDTO bean); | |
| 35 | - | |
| 36 | - ErrorCodeUpdateBO convert(ErrorCodeUpdateDTO bean); | |
| 37 | - | |
| 38 | - ErrorCodeVO convert(ErrorCodeBO bean); | |
| 30 | + PageResult<ErrorCodeVO> convertPage(IPage<ErrorCodeDO> page); | |
| 39 | 31 | |
| 40 | - List<ErrorCodeVO> convertList02(List<ErrorCodeBO> list); | |
| 32 | + ErrorCodeDO convert (ErrorCodeCreateDTO bean); | |
| 41 | 33 | |
| 42 | - PageResult<ErrorCodeVO> convertPage(PageResult<ErrorCodeBO> page); | |
| 34 | + ErrorCodeDO convert (ErrorCodeUpdateDTO bean); | |
| 43 | 35 | |
| 44 | - ErrorCodePageBO convert(ErrorCodePageDTO bean); | |
| 36 | + ErrorCodeDO convert(ErrorCodeAutoGenerateDTO bean); | |
| 45 | 37 | |
| 46 | - ErrorCodeDO convert(ErrorCodeAutoGenerateBO bean); | |
| 47 | 38 | |
| 48 | - List<ErrorCodeAutoGenerateBO> convertList03(List<ErrorCodeAutoGenerateDTO> list); | |
| 49 | 39 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/errorcode/ErrorCodeMapper.java
| 1 | 1 | package cn.iocoder.dashboard.modules.system.dal.mysql.errorcode; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; |
| 4 | +import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodePageDTO; | |
| 4 | 5 | import cn.iocoder.dashboard.modules.system.dal.dataobject.errorcode.ErrorCodeDO; |
| 5 | -import cn.iocoder.dashboard.modules.system.service.errorcode.bo.ErrorCodePageBO; | |
| 6 | 6 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 7 | 7 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| 8 | 8 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| ... | ... | @@ -15,10 +15,10 @@ import java.util.List; |
| 15 | 15 | |
| 16 | 16 | @Mapper |
| 17 | 17 | public interface ErrorCodeMapper extends BaseMapper<ErrorCodeDO> { |
| 18 | - default IPage<ErrorCodeDO> selectPage(ErrorCodePageBO pageBO) { | |
| 19 | - return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()), | |
| 20 | - new QueryWrapperX<ErrorCodeDO>().likeIfPresent("`group`", pageBO.getGroup()) | |
| 21 | - .eqIfPresent("code", pageBO.getCode()).likeIfPresent("message", pageBO.getMessage())); | |
| 18 | + default IPage<ErrorCodeDO> selectPage(ErrorCodePageDTO pageDTO) { | |
| 19 | + return selectPage(new Page<>(pageDTO.getPageNo(), pageDTO.getPageSize()), | |
| 20 | + new QueryWrapperX<ErrorCodeDO>().likeIfPresent("`group`", pageDTO.getGroup()) | |
| 21 | + .eqIfPresent("code", pageDTO.getCode()).likeIfPresent("message", pageDTO.getMessage())); | |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | default List<ErrorCodeDO> selectListByCodes(Collection<Integer> codes) { | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/errorcode/ErrorCodeService.java
| ... | ... | @@ -4,12 +4,15 @@ import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil; |
| 5 | 5 | import cn.iocoder.dashboard.common.pojo.CommonResult; |
| 6 | 6 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 7 | +import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodeAutoGenerateDTO; | |
| 8 | +import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodeCreateDTO; | |
| 9 | +import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodePageDTO; | |
| 10 | +import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodeUpdateDTO; | |
| 7 | 11 | import cn.iocoder.dashboard.modules.system.controller.errorcode.vo.ErrorCodeVO; |
| 8 | 12 | import cn.iocoder.dashboard.modules.system.convert.errorcode.ErrorCodeConvert; |
| 9 | 13 | import cn.iocoder.dashboard.modules.system.dal.dataobject.errorcode.ErrorCodeDO; |
| 10 | 14 | import cn.iocoder.dashboard.modules.system.dal.mysql.errorcode.ErrorCodeMapper; |
| 11 | 15 | import cn.iocoder.dashboard.modules.system.enums.errorcode.ErrorCodeTypeEnum; |
| 12 | -import cn.iocoder.dashboard.modules.system.service.errorcode.bo.*; | |
| 13 | 16 | import cn.iocoder.dashboard.util.collection.CollectionUtils; |
| 14 | 17 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| 15 | 18 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -41,13 +44,13 @@ public class ErrorCodeService { |
| 41 | 44 | /** |
| 42 | 45 | * 创建错误码 |
| 43 | 46 | * |
| 44 | - * @param createBO 创建错误码 BO | |
| 47 | + * @param createDTO 创建错误码 DTO | |
| 45 | 48 | * @return 错误码 |
| 46 | 49 | */ |
| 47 | - public ErrorCodeBO createErrorCode(@Valid ErrorCodeCreateBO createBO) { | |
| 48 | - checkDuplicateErrorCode(createBO.getCode(), null); | |
| 50 | + public ErrorCodeVO createErrorCode(@Valid ErrorCodeCreateDTO createDTO) { | |
| 51 | + checkDuplicateErrorCode(createDTO.getCode(), null); | |
| 49 | 52 | // 插入到数据库 |
| 50 | - ErrorCodeDO errorCodeDO = ErrorCodeConvert.INSTANCE.convert(createBO); | |
| 53 | + ErrorCodeDO errorCodeDO = ErrorCodeConvert.INSTANCE.convert(createDTO); | |
| 51 | 54 | errorCodeMapper.insert(errorCodeDO); |
| 52 | 55 | // 返回 |
| 53 | 56 | return ErrorCodeConvert.INSTANCE.convert(errorCodeDO); |
| ... | ... | @@ -56,33 +59,33 @@ public class ErrorCodeService { |
| 56 | 59 | /** |
| 57 | 60 | * 更新错误码 |
| 58 | 61 | * |
| 59 | - * @param updateBO 更新错误码 BO | |
| 62 | + * @param updateDTO 更新错误码 DTO | |
| 60 | 63 | */ |
| 61 | - public void updateErrorCode(@Valid ErrorCodeUpdateBO updateBO) { | |
| 62 | - checkDuplicateErrorCode(updateBO.getCode(), updateBO.getId()); | |
| 64 | + public void updateErrorCode(@Valid ErrorCodeUpdateDTO updateDTO) { | |
| 65 | + checkDuplicateErrorCode(updateDTO.getCode(), updateDTO.getId()); | |
| 63 | 66 | // 校验更新的错误码是否存在 |
| 64 | - if (errorCodeMapper.selectById(updateBO.getId()) == null) { | |
| 67 | + if (errorCodeMapper.selectById(updateDTO.getId()) == null) { | |
| 65 | 68 | throw ServiceExceptionUtil.exception(ERROR_CODE_NOT_EXISTS); |
| 66 | 69 | } |
| 67 | 70 | // 更新到数据库 |
| 68 | - ErrorCodeDO updateObject = ErrorCodeConvert.INSTANCE.convert(updateBO); | |
| 71 | + ErrorCodeDO updateObject = ErrorCodeConvert.INSTANCE.convert(updateDTO); | |
| 69 | 72 | errorCodeMapper.updateById(updateObject); |
| 70 | 73 | } |
| 71 | 74 | |
| 72 | 75 | @Transactional |
| 73 | - public void autoGenerateErrorCodes(@Valid List<ErrorCodeAutoGenerateBO> autoGenerateBOs) { | |
| 74 | - if (CollUtil.isEmpty(autoGenerateBOs)) { | |
| 76 | + public void autoGenerateErrorCodes(@Valid List<ErrorCodeAutoGenerateDTO> autoGenerateDTOs) { | |
| 77 | + if (CollUtil.isEmpty(autoGenerateDTOs)) { | |
| 75 | 78 | return; |
| 76 | 79 | } |
| 77 | 80 | List<ErrorCodeDO> errorCodeDOs = errorCodeMapper.selectListByCodes( |
| 78 | - CollectionUtils.convertSet(autoGenerateBOs, ErrorCodeAutoGenerateBO::getCode)); | |
| 81 | + CollectionUtils.convertSet(autoGenerateDTOs, ErrorCodeAutoGenerateDTO::getCode)); | |
| 79 | 82 | Map<Integer, ErrorCodeDO> errorCodeDOMap = CollectionUtils.convertMap(errorCodeDOs, ErrorCodeDO::getCode); |
| 80 | 83 | // 遍历 autoGenerateBOs 数组,逐个插入或更新。考虑到每次量级不大,就不走批量了 |
| 81 | - autoGenerateBOs.forEach(autoGenerateBO -> { | |
| 82 | - ErrorCodeDO errorCodeDO = errorCodeDOMap.get(autoGenerateBO.getCode()); | |
| 84 | + autoGenerateDTOs.forEach(autoGenerateDTO -> { | |
| 85 | + ErrorCodeDO errorCodeDO = errorCodeDOMap.get(autoGenerateDTO.getCode()); | |
| 83 | 86 | // 不存在,则进行新增 |
| 84 | 87 | if (errorCodeDO == null) { |
| 85 | - errorCodeDO = ErrorCodeConvert.INSTANCE.convert(autoGenerateBO) | |
| 88 | + errorCodeDO = ErrorCodeConvert.INSTANCE.convert(autoGenerateDTO) | |
| 86 | 89 | .setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); |
| 87 | 90 | errorCodeMapper.insert(errorCodeDO); |
| 88 | 91 | return; |
| ... | ... | @@ -93,23 +96,23 @@ public class ErrorCodeService { |
| 93 | 96 | return; |
| 94 | 97 | } |
| 95 | 98 | // 条件 2. 分组 group 必须匹配,避免存在错误码冲突的情况 |
| 96 | - if (!autoGenerateBO.getGroup().equals(errorCodeDO.getGroup())) { | |
| 99 | + if (!autoGenerateDTO.getGroup().equals(errorCodeDO.getGroup())) { | |
| 97 | 100 | log.error("[autoGenerateErrorCodes][自动创建({}/{}) 错误码失败,数据库中已经存在({}/{})]", |
| 98 | - autoGenerateBO.getCode(), autoGenerateBO.getGroup(), | |
| 101 | + autoGenerateDTO.getCode(), autoGenerateDTO.getGroup(), | |
| 99 | 102 | errorCodeDO.getCode(), errorCodeDO.getGroup()); |
| 100 | 103 | return; |
| 101 | 104 | } |
| 102 | 105 | // 条件 3. 错误提示语存在差异 |
| 103 | - if (autoGenerateBO.getMessage().equals(errorCodeDO.getMessage())) { | |
| 106 | + if (autoGenerateDTO.getMessage().equals(errorCodeDO.getMessage())) { | |
| 104 | 107 | return; |
| 105 | 108 | } |
| 106 | 109 | // 最终匹配,进行更新 |
| 107 | - errorCodeMapper.updateById(new ErrorCodeDO().setId(errorCodeDO.getId()).setMessage(autoGenerateBO.getMessage())); | |
| 110 | + errorCodeMapper.updateById(new ErrorCodeDO().setId(errorCodeDO.getId()).setMessage(autoGenerateDTO.getMessage())); | |
| 108 | 111 | }); |
| 109 | 112 | } |
| 110 | 113 | |
| 111 | - public CommonResult<Boolean> autoGenerateErrorCodes1(@Valid List<ErrorCodeAutoGenerateBO> autoGenerateBOs) { | |
| 112 | - autoGenerateErrorCodes(autoGenerateBOs); | |
| 114 | + public CommonResult<Boolean> autoGenerateErrorCodes1(@Valid List<ErrorCodeAutoGenerateDTO> autoGenerateDTOs) { | |
| 115 | + autoGenerateErrorCodes(autoGenerateDTOs); | |
| 113 | 116 | return success(Boolean.TRUE); |
| 114 | 117 | } |
| 115 | 118 | |
| ... | ... | @@ -134,7 +137,7 @@ public class ErrorCodeService { |
| 134 | 137 | * @param errorCodeId 错误码编号 |
| 135 | 138 | * @return 错误码 |
| 136 | 139 | */ |
| 137 | - public ErrorCodeBO getErrorCode(Integer errorCodeId) { | |
| 140 | + public ErrorCodeVO getErrorCode(Integer errorCodeId) { | |
| 138 | 141 | ErrorCodeDO errorCodeDO = errorCodeMapper.selectById(errorCodeId); |
| 139 | 142 | return ErrorCodeConvert.INSTANCE.convert(errorCodeDO); |
| 140 | 143 | } |
| ... | ... | @@ -145,7 +148,7 @@ public class ErrorCodeService { |
| 145 | 148 | * @param errorCodeIds 错误码编号列表 |
| 146 | 149 | * @return 错误码列表 |
| 147 | 150 | */ |
| 148 | - public List<ErrorCodeBO> listErrorCodes(List<Integer> errorCodeIds) { | |
| 151 | + public List<ErrorCodeVO> listErrorCodes(List<Integer> errorCodeIds) { | |
| 149 | 152 | List<ErrorCodeDO> errorCodeDOs = errorCodeMapper.selectBatchIds(errorCodeIds); |
| 150 | 153 | return ErrorCodeConvert.INSTANCE.convertList(errorCodeDOs); |
| 151 | 154 | } |
| ... | ... | @@ -153,11 +156,11 @@ public class ErrorCodeService { |
| 153 | 156 | /** |
| 154 | 157 | * 获得错误码分页 |
| 155 | 158 | * |
| 156 | - * @param pageBO 错误码分页查询 | |
| 159 | + * @param pageDTO 错误码分页查询 | |
| 157 | 160 | * @return 错误码分页结果 |
| 158 | 161 | */ |
| 159 | - public PageResult<ErrorCodeBO> pageErrorCode(ErrorCodePageBO pageBO) { | |
| 160 | - IPage<ErrorCodeDO> errorCodeDOPage = errorCodeMapper.selectPage(pageBO); | |
| 162 | + public PageResult<ErrorCodeVO> pageErrorCode(ErrorCodePageDTO pageDTO) { | |
| 163 | + IPage<ErrorCodeDO> errorCodeDOPage = errorCodeMapper.selectPage(pageDTO); | |
| 161 | 164 | return ErrorCodeConvert.INSTANCE.convertPage(errorCodeDOPage); |
| 162 | 165 | } |
| 163 | 166 | |
| ... | ... | @@ -183,15 +186,14 @@ public class ErrorCodeService { |
| 183 | 186 | } |
| 184 | 187 | } |
| 185 | 188 | |
| 186 | - public List<ErrorCodeBO> listErrorCodes(String group, Date minUpdateTime) { | |
| 189 | + public List<ErrorCodeVO> listErrorCodes(String group, Date minUpdateTime) { | |
| 187 | 190 | List<ErrorCodeDO> errorCodeDOs = errorCodeMapper.selectListByGroup(group, minUpdateTime); |
| 188 | 191 | return ErrorCodeConvert.INSTANCE.convertList(errorCodeDOs); |
| 189 | 192 | } |
| 190 | 193 | |
| 191 | 194 | public CommonResult<List<ErrorCodeVO>> listErrorCodes1(String group, Date minUpdateTime) { |
| 192 | 195 | List<ErrorCodeDO> errorCodeDOs = errorCodeMapper.selectListByGroup(group, minUpdateTime); |
| 193 | - final List<ErrorCodeBO> errorCodeBOS = ErrorCodeConvert.INSTANCE.convertList(errorCodeDOs); | |
| 194 | - return success(ErrorCodeConvert.INSTANCE.convertList02(errorCodeBOS)); | |
| 196 | + return success(ErrorCodeConvert.INSTANCE.convertList(errorCodeDOs)); | |
| 195 | 197 | } |
| 196 | 198 | |
| 197 | 199 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/errorcode/bo/ErrorCodeAutoGenerateBO.java deleted
| 1 | -package cn.iocoder.dashboard.modules.system.service.errorcode.bo; | |
| 2 | - | |
| 3 | -import lombok.Data; | |
| 4 | -import lombok.experimental.Accessors; | |
| 5 | - | |
| 6 | -import javax.validation.constraints.NotEmpty; | |
| 7 | -import javax.validation.constraints.NotNull; | |
| 8 | -import java.io.Serializable; | |
| 9 | - | |
| 10 | -/** | |
| 11 | - * 错误码自动生成 BO | |
| 12 | - */ | |
| 13 | -@Data | |
| 14 | -@Accessors(chain = true) | |
| 15 | -public class ErrorCodeAutoGenerateBO implements Serializable { | |
| 16 | - | |
| 17 | - /** | |
| 18 | - * 错误码编码 | |
| 19 | - */ | |
| 20 | - @NotNull(message = "错误码编码不能为空") | |
| 21 | - private Integer code; | |
| 22 | - /** | |
| 23 | - * 错误码错误提示 | |
| 24 | - */ | |
| 25 | - @NotEmpty(message = "错误码错误提示不能为空") | |
| 26 | - private String message; | |
| 27 | - /** | |
| 28 | - * 错误码分组 | |
| 29 | - */ | |
| 30 | - @NotNull(message = "错误码分组不能为空") | |
| 31 | - private String group; | |
| 32 | - | |
| 33 | -} | |
| 34 | 0 | \ No newline at end of file |
src/main/java/cn/iocoder/dashboard/modules/system/service/errorcode/bo/ErrorCodeBO.java deleted
| 1 | -package cn.iocoder.dashboard.modules.system.service.errorcode.bo; | |
| 2 | - | |
| 3 | -import lombok.Data; | |
| 4 | -import lombok.experimental.Accessors; | |
| 5 | - | |
| 6 | -import java.util.Date; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * 错误码 BO | |
| 10 | - */ | |
| 11 | -@Data | |
| 12 | -@Accessors(chain = true) | |
| 13 | -public class ErrorCodeBO { | |
| 14 | - | |
| 15 | - /** | |
| 16 | - * 错误码编号 | |
| 17 | - */ | |
| 18 | - private Integer id; | |
| 19 | - /** | |
| 20 | - * 错误码编码 | |
| 21 | - */ | |
| 22 | - private Integer code; | |
| 23 | - /** | |
| 24 | - * 错误码错误提示 | |
| 25 | - */ | |
| 26 | - private String message; | |
| 27 | - /** | |
| 28 | - * 错误码类型 | |
| 29 | - */ | |
| 30 | - private Integer type; | |
| 31 | - /** | |
| 32 | - * 错误码分组 | |
| 33 | - */ | |
| 34 | - private String group; | |
| 35 | - /** | |
| 36 | - * 错误码备注 | |
| 37 | - */ | |
| 38 | - private String memo; | |
| 39 | - /** | |
| 40 | - * 创建时间 | |
| 41 | - */ | |
| 42 | - private Date createTime; | |
| 43 | - /** | |
| 44 | - * 最后更新时间 | |
| 45 | - */ | |
| 46 | - private Date updateTime; | |
| 47 | - | |
| 48 | -} | |
| 49 | 0 | \ No newline at end of file |
src/main/java/cn/iocoder/dashboard/modules/system/service/errorcode/bo/ErrorCodeCreateBO.java deleted
| 1 | -package cn.iocoder.dashboard.modules.system.service.errorcode.bo; | |
| 2 | - | |
| 3 | -import lombok.Data; | |
| 4 | -import lombok.experimental.Accessors; | |
| 5 | - | |
| 6 | -import javax.validation.constraints.NotEmpty; | |
| 7 | -import javax.validation.constraints.NotNull; | |
| 8 | - | |
| 9 | -@Data | |
| 10 | -@Accessors(chain = true) | |
| 11 | -public class ErrorCodeCreateBO { | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * 错误码编码 | |
| 15 | - */ | |
| 16 | - @NotNull(message = "错误码编码不能为空") | |
| 17 | - private Integer code; | |
| 18 | - /** | |
| 19 | - * 错误码错误提示 | |
| 20 | - */ | |
| 21 | - @NotEmpty(message = "错误码错误提示不能为空") | |
| 22 | - private String message; | |
| 23 | - /** | |
| 24 | - * 错误码类型 | |
| 25 | - */ | |
| 26 | - @NotNull(message = "错误码类型不能为空") | |
| 27 | - private Integer type; | |
| 28 | - /** | |
| 29 | - * 错误码分组 | |
| 30 | - */ | |
| 31 | - private String group; | |
| 32 | - /** | |
| 33 | - * 错误码备注 | |
| 34 | - */ | |
| 35 | - private String memo; | |
| 36 | -} |
src/main/java/cn/iocoder/dashboard/modules/system/service/errorcode/bo/ErrorCodePageBO.java deleted
| 1 | -package cn.iocoder.dashboard.modules.system.service.errorcode.bo; | |
| 2 | - | |
| 3 | -import cn.iocoder.dashboard.common.pojo.PageParam; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | -import lombok.experimental.Accessors; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * 错误码分页 BO | |
| 10 | - */ | |
| 11 | -@Data | |
| 12 | -@EqualsAndHashCode(callSuper = true) | |
| 13 | -@Accessors(chain = true) | |
| 14 | -public class ErrorCodePageBO extends PageParam { | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * 错误码编码 | |
| 18 | - */ | |
| 19 | - private Integer code; | |
| 20 | - /** | |
| 21 | - * 错误码错误提示 | |
| 22 | - */ | |
| 23 | - private String message; | |
| 24 | - /** | |
| 25 | - * 错误码分组 | |
| 26 | - */ | |
| 27 | - private String group; | |
| 28 | - | |
| 29 | -} | |
| 30 | 0 | \ No newline at end of file |
src/main/java/cn/iocoder/dashboard/modules/system/service/errorcode/bo/ErrorCodeUpdateBO.java deleted
| 1 | -package cn.iocoder.dashboard.modules.system.service.errorcode.bo; | |
| 2 | - | |
| 3 | -import lombok.Data; | |
| 4 | -import lombok.experimental.Accessors; | |
| 5 | - | |
| 6 | -import javax.validation.constraints.NotEmpty; | |
| 7 | -import javax.validation.constraints.NotNull; | |
| 8 | - | |
| 9 | -/** | |
| 10 | - * 错误码更新 BO | |
| 11 | - */ | |
| 12 | -@Data | |
| 13 | -@Accessors(chain = true) | |
| 14 | -public class ErrorCodeUpdateBO { | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * 错误码编号 | |
| 18 | - */ | |
| 19 | - @NotNull(message = "错误码编号不能为空") | |
| 20 | - private Integer id; | |
| 21 | - /** | |
| 22 | - * 错误码编码 | |
| 23 | - */ | |
| 24 | - @NotNull(message = "错误码编码不能为空") | |
| 25 | - private Integer code; | |
| 26 | - /** | |
| 27 | - * 错误码错误提示 | |
| 28 | - */ | |
| 29 | - @NotEmpty(message = "错误码错误提示不能为空") | |
| 30 | - private String message; | |
| 31 | - /** | |
| 32 | - * 错误码类型 | |
| 33 | - */ | |
| 34 | - @NotNull(message = "错误码类型不能为空") | |
| 35 | - private Integer type; | |
| 36 | - /** | |
| 37 | - * 错误码分组 | |
| 38 | - */ | |
| 39 | - private String group; | |
| 40 | - /** | |
| 41 | - * 错误码备注 | |
| 42 | - */ | |
| 43 | - private String memo; | |
| 44 | - | |
| 45 | -} | |
| 46 | 0 | \ No newline at end of file |
src/main/resources/application.yaml
| ... | ... | @@ -33,6 +33,7 @@ mybatis-plus: |
| 33 | 33 | mapper-locations: classpath*:mapper/*.xml |
| 34 | 34 | type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject |
| 35 | 35 | |
| 36 | -ruoyi: | |
| 36 | +yudao: | |
| 37 | 37 | error-code: |
| 38 | 38 | group: test1 |
| 39 | + constantsClass: cn.iocoder.dashboard.common.exception.enums.GlobalErrorCodeConstants | ... | ... |