diff --git a/backend/src/main/java/com/qqchen/deploy/backend/workflow/delegate/NotificationNodeDelegate.java b/backend/src/main/java/com/qqchen/deploy/backend/workflow/delegate/NotificationNodeDelegate.java index ce403112..6548cbe5 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/workflow/delegate/NotificationNodeDelegate.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/workflow/delegate/NotificationNodeDelegate.java @@ -13,7 +13,12 @@ import lombok.extern.slf4j.Slf4j; import org.flowable.engine.delegate.BpmnError; import org.flowable.engine.delegate.DelegateExecution; import org.springframework.context.ApplicationEventPublisher; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -25,21 +30,9 @@ import java.util.concurrent.ConcurrentHashMap; @Component public class NotificationNodeDelegate extends BaseNodeDelegate { - @Resource - private ApplicationEventPublisher eventPublisher; + private final RestTemplate restTemplate = new RestTemplate(); - @Resource - private IJenkinsServiceIntegration jenkinsServiceIntegration; - - private static final int QUEUE_POLL_INTERVAL = 10; // 10秒 - - private static final int MAX_QUEUE_POLLS = 30; // 最多等待5分钟 - - // 轮询间隔(秒) - private static final int BUILD_POLL_INTERVAL = 10; - - // 最大轮询次数 - private static final int MAX_BUILD_POLLS = 180; // 30分钟超时 + private final String WX_HOOK_API = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=614b110b-8957-4be8-95b9-4eca84c15028"; // 用于存储实时输出的Map private static final Map outputMap = new ConcurrentHashMap<>(); @@ -58,7 +51,24 @@ public class NotificationNodeDelegate extends BaseNodeDelegate entity = new HttpEntity<>(format, headers); + +// restTemplate.exchange( +// WX_HOOK_API, +// HttpMethod.POST, +// entity, +// String.class +// ); } } diff --git a/backend/src/main/java/com/qqchen/deploy/backend/workflow/listener/event/handler/JobEventHandler.java b/backend/src/main/java/com/qqchen/deploy/backend/workflow/listener/event/handler/JobEventHandler.java index 26e63f3e..e73c57d9 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/workflow/listener/event/handler/JobEventHandler.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/workflow/listener/event/handler/JobEventHandler.java @@ -1,5 +1,6 @@ package com.qqchen.deploy.backend.workflow.listener.event.handler; +import cn.hutool.json.JSONUtil; import com.qqchen.deploy.backend.workflow.enums.WorkflowNodeInstanceStatusEnums; import com.qqchen.deploy.backend.workflow.event.TerminationProcessInstanceListenerEvent; import lombok.extern.slf4j.Slf4j; @@ -44,11 +45,15 @@ public class JobEventHandler implements IFlowableEventHandler { return; } JobEntityImpl job = (JobEntityImpl) entityEvent.getEntity(); + log.info("Processing job event: {}", JSONUtil.toJsonStr(job)); WorkflowNodeInstanceStatusEnums status = convertToNodeStatus(eventType); switch (status) { case FAILED -> { publisher.publishEvent(new TerminationProcessInstanceListenerEvent(job.getId(), job.getProcessInstanceId(), ((FlowableEntityExceptionEventImpl) event).getCause().getMessage())); } + default -> { + + } } // if (status != null) { // publisher.publishEvent(WorkflowNodeInstanceStatusChangeEvent.builder() @@ -67,7 +72,7 @@ public class JobEventHandler implements IFlowableEventHandler { private WorkflowNodeInstanceStatusEnums convertToNodeStatus(String eventType) { return switch (eventType) { -// case "JOB_EXECUTION_SUCCESS" -> WorkflowNodeInstanceStatusEnums.RUNNING; + case "JOB_EXECUTION_SUCCESS" -> WorkflowNodeInstanceStatusEnums.RUNNING; // case "JOB_EXECUTION_START" -> WorkflowNodeInstanceStatusEnums.RUNNING; case "JOB_EXECUTION_FAILURE" -> WorkflowNodeInstanceStatusEnums.FAILED; // case "JOB_EXECUTION_REJECTED" -> WorkflowNodeInstanceStatusEnums.FAILED; 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 new file mode 100644 index 00000000..84edc216 --- /dev/null +++ b/backend/src/main/java/com/qqchen/deploy/backend/workflow/listener/execution/GatewayExecutionListener.java @@ -0,0 +1,61 @@ +package com.qqchen.deploy.backend.workflow.listener.execution; + +import com.qqchen.deploy.backend.workflow.enums.WorkflowNodeInstanceStatusEnums; +import com.qqchen.deploy.backend.workflow.event.WorkflowNodeInstanceStatusChangeEvent; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.flowable.bpmn.model.FlowElement; +import org.flowable.engine.delegate.DelegateExecution; +import org.flowable.engine.delegate.ExecutionListener; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; + +@Slf4j +@Component("gatewayExecutionListener") +public class GatewayExecutionListener implements ExecutionListener { + + @Resource + private ApplicationEventPublisher eventPublisher; + + @Override + public void notify(DelegateExecution execution) { + // 获取当前节点信息 + FlowElement flowElement = execution.getCurrentFlowElement(); + String eventName = execution.getEventName(); + String processInstanceId = execution.getProcessInstanceId(); + String executionId = execution.getId(); + String nodeId = execution.getCurrentActivityId(); + 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) + .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 be614620..a1406772 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 @@ -168,7 +168,22 @@ public class BpmnConverter { */ private void configureFlowElement(FlowElement element, WorkflowDefinitionGraphNode node, Process process) { // 步骤1:创建基本的扩展元素 - Map> extensionElements = createBaseExtensionElements(); + 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); // 步骤2:根据节点类型进行特定配置 if (element instanceof ServiceTask) {