优化抄送任务并行分支执行逻辑

This commit is contained in:
hubin 2025-01-05 18:07:53 +08:00
parent c782a1ee93
commit 9e0a9d8b32
7 changed files with 157 additions and 2 deletions

View File

@ -53,6 +53,14 @@ public interface QueryService {
*/
boolean existActiveSubProcess(Long instanceId);
/**
* 判断流程实例下是否存在活跃任务
*
* @param instanceId 流程实例ID
* @return true 存在 false 不存在
*/
boolean existActiveTask(Long instanceId);
/**
* 根据任务ID获取任务对象
*

View File

@ -42,6 +42,8 @@ public interface FlwTaskDao {
Long selectCountByParentTaskId(Long parentTaskId);
Long selectCountByInstanceId(Long instanceId);
List<FlwTask> selectListByInstanceId(Long instanceId);
List<FlwTask> selectListByInstanceIdAndTaskName(Long instanceId, String taskName);

View File

@ -67,6 +67,11 @@ public class QueryServiceImpl implements QueryService {
return instanceDao.selectCountByParentInstanceId(instanceId) > 0;
}
@Override
public boolean existActiveTask(Long instanceId) {
return taskDao.selectCountByInstanceId(instanceId) > 0;
}
@Override
public FlwHisTask getHistTask(Long taskId) {
return hisTaskDao.selectById(taskId);

View File

@ -926,8 +926,20 @@ public class TaskServiceImpl implements TaskService {
*/
Optional<NodeModel> nextNodeOptional = nodeModel.nextNode();
if (nextNodeOptional.isPresent()) {
// 下一个节点如果在并行分支判断是否并行分支都执行结束
boolean _exec = true;
NodeModel ccNextNode = nextNodeOptional.get();
NodeModel _cnn = execution.getProcessModel().getNode(ccNextNode.getNodeKey());
if (_cnn.getParentNode().parallelNode()) {
// 抄送节点独立占据一个分支或者存在执行任务
if (ccNextNode.getParentNode().parallelNode() || taskDao.selectCountByInstanceId(flwTask.getInstanceId()) > 0) {
_exec = false;
}
}
if (_exec) {
// 执行下一个节点
nextNodeOptional.get().execute(execution.getEngine().getContext(), execution);
ccNextNode.execute(execution.getEngine().getContext(), execution);
}
} else {
// 不存在任何子节点结束流程
execution.endInstance(nodeModel);

View File

@ -65,6 +65,12 @@ public class FlwTaskDaoImpl implements FlwTaskDao {
.eq(FlwTask::getParentTaskId, parentTaskId));
}
@Override
public Long selectCountByInstanceId(Long instanceId) {
return taskMapper.selectCount(Wrappers.<FlwTask>lambdaQuery()
.eq(FlwTask::getInstanceId, instanceId));
}
@Override
public List<FlwTask> selectListByInstanceId(Long instanceId) {
return taskMapper.selectList(Wrappers.<FlwTask>lambdaQuery()

View File

@ -1,6 +1,7 @@
package test.mysql;
import com.aizuda.bpm.engine.assist.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
@ -48,4 +49,13 @@ public class TestParallelNode extends MysqlTest {
.ifPresent(flwTasks -> Assert.isFalse(flwTasks.isEmpty(), "task size should be zero"));
});
}
@Test
public void testCcTaskParallel() {
processId = this.deployByResource("test/ccTaskParallel.json", testCreator);
flowLongEngine.startInstanceById(processId, testCreator).flatMap(instance ->
flowLongEngine.queryService().getActiveTasksByInstanceId(instance.getId()))
.ifPresent(t -> Assertions.assertEquals(1, t.size()));
}
}

View File

@ -0,0 +1,112 @@
{
"id": 11010,
"key": "ccTaskParallel",
"name": "抄送任务并行分支",
"nodeConfig": {
"nodeName": "发起人",
"nodeKey": "flk1736056686549",
"type": 0,
"childNode": {
"nodeName": "并行路由",
"nodeKey": "flk1736056692729",
"type": 8,
"parallelNodes": [
{
"nodeName": "分支1",
"nodeKey": "flk17360566927291",
"type": 3,
"childNode": {
"nodeName": "抄送人",
"nodeKey": "flk1736056695797",
"type": 2,
"nodeAssigneeList": [
{
"id": "test001",
"name": "CEO"
}
],
"allowSelection": true,
"childNode": {
"nodeName": "审核人",
"nodeKey": "flk1736056818736",
"type": 1,
"setType": 1,
"nodeCandidate": {
"type": 1
},
"examineLevel": 1,
"examineMode": 1,
"directorLevel": 1,
"directorMode": 0,
"selectMode": 1,
"termAuto": false,
"term": 0,
"termMode": 1,
"typeOfApprove": 1,
"rejectStrategy": 2,
"rejectStart": 1,
"remind": false,
"approveSelf": 0,
"nodeAssigneeList": [
{
"id": "test002",
"name": "夏小华"
}
]
}
}
},
{
"nodeName": "分支2",
"nodeKey": "flk17360566927292",
"type": 3,
"childNode": {
"nodeName": "抄送人",
"nodeKey": "flk1736056697926",
"type": 2,
"nodeAssigneeList": [
{
"id": "test001",
"name": "CEO"
}
],
"allowSelection": true
}
}
],
"childNode": {
"nodeName": "审核人",
"nodeKey": "flk1736056705898",
"type": 1,
"setType": 1,
"nodeCandidate": {
"type": 1
},
"examineLevel": 1,
"examineMode": 1,
"directorLevel": 1,
"directorMode": 0,
"selectMode": 1,
"termAuto": false,
"term": 0,
"termMode": 1,
"typeOfApprove": 1,
"rejectStrategy": 2,
"rejectStart": 1,
"remind": false,
"approveSelf": 0,
"childNode": {
"nodeName": "结束",
"nodeKey": "flk17360566865491",
"type": -1
},
"nodeAssigneeList": [
{
"id": "test003",
"name": "陈小辉"
}
]
}
}
}
}