Skip to content

Commit

Permalink
优化调整PR部分代码
Browse files Browse the repository at this point in the history
  • Loading branch information
qmdx committed Sep 10, 2024
1 parent e8a8f1a commit 17dd250
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,29 +164,29 @@ public boolean executeNodeModel(FlowLongContext flowLongContext, String nodeKey)

// 获取当前任务列表,检查并行分支执行情况
List<String> nodeKeys = new LinkedList<>();
List<String> otherProcessKeys = new LinkedList<>();
flowLongContext.getQueryService().getActiveTasksByInstanceId(flwTask.getInstanceId()).ifPresent(flwTasks -> {
for (FlwTask ft : flwTasks) {
nodeKeys.add(ft.getTaskKey());
}
});

//查找流程关联的子流程
// 查找流程关联的子流程
List<String> otherProcessKeys = new LinkedList<>();
Optional<List<FlwInstance>> 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());
}
});
}));

Optional<NodeModel> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ protected List<FlwTask> saveTask(FlwTask flwTask, PerformType performType, List<
if (hisTaskDao.insert(flwHisTask)) {
// 设置为执行任务
execution.setFlwTask(flwHisTask);
// 即可归档,确保自增ID情况一致性
// 即刻归档,确保自增ID情况一致性
taskDao.deleteById(flwTask.getId());
// 记录发起人
hisTaskActorDao.insert(FlwHisTaskActor.ofFlwHisTask(flwHisTask));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public static NodeModel findNextNode(NodeModel nodeModel, List<String> currentTa

// 判断当前节点为并行分支或包容分支,需要判断当前并行是否走完
if (parentNode.parallelNode() || parentNode.inclusiveNode()) {
//只是找下一个节点
if (null == currentTask){
// 只是找下一个节点
if (null == currentTask) {
return parentNode.getChildNode();
}
// 找到另外的分支,看是否列表有执行,有就不能返回 childNode
Expand Down Expand Up @@ -185,8 +185,7 @@ private static List<String> getAllNextConditionNodeKeys(NodeModel nodeModel) {
public static List<NodeModel> getUnsetAssigneeNodes(NodeModel rootNodeModel) {
List<NodeModel> 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());
}

/**
Expand Down Expand Up @@ -335,10 +334,7 @@ public static Map<String, DynamicAssignee> 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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");
Expand All @@ -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));
}


Expand Down

0 comments on commit 17dd250

Please sign in to comment.