diff --git a/backend/src/main/java/com/qqchen/deploy/backend/workflow/listener/execution/GatewayExecutionListener.java b/backend/src/main/java/com/qqchen/deploy/backend/workflow/listener/execution/GatewayExecutionListener.java index 84edc216..78f881ab 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/workflow/listener/execution/GatewayExecutionListener.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/workflow/listener/execution/GatewayExecutionListener.java @@ -30,32 +30,15 @@ public class GatewayExecutionListener implements ExecutionListener { String nodeName = flowElement.getName(); String nodeType = flowElement.getClass().getSimpleName(); log.debug("Node execution event: {}, processInstanceId: {}, nodeId: {}, nodeType: {}, nodeName:{}", eventName, processInstanceId, nodeId, nodeType, nodeName); - LocalDateTime now = LocalDateTime.now(); - WorkflowNodeInstanceStatusEnums status = null; - LocalDateTime startTime = null; - LocalDateTime endTime = null; - switch (eventName) { - case ExecutionListener.EVENTNAME_START: - status = WorkflowNodeInstanceStatusEnums.RUNNING; - startTime = now; - break; - case ExecutionListener.EVENTNAME_END: - status = WorkflowNodeInstanceStatusEnums.COMPLETED; - endTime = now; - break; - default: - log.warn("Unexpected event type: {}", eventName); - return; - } eventPublisher.publishEvent(WorkflowNodeInstanceStatusChangeEvent.builder() .processInstanceId(processInstanceId) .executionId(executionId) .nodeId(nodeId) .nodeName(nodeName) .nodeType(nodeType) - .status(status) - .startTime(startTime) - .endTime(endTime) + .status(WorkflowNodeInstanceStatusEnums.COMPLETED) + .startTime(LocalDateTime.now()) + .endTime(LocalDateTime.now()) .build()); } } \ No newline at end of file diff --git a/backend/src/main/java/com/qqchen/deploy/backend/workflow/util/BpmnConverter.java b/backend/src/main/java/com/qqchen/deploy/backend/workflow/util/BpmnConverter.java index a1406772..2dbaa134 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/workflow/util/BpmnConverter.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/workflow/util/BpmnConverter.java @@ -65,7 +65,7 @@ public class BpmnConverter { return xml; } catch (Exception e) { - log.error("转换工作流定义为XML失败", e); + log.error("转换工作流��义为XML失败", e); throw new RuntimeException("转换工作流定义为XML失败: " + e.getMessage(), e); } } @@ -167,38 +167,42 @@ public class BpmnConverter { * @param process 当前流程 */ private void configureFlowElement(FlowElement element, WorkflowDefinitionGraphNode node, Process process) { - // 步骤1:创建基本的扩展元素 - Map> extensionElements = new HashMap<>(); - List executionListeners = new ArrayList<>(); - - if (element instanceof Gateway) { - // 网关节点只添加 start 监听器 - ExtensionElement startListener = createExecutionListener("start", "${globalNodeExecutionListener}"); - executionListeners.add(startListener); - } else { - // 其他节点添加 start 和 end 监听器 - ExtensionElement startListener = createExecutionListener("start", "${globalNodeExecutionListener}"); - ExtensionElement endListener = createExecutionListener("end", "${globalNodeExecutionListener}"); - executionListeners.add(startListener); - executionListeners.add(endListener); - } - - extensionElements.put("executionListener", executionListeners); + // 步骤1:配置执行监听器 + Map> extensionElements = configureExecutionListeners(element); // 步骤2:根据节点类型进行特定配置 if (element instanceof ServiceTask) { configureServiceTask((ServiceTask) element, node, process, extensionElements); - } else if (element instanceof Gateway) { - // 为网关节点只添加监听器,不添加边界事件 - element.setExtensionElements(extensionElements); - } else if (element instanceof StartEvent || element instanceof EndEvent) { - // 为开始节点和结束节点设置监听器 + } else { element.setExtensionElements(extensionElements); } } /** - * 创建基本的扩展元素(包含执行监听器) + * 配置节点的执行监听器 + * + * @param element 流程节点元素 + * @return 配置好的扩展元素Map + */ + private Map> configureExecutionListeners(FlowElement element) { + Map> extensionElements = new HashMap<>(); + List executionListeners = new ArrayList<>(); + + if (element instanceof Gateway) { + // 网关节点只添加 start 监听器 + executionListeners.add(createExecutionListener("start", "${gatewayExecutionListener}")); + } else { + // 其他节点添加 start 和 end 监听器 + executionListeners.add(createExecutionListener("start", "${globalNodeExecutionListener}")); + executionListeners.add(createExecutionListener("end", "${globalNodeExecutionListener}")); + } + + extensionElements.put("executionListener", executionListeners); + return extensionElements; + } + + /** + * 创��基本的扩展元素(包含执行监听器) * * @return 包含基本扩展元素的Map */ @@ -489,7 +493,8 @@ public class BpmnConverter { log.debug("转换连线: from {} to {}", edge.getFrom(), edge.getTo()); SequenceFlow flow = new SequenceFlow(); - flow.setId("FLOW_" + edge.getId().replaceAll("[^a-zA-Z0-9-_.]", "_")); + String flowId = "FLOW_" + edge.getId().replaceAll("[^a-zA-Z0-9-_.]", "_"); + flow.setId(flowId); flow.setName(edge.getName()); flow.setSourceRef(idMapping.get(edge.getFrom())); flow.setTargetRef(idMapping.get(edge.getTo())); @@ -502,6 +507,13 @@ public class BpmnConverter { } } +// // 添加 take 事件监听器 +// Map> extensionElements = new HashMap<>(); +// List executionListeners = new ArrayList<>(); +// executionListeners.add(createExecutionListener("take", "${sequenceFlowTakeListener}")); +// extensionElements.put("executionListener", executionListeners); +// flow.setExtensionElements(extensionElements); + process.addFlowElement(flow); } }