错误码的管理的迁移

This commit is contained in:
YunaiV 2020-07-20 20:29:41 +08:00
parent 187b17ed01
commit e6201b00c1
4 changed files with 15 additions and 5 deletions

View File

@ -38,7 +38,7 @@ public class ErrorCodeRemoteLoader {
@EventListener(ApplicationReadyEvent.class) @EventListener(ApplicationReadyEvent.class)
public void loadErrorCodes() { public void loadErrorCodes() {
// ErrorCodeRpc 加载 ErrorCode 错误码 // ErrorCodeRpc 全量加载 ErrorCode 错误码
CommonResult<List<ErrorCodeVO>> listErrorCodesResult = errorCodeRpc.listErrorCodes(group, null); CommonResult<List<ErrorCodeVO>> listErrorCodesResult = errorCodeRpc.listErrorCodes(group, null);
listErrorCodesResult.checkError(); listErrorCodesResult.checkError();
logger.info("[loadErrorCodes][从 group({}) 全量加载到 {} 个 ErrorCode 错误码]", group, listErrorCodesResult.getData().size()); logger.info("[loadErrorCodes][从 group({}) 全量加载到 {} 个 ErrorCode 错误码]", group, listErrorCodesResult.getData().size());
@ -52,7 +52,8 @@ public class ErrorCodeRemoteLoader {
@Scheduled(fixedDelay = REFRESH_ERROR_CODE_PERIOD, initialDelay = REFRESH_ERROR_CODE_PERIOD) @Scheduled(fixedDelay = REFRESH_ERROR_CODE_PERIOD, initialDelay = REFRESH_ERROR_CODE_PERIOD)
public void refreshErrorCodes() { public void refreshErrorCodes() {
// ErrorCodeRpc 加载 ErrorCode 错误码 // ErrorCodeRpc 增量加载 ErrorCode 错误码
// TODO 优化点假设删除错误码的配置会存在问题
CommonResult<List<ErrorCodeVO>> listErrorCodesResult = errorCodeRpc.listErrorCodes(group, maxUpdateTime); CommonResult<List<ErrorCodeVO>> listErrorCodesResult = errorCodeRpc.listErrorCodes(group, maxUpdateTime);
listErrorCodesResult.checkError(); listErrorCodesResult.checkError();
if (CollectionUtils.isEmpty(listErrorCodesResult.getData())) { if (CollectionUtils.isEmpty(listErrorCodesResult.getData())) {

View File

@ -7,6 +7,7 @@ import cn.iocoder.mall.managementweb.controller.errorcode.dto.ErrorCodePageDTO;
import cn.iocoder.mall.managementweb.controller.errorcode.dto.ErrorCodeUpdateDTO; import cn.iocoder.mall.managementweb.controller.errorcode.dto.ErrorCodeUpdateDTO;
import cn.iocoder.mall.managementweb.controller.errorcode.vo.ErrorCodeVO; import cn.iocoder.mall.managementweb.controller.errorcode.vo.ErrorCodeVO;
import cn.iocoder.mall.managementweb.manager.errorcode.ErrorCodeManager; import cn.iocoder.mall.managementweb.manager.errorcode.ErrorCodeManager;
import cn.iocoder.security.annotations.RequiresPermissions;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -32,12 +33,14 @@ public class ErrorCodeController {
@PostMapping("/create") @PostMapping("/create")
@ApiOperation("创建错误码") @ApiOperation("创建错误码")
@RequiresPermissions("system:error-code:create")
public CommonResult<Integer> createErrorCode(@Valid ErrorCodeCreateDTO createDTO) { public CommonResult<Integer> createErrorCode(@Valid ErrorCodeCreateDTO createDTO) {
return success(errorCodeManager.createErrorCode(createDTO)); return success(errorCodeManager.createErrorCode(createDTO));
} }
@PostMapping("/update") @PostMapping("/update")
@ApiOperation("更新错误码") @ApiOperation("更新错误码")
@RequiresPermissions("system:error-code:update")
public CommonResult<Boolean> updateErrorCode(@Valid ErrorCodeUpdateDTO updateDTO) { public CommonResult<Boolean> updateErrorCode(@Valid ErrorCodeUpdateDTO updateDTO) {
errorCodeManager.updateErrorCode(updateDTO); errorCodeManager.updateErrorCode(updateDTO);
return success(true); return success(true);
@ -46,6 +49,7 @@ public class ErrorCodeController {
@PostMapping("/delete") @PostMapping("/delete")
@ApiOperation("删除错误码") @ApiOperation("删除错误码")
@ApiImplicitParam(name = "errorCodeId", value = "错误码编号", required = true) @ApiImplicitParam(name = "errorCodeId", value = "错误码编号", required = true)
@RequiresPermissions("system:error-code:delete")
public CommonResult<Boolean> deleteErrorCode(@RequestParam("errorCodeId") Integer errorCodeId) { public CommonResult<Boolean> deleteErrorCode(@RequestParam("errorCodeId") Integer errorCodeId) {
errorCodeManager.deleteErrorCode(errorCodeId); errorCodeManager.deleteErrorCode(errorCodeId);
return success(true); return success(true);
@ -54,12 +58,14 @@ public class ErrorCodeController {
@GetMapping("/get") @GetMapping("/get")
@ApiOperation("获得错误码") @ApiOperation("获得错误码")
@ApiImplicitParam(name = "errorCodeId", value = "错误码编号", required = true) @ApiImplicitParam(name = "errorCodeId", value = "错误码编号", required = true)
@RequiresPermissions("system:error-code:page")
public CommonResult<ErrorCodeVO> getErrorCode(@RequestParam("errorCodeId") Integer errorCodeId) { public CommonResult<ErrorCodeVO> getErrorCode(@RequestParam("errorCodeId") Integer errorCodeId) {
return success(errorCodeManager.getErrorCode(errorCodeId)); return success(errorCodeManager.getErrorCode(errorCodeId));
} }
@GetMapping("/page") @GetMapping("/page")
@ApiOperation("获得错误码分页") @ApiOperation("获得错误码分页")
@RequiresPermissions("system:error-code:page")
public CommonResult<PageResult<ErrorCodeVO>> pageErrorCode(ErrorCodePageDTO pageDTO) { public CommonResult<PageResult<ErrorCodeVO>> pageErrorCode(ErrorCodePageDTO pageDTO) {
return success(errorCodeManager.pageErrorCode(pageDTO)); return success(errorCodeManager.pageErrorCode(pageDTO));
} }

View File

@ -7,6 +7,7 @@ import cn.iocoder.mall.managementweb.controller.errorcode.dto.ErrorCodePageDTO;
import cn.iocoder.mall.managementweb.controller.errorcode.dto.ErrorCodeUpdateDTO; import cn.iocoder.mall.managementweb.controller.errorcode.dto.ErrorCodeUpdateDTO;
import cn.iocoder.mall.managementweb.controller.errorcode.vo.ErrorCodeVO; import cn.iocoder.mall.managementweb.controller.errorcode.vo.ErrorCodeVO;
import cn.iocoder.mall.managementweb.convert.errorcode.ErrorCodeConvert; import cn.iocoder.mall.managementweb.convert.errorcode.ErrorCodeConvert;
import cn.iocoder.mall.systemservice.enums.errorcode.ErrorCodeTypeEnum;
import cn.iocoder.mall.systemservice.rpc.errorcode.ErrorCodeRpc; import cn.iocoder.mall.systemservice.rpc.errorcode.ErrorCodeRpc;
import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -29,7 +30,8 @@ public class ErrorCodeManager {
* @return 错误码 * @return 错误码
*/ */
public Integer createErrorCode(ErrorCodeCreateDTO createDTO) { public Integer createErrorCode(ErrorCodeCreateDTO createDTO) {
CommonResult<Integer> createErrorCodeResult = errorCodeRpc.createErrorCode(ErrorCodeConvert.INSTANCE.convert(createDTO)); CommonResult<Integer> createErrorCodeResult = errorCodeRpc.createErrorCode(ErrorCodeConvert.INSTANCE.convert(createDTO)
.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()));
createErrorCodeResult.checkError(); createErrorCodeResult.checkError();
return createErrorCodeResult.getData(); return createErrorCodeResult.getData();
} }
@ -40,7 +42,8 @@ public class ErrorCodeManager {
* @param updateDTO 更新错误码 DTO * @param updateDTO 更新错误码 DTO
*/ */
public void updateErrorCode(ErrorCodeUpdateDTO updateDTO) { public void updateErrorCode(ErrorCodeUpdateDTO updateDTO) {
CommonResult<Boolean> updateErrorCodeResult = errorCodeRpc.updateErrorCode(ErrorCodeConvert.INSTANCE.convert(updateDTO)); CommonResult<Boolean> updateErrorCodeResult = errorCodeRpc.updateErrorCode(ErrorCodeConvert.INSTANCE.convert(updateDTO)
.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()));
updateErrorCodeResult.checkError(); updateErrorCodeResult.checkError();
} }

View File

@ -19,7 +19,7 @@ public enum ErrorCodeTypeEnum implements IntArrayValuable {
*/ */
AUTO_GENERATION(1), AUTO_GENERATION(1),
/** /**
* 手动处理 * 手动编辑
*/ */
MANUAL_OPERATION(2); MANUAL_OPERATION(2);