From 673dc84d73fe0efcb27f2228b4ecc0eb17984c52 Mon Sep 17 00:00:00 2001 From: hubin Date: Wed, 20 Nov 2024 21:04:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=8E=B7=E5=8F=96=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E5=B7=B2=E4=BD=BF=E7=94=A8=E7=9A=84=E8=8A=82=E7=82=B9?= =?UTF-8?q?key=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- .../com/aizuda/bpm/engine/core/Execution.java | 9 ++- .../aizuda/bpm/engine/model/ModelHelper.java | 59 +++++++++++++++++++ .../src/test/java/test/mysql/TestModel.java | 24 ++++++++ pom.xml | 2 +- 5 files changed, 93 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index ae17d70..6e73b2c 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ buildscript { ext { springBootVersion = "2.7.0" - mybatisPlusVersion = "3.5.9" + mybatisPlusVersion = "3.5.8" solonVersion = "3.0.1" } diff --git a/flowlong-core/src/main/java/com/aizuda/bpm/engine/core/Execution.java b/flowlong-core/src/main/java/com/aizuda/bpm/engine/core/Execution.java index 49e7b3d..e50a926 100644 --- a/flowlong-core/src/main/java/com/aizuda/bpm/engine/core/Execution.java +++ b/flowlong-core/src/main/java/com/aizuda/bpm/engine/core/Execution.java @@ -8,7 +8,6 @@ import com.aizuda.bpm.engine.FlowLongEngine; import com.aizuda.bpm.engine.TaskActorProvider; import com.aizuda.bpm.engine.assist.Assert; import com.aizuda.bpm.engine.entity.FlwInstance; -import com.aizuda.bpm.engine.entity.FlwProcess; import com.aizuda.bpm.engine.entity.FlwTask; import com.aizuda.bpm.engine.entity.FlwTaskActor; import com.aizuda.bpm.engine.model.ModelHelper; @@ -124,6 +123,14 @@ public class Execution implements Serializable { this.args = args; } + /** + * 构造函数,仅适用于模型条件节点查找 + */ + public Execution(FlowCreator flowCreator, Map args) { + this.flowCreator = flowCreator; + this.args = args; + } + /** * 根据当前执行对象execution、子流程定义process、当前节点名称产生子流程的执行对象 * diff --git a/flowlong-core/src/main/java/com/aizuda/bpm/engine/model/ModelHelper.java b/flowlong-core/src/main/java/com/aizuda/bpm/engine/model/ModelHelper.java index 7b494bb..3aa6016 100644 --- a/flowlong-core/src/main/java/com/aizuda/bpm/engine/model/ModelHelper.java +++ b/flowlong-core/src/main/java/com/aizuda/bpm/engine/model/ModelHelper.java @@ -6,6 +6,8 @@ package com.aizuda.bpm.engine.model; import com.aizuda.bpm.engine.FlowConstants; import com.aizuda.bpm.engine.FlowDataTransfer; import com.aizuda.bpm.engine.assist.ObjectUtils; +import com.aizuda.bpm.engine.core.Execution; +import com.aizuda.bpm.engine.core.FlowLongContext; import com.aizuda.bpm.engine.core.enums.NodeSetType; import com.aizuda.bpm.engine.core.enums.TaskType; @@ -368,4 +370,61 @@ public class ModelHelper { FlowDataTransfer.removeByKey(FlowConstants.processDynamicAssignee); } } + + /** + * 获取当前已使用的节点key列表 + * + * @param flowLongContext 流程上下文 {@link FlowLongContext} + * @param execution 流程执行对象 {@link Execution} + * @param rootNodeModel 模型根节点 {@link NodeModel} + * @param currentNodeKey 当前所在节点 + * @return 当前已使用的节点key列表 + */ + public static List getAllUsedNodeKeys(FlowLongContext flowLongContext, Execution execution, NodeModel rootNodeModel, String currentNodeKey) { + List currentUsedNodeKeys = new ArrayList<>(); + if (null != rootNodeModel) { + String nodeKey = rootNodeModel.getNodeKey(); + if (Objects.equals(currentNodeKey, nodeKey)) { + // 找到执行最后一个节点直接结束 + currentUsedNodeKeys.add(nodeKey); + } else { + // 处理完成节点 + if (rootNodeModel.conditionNode()) { + // 条件节点 + List conditionNodes = rootNodeModel.getConditionNodes(); + if (ObjectUtils.isNotEmpty(conditionNodes)) { + // 找到对应节点 + flowLongContext.getFlowConditionHandler().getConditionNode(flowLongContext, execution, rootNodeModel).ifPresent(t -> { + // 添加执行条件节点 + currentUsedNodeKeys.add(t.getNodeKey()); + + // 条件节点分支子节点 + getChildAllUsedNodeKeys(currentUsedNodeKeys, flowLongContext, execution, t.getChildNode(), currentNodeKey); + }); + } + + // 条件节点子节点 + getChildAllUsedNodeKeys(currentUsedNodeKeys, flowLongContext, execution, rootNodeModel.getChildNode(), currentNodeKey); + } else { + + // 普通节点 + currentUsedNodeKeys.add(nodeKey); + + // 找子节点 + NodeModel childNodeModel = rootNodeModel.getChildNode(); + if (null != childNodeModel) { + getChildAllUsedNodeKeys(currentUsedNodeKeys, flowLongContext, execution, childNodeModel, currentNodeKey); + } + } + } + } + return currentUsedNodeKeys; + } + + public static void getChildAllUsedNodeKeys(List currentUsedNodeKeys, FlowLongContext flowLongContext, + Execution execution, NodeModel rootNodeModel, String currentNodeKey) { + if (!currentUsedNodeKeys.contains(currentNodeKey)) { + currentUsedNodeKeys.addAll(getAllUsedNodeKeys(flowLongContext, execution, rootNodeModel, currentNodeKey)); + } + } } diff --git a/flowlong-spring-boot-starter/src/test/java/test/mysql/TestModel.java b/flowlong-spring-boot-starter/src/test/java/test/mysql/TestModel.java index 09ac671..0022c7c 100644 --- a/flowlong-spring-boot-starter/src/test/java/test/mysql/TestModel.java +++ b/flowlong-spring-boot-starter/src/test/java/test/mysql/TestModel.java @@ -5,6 +5,7 @@ package test.mysql; import com.aizuda.bpm.engine.FlowDataTransfer; import com.aizuda.bpm.engine.assist.StreamUtils; +import com.aizuda.bpm.engine.core.Execution; import com.aizuda.bpm.engine.core.FlowCreator; import com.aizuda.bpm.engine.core.FlowLongContext; import com.aizuda.bpm.engine.model.*; @@ -193,4 +194,27 @@ public class TestModel extends MysqlTest { ProcessModel errorModel01 = getProcessModel("test/errorModel01.json"); Assertions.assertFalse(ModelHelper.checkExistApprovalNode(errorModel01.getNodeConfig())); } + + /** + * 测试获取当前已使用的节点key列表 + */ + @Test + public void testCurrentUsedNodeKeys() { + ProcessModel processModel = getProcessModel("test/ccToCondition.json"); + + Assertions.assertEquals(2, ModelHelper.getAllUsedNodeKeys(flowLongEngine.getContext(), new Execution(testCreator, null), + processModel.getNodeConfig(), "k002").size()); + + Assertions.assertEquals(4, ModelHelper.getAllUsedNodeKeys(flowLongEngine.getContext(), new Execution(testCreator, new HashMap() {{ + put("day", 3); + }}), processModel.getNodeConfig(), "k007").size()); + + Assertions.assertEquals(4, ModelHelper.getAllUsedNodeKeys(flowLongEngine.getContext(), new Execution(testCreator, new HashMap() {{ + put("day", 8); + }}), processModel.getNodeConfig(), "k005").size()); + + Assertions.assertEquals(5, ModelHelper.getAllUsedNodeKeys(flowLongEngine.getContext(), new Execution(testCreator, new HashMap() {{ + put("day", 8); + }}), processModel.getNodeConfig(), "k008").size()); + } } diff --git a/pom.xml b/pom.xml index 43d6676..23005f3 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 8 8 2.7.0 - 3.5.9 + 3.5.8 8.0.32 3.0.1 3.1.2