|
@@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.bpm.framework.flowable.core.util;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
-import cn.hutool.core.lang.TypeReference;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
@@ -338,31 +337,26 @@ public class BpmnModelUtils {
|
|
|
|
|
|
/**
|
|
|
* 仿钉钉流程设计模型数据结构(json) 转换成 Bpmn Model (待完善)
|
|
|
- * @param processId 流程标识
|
|
|
- * @param processName 流程名称
|
|
|
+ *
|
|
|
+ * @param processId 流程标识
|
|
|
+ * @param processName 流程名称
|
|
|
* @param simpleModelNode 仿钉钉流程设计模型数据结构
|
|
|
* @return Bpmn Model
|
|
|
*/
|
|
|
- public static BpmnModel convertSimpleModelToBpmnModel(String processId, String processName,BpmSimpleModelNodeVO simpleModelNode) {
|
|
|
+ public static BpmnModel convertSimpleModelToBpmnModel(String processId, String processName, BpmSimpleModelNodeVO simpleModelNode) {
|
|
|
BpmnModel bpmnModel = new BpmnModel();
|
|
|
Process mainProcess = new Process();
|
|
|
mainProcess.setId(processId);
|
|
|
mainProcess.setName(processName);
|
|
|
mainProcess.setExecutable(Boolean.TRUE);
|
|
|
bpmnModel.addProcess(mainProcess);
|
|
|
- // 目前前端传进来的节点。 没有 start event 节点 和 end event 节点。
|
|
|
- // 在最前面加上 start event node
|
|
|
- BpmSimpleModelNodeVO startEventNode = new BpmSimpleModelNodeVO();
|
|
|
- startEventNode.setId(BpmnModelConstants.START_EVENT_ID);
|
|
|
- startEventNode.setName("开始");
|
|
|
- startEventNode.setType(BpmSimpleModelNodeType.START_NODE.getType());
|
|
|
- startEventNode.setChildNode(simpleModelNode);
|
|
|
+ // 前端模型数据结构。 有 start event 节点. 没有 end event 节点。
|
|
|
// 添加 FlowNode
|
|
|
- addBpmnFlowNode(mainProcess, startEventNode);
|
|
|
+ addBpmnFlowNode(mainProcess, simpleModelNode);
|
|
|
// 单独添加 end event 节点
|
|
|
addBpmnEndEventNode(mainProcess);
|
|
|
// 添加节点之间的连线 Sequence Flow
|
|
|
- addBpmnSequenceFlow(mainProcess, startEventNode);
|
|
|
+ addBpmnSequenceFlow(mainProcess, simpleModelNode);
|
|
|
// 自动布局
|
|
|
new BpmnAutoLayout(bpmnModel).execute();
|
|
|
|
|
@@ -371,24 +365,24 @@ public class BpmnModelUtils {
|
|
|
|
|
|
private static void addBpmnSequenceFlow(Process mainProcess, BpmSimpleModelNodeVO node) {
|
|
|
// 节点为 null 退出
|
|
|
- if (node == null) {
|
|
|
+ if (node == null || node.getId() == null) {
|
|
|
return;
|
|
|
}
|
|
|
BpmSimpleModelNodeVO childNode = node.getChildNode();
|
|
|
// 如果后续节点为 null. 添加与结束节点的连线
|
|
|
- if (childNode == null) {
|
|
|
- addBpmnSequenceFlowElement(mainProcess, node.getId(),BpmnModelConstants.END_EVENT_ID, null);
|
|
|
+ if (childNode == null || childNode.getId() == null) {
|
|
|
+ addBpmnSequenceFlowElement(mainProcess, node.getId(), BpmnModelConstants.END_EVENT_ID, null);
|
|
|
return;
|
|
|
}
|
|
|
BpmSimpleModelNodeType nodeType = BpmSimpleModelNodeType.valueOf(node.getType());
|
|
|
Assert.notNull(nodeType, "模型节点类型不支持");
|
|
|
- switch(nodeType){
|
|
|
- case START_NODE :
|
|
|
- case START_USER_NODE :
|
|
|
- case APPROVE_USER_NODE :
|
|
|
+ switch (nodeType) {
|
|
|
+ case START_NODE:
|
|
|
+ case START_USER_NODE:
|
|
|
+ case APPROVE_USER_NODE:
|
|
|
addBpmnSequenceFlowElement(mainProcess, node.getId(), childNode.getId(), null);
|
|
|
break;
|
|
|
- default : {
|
|
|
+ default: {
|
|
|
// TODO 其它节点类型的实现
|
|
|
}
|
|
|
}
|
|
@@ -396,7 +390,7 @@ public class BpmnModelUtils {
|
|
|
addBpmnSequenceFlow(mainProcess, childNode);
|
|
|
}
|
|
|
|
|
|
- private static void addBpmnSequenceFlowElement(Process mainProcess, String sourceId, String targetId, String conditionExpression) {
|
|
|
+ private static void addBpmnSequenceFlowElement(Process mainProcess, String sourceId, String targetId, String conditionExpression) {
|
|
|
SequenceFlow sequenceFlow = new SequenceFlow(sourceId, targetId);
|
|
|
if (StrUtil.isNotEmpty(conditionExpression)) {
|
|
|
sequenceFlow.setConditionExpression(conditionExpression);
|
|
@@ -407,20 +401,20 @@ public class BpmnModelUtils {
|
|
|
|
|
|
private static void addBpmnFlowNode(Process mainProcess, BpmSimpleModelNodeVO simpleModelNode) {
|
|
|
// 节点为 null 退出
|
|
|
- if (simpleModelNode == null) {
|
|
|
+ if (simpleModelNode == null || simpleModelNode.getId() == null) {
|
|
|
return;
|
|
|
}
|
|
|
BpmSimpleModelNodeType nodeType = BpmSimpleModelNodeType.valueOf(simpleModelNode.getType());
|
|
|
Assert.notNull(nodeType, "模型节点类型不支持");
|
|
|
- switch(nodeType){
|
|
|
- case START_NODE :
|
|
|
+ switch (nodeType) {
|
|
|
+ case START_NODE:
|
|
|
addBpmnStartEventNode(mainProcess, simpleModelNode);
|
|
|
break;
|
|
|
- case START_USER_NODE :
|
|
|
- case APPROVE_USER_NODE :
|
|
|
+ case START_USER_NODE:
|
|
|
+ case APPROVE_USER_NODE:
|
|
|
addBpmnUserTaskEventNode(mainProcess, simpleModelNode);
|
|
|
break;
|
|
|
- default : {
|
|
|
+ default: {
|
|
|
// TODO 其它节点类型的实现
|
|
|
}
|
|
|
}
|
|
@@ -454,17 +448,16 @@ public class BpmnModelUtils {
|
|
|
UserTask userTask = new UserTask();
|
|
|
userTask.setId(node.getId());
|
|
|
userTask.setName(node.getName());
|
|
|
- Integer candidateStrategy = MapUtil.getInt(node.getAttributes(),BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY);
|
|
|
- List<Integer> candidateParam = MapUtil.get(node.getAttributes(), BpmnModelConstants.USER_TASK_CANDIDATE_PARAM, new TypeReference<>() {});
|
|
|
+ Integer candidateStrategy = MapUtil.getInt(node.getAttributes(), BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY);
|
|
|
// 添加自定义属性
|
|
|
addExtensionAttribute(userTask, BpmnModelConstants.NAMESPACE, BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY,
|
|
|
candidateStrategy == null ? null : String.valueOf(candidateStrategy));
|
|
|
addExtensionAttribute(userTask, BpmnModelConstants.NAMESPACE, BpmnModelConstants.USER_TASK_CANDIDATE_PARAM,
|
|
|
- CollUtil.join(candidateParam, ","));
|
|
|
+ MapUtil.getStr(node.getAttributes(), BpmnModelConstants.USER_TASK_CANDIDATE_PARAM));
|
|
|
mainProcess.addFlowElement(userTask);
|
|
|
}
|
|
|
|
|
|
- private static void addExtensionAttribute(FlowElement element, String namespace, String name, String value) {
|
|
|
+ private static void addExtensionAttribute(FlowElement element, String namespace, String name, String value) {
|
|
|
if (value == null) {
|
|
|
return;
|
|
|
}
|