From 4293fde5adc867311ebfefd96d93602035d3f0b7 Mon Sep 17 00:00:00 2001 From: benpaodeyouyusi Date: Fri, 22 May 2020 15:42:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../convert/errorcode/ErrorCodeConvert.java | 7 +- .../biz/dao/errorcode/ErrorCodeMapper.java | 38 +++++++---- .../biz/dataobject/errorcode/ErrorCodeDO.java | 10 +++ .../biz/dto/errorcode/ErrorCodeAddDTO.java | 8 +++ .../dto/errorcode/ErrorCodeGetListDTO.java | 2 +- .../biz/dto/errorcode/ErrorCodePageDTO.java | 7 +- .../biz/dto/errorcode/ErrorCodeUpdateDTO.java | 14 +++- .../service/errorcode/ErrorCodeService.java | 21 ++++-- .../errorcode/ErrorCodeServiceImpl.java | 65 +++++++++---------- .../errorcode/ErrorCodeAddRequest.java | 8 +++ .../rpc/api/errorcode/ErrorCodeRPC.java | 12 +++- .../errorcode/ErrorCodeAddRequest.java | 33 ++++++++++ .../convert/errorcode/ErrorCodeConvert.java | 7 ++ .../rpc/rpc/errorcode/ErrorCodeRPCImpl.java | 43 +++++++++++- 14 files changed, 212 insertions(+), 63 deletions(-) create mode 100644 system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/errorcode/ErrorCodeAddRequest.java diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/errorcode/ErrorCodeConvert.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/errorcode/ErrorCodeConvert.java index 10eed4aab..279cb2a84 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/errorcode/ErrorCodeConvert.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/errorcode/ErrorCodeConvert.java @@ -1,11 +1,14 @@ package cn.iocoder.mall.system.biz.convert.errorcode; +import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.system.biz.bo.errorcode.ErrorCodeBO; import cn.iocoder.mall.system.biz.dataobject.errorcode.ErrorCodeDO; import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeAddDTO; import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeDTO; import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeUpdateDTO; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; import java.util.List; @@ -24,8 +27,8 @@ public interface ErrorCodeConvert { List convertList(List beans); -// @Mapping(source = "records", target = "list") -// PageResult convertPage(IPage page); + @Mapping(source = "records", target = "list") + PageResult convertPage(IPage page); ErrorCodeDO convert(ErrorCodeAddDTO bean); diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/errorcode/ErrorCodeMapper.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/errorcode/ErrorCodeMapper.java index 5d95a15e4..1fd45cc24 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/errorcode/ErrorCodeMapper.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/errorcode/ErrorCodeMapper.java @@ -1,12 +1,21 @@ package cn.iocoder.mall.system.biz.dao.errorcode; import cn.iocoder.mall.mybatis.query.QueryWrapperX; +import cn.iocoder.mall.system.biz.dataobject.authorization.RoleDO; import cn.iocoder.mall.system.biz.dataobject.errorcode.ErrorCodeDO; +import cn.iocoder.mall.system.biz.dto.authorization.RolePageDTO; +import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeDTO; +import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodePageDTO; import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum; import cn.iocoder.mall.system.biz.enums.errorcode.ErrorCodeTypeEnum; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.stereotype.Repository; +import java.util.Collection; +import java.util.List; + /** * @author ding */ @@ -14,18 +23,23 @@ import org.springframework.stereotype.Repository; public interface ErrorCodeMapper extends BaseMapper { default ErrorCodeDO selectByCode(Integer code){ - //从db查询 - ErrorCodeDO errorCodeDO = selectOne(new QueryWrapperX().eqIfPresent("code", code)); - if (null == errorCodeDO){ - //从enum查询 - for (SystemErrorCodeEnum item : SystemErrorCodeEnum.values()) { - if(code.equals(item.getCode())){ - return new ErrorCodeDO().setCode(item.getCode()). - setId(0).setType(ErrorCodeTypeEnum.SYSTEM.getType()); - } - } - } - return null; + return selectOne(new QueryWrapperX().eqIfPresent("code", code)); + } + default IPage selectPage(ErrorCodePageDTO errorCodePageDTO) { + return selectPage(new Page<>(errorCodePageDTO.getPageNo(), errorCodePageDTO.getPageSize()), + new QueryWrapperX().likeIfPresent("message", errorCodePageDTO.getMessage())); + } + + default List selectListByIds(Collection ids) { + return selectList(new QueryWrapperX().inIfPresent("id", ids)); + } + + default ErrorCodeDO selectByMessage(String message) { + return selectOne(new QueryWrapperX().eqIfPresent("message", message)); + } + + default List selectByGroup(Integer group) { + return selectList(new QueryWrapperX().eqIfPresent("group", group)); } } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/errorcode/ErrorCodeDO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/errorcode/ErrorCodeDO.java index 0ce8e3ce7..7e12dad65 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/errorcode/ErrorCodeDO.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/errorcode/ErrorCodeDO.java @@ -31,6 +31,16 @@ public class ErrorCodeDO extends DeletableDO { */ private Integer type; + /** + * 错误码分组 + */ + private Integer group; + + /** + * 错误码备注 + */ + private String remark; + // TODO FROM 芋艿 to 鱿鱼丝:增加一个分组字段。方便做归类 // TODO FROM 芋艿 to 鱿鱼丝:增加个备注字段,方便做备注哈。 diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodeAddDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodeAddDTO.java index 1e55ec16e..57618bd39 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodeAddDTO.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodeAddDTO.java @@ -18,4 +18,12 @@ public class ErrorCodeAddDTO { @NotEmpty(message = "错误码错误信息") private String message; + + @NotNull(message = "错误码分组id") + private Integer group; + + /** + * 错误码备注 + */ + private String remark; } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodeGetListDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodeGetListDTO.java index 02af2e5bb..bf9f01550 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodeGetListDTO.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodeGetListDTO.java @@ -17,5 +17,5 @@ public class ErrorCodeGetListDTO { * * 如果传入空,则不进行错误码编号的过滤 */ - private Collection codes; + private Collection ids; } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodePageDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodePageDTO.java index 9db3edd29..6ab7671f7 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodePageDTO.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodePageDTO.java @@ -1,10 +1,15 @@ package cn.iocoder.mall.system.biz.dto.errorcode; import cn.iocoder.common.framework.vo.PageParam; +import lombok.Data; /** * @author ding */ +@Data public class ErrorCodePageDTO extends PageParam { - + /** + * 错误码信息 + */ + private String message; } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodeUpdateDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodeUpdateDTO.java index f26ee519b..e07ecff0c 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodeUpdateDTO.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/errorcode/ErrorCodeUpdateDTO.java @@ -13,10 +13,8 @@ import javax.validation.constraints.NotNull; @Accessors(chain = true) public class ErrorCodeUpdateDTO { - /** - * 错误码编号,内置错误码的id是没有的 - */ // TODO FROM 芋艿 to 鱿鱼丝:必要的参数校验噢 + @NotNull(message = "错误码id不能为空") private Integer id; @NotNull(message = "错误码编码不能为空") @@ -29,4 +27,14 @@ public class ErrorCodeUpdateDTO { * 错误码类型 {@link ErrorCodeTypeEnum} */ private Integer type; + + /** + * 错误码分组 + */ + private Integer group; + + /** + * 错误码备注 + */ + private String remark; } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorcode/ErrorCodeService.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorcode/ErrorCodeService.java index 31c23a86d..9a355de6e 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorcode/ErrorCodeService.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorcode/ErrorCodeService.java @@ -2,17 +2,16 @@ package cn.iocoder.mall.system.biz.service.errorcode; import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.system.biz.bo.errorcode.ErrorCodeBO; -import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeAddDTO; -import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeDeleteDTO; -import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodePageDTO; -import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeUpdateDTO; +import cn.iocoder.mall.system.biz.dataobject.errorcode.ErrorCodeDO; +import cn.iocoder.mall.system.biz.dto.errorcode.*; +import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; /** * @author ding */ -public interface ErrorCodeService { +public interface ErrorCodeService extends IService{ /** * 根据code查询错误码 * @param code code @@ -24,13 +23,14 @@ public interface ErrorCodeService { * 从db取出错误码列表数据 * @return db错误码列表 */ - List getErrorCodeList(); + List getErrorCodeList(ErrorCodeGetListDTO errorCodeGetListDTO); /** * 取出所有错误码列表数据 + * @param group 分组标示 * @return 所有错误码列表 */ - List getErrorCodeListAll(); + List getErrorCodeByGroup(Integer group); /** * 分页取出所有错误码列表数据 @@ -46,6 +46,13 @@ public interface ErrorCodeService { */ Integer addErrorCode(ErrorCodeAddDTO errorCodeAddDTO); + /** + * 批量添加错误码信息 + * @param list 错误码集合 + * @return + */ + Boolean addErrorCodeList(List list); + /** * 更新错误码,系统内置错误码是不允许更新 * @param errorCodeUpdateDTO 错误码信息 diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorcode/ErrorCodeServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorcode/ErrorCodeServiceImpl.java index 192ea11ff..c41404780 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorcode/ErrorCodeServiceImpl.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorcode/ErrorCodeServiceImpl.java @@ -8,15 +8,15 @@ import cn.iocoder.mall.system.biz.bo.errorcode.ErrorCodeBO; import cn.iocoder.mall.system.biz.convert.errorcode.ErrorCodeConvert; import cn.iocoder.mall.system.biz.dao.errorcode.ErrorCodeMapper; import cn.iocoder.mall.system.biz.dataobject.errorcode.ErrorCodeDO; -import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeAddDTO; -import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeDeleteDTO; -import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodePageDTO; -import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeUpdateDTO; +import cn.iocoder.mall.system.biz.dto.errorcode.*; import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum; import cn.iocoder.mall.system.biz.enums.errorcode.ErrorCodeTypeEnum; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -24,7 +24,7 @@ import java.util.List; * @author ding */ @Service -public class ErrorCodeServiceImpl implements ErrorCodeService { +public class ErrorCodeServiceImpl extends ServiceImpl implements ErrorCodeService { @Autowired private ErrorCodeMapper errorCodeMapper; @@ -36,32 +36,23 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { } @Override - public List getErrorCodeList() { + public List getErrorCodeList(ErrorCodeGetListDTO errorCodeGetListDTO) { // TODO FROM 芋艿 to 鱿鱼丝:QueryWrapperX 只存在 mapper 里,不直接体现在 Service - List list = errorCodeMapper.selectList(new QueryWrapperX()); - return ErrorCodeConvert.INSTANCE.convertList(list); + return ErrorCodeConvert.INSTANCE.convertList(errorCodeMapper.selectListByIds(errorCodeGetListDTO.getIds())); } @Override - public List getErrorCodeListAll() { - List list = errorCodeMapper.selectList(new QueryWrapperX()); + public List getErrorCodeByGroup(Integer group) { + List list = errorCodeMapper.selectByGroup(group); // TODO FROM 芋艿 to 鱿鱼丝:这块微信交流一波哈。 - for (SystemErrorCodeEnum item : SystemErrorCodeEnum.values()) { - list.add(new ErrorCodeDO().setId(0).setCode(item.getCode()). - setMessage(item.getMessage()).setType(ErrorCodeTypeEnum.SYSTEM.getType())); - } return ErrorCodeConvert.INSTANCE.convertList(list); } @Override public PageResult getErrorCodePage(ErrorCodePageDTO pageDTO) { - List list = errorCodeMapper.selectList(new QueryWrapperX()); - for (SystemErrorCodeEnum item : SystemErrorCodeEnum.values()) { - list.add(new ErrorCodeDO().setId(0).setCode(item.getCode()). - setMessage(item.getMessage()).setType(ErrorCodeTypeEnum.SYSTEM.getType())); - } - return listToPageList(pageDTO.getPageNo(),pageDTO.getPageSize(),list); + IPage list = errorCodeMapper.selectPage(pageDTO); + return ErrorCodeConvert.INSTANCE.convertPage(list); } @Override @@ -70,7 +61,6 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { checkDuplicateErrorCode(errorCodeAddDTO.getCode(), null); // 保存到数据库 ErrorCodeDO errorCode = ErrorCodeConvert.INSTANCE.convert(errorCodeAddDTO); - errorCode.setType(ErrorCodeTypeEnum.CUSTOM.getType()); errorCode.setCreateTime(new Date()); errorCode.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); errorCodeMapper.insert(errorCode); @@ -79,6 +69,22 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { return errorCode.getId(); } + @Override + public Boolean addErrorCodeList(List list) { + List doList = new ArrayList<>(); + for (ErrorCodeAddDTO errorCodeAddDTO:list + ) { + // 校验错误码 + checkDuplicateErrorCode(errorCodeAddDTO.getCode(), null); + ErrorCodeDO errorCode = ErrorCodeConvert.INSTANCE.convert(errorCodeAddDTO); + errorCode.setCreateTime(new Date()); + errorCode.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); + doList.add(errorCode); + } + // TODO 插入操作日志 + return this.saveBatch(doList); + } + @Override public void updateErrorCode(ErrorCodeUpdateDTO errorCodeUpdateDTO) { // 校验错误码是否存在 @@ -105,6 +111,10 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { if (errorCodeDO == null) { throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ERROR_CODE_NOT_EXISTS); } + // 内置错误码,不允许删除 + if (ErrorCodeTypeEnum.SYSTEM.getType().equals(errorCodeDO.getType())) { + throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ERROR_CAN_NOT_UPDATE_SYSTEM_TYPE_ERROR); + } // TODO FROM 芋艿 to 鱿鱼丝:不能删除内置错误码 // 更新到数据库,标记删除 errorCodeMapper.deleteById(errorCodeDO.getId()); @@ -126,17 +136,4 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ERROR_CODE_DUPLICATE, errorCodeDO.getCode()); } } - - private PageResult listToPageList(int currentPage, int rows, List list){ - // TODO FROM 芋艿 to 鱿鱼须:可以直接使用数据库分页哇 - currentPage = currentPage * rows; - Integer sum = list.size(); // TODO FROM 芋艿 to 鱿鱼须:这里 int 就可以啦。一般情况下,如果 IDEA 提示警告,要尽量去掉噢。 - if (currentPage + rows > sum){ - list = list.subList(currentPage, sum); - }else { - list = list.subList(currentPage, currentPage + rows); - } - // TODO FROM 芋艿 to 鱿鱼丝:泛型噢 - return new PageResult().setList(list).setTotal(sum); - } } diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/errorcode/ErrorCodeAddRequest.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/errorcode/ErrorCodeAddRequest.java index 82861e9b8..5a45a3c1b 100644 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/errorcode/ErrorCodeAddRequest.java +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/errorcode/ErrorCodeAddRequest.java @@ -20,4 +20,12 @@ public class ErrorCodeAddRequest { @NotEmpty(message = "错误码编码不能为空") private Integer code; + @ApiModelProperty(value = "错误码分组,字典表获取") + @NotEmpty(message = "错误码分组不能为空") + private Integer group; + + @ApiModelProperty(value = "错误码角色,系统内置(枚举)还是自定义") + @NotEmpty(message = "错误码角色不能空") + private Integer type; + } diff --git a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/errorcode/ErrorCodeRPC.java b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/errorcode/ErrorCodeRPC.java index b0a8eace7..07d602ba4 100644 --- a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/errorcode/ErrorCodeRPC.java +++ b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/errorcode/ErrorCodeRPC.java @@ -1,16 +1,26 @@ package cn.iocoder.mall.system.rpc.api.errorcode; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.system.rpc.request.errorcode.ErrorCodeAddRequest; +import cn.iocoder.mall.system.rpc.request.systemlog.ExceptionLogAddRequest; import cn.iocoder.mall.system.rpc.response.errorcode.ErrorCodeResponse; import java.util.List; /** * ErrorCode RPC 接口 + * 提供其他服务初始化加载错误码到db中,同时提供读取该服务的错误码信息, + * 同时提供删除接口, * @author ding */ public interface ErrorCodeRPC { - CommonResult> getErrorCode(); + CommonResult> getErrorCodeByGroup(Integer group); + + CommonResult addErrorCode(ErrorCodeAddRequest errorCodeAddRequest); + + CommonResult addErrorCodeList(List list); + + CommonResult deleteErrorCodeByGroup(Integer group, Integer type); } diff --git a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/errorcode/ErrorCodeAddRequest.java b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/errorcode/ErrorCodeAddRequest.java new file mode 100644 index 000000000..79d35d091 --- /dev/null +++ b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/errorcode/ErrorCodeAddRequest.java @@ -0,0 +1,33 @@ +package cn.iocoder.mall.system.rpc.request.errorcode; + + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import java.io.Serializable; + +/** + * 错误码模块,枚举初始化错误码时使用 + * @author ding + */ +@Data +@Accessors(chain = true) +public class ErrorCodeAddRequest implements Serializable { + @ApiModelProperty(value = "错误码信息", required = true) + @NotEmpty(message = "错误码信息不能为空") + private String message; + + @ApiModelProperty(value = "错误码编码") + @NotEmpty(message = "错误码编码不能为空") + private Integer code; + + @ApiModelProperty(value = "错误码分组,字典表获取") + @NotEmpty(message = "错误码分组不能为空") + private Integer group; + + @ApiModelProperty(value = "错误码角色,系统内置(枚举)还是自定义") + @NotEmpty(message = "错误码角色不能空") + private Integer type; +} diff --git a/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/convert/errorcode/ErrorCodeConvert.java b/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/convert/errorcode/ErrorCodeConvert.java index f1d281b66..af84d591f 100644 --- a/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/convert/errorcode/ErrorCodeConvert.java +++ b/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/convert/errorcode/ErrorCodeConvert.java @@ -1,6 +1,8 @@ package cn.iocoder.mall.system.rpc.convert.errorcode; import cn.iocoder.mall.system.biz.bo.errorcode.ErrorCodeBO; +import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeAddDTO; +import cn.iocoder.mall.system.rpc.request.errorcode.ErrorCodeAddRequest; import cn.iocoder.mall.system.rpc.response.errorcode.ErrorCodeResponse; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -13,4 +15,9 @@ public interface ErrorCodeConvert { ErrorCodeConvert INSTANCE = Mappers.getMapper(ErrorCodeConvert.class); List convert(List bean); + + ErrorCodeAddDTO convert(ErrorCodeAddRequest errorCodeAddRequest); + + List convertList(List bean); + } diff --git a/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/errorcode/ErrorCodeRPCImpl.java b/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/errorcode/ErrorCodeRPCImpl.java index 7f01a90af..efba09450 100644 --- a/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/errorcode/ErrorCodeRPCImpl.java +++ b/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/errorcode/ErrorCodeRPCImpl.java @@ -6,6 +6,7 @@ import cn.iocoder.mall.system.biz.service.errorcode.ErrorCodeService; import cn.iocoder.mall.system.rpc.api.errorcode.ErrorCodeRPC; import cn.iocoder.mall.system.rpc.convert.errorcode.ErrorCodeConvert; import cn.iocoder.mall.system.rpc.convert.user.UserConvert; +import cn.iocoder.mall.system.rpc.request.errorcode.ErrorCodeAddRequest; import cn.iocoder.mall.system.rpc.response.errorcode.ErrorCodeResponse; import org.apache.dubbo.config.annotation.Service; import org.springframework.beans.factory.annotation.Autowired; @@ -22,9 +23,47 @@ public class ErrorCodeRPCImpl implements ErrorCodeRPC { @Autowired private ErrorCodeService errorCodeService; + /** + * 根据分组获取错误码信息 + * @param group 分组 + * @return 错误码信息 + */ @Override - public CommonResult> getErrorCode() { - List list = errorCodeService.getErrorCodeListAll(); + public CommonResult> getErrorCodeByGroup(Integer group) { + List list = errorCodeService.getErrorCodeByGroup(group); return CommonResult.success(ErrorCodeConvert.INSTANCE.convert(list)); } + + /** + * 添加错误码信息,如果是枚举错误码,角色一定是系统内置 + * @param errorCodeAddRequest 错误码 + * @return 是否成功 + */ + @Override + public CommonResult addErrorCode(ErrorCodeAddRequest errorCodeAddRequest) { + errorCodeService.addErrorCode(ErrorCodeConvert.INSTANCE.convert(errorCodeAddRequest)); + return CommonResult.success(true); + } + + /** + * 批量添加错误码信息 + * @param list 错误码信息集合 + * @return 是否成功 + */ + @Override + public CommonResult addErrorCodeList(List list) { + errorCodeService.addErrorCodeList(ErrorCodeConvert.INSTANCE.convertList(list)); + return CommonResult.success(true); + } + + /** + * 根据分组和角色条件删除错误码信息,只能删除db信息,删除后会进行校验,刷新utils + * @param group 分组 + * @param type 角色 + * @return 是否成功 + */ + @Override + public CommonResult deleteErrorCodeByGroup(Integer group, Integer type) { + return null; + } }