Commit 3580b416bca557bc15caec9d0723ec979410ad99
1 parent
06774a7a
完成 error code 的自动创建和刷新机制
Showing
9 changed files
with
89 additions
and
83 deletions
src/main/java/cn/iocoder/dashboard/framework/errorcode/config/ErrorCodeAutoConfiguration.java renamed to src/main/java/cn/iocoder/dashboard/framework/errorcode/config/ErrorCodeConfiguration.java
| ... | ... | @@ -17,13 +17,13 @@ import org.springframework.scheduling.annotation.EnableScheduling; |
| 17 | 17 | @Configuration |
| 18 | 18 | @EnableConfigurationProperties(ErrorCodeProperties.class) |
| 19 | 19 | @EnableScheduling // 开启调度任务的功能,因为 ErrorCodeRemoteLoader 通过定时刷新错误码 |
| 20 | -public class ErrorCodeAutoConfiguration { | |
| 20 | +public class ErrorCodeConfiguration { | |
| 21 | 21 | |
| 22 | 22 | @Bean |
| 23 | 23 | public ErrorCodeAutoGenerator errorCodeAutoGenerator(@Value("${spring.application.name}") String applicationName, |
| 24 | 24 | ErrorCodeProperties errorCodeProperties, |
| 25 | 25 | ErrorCodeFrameworkService errorCodeFrameworkService) { |
| 26 | - return new ErrorCodeAutoGeneratorImpl(applicationName, errorCodeProperties.getConstantsClass(), | |
| 26 | + return new ErrorCodeAutoGeneratorImpl(applicationName, errorCodeProperties.getConstantsClassList(), | |
| 27 | 27 | errorCodeFrameworkService); |
| 28 | 28 | } |
| 29 | 29 | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/errorcode/config/ErrorCodeProperties.java
| ... | ... | @@ -4,7 +4,8 @@ import lombok.Data; |
| 4 | 4 | import org.springframework.boot.context.properties.ConfigurationProperties; |
| 5 | 5 | import org.springframework.validation.annotation.Validated; |
| 6 | 6 | |
| 7 | -import javax.validation.constraints.NotEmpty; | |
| 7 | +import javax.validation.constraints.NotNull; | |
| 8 | +import java.util.List; | |
| 8 | 9 | |
| 9 | 10 | /** |
| 10 | 11 | * 错误码的配置属性类 |
| ... | ... | @@ -19,7 +20,7 @@ public class ErrorCodeProperties { |
| 19 | 20 | /** |
| 20 | 21 | * 错误码枚举类 |
| 21 | 22 | */ |
| 22 | - @NotEmpty(message = "错误码枚举类不能为空") | |
| 23 | - private String constantsClass; | |
| 23 | + @NotNull(message = "错误码枚举类不能为空") | |
| 24 | + private List<String> constantsClassList; | |
| 24 | 25 | |
| 25 | 26 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/errorcode/core/generator/ErrorCodeAutoGeneratorImpl.java
| 1 | 1 | package cn.iocoder.dashboard.framework.errorcode.core.generator; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.util.ClassUtil; | |
| 5 | +import cn.hutool.core.util.ReflectUtil; | |
| 3 | 6 | import cn.iocoder.dashboard.common.exception.ErrorCode; |
| 4 | 7 | import cn.iocoder.dashboard.framework.errorcode.core.dto.ErrorCodeAutoGenerateReqDTO; |
| 5 | 8 | import cn.iocoder.dashboard.framework.errorcode.core.service.ErrorCodeFrameworkService; |
| ... | ... | @@ -8,7 +11,6 @@ import lombok.extern.slf4j.Slf4j; |
| 8 | 11 | import org.springframework.boot.context.event.ApplicationReadyEvent; |
| 9 | 12 | import org.springframework.context.event.EventListener; |
| 10 | 13 | import org.springframework.scheduling.annotation.Async; |
| 11 | -import org.springframework.util.StringUtils; | |
| 12 | 14 | |
| 13 | 15 | import java.util.ArrayList; |
| 14 | 16 | import java.util.Arrays; |
| ... | ... | @@ -16,7 +18,7 @@ import java.util.List; |
| 16 | 18 | |
| 17 | 19 | /** |
| 18 | 20 | * ErrorCodeAutoGenerator 的实现类 |
| 19 | - * 目的是,扫描指定的 {@link #errorCodeConstantsClass} 类,写入到 system 的数据库中 | |
| 21 | + * 目的是,扫描指定的 {@link #constantsClassList} 类,写入到 infra 服务中 | |
| 20 | 22 | * |
| 21 | 23 | * @author dylan |
| 22 | 24 | */ |
| ... | ... | @@ -31,7 +33,7 @@ public class ErrorCodeAutoGeneratorImpl implements ErrorCodeAutoGenerator { |
| 31 | 33 | /** |
| 32 | 34 | * 错误码枚举类 |
| 33 | 35 | */ |
| 34 | - private final String errorCodeConstantsClass; | |
| 36 | + private final List<String> constantsClassList; | |
| 35 | 37 | /** |
| 36 | 38 | * 错误码 Service |
| 37 | 39 | */ |
| ... | ... | @@ -41,38 +43,36 @@ public class ErrorCodeAutoGeneratorImpl implements ErrorCodeAutoGenerator { |
| 41 | 43 | @EventListener(ApplicationReadyEvent.class) |
| 42 | 44 | @Async // 异步,保证项目的启动过程,毕竟非关键流程 |
| 43 | 45 | public void execute() { |
| 44 | - // 第一步,获得错误码类 | |
| 45 | - Class<?> errorCodeConstantsClazz = parseErrorCodeConstantsClass(); | |
| 46 | - if (errorCodeConstantsClazz == null) { | |
| 47 | - return; | |
| 48 | - } | |
| 49 | - | |
| 50 | - // 第二步,获得错误码数组 | |
| 51 | - List<ErrorCodeAutoGenerateReqDTO> autoGenerateDTOs = parseErrorCode(errorCodeConstantsClazz); | |
| 46 | + // 第一步,解析错误码 | |
| 47 | + List<ErrorCodeAutoGenerateReqDTO> autoGenerateDTOs = parseErrorCode(); | |
| 52 | 48 | log.info("[execute][解析到错误码数量为 ({}) 个]", autoGenerateDTOs.size()); |
| 53 | 49 | |
| 54 | - // 第三步,写入到 system 的数据库 | |
| 50 | + // 第二步,写入到 infra 服务 | |
| 55 | 51 | errorCodeService.autoGenerateErrorCodes(autoGenerateDTOs); |
| 56 | - log.info("[execute][写入到 system 组件完成]"); | |
| 52 | + log.info("[execute][写入到 infra 组件完成]"); | |
| 57 | 53 | } |
| 58 | 54 | |
| 59 | 55 | /** |
| 60 | - * 解析 errorCodeConstantsClass 变量,获得错误码类 | |
| 56 | + * 解析 constantsClassList 变量,转换成错误码数组 | |
| 61 | 57 | * |
| 62 | - * @return 错误码类 | |
| 58 | + * @return 错误码数组 | |
| 63 | 59 | */ |
| 64 | - private Class<?> parseErrorCodeConstantsClass() { | |
| 60 | + private List<ErrorCodeAutoGenerateReqDTO> parseErrorCode() { | |
| 65 | 61 | // 校验 errorCodeConstantsClass 参数 |
| 66 | - if (!StringUtils.hasText(errorCodeConstantsClass)) { | |
| 67 | - log.info("[execute][未配置 yudao.error-code.constants-class 配置项,不进行自动写入到当前服务中]"); | |
| 68 | - return null; | |
| 69 | - } | |
| 70 | - try { | |
| 71 | - return Class.forName(errorCodeConstantsClass); | |
| 72 | - } catch (ClassNotFoundException e) { | |
| 73 | - log.error("[execute][配置的 ({}) 找不到对应的类]", errorCodeConstantsClass); | |
| 74 | - return null; | |
| 62 | + if (CollUtil.isEmpty(constantsClassList)) { | |
| 63 | + log.info("[execute][未配置 yudao.error-code.constants-class-list 配置项,不进行自动写入到 infra 服务中]"); | |
| 64 | + return new ArrayList<>(); | |
| 75 | 65 | } |
| 66 | + | |
| 67 | + // 解析错误码 | |
| 68 | + List<ErrorCodeAutoGenerateReqDTO> autoGenerateDTOs = new ArrayList<>(); | |
| 69 | + constantsClassList.forEach(constantsClass -> { | |
| 70 | + // 解析错误码枚举类 | |
| 71 | + Class<?> errorCodeConstantsClazz = ClassUtil.loadClass(constantsClass); | |
| 72 | + // 解析错误码 | |
| 73 | + autoGenerateDTOs.addAll(parseErrorCode(errorCodeConstantsClazz)); | |
| 74 | + }); | |
| 75 | + return autoGenerateDTOs; | |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| ... | ... | @@ -80,19 +80,16 @@ public class ErrorCodeAutoGeneratorImpl implements ErrorCodeAutoGenerator { |
| 80 | 80 | * |
| 81 | 81 | * @return 错误码数组 |
| 82 | 82 | */ |
| 83 | - private List<ErrorCodeAutoGenerateReqDTO> parseErrorCode(Class<?> errorCodeConstantsClazz) { | |
| 83 | + private List<ErrorCodeAutoGenerateReqDTO> parseErrorCode(Class<?> constantsClass) { | |
| 84 | 84 | List<ErrorCodeAutoGenerateReqDTO> autoGenerateDTOs = new ArrayList<>(); |
| 85 | - Arrays.stream(errorCodeConstantsClazz.getFields()).forEach(field -> { | |
| 85 | + Arrays.stream(constantsClass.getFields()).forEach(field -> { | |
| 86 | 86 | if (field.getType() != ErrorCode.class) { |
| 87 | 87 | return; |
| 88 | 88 | } |
| 89 | - try { | |
| 90 | - ErrorCode errorCode = (ErrorCode) field.get(errorCodeConstantsClazz); | |
| 91 | - autoGenerateDTOs.add(new ErrorCodeAutoGenerateReqDTO().setApplicationName(applicationName) | |
| 92 | - .setCode(errorCode.getCode()).setMessage(errorCode.getMsg())); | |
| 93 | - } catch (IllegalAccessException e) { | |
| 94 | - throw new RuntimeException(e); | |
| 95 | - } | |
| 89 | + // 转换成 ErrorCodeAutoGenerateReqDTO 对象 | |
| 90 | + ErrorCode errorCode = (ErrorCode) ReflectUtil.getFieldValue(constantsClass, field); | |
| 91 | + autoGenerateDTOs.add(new ErrorCodeAutoGenerateReqDTO().setApplicationName(applicationName) | |
| 92 | + .setCode(errorCode.getCode()).setMessage(errorCode.getMsg())); | |
| 96 | 93 | }); |
| 97 | 94 | return autoGenerateDTOs; |
| 98 | 95 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/errorcode/core/loader/ErrorCodeLoaderImpl.java
src/main/java/cn/iocoder/dashboard/modules/system/convert/errorcode/SysErrorCodeConvert.java renamed to src/main/java/cn/iocoder/dashboard/modules/infra/convert/errorcode/SysErrorCodeConvert.java
| 1 | -package cn.iocoder.dashboard.modules.system.convert.errorcode; | |
| 1 | +package cn.iocoder.dashboard.modules.infra.convert.errorcode; | |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.dashboard.framework.errorcode.core.dto.ErrorCodeAutoGenerateReqDTO; |
| ... | ... | @@ -6,7 +6,7 @@ import cn.iocoder.dashboard.framework.errorcode.core.dto.ErrorCodeRespDTO; |
| 6 | 6 | import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodeCreateDTO; |
| 7 | 7 | import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodeUpdateDTO; |
| 8 | 8 | import cn.iocoder.dashboard.modules.system.controller.errorcode.vo.ErrorCodeVO; |
| 9 | -import cn.iocoder.dashboard.modules.system.dal.dataobject.errorcode.ErrorCodeDO; | |
| 9 | +import cn.iocoder.dashboard.modules.infra.dal.dataobject.errorcode.InfErrorCodeDO; | |
| 10 | 10 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| 11 | 11 | import org.mapstruct.Mapper; |
| 12 | 12 | import org.mapstruct.Mapping; |
| ... | ... | @@ -20,19 +20,19 @@ public interface SysErrorCodeConvert { |
| 20 | 20 | |
| 21 | 21 | SysErrorCodeConvert INSTANCE = Mappers.getMapper(SysErrorCodeConvert.class); |
| 22 | 22 | |
| 23 | - ErrorCodeVO convert (ErrorCodeDO bean); | |
| 23 | + ErrorCodeVO convert (InfErrorCodeDO bean); | |
| 24 | 24 | |
| 25 | - List<ErrorCodeVO> convertList(List<ErrorCodeDO> list); | |
| 25 | + List<ErrorCodeVO> convertList(List<InfErrorCodeDO> list); | |
| 26 | 26 | |
| 27 | 27 | @Mapping(source = "records", target = "list") |
| 28 | - PageResult<ErrorCodeVO> convertPage(IPage<ErrorCodeDO> page); | |
| 28 | + PageResult<ErrorCodeVO> convertPage(IPage<InfErrorCodeDO> page); | |
| 29 | 29 | |
| 30 | - ErrorCodeDO convert (ErrorCodeCreateDTO bean); | |
| 30 | + InfErrorCodeDO convert (ErrorCodeCreateDTO bean); | |
| 31 | 31 | |
| 32 | - ErrorCodeDO convert (ErrorCodeUpdateDTO bean); | |
| 32 | + InfErrorCodeDO convert (ErrorCodeUpdateDTO bean); | |
| 33 | 33 | |
| 34 | - ErrorCodeDO convert(ErrorCodeAutoGenerateReqDTO bean); | |
| 34 | + InfErrorCodeDO convert(ErrorCodeAutoGenerateReqDTO bean); | |
| 35 | 35 | |
| 36 | - List<ErrorCodeRespDTO> convertList02(List<ErrorCodeDO> list); | |
| 36 | + List<ErrorCodeRespDTO> convertList02(List<InfErrorCodeDO> list); | |
| 37 | 37 | |
| 38 | 38 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/errorcode/ErrorCodeDO.java renamed to src/main/java/cn/iocoder/dashboard/modules/infra/dal/dataobject/errorcode/InfErrorCodeDO.java
| 1 | -package cn.iocoder.dashboard.modules.system.dal.dataobject.errorcode; | |
| 1 | +package cn.iocoder.dashboard.modules.infra.dal.dataobject.errorcode; | |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; |
| 4 | 4 | import cn.iocoder.dashboard.modules.system.enums.errorcode.SysErrorCodeTypeEnum; |
| ... | ... | @@ -8,17 +8,22 @@ import lombok.Data; |
| 8 | 8 | import lombok.EqualsAndHashCode; |
| 9 | 9 | import lombok.ToString; |
| 10 | 10 | |
| 11 | -@TableName(value = "sys_error_code") | |
| 11 | +/** | |
| 12 | + * 错误码表 | |
| 13 | + * | |
| 14 | + * @author 芋道源码 | |
| 15 | + */ | |
| 16 | +@TableName(value = "inf_error_code") | |
| 12 | 17 | @Data |
| 13 | 18 | @EqualsAndHashCode(callSuper = true) |
| 14 | 19 | @ToString(callSuper = true) |
| 15 | -public class ErrorCodeDO extends BaseDO { | |
| 20 | +public class InfErrorCodeDO extends BaseDO { | |
| 16 | 21 | |
| 17 | 22 | /** |
| 18 | - * 错误码编号 | |
| 23 | + * 错误码编号,自增 | |
| 19 | 24 | */ |
| 20 | 25 | @TableId |
| 21 | - private Integer id; | |
| 26 | + private Long id; | |
| 22 | 27 | /** |
| 23 | 28 | * 错误码类型 |
| 24 | 29 | * | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/errorcode/ErrorCodeMapper.java renamed to src/main/java/cn/iocoder/dashboard/modules/infra/dal/mysql/errorcode/InfErrorCodeMapper.java
| 1 | -package cn.iocoder.dashboard.modules.system.dal.mysql.errorcode; | |
| 1 | +package cn.iocoder.dashboard.modules.infra.dal.mysql.errorcode; | |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; |
| 4 | 4 | import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodePageDTO; |
| 5 | -import cn.iocoder.dashboard.modules.system.dal.dataobject.errorcode.ErrorCodeDO; | |
| 5 | +import cn.iocoder.dashboard.modules.infra.dal.dataobject.errorcode.InfErrorCodeDO; | |
| 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; |
| ... | ... | @@ -14,24 +14,24 @@ import java.util.Date; |
| 14 | 14 | import java.util.List; |
| 15 | 15 | |
| 16 | 16 | @Mapper |
| 17 | -public interface ErrorCodeMapper extends BaseMapper<ErrorCodeDO> { | |
| 17 | +public interface InfErrorCodeMapper extends BaseMapper<InfErrorCodeDO> { | |
| 18 | 18 | |
| 19 | - default IPage<ErrorCodeDO> selectPage(ErrorCodePageDTO pageDTO) { | |
| 19 | + default IPage<InfErrorCodeDO> selectPage(ErrorCodePageDTO pageDTO) { | |
| 20 | 20 | return selectPage(new Page<>(pageDTO.getPageNo(), pageDTO.getPageSize()), |
| 21 | - new QueryWrapperX<ErrorCodeDO>().likeIfPresent("`group`", pageDTO.getGroup()) | |
| 21 | + new QueryWrapperX<InfErrorCodeDO>().likeIfPresent("`group`", pageDTO.getGroup()) | |
| 22 | 22 | .eqIfPresent("code", pageDTO.getCode()).likeIfPresent("message", pageDTO.getMessage())); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - default List<ErrorCodeDO> selectListByCodes(Collection<Integer> codes) { | |
| 26 | - return selectList(new QueryWrapper<ErrorCodeDO>().in("code", codes)); | |
| 25 | + default List<InfErrorCodeDO> selectListByCodes(Collection<Integer> codes) { | |
| 26 | + return selectList(new QueryWrapper<InfErrorCodeDO>().in("code", codes)); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - default ErrorCodeDO selectByCode(Integer code) { | |
| 30 | - return selectOne(new QueryWrapper<ErrorCodeDO>().eq("code", code)); | |
| 29 | + default InfErrorCodeDO selectByCode(Integer code) { | |
| 30 | + return selectOne(new QueryWrapper<InfErrorCodeDO>().eq("code", code)); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - default List<ErrorCodeDO> selectListByApplicationNameAndUpdateTimeGt(String applicationName, Date minUpdateTime) { | |
| 34 | - return selectList(new QueryWrapperX<ErrorCodeDO>().eq("application_name", applicationName) | |
| 33 | + default List<InfErrorCodeDO> selectListByApplicationNameAndUpdateTimeGt(String applicationName, Date minUpdateTime) { | |
| 34 | + return selectList(new QueryWrapperX<InfErrorCodeDO>().eq("application_name", applicationName) | |
| 35 | 35 | .gtIfPresent("update_time", minUpdateTime)); |
| 36 | 36 | } |
| 37 | 37 | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/errorcode/impl/ErrorCodeServiceImpl.java
| ... | ... | @@ -9,9 +9,9 @@ import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodeCre |
| 9 | 9 | import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodePageDTO; |
| 10 | 10 | import cn.iocoder.dashboard.modules.system.controller.errorcode.dto.ErrorCodeUpdateDTO; |
| 11 | 11 | import cn.iocoder.dashboard.modules.system.controller.errorcode.vo.ErrorCodeVO; |
| 12 | -import cn.iocoder.dashboard.modules.system.convert.errorcode.SysErrorCodeConvert; | |
| 13 | -import cn.iocoder.dashboard.modules.system.dal.dataobject.errorcode.ErrorCodeDO; | |
| 14 | -import cn.iocoder.dashboard.modules.system.dal.mysql.errorcode.ErrorCodeMapper; | |
| 12 | +import cn.iocoder.dashboard.modules.infra.convert.errorcode.SysErrorCodeConvert; | |
| 13 | +import cn.iocoder.dashboard.modules.infra.dal.dataobject.errorcode.InfErrorCodeDO; | |
| 14 | +import cn.iocoder.dashboard.modules.infra.dal.mysql.errorcode.InfErrorCodeMapper; | |
| 15 | 15 | import cn.iocoder.dashboard.modules.system.enums.errorcode.SysErrorCodeTypeEnum; |
| 16 | 16 | import cn.iocoder.dashboard.modules.system.service.errorcode.SysErrorCodeService; |
| 17 | 17 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| ... | ... | @@ -39,7 +39,7 @@ import static cn.iocoder.dashboard.util.collection.CollectionUtils.convertSet; |
| 39 | 39 | public class ErrorCodeServiceImpl implements SysErrorCodeService { |
| 40 | 40 | |
| 41 | 41 | @Resource |
| 42 | - private ErrorCodeMapper errorCodeMapper; | |
| 42 | + private InfErrorCodeMapper errorCodeMapper; | |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * 创建错误码 |
| ... | ... | @@ -50,7 +50,7 @@ public class ErrorCodeServiceImpl implements SysErrorCodeService { |
| 50 | 50 | public ErrorCodeVO createErrorCode(ErrorCodeCreateDTO createDTO) { |
| 51 | 51 | checkDuplicateErrorCode(createDTO.getCode(), null); |
| 52 | 52 | // 插入到数据库 |
| 53 | - ErrorCodeDO errorCodeDO = SysErrorCodeConvert.INSTANCE.convert(createDTO); | |
| 53 | + InfErrorCodeDO errorCodeDO = SysErrorCodeConvert.INSTANCE.convert(createDTO); | |
| 54 | 54 | errorCodeMapper.insert(errorCodeDO); |
| 55 | 55 | // 返回 |
| 56 | 56 | return SysErrorCodeConvert.INSTANCE.convert(errorCodeDO); |
| ... | ... | @@ -68,7 +68,7 @@ public class ErrorCodeServiceImpl implements SysErrorCodeService { |
| 68 | 68 | throw ServiceExceptionUtil.exception(ERROR_CODE_NOT_EXISTS); |
| 69 | 69 | } |
| 70 | 70 | // 更新到数据库 |
| 71 | - ErrorCodeDO updateObject = SysErrorCodeConvert.INSTANCE.convert(updateDTO); | |
| 71 | + InfErrorCodeDO updateObject = SysErrorCodeConvert.INSTANCE.convert(updateDTO); | |
| 72 | 72 | errorCodeMapper.updateById(updateObject); |
| 73 | 73 | } |
| 74 | 74 | |
| ... | ... | @@ -93,7 +93,7 @@ public class ErrorCodeServiceImpl implements SysErrorCodeService { |
| 93 | 93 | * @return 错误码 |
| 94 | 94 | */ |
| 95 | 95 | public ErrorCodeVO getErrorCode(Integer errorCodeId) { |
| 96 | - ErrorCodeDO errorCodeDO = errorCodeMapper.selectById(errorCodeId); | |
| 96 | + InfErrorCodeDO errorCodeDO = errorCodeMapper.selectById(errorCodeId); | |
| 97 | 97 | return SysErrorCodeConvert.INSTANCE.convert(errorCodeDO); |
| 98 | 98 | } |
| 99 | 99 | |
| ... | ... | @@ -104,7 +104,7 @@ public class ErrorCodeServiceImpl implements SysErrorCodeService { |
| 104 | 104 | * @return 错误码列表 |
| 105 | 105 | */ |
| 106 | 106 | public List<ErrorCodeVO> listErrorCodes(List<Integer> errorCodeIds) { |
| 107 | - List<ErrorCodeDO> errorCodeDOs = errorCodeMapper.selectBatchIds(errorCodeIds); | |
| 107 | + List<InfErrorCodeDO> errorCodeDOs = errorCodeMapper.selectBatchIds(errorCodeIds); | |
| 108 | 108 | return SysErrorCodeConvert.INSTANCE.convertList(errorCodeDOs); |
| 109 | 109 | } |
| 110 | 110 | |
| ... | ... | @@ -115,7 +115,7 @@ public class ErrorCodeServiceImpl implements SysErrorCodeService { |
| 115 | 115 | * @return 错误码分页结果 |
| 116 | 116 | */ |
| 117 | 117 | public PageResult<ErrorCodeVO> pageErrorCode(ErrorCodePageDTO pageDTO) { |
| 118 | - IPage<ErrorCodeDO> errorCodeDOPage = errorCodeMapper.selectPage(pageDTO); | |
| 118 | + IPage<InfErrorCodeDO> errorCodeDOPage = errorCodeMapper.selectPage(pageDTO); | |
| 119 | 119 | return SysErrorCodeConvert.INSTANCE.convertPage(errorCodeDOPage); |
| 120 | 120 | } |
| 121 | 121 | |
| ... | ... | @@ -128,7 +128,7 @@ public class ErrorCodeServiceImpl implements SysErrorCodeService { |
| 128 | 128 | * @param id 错误码编号 |
| 129 | 129 | */ |
| 130 | 130 | private void checkDuplicateErrorCode(Integer code, Integer id) { |
| 131 | - ErrorCodeDO errorCodeDO = errorCodeMapper.selectByCode(code); | |
| 131 | + InfErrorCodeDO errorCodeDO = errorCodeMapper.selectByCode(code); | |
| 132 | 132 | if (errorCodeDO == null) { |
| 133 | 133 | return; |
| 134 | 134 | } |
| ... | ... | @@ -148,13 +148,13 @@ public class ErrorCodeServiceImpl implements SysErrorCodeService { |
| 148 | 148 | return; |
| 149 | 149 | } |
| 150 | 150 | // 获得错误码 |
| 151 | - List<ErrorCodeDO> errorCodeDOs = errorCodeMapper.selectListByCodes( | |
| 151 | + List<InfErrorCodeDO> errorCodeDOs = errorCodeMapper.selectListByCodes( | |
| 152 | 152 | convertSet(autoGenerateDTOs, ErrorCodeAutoGenerateReqDTO::getCode)); |
| 153 | - Map<Integer, ErrorCodeDO> errorCodeDOMap = convertMap(errorCodeDOs, ErrorCodeDO::getCode); | |
| 153 | + Map<Integer, InfErrorCodeDO> errorCodeDOMap = convertMap(errorCodeDOs, InfErrorCodeDO::getCode); | |
| 154 | 154 | |
| 155 | 155 | // 遍历 autoGenerateBOs 数组,逐个插入或更新。考虑到每次量级不大,就不走批量了 |
| 156 | 156 | autoGenerateDTOs.forEach(autoGenerateDTO -> { |
| 157 | - ErrorCodeDO errorCodeDO = errorCodeDOMap.get(autoGenerateDTO.getCode()); | |
| 157 | + InfErrorCodeDO errorCodeDO = errorCodeDOMap.get(autoGenerateDTO.getCode()); | |
| 158 | 158 | // 不存在,则进行新增 |
| 159 | 159 | if (errorCodeDO == null) { |
| 160 | 160 | errorCodeDO = SysErrorCodeConvert.INSTANCE.convert(autoGenerateDTO) |
| ... | ... | @@ -179,13 +179,13 @@ public class ErrorCodeServiceImpl implements SysErrorCodeService { |
| 179 | 179 | return; |
| 180 | 180 | } |
| 181 | 181 | // 最终匹配,进行更新 |
| 182 | - errorCodeMapper.updateById(new ErrorCodeDO().setId(errorCodeDO.getId()).setMessage(autoGenerateDTO.getMessage())); | |
| 182 | + errorCodeMapper.updateById(new InfErrorCodeDO().setId(errorCodeDO.getId()).setMessage(autoGenerateDTO.getMessage())); | |
| 183 | 183 | }); |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | @Override |
| 187 | 187 | public List<ErrorCodeRespDTO> getErrorCodeList(String applicationName, Date minUpdateTime) { |
| 188 | - List<ErrorCodeDO> errorCodeDOs = errorCodeMapper.selectListByApplicationNameAndUpdateTimeGt( | |
| 188 | + List<InfErrorCodeDO> errorCodeDOs = errorCodeMapper.selectListByApplicationNameAndUpdateTimeGt( | |
| 189 | 189 | applicationName, minUpdateTime); |
| 190 | 190 | return SysErrorCodeConvert.INSTANCE.convertList02(errorCodeDOs); |
| 191 | 191 | } | ... | ... |
src/main/resources/application.yaml
| ... | ... | @@ -33,7 +33,10 @@ mybatis-plus: |
| 33 | 33 | mapper-locations: classpath*:mapper/*.xml |
| 34 | 34 | type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject |
| 35 | 35 | |
| 36 | +--- #################### 芋道相关配置 #################### | |
| 37 | + | |
| 36 | 38 | yudao: |
| 37 | - error-code: | |
| 38 | - group: test1 | |
| 39 | - constantsClass: cn.iocoder.dashboard.common.exception.enums.GlobalErrorCodeConstants | |
| 39 | + error-code: # 错误码相关配置项 | |
| 40 | + constants-class-list: | |
| 41 | + - cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants | |
| 42 | + - cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants | ... | ... |