通用解析
This commit is contained in:
parent
96e122b54a
commit
9c906be60a
0
backend/mvnw
vendored
Normal file → Executable file
0
backend/mvnw
vendored
Normal file → Executable file
@ -0,0 +1,59 @@
|
|||||||
|
package com.qqchen.deploy.backend.workflow.constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BPMN相关常量
|
||||||
|
*/
|
||||||
|
public class BpmnConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点类型
|
||||||
|
*/
|
||||||
|
public static class NodeShape {
|
||||||
|
public static final String START = "start";
|
||||||
|
public static final String END = "end";
|
||||||
|
public static final String EDGE = "edge";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点属性
|
||||||
|
*/
|
||||||
|
public static class NodeAttribute {
|
||||||
|
public static final String SHAPE = "shape";
|
||||||
|
public static final String ID = "id";
|
||||||
|
public static final String LABEL = "label";
|
||||||
|
public static final String SOURCE = "source";
|
||||||
|
public static final String TARGET = "target";
|
||||||
|
public static final String DATA = "data";
|
||||||
|
public static final String CONDITION = "condition";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认节点ID
|
||||||
|
*/
|
||||||
|
public static class DefaultNodeId {
|
||||||
|
public static final String START_EVENT = "startEvent";
|
||||||
|
public static final String END_EVENT = "endEvent";
|
||||||
|
public static final String START_FLOW = "flow_start";
|
||||||
|
public static final String END_FLOW = "flow_end";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认节点名称
|
||||||
|
*/
|
||||||
|
public static class DefaultNodeName {
|
||||||
|
public static final String START_EVENT = "开始";
|
||||||
|
public static final String END_EVENT = "结束";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 委托表达式类型
|
||||||
|
*/
|
||||||
|
public static class DelegateExpression {
|
||||||
|
public static final String TYPE = "delegateExpression";
|
||||||
|
public static final String SHELL_TASK = "${shellTaskDelegate}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private BpmnConstants() {
|
||||||
|
// 防止实例化
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.qqchen.deploy.backend.workflow.handler.impl;
|
package com.qqchen.deploy.backend.workflow.handler.impl;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.qqchen.deploy.backend.workflow.constants.BpmnConstants;
|
||||||
import com.qqchen.deploy.backend.workflow.enums.BpmnNodeType;
|
import com.qqchen.deploy.backend.workflow.enums.BpmnNodeType;
|
||||||
import com.qqchen.deploy.backend.workflow.handler.BpmnNodeHandler;
|
import com.qqchen.deploy.backend.workflow.handler.BpmnNodeHandler;
|
||||||
import com.qqchen.deploy.backend.workflow.model.BpmnNodeConfig;
|
import com.qqchen.deploy.backend.workflow.model.BpmnNodeConfig;
|
||||||
@ -20,8 +21,8 @@ public class ShellTaskHandler implements BpmnNodeHandler<ServiceTask> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(JsonNode nodeData, ServiceTask element, BpmnNodeConfig config) {
|
public void handle(JsonNode nodeData, ServiceTask element, BpmnNodeConfig config) {
|
||||||
element.setImplementationType("delegateExpression");
|
element.setImplementationType(BpmnConstants.DelegateExpression.TYPE);
|
||||||
element.setImplementation("${shellTaskDelegate}");
|
element.setImplementation(BpmnConstants.DelegateExpression.SHELL_TASK);
|
||||||
element.setAsynchronous(true); // Shell任务默认异步执行
|
element.setAsynchronous(true); // Shell任务默认异步执行
|
||||||
|
|
||||||
// 从配置中获取字段
|
// 从配置中获取字段
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.qqchen.deploy.backend.workflow.util;
|
|||||||
|
|
||||||
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.BpmnConstants;
|
||||||
import com.qqchen.deploy.backend.workflow.enums.BpmnNodeType;
|
import com.qqchen.deploy.backend.workflow.enums.BpmnNodeType;
|
||||||
import com.qqchen.deploy.backend.workflow.handler.BpmnNodeHandler;
|
import com.qqchen.deploy.backend.workflow.handler.BpmnNodeHandler;
|
||||||
import com.qqchen.deploy.backend.workflow.model.BpmnNodeConfig;
|
import com.qqchen.deploy.backend.workflow.model.BpmnNodeConfig;
|
||||||
@ -49,7 +50,7 @@ public class BpmnConverter {
|
|||||||
Process process = new Process();
|
Process process = new Process();
|
||||||
process.setId(processId);
|
process.setId(processId);
|
||||||
process.setName(processId);
|
process.setName(processId);
|
||||||
process.setExecutable(true); // 设置为可执行
|
process.setExecutable(true);
|
||||||
bpmnModel.addProcess(process);
|
bpmnModel.addProcess(process);
|
||||||
|
|
||||||
// 处理节点
|
// 处理节点
|
||||||
@ -63,19 +64,20 @@ public class BpmnConverter {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String shape = cell.path("shape").asText();
|
String shape = cell.path(BpmnConstants.NodeAttribute.SHAPE).asText();
|
||||||
String id = cell.path("id").asText();
|
String id = cell.path(BpmnConstants.NodeAttribute.ID).asText();
|
||||||
String label = cell.path("data").path("label").asText("");
|
String label = cell.path(BpmnConstants.NodeAttribute.DATA)
|
||||||
|
.path(BpmnConstants.NodeAttribute.LABEL).asText("");
|
||||||
|
|
||||||
// 处理特殊节点类型
|
// 处理特殊节点类型
|
||||||
if ("start".equals(shape)) {
|
if (BpmnConstants.NodeShape.START.equals(shape)) {
|
||||||
StartEvent startEvent = new StartEvent();
|
StartEvent startEvent = new StartEvent();
|
||||||
startEvent.setId(id);
|
startEvent.setId(id);
|
||||||
startEvent.setName(label);
|
startEvent.setName(label);
|
||||||
process.addFlowElement(startEvent);
|
process.addFlowElement(startEvent);
|
||||||
elementMap.put(id, startEvent);
|
elementMap.put(id, startEvent);
|
||||||
continue;
|
continue;
|
||||||
} else if ("end".equals(shape)) {
|
} else if (BpmnConstants.NodeShape.END.equals(shape)) {
|
||||||
EndEvent endEvent = new EndEvent();
|
EndEvent endEvent = new EndEvent();
|
||||||
endEvent.setId(id);
|
endEvent.setId(id);
|
||||||
endEvent.setName(label);
|
endEvent.setName(label);
|
||||||
@ -140,14 +142,14 @@ public class BpmnConverter {
|
|||||||
// 如果没有开始事件,创建一个并连接到第一个任务
|
// 如果没有开始事件,创建一个并连接到第一个任务
|
||||||
if (startEvent == null && firstElement != null) {
|
if (startEvent == null && firstElement != null) {
|
||||||
startEvent = new StartEvent();
|
startEvent = new StartEvent();
|
||||||
startEvent.setId("startEvent");
|
startEvent.setId(BpmnConstants.DefaultNodeId.START_EVENT);
|
||||||
startEvent.setName("开始");
|
startEvent.setName(BpmnConstants.DefaultNodeName.START_EVENT);
|
||||||
process.addFlowElement(startEvent);
|
process.addFlowElement(startEvent);
|
||||||
elementMap.put(startEvent.getId(), startEvent);
|
elementMap.put(startEvent.getId(), startEvent);
|
||||||
|
|
||||||
// 创建从开始事件到第一个任务的连线
|
// 创建从开始事件到第一个任务的连线
|
||||||
SequenceFlow startFlow = new SequenceFlow();
|
SequenceFlow startFlow = new SequenceFlow();
|
||||||
startFlow.setId("flow_start");
|
startFlow.setId(BpmnConstants.DefaultNodeId.START_FLOW);
|
||||||
startFlow.setSourceRef(startEvent.getId());
|
startFlow.setSourceRef(startEvent.getId());
|
||||||
startFlow.setTargetRef(firstElement.getId());
|
startFlow.setTargetRef(firstElement.getId());
|
||||||
process.addFlowElement(startFlow);
|
process.addFlowElement(startFlow);
|
||||||
@ -156,14 +158,14 @@ public class BpmnConverter {
|
|||||||
// 如果没有结束事件,创建一个并从最后一个任务连接到它
|
// 如果没有结束事件,创建一个并从最后一个任务连接到它
|
||||||
if (endEvent == null && lastElement != null) {
|
if (endEvent == null && lastElement != null) {
|
||||||
endEvent = new EndEvent();
|
endEvent = new EndEvent();
|
||||||
endEvent.setId("endEvent");
|
endEvent.setId(BpmnConstants.DefaultNodeId.END_EVENT);
|
||||||
endEvent.setName("结束");
|
endEvent.setName(BpmnConstants.DefaultNodeName.END_EVENT);
|
||||||
process.addFlowElement(endEvent);
|
process.addFlowElement(endEvent);
|
||||||
elementMap.put(endEvent.getId(), endEvent);
|
elementMap.put(endEvent.getId(), endEvent);
|
||||||
|
|
||||||
// 创建从最后一个任务到结束事件的连线
|
// 创建从最后一个任务到结束事件的连线
|
||||||
SequenceFlow endFlow = new SequenceFlow();
|
SequenceFlow endFlow = new SequenceFlow();
|
||||||
endFlow.setId("flow_end");
|
endFlow.setId(BpmnConstants.DefaultNodeId.END_FLOW);
|
||||||
endFlow.setSourceRef(lastElement.getId());
|
endFlow.setSourceRef(lastElement.getId());
|
||||||
endFlow.setTargetRef(endEvent.getId());
|
endFlow.setTargetRef(endEvent.getId());
|
||||||
process.addFlowElement(endFlow);
|
process.addFlowElement(endFlow);
|
||||||
@ -171,11 +173,13 @@ public class BpmnConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNode(JsonNode cell) {
|
private boolean isNode(JsonNode cell) {
|
||||||
return cell.has("shape") && !cell.path("shape").asText().equals("edge");
|
return cell.has(BpmnConstants.NodeAttribute.SHAPE) &&
|
||||||
|
!BpmnConstants.NodeShape.EDGE.equals(cell.path(BpmnConstants.NodeAttribute.SHAPE).asText());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEdge(JsonNode cell) {
|
private boolean isEdge(JsonNode cell) {
|
||||||
return cell.has("shape") && cell.path("shape").asText().equals("edge");
|
return cell.has(BpmnConstants.NodeAttribute.SHAPE) &&
|
||||||
|
BpmnConstants.NodeShape.EDGE.equals(cell.path(BpmnConstants.NodeAttribute.SHAPE).asText());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -187,9 +191,9 @@ public class BpmnConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleSequenceFlow(JsonNode cell, Process process, Map<String, FlowElement> elementMap) {
|
private void handleSequenceFlow(JsonNode cell, Process process, Map<String, FlowElement> elementMap) {
|
||||||
String sourceId = cell.path("source").asText();
|
String sourceId = cell.path(BpmnConstants.NodeAttribute.SOURCE).asText();
|
||||||
String targetId = cell.path("target").asText();
|
String targetId = cell.path(BpmnConstants.NodeAttribute.TARGET).asText();
|
||||||
String id = cell.path("id").asText();
|
String id = cell.path(BpmnConstants.NodeAttribute.ID).asText();
|
||||||
|
|
||||||
FlowElement sourceElement = elementMap.get(sourceId);
|
FlowElement sourceElement = elementMap.get(sourceId);
|
||||||
FlowElement targetElement = elementMap.get(targetId);
|
FlowElement targetElement = elementMap.get(targetId);
|
||||||
@ -201,13 +205,15 @@ public class BpmnConverter {
|
|||||||
sequenceFlow.setTargetRef(targetId);
|
sequenceFlow.setTargetRef(targetId);
|
||||||
|
|
||||||
// 设置连线名称
|
// 设置连线名称
|
||||||
JsonNode label = cell.path("data").path("label");
|
JsonNode label = cell.path(BpmnConstants.NodeAttribute.DATA)
|
||||||
|
.path(BpmnConstants.NodeAttribute.LABEL);
|
||||||
if (!label.isMissingNode()) {
|
if (!label.isMissingNode()) {
|
||||||
sequenceFlow.setName(label.asText());
|
sequenceFlow.setName(label.asText());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置条件表达式
|
// 设置条件表达式
|
||||||
JsonNode condition = cell.path("data").path("condition");
|
JsonNode condition = cell.path(BpmnConstants.NodeAttribute.DATA)
|
||||||
|
.path(BpmnConstants.NodeAttribute.CONDITION);
|
||||||
if (!condition.isMissingNode()) {
|
if (!condition.isMissingNode()) {
|
||||||
sequenceFlow.setConditionExpression(condition.asText());
|
sequenceFlow.setConditionExpression(condition.asText());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user