diff --git a/backend/src/main/java/com/qqchen/deploy/backend/workflow/constants/WorkFlowConstants.java b/backend/src/main/java/com/qqchen/deploy/backend/workflow/constants/WorkFlowConstants.java index d81930c7..7ac1a9d1 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/workflow/constants/WorkFlowConstants.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/workflow/constants/WorkFlowConstants.java @@ -11,4 +11,21 @@ public interface WorkFlowConstants { String SEQUENCE_FLOW_ERROR_PREFIX = "SEQUENCE_FLOW_ERROR_"; String ASYNC_CONTINUATION = "async-continuation"; + + String WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME = "PREVIOUS_NODE_EXECUTION_STATUS"; + + /** + * 执行状态:成功 + */ + String WORKFLOW_NODE_EXECUTION_STATUS_SUCCESS = "SUCCESS"; + + /** + * 执行状态:失败 + */ + String WORKFLOW_NODE_EXECUTION_STATUS_FAILURE = "FAILURE"; + + /** + * 执行状态:中止 + */ + String WORKFLOW_NODE_EXECUTION_STATUS_ABORTED = "ABORTED"; } diff --git a/backend/src/main/java/com/qqchen/deploy/backend/workflow/delegate/BaseNodeDelegate.java b/backend/src/main/java/com/qqchen/deploy/backend/workflow/delegate/BaseNodeDelegate.java index a6571c9f..c89327bd 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/workflow/delegate/BaseNodeDelegate.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/workflow/delegate/BaseNodeDelegate.java @@ -2,12 +2,20 @@ package com.qqchen.deploy.backend.workflow.delegate; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants; import lombok.extern.slf4j.Slf4j; +import org.flowable.engine.delegate.BpmnError; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.JavaDelegate; import org.flowable.common.engine.api.delegate.Expression; import org.springframework.beans.factory.annotation.Autowired; +import static com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants.WORKFLOW_NODE_EXECUTION_STATUS_FAILURE; +import static com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants.WORKFLOW_NODE_EXECUTION_STATUS_SUCCESS; +import static com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants.WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME; + +import java.util.Optional; + /** * 任务委派者基类 * 负责处理panelVariables和localVariables的转换和注入 @@ -18,25 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired; @Slf4j public abstract class BaseNodeDelegate
implements JavaDelegate { - /** - * 执行状态变量名 - */ - protected static final String EXECUTION_STATUS = "executionStatus"; - /** - * 执行状态:成功 - */ - protected static final String STATUS_SUCCESS = "success"; - - /** - * 执行状态:失败 - */ - protected static final String STATUS_FAILURE = "failure"; - - /** - * 执行状态:中止 - */ - protected static final String STATUS_ABORTED = "aborted"; @Autowired private ObjectMapper objectMapper; @@ -68,15 +58,15 @@ public abstract class BaseNodeDelegate
implements JavaDelegate { executeInternal(execution, panelVars, localVars); // 如果节点没有设置状态,默认设置成功状态 - if (execution.getVariable(EXECUTION_STATUS) == null) { - setExecutionStatus(execution, STATUS_SUCCESS); + String status = getExecutionStatus(execution); + if (status == null) { + setExecutionStatus(execution, WORKFLOW_NODE_EXECUTION_STATUS_SUCCESS); } } catch (Exception e) { // 设置失败状态 - setExecutionStatus(execution, STATUS_FAILURE); + setExecutionStatus(execution, WORKFLOW_NODE_EXECUTION_STATUS_FAILURE); log.error("Task execution failed", e); - throw new RuntimeException("Task execution failed: " + e.getMessage(), e); } } @@ -87,7 +77,7 @@ public abstract class BaseNodeDelegate
implements JavaDelegate { * @param status 状态值 */ protected void setExecutionStatus(DelegateExecution execution, String status) { - execution.setVariable(EXECUTION_STATUS, status); + execution.setVariable(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME, status); log.debug("Set execution status: {}", status); } @@ -113,4 +103,17 @@ public abstract class BaseNodeDelegate
implements JavaDelegate {
* @param localVariables 转换后的Local变量
*/
protected abstract void executeInternal(DelegateExecution execution, P panelVariables, L localVariables);
+
+ /**
+ * 获取执行状态
+ *
+ * @param execution 执行上下文
+ * @return 执行状态,如果不存在则返回null
+ */
+ protected String getExecutionStatus(DelegateExecution execution) {
+ return Optional.ofNullable(execution.getVariables())
+ .map(vars -> vars.get(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME))
+ .map(Object::toString)
+ .orElse(null);
+ }
}
\ No newline at end of file
diff --git a/backend/src/main/java/com/qqchen/deploy/backend/workflow/delegate/DeployNodeDelegate.java b/backend/src/main/java/com/qqchen/deploy/backend/workflow/delegate/DeployNodeDelegate.java
index e81f4eb3..48e22b58 100644
--- a/backend/src/main/java/com/qqchen/deploy/backend/workflow/delegate/DeployNodeDelegate.java
+++ b/backend/src/main/java/com/qqchen/deploy/backend/workflow/delegate/DeployNodeDelegate.java
@@ -56,10 +56,10 @@ public class DeployNodeDelegate extends BaseNodeDelegate