大声道撒旦

This commit is contained in:
dengqichen 2025-01-06 15:28:26 +08:00
parent 7618bb3ef6
commit d64504284e
3 changed files with 15 additions and 22 deletions

View File

@ -12,17 +12,17 @@ public interface WorkFlowConstants {
String ASYNC_CONTINUATION = "async-continuation"; String ASYNC_CONTINUATION = "async-continuation";
String WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME = "PREVIOUS_NODE_EXECUTION_STATUS"; String WORKFLOW_PREVIOUS_NODE_EXECUTION_STATE_VARIABLE_NAME = "PREVIOUS_NODE_EXECUTION_STATE";
/** /**
* 执行状态成功 * 执行状态成功
*/ */
String WORKFLOW_NODE_EXECUTION_STATUS_SUCCESS = "SUCCESS"; String WORKFLOW_NODE_EXECUTION_STATE_SUCCESS = "SUCCESS";
/** /**
* 执行状态失败 * 执行状态失败
*/ */
String WORKFLOW_NODE_EXECUTION_STATUS_FAILURE = "FAILURE"; String WORKFLOW_NODE_EXECUTION_STATE_FAILURE = "FAILURE";
/** /**
* 执行状态中止 * 执行状态中止

View File

@ -2,20 +2,16 @@ package com.qqchen.deploy.backend.workflow.delegate;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants;
import lombok.extern.slf4j.Slf4j; 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.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate; import org.flowable.engine.delegate.JavaDelegate;
import org.flowable.common.engine.api.delegate.Expression; import org.flowable.common.engine.api.delegate.Expression;
import org.springframework.beans.factory.annotation.Autowired; 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_STATE_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_NODE_EXECUTION_STATE_SUCCESS;
import static com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants.WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME; import static com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants.WORKFLOW_PREVIOUS_NODE_EXECUTION_STATE_VARIABLE_NAME;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
/** /**
@ -60,12 +56,12 @@ public abstract class BaseNodeDelegate<P, L> implements JavaDelegate {
// 如果节点没有设置状态默认设置成功状态 // 如果节点没有设置状态默认设置成功状态
String status = getExecutionStatus(execution); String status = getExecutionStatus(execution);
if (status == null) { if (status == null) {
setExecutionStatus(execution, WORKFLOW_NODE_EXECUTION_STATUS_SUCCESS); setExecutionStatus(execution, WORKFLOW_NODE_EXECUTION_STATE_SUCCESS);
} }
} catch (Exception e) { } catch (Exception e) {
// 设置失败状态 // 设置失败状态
setExecutionStatus(execution, WORKFLOW_NODE_EXECUTION_STATUS_FAILURE); setExecutionStatus(execution, WORKFLOW_NODE_EXECUTION_STATE_FAILURE);
log.error("Task execution failed", e); log.error("Task execution failed", e);
} }
} }
@ -77,7 +73,7 @@ public abstract class BaseNodeDelegate<P, L> implements JavaDelegate {
* @param status 状态值 * @param status 状态值
*/ */
protected void setExecutionStatus(DelegateExecution execution, String status) { protected void setExecutionStatus(DelegateExecution execution, String status) {
execution.setVariable(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME, status); execution.setVariable(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATE_VARIABLE_NAME, status);
log.debug("Set execution status: {}", status); log.debug("Set execution status: {}", status);
} }
@ -109,7 +105,7 @@ public abstract class BaseNodeDelegate<P, L> implements JavaDelegate {
*/ */
private void clearPreviousNodeStatus(DelegateExecution execution) { private void clearPreviousNodeStatus(DelegateExecution execution) {
// 只有在当前节点是ServiceTask时才清除状态 // 只有在当前节点是ServiceTask时才清除状态
execution.removeVariable(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME); execution.removeVariable(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATE_VARIABLE_NAME);
log.debug("Cleared previous node status for node: {}", execution.getCurrentActivityId()); log.debug("Cleared previous node status for node: {}", execution.getCurrentActivityId());
} }
@ -121,7 +117,7 @@ public abstract class BaseNodeDelegate<P, L> implements JavaDelegate {
*/ */
protected String getExecutionStatus(DelegateExecution execution) { protected String getExecutionStatus(DelegateExecution execution) {
return Optional.ofNullable(execution.getVariables()) return Optional.ofNullable(execution.getVariables())
.map(vars -> vars.get(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME)) .map(vars -> vars.get(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATE_VARIABLE_NAME))
.map(Object::toString) .map(Object::toString)
.orElse(null); .orElse(null);
} }

View File

@ -17,11 +17,11 @@ import jakarta.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Optional; import java.util.Optional;
import static com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants.WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME; import static com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants.WORKFLOW_PREVIOUS_NODE_EXECUTION_STATE_VARIABLE_NAME;
@Slf4j @Slf4j
@Component("globalNodeExecutionListener") @Component("globalNodeExecutionListener")
public class GlobalExecutionListener implements ExecutionListener { public class GlobalNodeExecutionListener implements ExecutionListener {
@Resource @Resource
@Lazy @Lazy
@ -43,7 +43,7 @@ public class GlobalExecutionListener implements ExecutionListener {
LocalDateTime startTime = null; LocalDateTime startTime = null;
LocalDateTime endTime = null; LocalDateTime endTime = null;
String nodeExecutionStatus = Optional.ofNullable(execution.getVariables()) String nodeExecutionStatus = Optional.ofNullable(execution.getVariables())
.map(vars -> vars.get(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME)) .map(vars -> vars.get(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATE_VARIABLE_NAME))
.map(Object::toString) .map(Object::toString)
.orElse(null); .orElse(null);
switch (eventName) { switch (eventName) {
@ -55,7 +55,7 @@ public class GlobalExecutionListener implements ExecutionListener {
if (StringUtils.isEmpty(nodeExecutionStatus)) { if (StringUtils.isEmpty(nodeExecutionStatus)) {
status = WorkflowNodeInstanceStatusEnums.COMPLETED; status = WorkflowNodeInstanceStatusEnums.COMPLETED;
} else { } else {
if (WorkFlowConstants.WORKFLOW_NODE_EXECUTION_STATUS_SUCCESS.equals(nodeExecutionStatus)) { if (WorkFlowConstants.WORKFLOW_NODE_EXECUTION_STATE_SUCCESS.equals(nodeExecutionStatus)) {
status = WorkflowNodeInstanceStatusEnums.COMPLETED; status = WorkflowNodeInstanceStatusEnums.COMPLETED;
} else { } else {
status = WorkflowNodeInstanceStatusEnums.FAILED; status = WorkflowNodeInstanceStatusEnums.FAILED;
@ -77,8 +77,5 @@ public class GlobalExecutionListener implements ExecutionListener {
.startTime(startTime) .startTime(startTime)
.endTime(endTime) .endTime(endTime)
.build()); .build());
if (StringUtils.isNotEmpty(nodeExecutionStatus)) {
execution.removeVariable(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME);
}
} }
} }