大声道撒旦

This commit is contained in:
dengqichen 2024-12-25 18:02:53 +08:00
parent daf582544f
commit 6cccc209c6
4 changed files with 108 additions and 17 deletions

View File

@ -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<NotificationNodePanelVariables, NotificationNodeLocalVariables> {
@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<String, StringBuilder> outputMap = new ConcurrentHashMap<>();
@ -58,7 +51,24 @@ public class NotificationNodeDelegate extends BaseNodeDelegate<NotificationNodeP
@Override
protected void executeInternal(DelegateExecution execution, NotificationNodePanelVariables panelVariables, NotificationNodeLocalVariables localVariables) {
System.out.println(panelVariables.getText());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
String format = String.format("{\n" +
" \"msgtype\": \"text\",\n" +
" \"text\": {\n" +
" \"content\": \"%s\"\n" +
" }\n" +
"}", panelVariables.getText() + ":这是一个面板填写的变量");
HttpEntity<String> entity = new HttpEntity<>(format, headers);
// restTemplate.exchange(
// WX_HOOK_API,
// HttpMethod.POST,
// entity,
// String.class
// );
}
}

View File

@ -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;

View File

@ -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());
}
}

View File

@ -168,7 +168,22 @@ public class BpmnConverter {
*/
private void configureFlowElement(FlowElement element, WorkflowDefinitionGraphNode node, Process process) {
// 步骤1创建基本的扩展元素
Map<String, List<ExtensionElement>> extensionElements = createBaseExtensionElements();
Map<String, List<ExtensionElement>> extensionElements = new HashMap<>();
List<ExtensionElement> 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) {