仿钉钉流程设计-包容网关的实现

This commit is contained in:
jason 2024-04-07 22:20:46 +08:00
parent df936deeca
commit 98998cff6f
2 changed files with 26 additions and 6 deletions

View File

@ -25,6 +25,8 @@ public enum BpmSimpleModelNodeType implements IntArrayValuable {
EXCLUSIVE_GATEWAY_NODE(4, "排他网关"),
PARALLEL_GATEWAY_FORK_NODE(5, "并行网关分叉节点"),
PARALLEL_GATEWAY_JOIN_NODE(6, "并行网关聚合节点"),
INCLUSIVE_GATEWAY_FORK_NODE(7, "包容网关分叉节点"),
INCLUSIVE_GATEWAY_JOIN_NODE(8, "包容网关聚合节点"),
END_EVENT_NODE(-2, "结束节点");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmSimpleModelNodeType::getType).toArray();
@ -33,9 +35,8 @@ public enum BpmSimpleModelNodeType implements IntArrayValuable {
private final String name;
public static boolean isGatewayNode(Integer type) {
// TODO 后续增加并行网关的支持
return Objects.equals(EXCLUSIVE_GATEWAY_NODE.getType(), type)
|| Objects.equals(PARALLEL_GATEWAY_FORK_NODE.getType(), type);
return Objects.equals(EXCLUSIVE_GATEWAY_NODE.getType(), type) || Objects.equals(PARALLEL_GATEWAY_FORK_NODE.getType(), type)
|| Objects.equals(INCLUSIVE_GATEWAY_FORK_NODE.getType(), type) ;
}
public static BpmSimpleModelNodeType valueOf(Integer type) {

View File

@ -386,14 +386,16 @@ public class BpmnModelUtils {
case START_EVENT_NODE:
case APPROVE_USER_NODE:
case SCRIPT_TASK_NODE:
case PARALLEL_GATEWAY_JOIN_NODE:{
case PARALLEL_GATEWAY_JOIN_NODE:
case INCLUSIVE_GATEWAY_JOIN_NODE:{
addBpmnSequenceFlowElement(mainProcess, node.getId(), childNode.getId(), null, null);
// 递归调用后续节点
addBpmnSequenceFlow(mainProcess, childNode, endId);
break;
}
case PARALLEL_GATEWAY_FORK_NODE:
case EXCLUSIVE_GATEWAY_NODE: {
case EXCLUSIVE_GATEWAY_NODE:
case INCLUSIVE_GATEWAY_FORK_NODE:{
String gateWayEndId = (childNode == null || childNode.getId() == null) ? BpmnModelConstants.END_EVENT_ID : childNode.getId();
List<BpmSimpleModelNodeVO> conditionNodes = node.getConditionNodes();
Assert.notEmpty(conditionNodes, "网关节点的条件节点不能为空");
@ -455,6 +457,12 @@ public class BpmnModelUtils {
case PARALLEL_GATEWAY_JOIN_NODE:
addBpmnParallelGatewayNode(mainProcess, simpleModelNode);
break;
case INCLUSIVE_GATEWAY_FORK_NODE:
addBpmnInclusiveGatewayNode(mainProcess, simpleModelNode, Boolean.TRUE);
break;
case INCLUSIVE_GATEWAY_JOIN_NODE:
addBpmnInclusiveGatewayNode(mainProcess, simpleModelNode, Boolean.FALSE);
break;
default: {
// TODO 其它节点类型的实现
}
@ -507,11 +515,22 @@ public class BpmnModelUtils {
Assert.notEmpty(node.getConditionNodes(), "网关节点的条件节点不能为空");
ExclusiveGateway exclusiveGateway = new ExclusiveGateway();
exclusiveGateway.setId(node.getId());
// 条件节点的最后一个条件为 网关的 default sequence flow
// 网关的最后一个条件为 网关的 default sequence flow
exclusiveGateway.setDefaultFlow(String.format("%s_SequenceFlow_%d", node.getId(), node.getConditionNodes().size()));
mainProcess.addFlowElement(exclusiveGateway);
}
private static void addBpmnInclusiveGatewayNode(Process mainProcess, BpmSimpleModelNodeVO node, Boolean isFork) {
InclusiveGateway inclusiveGateway = new InclusiveGateway();
inclusiveGateway.setId(node.getId());
if (isFork) {
Assert.notEmpty(node.getConditionNodes(), "网关节点的条件节点不能为空");
// 网关的最后一个条件为 网关的 default sequence flow
inclusiveGateway.setDefaultFlow(String.format("%s_SequenceFlow_%d", node.getId(), node.getConditionNodes().size()));
}
mainProcess.addFlowElement(inclusiveGateway);
}
private static void addBpmnEndEventNode(Process mainProcess) {
EndEvent endEvent = new EndEvent();
endEvent.setId(BpmnModelConstants.END_EVENT_ID);