From 17dd2505a93b36d2e645cb01fee738d88462843d Mon Sep 17 00:00:00 2001 From: hubin Date: Tue, 10 Sep 2024 22:13:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B0=83=E6=95=B4PR=E9=83=A8?= =?UTF-8?q?=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/aizuda/bpm/engine/core/Execution.java | 12 ++++++------ .../aizuda/bpm/engine/impl/TaskServiceImpl.java | 2 +- .../com/aizuda/bpm/engine/model/ModelHelper.java | 12 ++++-------- ...SubProcess.java => TestParallelSubProcess.java} | 14 ++------------ 4 files changed, 13 insertions(+), 27 deletions(-) rename flowlong-spring-boot-starter/src/test/java/test/mysql/{TestParalleSubProcess.java => TestParallelSubProcess.java} (82%) 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 939769fc..49e7b3dc 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 @@ -164,20 +164,19 @@ public boolean executeNodeModel(FlowLongContext flowLongContext, String nodeKey) // 获取当前任务列表,检查并行分支执行情况 List nodeKeys = new LinkedList<>(); - List otherProcessKeys = new LinkedList<>(); flowLongContext.getQueryService().getActiveTasksByInstanceId(flwTask.getInstanceId()).ifPresent(flwTasks -> { for (FlwTask ft : flwTasks) { nodeKeys.add(ft.getTaskKey()); } }); - //查找流程关联的子流程 + // 查找流程关联的子流程 + List otherProcessKeys = new LinkedList<>(); Optional> subProcessList = flowLongContext.getQueryService().getSubProcessByInstanceId(flwTask.getInstanceId()); - subProcessList.ifPresent(subProcesses -> subProcesses.forEach(process ->{ + subProcessList.ifPresent(subProcesses -> subProcesses.forEach(process -> { ProcessModel otherModel = flowLongContext.getRuntimeService().getProcessModelByInstanceId(process.getId()); otherProcessKeys.addAll(new ArrayList<>(ModelHelper.getRootNodeAllChildNodes(otherModel.getNodeConfig()).stream().map(NodeModel::getNodeKey).collect(Collectors.toList()))); flowLongContext.getQueryService().getActiveTasksByInstanceId(process.getId()).ifPresent(flwTasks -> { - //其他的key for (FlwTask ft : flwTasks) { nodeKeys.add(ft.getTaskKey()); } @@ -185,8 +184,9 @@ public boolean executeNodeModel(FlowLongContext flowLongContext, String nodeKey) })); Optional executeNodeOptional = Optional.empty(); - //如果有额外的流程,先判断当前的task是否在流程里面,如果不在直找下一个节点 - if (!(!otherProcessKeys.isEmpty() && !nodeKeys.isEmpty() && !Collections.disjoint(nodeKeys, otherProcessKeys))){ + + // 如果有额外的流程,先判断当前的task是否在流程里面,如果不在直找下一个节点 + if (!(!otherProcessKeys.isEmpty() && !nodeKeys.isEmpty() && !Collections.disjoint(nodeKeys, otherProcessKeys))) { executeNodeOptional = nodeModel.nextNode(nodeKeys); } diff --git a/flowlong-core/src/main/java/com/aizuda/bpm/engine/impl/TaskServiceImpl.java b/flowlong-core/src/main/java/com/aizuda/bpm/engine/impl/TaskServiceImpl.java index 184f65ca..11409d00 100644 --- a/flowlong-core/src/main/java/com/aizuda/bpm/engine/impl/TaskServiceImpl.java +++ b/flowlong-core/src/main/java/com/aizuda/bpm/engine/impl/TaskServiceImpl.java @@ -1029,7 +1029,7 @@ protected List saveTask(FlwTask flwTask, PerformType performType, List< if (hisTaskDao.insert(flwHisTask)) { // 设置为执行任务 execution.setFlwTask(flwHisTask); - // 即可归档,确保自增ID情况一致性 + // 即刻归档,确保自增ID情况一致性 taskDao.deleteById(flwTask.getId()); // 记录发起人 hisTaskActorDao.insert(FlwHisTaskActor.ofFlwHisTask(flwHisTask)); 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 aa98a4cb..b168945e 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 @@ -50,8 +50,8 @@ public static NodeModel findNextNode(NodeModel nodeModel, List currentTa // 判断当前节点为并行分支或包容分支,需要判断当前并行是否走完 if (parentNode.parallelNode() || parentNode.inclusiveNode()) { - //只是找下一个节点 - if (null == currentTask){ + // 只是找下一个节点 + if (null == currentTask) { return parentNode.getChildNode(); } // 找到另外的分支,看是否列表有执行,有就不能返回 childNode @@ -185,8 +185,7 @@ private static List getAllNextConditionNodeKeys(NodeModel nodeModel) { public static List getUnsetAssigneeNodes(NodeModel rootNodeModel) { List nodeModels = getRootNodeAllChildNodes(rootNodeModel); // 过滤发起和结束节点 - return nodeModels.stream().filter(t -> ObjectUtils.isEmpty(t.getNodeAssigneeList()) && NodeSetType.initiatorThemselves.ne(t.getSetType()) - && (TaskType.approval.eq(t.getType()) || TaskType.cc.eq(t.getType()))).collect(Collectors.toList()); + return nodeModels.stream().filter(t -> ObjectUtils.isEmpty(t.getNodeAssigneeList()) && NodeSetType.initiatorThemselves.ne(t.getSetType()) && (TaskType.approval.eq(t.getType()) || TaskType.cc.eq(t.getType()))).collect(Collectors.toList()); } /** @@ -335,10 +334,7 @@ public static Map getAssigneeMap(NodeModel rootNodeMode * @return JSON BPM 节点 */ public static NodeModel getNodeModel(String nodeKey, NodeModel rootNodeModel) { - return getRootNodeAllChildNodes(rootNodeModel).stream() - .filter(e -> Objects.equals(nodeKey, e.getNodeKey())) - .findFirst() - .orElse(null); + return getRootNodeAllChildNodes(rootNodeModel).stream().filter(e -> Objects.equals(nodeKey, e.getNodeKey())).findFirst().orElse(null); } /** diff --git a/flowlong-spring-boot-starter/src/test/java/test/mysql/TestParalleSubProcess.java b/flowlong-spring-boot-starter/src/test/java/test/mysql/TestParallelSubProcess.java similarity index 82% rename from flowlong-spring-boot-starter/src/test/java/test/mysql/TestParalleSubProcess.java rename to flowlong-spring-boot-starter/src/test/java/test/mysql/TestParallelSubProcess.java index 66a598a4..dae1b49e 100644 --- a/flowlong-spring-boot-starter/src/test/java/test/mysql/TestParalleSubProcess.java +++ b/flowlong-spring-boot-starter/src/test/java/test/mysql/TestParallelSubProcess.java @@ -4,22 +4,18 @@ package test.mysql; import com.aizuda.bpm.engine.ProcessService; -import com.aizuda.bpm.engine.assist.Assert; import com.aizuda.bpm.engine.core.FlowCreator; import com.aizuda.bpm.engine.entity.FlwProcess; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.util.HashMap; -import java.util.Map; - /** * 测试子流程 * * @author xdg */ -public class TestParalleSubProcess extends MysqlTest { +public class TestParallelSubProcess extends MysqlTest { @BeforeEach public void before() { @@ -40,9 +36,6 @@ public void testProcess() { Assertions.assertNotNull(processService.getProcessByVersion(process.getTenantId(), process.getProcessKey(), process.getProcessVersion())); } - // 启动指定流程定义ID启动流程实例 - FlowCreator flowCreator = this.getFlowCreator(); - // 发起,执行条件路由 // 启动指定流程定义ID启动流程实例 flowLongEngine.startInstanceById(processId, testCreator).ifPresent(instance -> { this.executeTaskByKey(instance.getId(), test2Creator, "k003"); @@ -52,11 +45,8 @@ public void testProcess() { this.executeActiveTasks(flwHisTask.getCallInstanceId(), test3Creator); } })); - this.executeTaskByKey(instance.getId(), test2Creator,"k005"); + this.executeTaskByKey(instance.getId(), test2Creator, "k005"); }); - - // 卸载指定的定义流程 - // Assertions.assertTrue(processService.undeploy(processId)); }