From b658333300c89cac0475e5ca941de1d894ef0d2d Mon Sep 17 00:00:00 2001 From: SamLee <1142245564@qq.com> Date: Tue, 29 Mar 2022 00:32:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:ProcessController.preCheck=E7=9A=84context?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E6=8C=87=E9=92=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../support/exception/ProcessException.java | 39 +++++++++++++++++++ .../support/pipeline/ProcessController.java | 28 ++++++++----- 2 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 austin-support/src/main/java/com/java3y/austin/support/exception/ProcessException.java diff --git a/austin-support/src/main/java/com/java3y/austin/support/exception/ProcessException.java b/austin-support/src/main/java/com/java3y/austin/support/exception/ProcessException.java new file mode 100644 index 0000000..129cfab --- /dev/null +++ b/austin-support/src/main/java/com/java3y/austin/support/exception/ProcessException.java @@ -0,0 +1,39 @@ +package com.java3y.austin.support.exception; + +import com.java3y.austin.common.enums.RespStatusEnum; +import com.java3y.austin.support.pipeline.ProcessContext; + +/** + * @author SamLee + * @since 2022-03-29 + */ +public class ProcessException extends RuntimeException { + + /** + * 流程处理上下文 + */ + private final ProcessContext processContext; + + public ProcessException(ProcessContext processContext) { + super(); + this.processContext = processContext; + } + + public ProcessException(ProcessContext processContext, Throwable cause) { + super(cause); + this.processContext = processContext; + } + + @Override + public String getMessage() { + if (this.processContext != null) { + return this.processContext.getResponse().getMsg(); + } else { + return RespStatusEnum.CONTEXT_IS_NULL.getMsg(); + } + } + + public ProcessContext getProcessContext() { + return processContext; + } +} diff --git a/austin-support/src/main/java/com/java3y/austin/support/pipeline/ProcessController.java b/austin-support/src/main/java/com/java3y/austin/support/pipeline/ProcessController.java index 977178b..82fdddb 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/pipeline/ProcessController.java +++ b/austin-support/src/main/java/com/java3y/austin/support/pipeline/ProcessController.java @@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.java3y.austin.common.enums.RespStatusEnum; import com.java3y.austin.common.vo.BasicResultVO; +import com.java3y.austin.support.exception.ProcessException; import lombok.Data; import lombok.extern.slf4j.Slf4j; @@ -34,10 +35,13 @@ public class ProcessController { */ public ProcessContext process(ProcessContext context) { - /** - * 前置检查 - */ - if (!preCheck(context)) { + try { + /** + * 前置检查 + */ + preCheck(context); + } catch(ProcessException e) { + context = e.getProcessContext(); return context; } @@ -55,36 +59,40 @@ public class ProcessController { } - private Boolean preCheck(ProcessContext context) { + /** + * 执行前检查,出错则抛出异常 + * @param context 执行上下文 + * @throws ProcessException 异常信息 + */ + private void preCheck(ProcessContext context) throws ProcessException { // 上下文 if (context == null) { context = new ProcessContext(); context.setResponse(BasicResultVO.fail(RespStatusEnum.CONTEXT_IS_NULL)); - return false; + throw new ProcessException(context); } // 业务代码 String businessCode = context.getCode(); if (StrUtil.isBlank(businessCode)) { context.setResponse(BasicResultVO.fail(RespStatusEnum.BUSINESS_CODE_IS_NULL)); - return false; + throw new ProcessException(context); } // 执行模板 ProcessTemplate processTemplate = templateConfig.get(businessCode); if (processTemplate == null) { context.setResponse(BasicResultVO.fail(RespStatusEnum.PROCESS_TEMPLATE_IS_NULL)); - return false; + throw new ProcessException(context); } // 执行模板列表 List processList = processTemplate.getProcessList(); if (CollUtil.isEmpty(processList)) { context.setResponse(BasicResultVO.fail(RespStatusEnum.PROCESS_LIST_IS_NULL)); - return false; + throw new ProcessException(context); } - return true; }