diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/config/ServiceExceptionConfiguration.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/config/ServiceExceptionConfiguration.java index db8792b92..7f1433e2f 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/config/ServiceExceptionConfiguration.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/config/ServiceExceptionConfiguration.java @@ -2,9 +2,8 @@ package cn.iocoder.mall.system.biz.config; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.mall.system.biz.bo.errorcode.ErrorCodeBO; -import cn.iocoder.mall.system.biz.dataobject.errorcode.ErrorCodeDO; import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum; -import cn.iocoder.mall.system.biz.service.errorCode.ErrorCodeService; +import cn.iocoder.mall.system.biz.service.errorcode.ErrorCodeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.annotation.Configuration; @@ -15,18 +14,18 @@ import java.util.List; @Configuration public class ServiceExceptionConfiguration { -// @Autowired -// private ErrorCodeService errorCodeService; + @Autowired + private ErrorCodeService errorCodeService; @EventListener(ApplicationReadyEvent.class) // 可参考 https://www.cnblogs.com/ssslinppp/p/7607509.html public void initMessages() { -// List list = errorCodeService.getErrorCodeList(); + List list = errorCodeService.getErrorCodeList(); for (SystemErrorCodeEnum item : SystemErrorCodeEnum.values()) { ServiceExceptionUtil.put(item.getCode(), item.getMessage()); } -// for (ErrorCodeBO bo : list) { -// ServiceExceptionUtil.put(bo.getCode(),bo.getMessage()); -// } + for (ErrorCodeBO bo : list) { + ServiceExceptionUtil.put(bo.getCode(),bo.getMessage()); + } } } 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 similarity index 75% rename from system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorCode/ErrorCodeService.java rename to system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorcode/ErrorCodeService.java index bafebd248..31c23a86d 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 @@ -1,4 +1,4 @@ -package cn.iocoder.mall.system.biz.service.errorCode; +package cn.iocoder.mall.system.biz.service.errorcode; import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.system.biz.bo.errorcode.ErrorCodeBO; @@ -20,8 +20,23 @@ public interface ErrorCodeService { */ ErrorCodeBO getErrorCode(Integer code); + /** + * 从db取出错误码列表数据 + * @return db错误码列表 + */ List getErrorCodeList(); + /** + * 取出所有错误码列表数据 + * @return 所有错误码列表 + */ + List getErrorCodeListAll(); + + /** + * 分页取出所有错误码列表数据 + * @param pageDTO 分页数据 + * @return 错误码列表 + */ PageResult getErrorCodePage(ErrorCodePageDTO pageDTO); /** 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 similarity index 72% rename from system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorCode/ErrorCodeServiceImpl.java rename to system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorcode/ErrorCodeServiceImpl.java index 04d963574..c30ff3c0a 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 @@ -1,4 +1,4 @@ -package cn.iocoder.mall.system.biz.service.errorCode; +package cn.iocoder.mall.system.biz.service.errorcode; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.PageResult; @@ -41,12 +41,25 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { return ErrorCodeConvert.INSTANCE.convertList(list); } + @Override + public List getErrorCodeListAll() { + 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 ErrorCodeConvert.INSTANCE.convertList(list); + } + @Override public PageResult getErrorCodePage(ErrorCodePageDTO pageDTO) { -// List list = errorCodeMapper.selectList(new QueryWrapperX()); -// List<> - return null; + 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); } @Override @@ -85,14 +98,15 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { @Override public void deleteErrorCode(ErrorCodeDeleteDTO errorCodeDeleteDTO) { - // 校验角色是否存在 + // 校验错误码是否存在 ErrorCodeDO errorCodeDO = errorCodeMapper.selectById(errorCodeDeleteDTO.getId()); if (errorCodeDO == null) { throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ERROR_CODE_NOT_EXISTS); } // 更新到数据库,标记删除 errorCodeMapper.deleteById(errorCodeDO.getId()); - // TODO: 2020-05-08 刷新对外提供的错误码列表 + // TODO: 2020-05-10 刷新对外提供的错误码列表 + // TODO: 2020-05-10 ServiceExceptionUtil中未提供去除错误码操作,后续新增此接口是否影响? } /** @@ -109,4 +123,15 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.ERROR_CODE_DUPLICATE, errorCodeDO.getCode()); } } + + private PageResult listToPageList(int currentPage, int rows, List list){ + currentPage = currentPage * rows; + Integer sum = list.size(); + if (currentPage + rows > sum){ + list = list.subList(currentPage, sum); + }else { + list = list.subList(currentPage, currentPage + rows); + } + return new PageResult().setList(list).setTotal(sum); + } } diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/errorCode/SystemErrorCodeController.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/errorCode/SystemErrorCodeController.java index 8c85e2807..863b60fcf 100644 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/errorCode/SystemErrorCodeController.java +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/errorCode/SystemErrorCodeController.java @@ -3,16 +3,17 @@ package cn.iocoder.mall.system.rest.controller.errorCode; import cn.iocoder.common.framework.constant.MallConstants; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.security.core.annotation.RequiresPermissions; 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.service.errorCode.ErrorCodeService; +import cn.iocoder.mall.system.biz.service.errorcode.ErrorCodeService; import cn.iocoder.mall.system.rest.convert.errorcode.ErrorCodeConvert; import cn.iocoder.mall.system.rest.request.errorcode.ErrorCodeAddRequest; import cn.iocoder.mall.system.rest.request.errorcode.ErrorCodePageRequest; -import cn.iocoder.mall.system.rest.request.errorcode.ErrorCodePageResponse; +import cn.iocoder.mall.system.rest.response.errorcode.ErrorCodePageResponse; import cn.iocoder.mall.system.rest.request.errorcode.ErrorCodeUpdateRequest; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -26,7 +27,7 @@ import org.springframework.web.bind.annotation.*; * @author youyusi */ @RestController -@RequestMapping(MallConstants.ROOT_PATH_ADMIN + "/errorCode") +@RequestMapping(MallConstants.ROOT_PATH_ADMIN + "/errorcode") @Api("错误码") public class SystemErrorCodeController { @Autowired @@ -34,7 +35,7 @@ public class SystemErrorCodeController { @GetMapping("/page") @ApiOperation(value = "错误码分页") -// @RequiresPermissions("system:errorCode:page") + @RequiresPermissions("system:errorcode:page") public CommonResult> page(ErrorCodePageRequest request) { ErrorCodePageDTO pageDTO = ErrorCodeConvert.INSTANCE.convert(request); PageResult pageResult = errorCodeService.getErrorCodePage(pageDTO); @@ -43,7 +44,7 @@ public class SystemErrorCodeController { @PostMapping("/add") @ApiOperation(value = "创建错误码") -// @RequiresPermissions("system:errorCode:add") + @RequiresPermissions("system:errorcode:add") public CommonResult add(ErrorCodeAddRequest request) { ErrorCodeAddDTO addDTO = ErrorCodeConvert.INSTANCE.convert(request); return CommonResult.success(errorCodeService.addErrorCode(addDTO)); @@ -51,7 +52,7 @@ public class SystemErrorCodeController { @PostMapping("/update") @ApiOperation(value = "更新错误码") -// @RequiresPermissions("system:errorCode:update") + @RequiresPermissions("system:errorcode:update") public CommonResult update(ErrorCodeUpdateRequest request) { ErrorCodeUpdateDTO updateDTO = ErrorCodeConvert.INSTANCE.convert(request); errorCodeService.updateErrorCode(updateDTO); @@ -60,7 +61,7 @@ public class SystemErrorCodeController { @PostMapping("/delete") @ApiOperation(value = "删除错误码") -// @RequiresPermissions("system:errorCode:delete") + @RequiresPermissions("system:errorcode:delete") @ApiImplicitParam(name = "id", value = "错误码编号", required = true, example = "1") public CommonResult delete(@RequestParam("id") Integer id) { ErrorCodeDeleteDTO deleteDTO = new ErrorCodeDeleteDTO().setId(id); diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/errorcode/ErrorCodeConvert.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/errorcode/ErrorCodeConvert.java index f869a5d7b..49dabc8bb 100644 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/errorcode/ErrorCodeConvert.java +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/convert/errorcode/ErrorCodeConvert.java @@ -1,23 +1,14 @@ package cn.iocoder.mall.system.rest.convert.errorcode; import cn.iocoder.common.framework.vo.PageResult; -import cn.iocoder.mall.system.biz.bo.authorization.RoleBO; import cn.iocoder.mall.system.biz.bo.errorcode.ErrorCodeBO; -import cn.iocoder.mall.system.biz.dto.authorization.RoleAddDTO; -import cn.iocoder.mall.system.biz.dto.authorization.RolePageDTO; -import cn.iocoder.mall.system.biz.dto.authorization.RoleUpdateDTO; import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeAddDTO; import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodePageDTO; import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeUpdateDTO; -import cn.iocoder.mall.system.rest.convert.authorization.AdminsRoleConvert; -import cn.iocoder.mall.system.rest.request.authorization.AdminsRoleAddRequest; -import cn.iocoder.mall.system.rest.request.authorization.AdminsRolePageRequest; -import cn.iocoder.mall.system.rest.request.authorization.AdminsRoleUpdateRequest; import cn.iocoder.mall.system.rest.request.errorcode.ErrorCodeAddRequest; import cn.iocoder.mall.system.rest.request.errorcode.ErrorCodePageRequest; -import cn.iocoder.mall.system.rest.request.errorcode.ErrorCodePageResponse; +import cn.iocoder.mall.system.rest.response.errorcode.ErrorCodePageResponse; import cn.iocoder.mall.system.rest.request.errorcode.ErrorCodeUpdateRequest; -import cn.iocoder.mall.system.rest.response.authorization.AdminsRolePageResponse; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/errorcode/ErrorCodePageResponse.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/errorcode/ErrorCodePageResponse.java similarity index 91% rename from system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/errorcode/ErrorCodePageResponse.java rename to system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/errorcode/ErrorCodePageResponse.java index b9a2c17e9..a03097773 100644 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/request/errorcode/ErrorCodePageResponse.java +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/errorcode/ErrorCodePageResponse.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.system.rest.request.errorcode; +package cn.iocoder.mall.system.rest.response.errorcode; import io.swagger.annotations.ApiModel; import lombok.Data; 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 new file mode 100644 index 000000000..b0a8eace7 --- /dev/null +++ b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/errorcode/ErrorCodeRPC.java @@ -0,0 +1,16 @@ +package cn.iocoder.mall.system.rpc.api.errorcode; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.system.rpc.response.errorcode.ErrorCodeResponse; + +import java.util.List; + +/** + * ErrorCode RPC 接口 + * @author ding + */ +public interface ErrorCodeRPC { + + CommonResult> getErrorCode(); + +} diff --git a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/errorcode/ErrorCodeResponse.java b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/errorcode/ErrorCodeResponse.java new file mode 100644 index 000000000..c88dcfe7f --- /dev/null +++ b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/errorcode/ErrorCodeResponse.java @@ -0,0 +1,33 @@ +package cn.iocoder.mall.system.rpc.response.errorcode; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Date; + +/** + * 类 描 述:错误码模块 + * @author ding + */ +@ApiModel("管理员 - 错误码模块 - 查询错误码") +@Data +@Accessors(chain = true) +public class ErrorCodeResponse { + /** + * 错误码编号 + */ + private Integer id; + /** + * 错误码编码 + */ + private Integer code; + /** + * 错误码错误信息 + */ + private String message; + /** + * 添加时间 + */ + private Date createTime; +} 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 new file mode 100644 index 000000000..f1d281b66 --- /dev/null +++ b/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/convert/errorcode/ErrorCodeConvert.java @@ -0,0 +1,16 @@ +package cn.iocoder.mall.system.rpc.convert.errorcode; + +import cn.iocoder.mall.system.biz.bo.errorcode.ErrorCodeBO; +import cn.iocoder.mall.system.rpc.response.errorcode.ErrorCodeResponse; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface ErrorCodeConvert { + + ErrorCodeConvert INSTANCE = Mappers.getMapper(ErrorCodeConvert.class); + + List convert(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 new file mode 100644 index 000000000..7f01a90af --- /dev/null +++ b/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/errorcode/ErrorCodeRPCImpl.java @@ -0,0 +1,30 @@ +package cn.iocoder.mall.system.rpc.rpc.errorcode; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.system.biz.bo.errorcode.ErrorCodeBO; +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.response.errorcode.ErrorCodeResponse; +import org.apache.dubbo.config.annotation.Service; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +/** + * + * @author ding + */ +@Service(version = "${dubbo.provider.ErrorCodeRPC.version}", validation = "true") +public class ErrorCodeRPCImpl implements ErrorCodeRPC { + + @Autowired + private ErrorCodeService errorCodeService; + + @Override + public CommonResult> getErrorCode() { + List list = errorCodeService.getErrorCodeListAll(); + return CommonResult.success(ErrorCodeConvert.INSTANCE.convert(list)); + } +} diff --git a/system/system-rpc/src/main/resources/rpc.yaml b/system/system-rpc/src/main/resources/rpc.yaml index e056da380..c44353e1f 100644 --- a/system/system-rpc/src/main/resources/rpc.yaml +++ b/system/system-rpc/src/main/resources/rpc.yaml @@ -25,6 +25,8 @@ dubbo: version: 1.0.0 UserAddressRPC: version: 1.0.0 + ErrorCodeRPC: + version: 1.0.0 # Dubbo 服务消费者的配置 consumer: @@ -38,3 +40,5 @@ dubbo: version: 1.0.0 UserRPC: version: 1.0.0 + ErrorCodeRPC: + version: 1.0.0