支持获取当前已使用的节点key列表
This commit is contained in:
parent
a32385920a
commit
673dc84d73
@ -2,7 +2,7 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
ext {
|
ext {
|
||||||
springBootVersion = "2.7.0"
|
springBootVersion = "2.7.0"
|
||||||
mybatisPlusVersion = "3.5.9"
|
mybatisPlusVersion = "3.5.8"
|
||||||
solonVersion = "3.0.1"
|
solonVersion = "3.0.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import com.aizuda.bpm.engine.FlowLongEngine;
|
|||||||
import com.aizuda.bpm.engine.TaskActorProvider;
|
import com.aizuda.bpm.engine.TaskActorProvider;
|
||||||
import com.aizuda.bpm.engine.assist.Assert;
|
import com.aizuda.bpm.engine.assist.Assert;
|
||||||
import com.aizuda.bpm.engine.entity.FlwInstance;
|
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.FlwTask;
|
||||||
import com.aizuda.bpm.engine.entity.FlwTaskActor;
|
import com.aizuda.bpm.engine.entity.FlwTaskActor;
|
||||||
import com.aizuda.bpm.engine.model.ModelHelper;
|
import com.aizuda.bpm.engine.model.ModelHelper;
|
||||||
@ -124,6 +123,14 @@ public class Execution implements Serializable {
|
|||||||
this.args = args;
|
this.args = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造函数,仅适用于模型条件节点查找
|
||||||
|
*/
|
||||||
|
public Execution(FlowCreator flowCreator, Map<String, Object> args) {
|
||||||
|
this.flowCreator = flowCreator;
|
||||||
|
this.args = args;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据当前执行对象execution、子流程定义process、当前节点名称产生子流程的执行对象
|
* 根据当前执行对象execution、子流程定义process、当前节点名称产生子流程的执行对象
|
||||||
*
|
*
|
||||||
|
@ -6,6 +6,8 @@ package com.aizuda.bpm.engine.model;
|
|||||||
import com.aizuda.bpm.engine.FlowConstants;
|
import com.aizuda.bpm.engine.FlowConstants;
|
||||||
import com.aizuda.bpm.engine.FlowDataTransfer;
|
import com.aizuda.bpm.engine.FlowDataTransfer;
|
||||||
import com.aizuda.bpm.engine.assist.ObjectUtils;
|
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.NodeSetType;
|
||||||
import com.aizuda.bpm.engine.core.enums.TaskType;
|
import com.aizuda.bpm.engine.core.enums.TaskType;
|
||||||
|
|
||||||
@ -368,4 +370,61 @@ public class ModelHelper {
|
|||||||
FlowDataTransfer.removeByKey(FlowConstants.processDynamicAssignee);
|
FlowDataTransfer.removeByKey(FlowConstants.processDynamicAssignee);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前已使用的节点key列表
|
||||||
|
*
|
||||||
|
* @param flowLongContext 流程上下文 {@link FlowLongContext}
|
||||||
|
* @param execution 流程执行对象 {@link Execution}
|
||||||
|
* @param rootNodeModel 模型根节点 {@link NodeModel}
|
||||||
|
* @param currentNodeKey 当前所在节点
|
||||||
|
* @return 当前已使用的节点key列表
|
||||||
|
*/
|
||||||
|
public static List<String> getAllUsedNodeKeys(FlowLongContext flowLongContext, Execution execution, NodeModel rootNodeModel, String currentNodeKey) {
|
||||||
|
List<String> currentUsedNodeKeys = new ArrayList<>();
|
||||||
|
if (null != rootNodeModel) {
|
||||||
|
String nodeKey = rootNodeModel.getNodeKey();
|
||||||
|
if (Objects.equals(currentNodeKey, nodeKey)) {
|
||||||
|
// 找到执行最后一个节点直接结束
|
||||||
|
currentUsedNodeKeys.add(nodeKey);
|
||||||
|
} else {
|
||||||
|
// 处理完成节点
|
||||||
|
if (rootNodeModel.conditionNode()) {
|
||||||
|
// 条件节点
|
||||||
|
List<ConditionNode> 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<String> currentUsedNodeKeys, FlowLongContext flowLongContext,
|
||||||
|
Execution execution, NodeModel rootNodeModel, String currentNodeKey) {
|
||||||
|
if (!currentUsedNodeKeys.contains(currentNodeKey)) {
|
||||||
|
currentUsedNodeKeys.addAll(getAllUsedNodeKeys(flowLongContext, execution, rootNodeModel, currentNodeKey));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ package test.mysql;
|
|||||||
|
|
||||||
import com.aizuda.bpm.engine.FlowDataTransfer;
|
import com.aizuda.bpm.engine.FlowDataTransfer;
|
||||||
import com.aizuda.bpm.engine.assist.StreamUtils;
|
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.FlowCreator;
|
||||||
import com.aizuda.bpm.engine.core.FlowLongContext;
|
import com.aizuda.bpm.engine.core.FlowLongContext;
|
||||||
import com.aizuda.bpm.engine.model.*;
|
import com.aizuda.bpm.engine.model.*;
|
||||||
@ -193,4 +194,27 @@ public class TestModel extends MysqlTest {
|
|||||||
ProcessModel errorModel01 = getProcessModel("test/errorModel01.json");
|
ProcessModel errorModel01 = getProcessModel("test/errorModel01.json");
|
||||||
Assertions.assertFalse(ModelHelper.checkExistApprovalNode(errorModel01.getNodeConfig()));
|
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<String, Object>() {{
|
||||||
|
put("day", 3);
|
||||||
|
}}), processModel.getNodeConfig(), "k007").size());
|
||||||
|
|
||||||
|
Assertions.assertEquals(4, ModelHelper.getAllUsedNodeKeys(flowLongEngine.getContext(), new Execution(testCreator, new HashMap<String, Object>() {{
|
||||||
|
put("day", 8);
|
||||||
|
}}), processModel.getNodeConfig(), "k005").size());
|
||||||
|
|
||||||
|
Assertions.assertEquals(5, ModelHelper.getAllUsedNodeKeys(flowLongEngine.getContext(), new Execution(testCreator, new HashMap<String, Object>() {{
|
||||||
|
put("day", 8);
|
||||||
|
}}), processModel.getNodeConfig(), "k008").size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
2
pom.xml
2
pom.xml
@ -21,7 +21,7 @@
|
|||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
<spring-boot.version>2.7.0</spring-boot.version>
|
<spring-boot.version>2.7.0</spring-boot.version>
|
||||||
<mybatis.plus-version>3.5.9</mybatis.plus-version>
|
<mybatis.plus-version>3.5.8</mybatis.plus-version>
|
||||||
<mysql.version>8.0.32</mysql.version>
|
<mysql.version>8.0.32</mysql.version>
|
||||||
<solon.version>3.0.1</solon.version>
|
<solon.version>3.0.1</solon.version>
|
||||||
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
|
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user