This commit is contained in:
asp_ly 2024-12-25 21:38:14 +08:00
parent 0a249161dd
commit 9f72d03a38
2 changed files with 21 additions and 4 deletions

View File

@ -4,6 +4,7 @@ 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.bpmn.model.ServiceTask;
import org.flowable.engine.delegate.BpmnError;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
@ -27,17 +28,19 @@ import java.util.Optional;
public abstract class BaseNodeDelegate<P, L> implements JavaDelegate {
@Autowired
private ObjectMapper objectMapper;
// 字段注入由Flowable自动设置
protected Expression panelVariables;
protected Expression localVariables;
@Override
public void execute(DelegateExecution execution) {
try {
// 在节点执行前清除前一个节点的状态
clearPreviousNodeStatus(execution);
// 获取并转换Panel变量
P panelVars = null;
if (panelVariables != null) {
@ -74,7 +77,7 @@ public abstract class BaseNodeDelegate<P, L> implements JavaDelegate {
* 设置执行状态
*
* @param execution 执行上下文
* @param status 状态值
* @param status 状态值
*/
protected void setExecutionStatus(DelegateExecution execution, String status) {
execution.setVariable(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME, status);
@ -98,12 +101,21 @@ public abstract class BaseNodeDelegate<P, L> implements JavaDelegate {
/**
* 执行具体的任务逻辑
*
* @param execution DelegateExecution对象
* @param execution DelegateExecution对象
* @param panelVariables 转换后的Panel变量
* @param localVariables 转换后的Local变量
*/
protected abstract void executeInternal(DelegateExecution execution, P panelVariables, L localVariables);
/**
* 清除前一个节点的状态
*/
private void clearPreviousNodeStatus(DelegateExecution execution) {
// 只有在当前节点是ServiceTask时才清除状态
execution.removeVariable(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME);
log.debug("Cleared previous node status for node: {}", execution.getCurrentActivityId());
}
/**
* 获取执行状态
*

View File

@ -1,5 +1,6 @@
package com.qqchen.deploy.backend.workflow.listener.execution;
import com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants;
import com.qqchen.deploy.backend.workflow.enums.WorkflowNodeInstanceStatusEnums;
import com.qqchen.deploy.backend.workflow.event.WorkflowNodeInstanceStatusChangeEvent;
import lombok.extern.slf4j.Slf4j;
@ -53,7 +54,11 @@ public class GlobalExecutionListener implements ExecutionListener {
if (StringUtils.isEmpty(nodeExecutionStatus)) {
status = WorkflowNodeInstanceStatusEnums.COMPLETED;
} else {
status = WorkflowNodeInstanceStatusEnums.FAILED;
if (WorkFlowConstants.WORKFLOW_NODE_EXECUTION_STATUS_SUCCESS.equals(nodeExecutionStatus)) {
status = WorkflowNodeInstanceStatusEnums.COMPLETED;
} else {
status = WorkflowNodeInstanceStatusEnums.FAILED;
}
}
endTime = now;
break;