Commit 27235016ad9e70e92323b224cbc66ce4b43493e1
1 parent
65b81147
perf: [BPM 工作流] 驳回预测 review 修改
Showing
3 changed files
with
16 additions
and
19 deletions
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/enums/BpmnVariableConstants.java
| ... | ... | @@ -54,11 +54,11 @@ public class BpmnVariableConstants { |
| 54 | 54 | public static final String PROCESS_INSTANCE_VARIABLE_RETURN_FLAG = "RETURN_FLAG_%s"; |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | - * 流程实例的变量前缀 - 用于退回操作,记录需要预测的节点:格式 NEED_SIMULATE_TASK_{节点定义 id} | |
| 57 | + * 流程实例的变量 - 用于退回操作,记录需要预测的节点 ids, 变量值类型为 Set | |
| 58 | 58 | * |
| 59 | 59 | * 目的是:退回操作,预测节点会不准,在流程变量中记录需要预测的节点,来辅助预测 |
| 60 | 60 | */ |
| 61 | - public static final String PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_PREFIX = "NEED_SIMULATE_TASK_"; | |
| 61 | + public static final String PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_TASK_IDS = "NEED_SIMULATE_TASK_IDS"; | |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * 流程实例的变量 - 是否跳过表达式 | ... | ... |
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
| ... | ... | @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.bpm.service.task; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.collection.ListUtil; |
| 5 | +import cn.hutool.core.convert.Convert; | |
| 5 | 6 | import cn.hutool.core.date.DateUtil; |
| 6 | 7 | import cn.hutool.core.lang.Assert; |
| 7 | -import cn.hutool.core.map.MapUtil; | |
| 8 | 8 | import cn.hutool.core.util.*; |
| 9 | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 10 | 10 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| ... | ... | @@ -72,7 +72,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. |
| 72 | 72 | import static cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmApprovalDetailRespVO.ActivityNode; |
| 73 | 73 | import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*; |
| 74 | 74 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.START_USER_NODE_ID; |
| 75 | -import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_PREFIX; | |
| 75 | +import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_TASK_IDS; | |
| 76 | 76 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils.parseNodeType; |
| 77 | 77 | import static java.util.Arrays.asList; |
| 78 | 78 | import static java.util.Collections.singletonList; |
| ... | ... | @@ -223,11 +223,8 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService |
| 223 | 223 | // 3.2 获取由于退回操作,需要预测的节点。从流程变量中获取,回退操作会设置这些变量 |
| 224 | 224 | Set<String> needSimulateTaskDefKeysByReturn = new HashSet<>(); |
| 225 | 225 | if (StrUtil.isNotEmpty(reqVO.getProcessInstanceId())) { |
| 226 | - Map<String, Object> variables = runtimeService.getVariables(reqVO.getProcessInstanceId()); | |
| 227 | - Map<String, Object> simulateTaskVariables = MapUtil.filter(variables, | |
| 228 | - item -> item.getKey().startsWith(PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_PREFIX)); | |
| 229 | - simulateTaskVariables.forEach((key, value) -> | |
| 230 | - needSimulateTaskDefKeysByReturn.add(StrUtil.removePrefix(key, PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_PREFIX))); | |
| 226 | + Object needSimulateTaskIds = runtimeService.getVariable(reqVO.getProcessInstanceId(), PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_TASK_IDS); | |
| 227 | + needSimulateTaskDefKeysByReturn.addAll(Convert.toSet(String.class, needSimulateTaskIds)); | |
| 231 | 228 | } |
| 232 | 229 | // 移除运行中的节点,运行中的节点无需预测 |
| 233 | 230 | if (CollUtil.isNotEmpty(runActivityNodes)) { | ... | ... |
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| ... | ... | @@ -601,9 +601,13 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 601 | 601 | bpmnModel, reqVO.getNextAssignees(), instance); |
| 602 | 602 | runtimeService.setVariables(task.getProcessInstanceId(), variables); |
| 603 | 603 | |
| 604 | - // 5. 移除辅助预测的流程变量,这些变量在回退操作中设置 | |
| 605 | - String simulateVariableName = StrUtil.concat(false, PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_PREFIX, task.getTaskDefinitionKey()); | |
| 606 | - runtimeService.removeVariable(task.getProcessInstanceId(), simulateVariableName); | |
| 604 | + // 5. 如果当前节点 Id 存在于需要预测的流程节点中,从中移除。 流程变量在回退操作中设置 | |
| 605 | + Object needSimulateTaskIds = runtimeService.getVariable(task.getProcessInstanceId(), PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_TASK_IDS); | |
| 606 | + Set<String> needSimulateTaskIdsByReturn = Convert.toSet(String.class, needSimulateTaskIds); | |
| 607 | + if (needSimulateTaskIdsByReturn.contains(task.getTaskDefinitionKey())) { | |
| 608 | + needSimulateTaskIdsByReturn.remove(task.getTaskDefinitionKey()); | |
| 609 | + runtimeService.setVariable(task.getProcessInstanceId(), PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_TASK_IDS, needSimulateTaskIdsByReturn); | |
| 610 | + } | |
| 607 | 611 | |
| 608 | 612 | // 6. 调用 BPM complete 去完成任务 |
| 609 | 613 | taskService.complete(task.getId(), variables, true); |
| ... | ... | @@ -932,11 +936,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 932 | 936 | }); |
| 933 | 937 | |
| 934 | 938 | // 3. 构建需要预测的任务流程变量 |
| 935 | - // TODO @jason:【驳回预测相关】是不是搞成一个变量,里面是 set 更简洁一点呀? | |
| 936 | 939 | Set<String> needSimulateTaskDefinitionKeys = getNeedSimulateTaskDefinitionKeys(bpmnModel, currentTask, targetElement); |
| 937 | - Map<String, Object> needSimulateVariables = convertMap(needSimulateTaskDefinitionKeys, | |
| 938 | - key -> StrUtil.concat(false, PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_PREFIX, key), item -> Boolean.TRUE); | |
| 939 | - | |
| 940 | 940 | |
| 941 | 941 | // 4. 执行驳回 |
| 942 | 942 | // 使用 moveExecutionsToSingleActivityId 替换 moveActivityIdsToSingleActivityId 原因: |
| ... | ... | @@ -944,9 +944,9 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 944 | 944 | runtimeService.createChangeActivityStateBuilder() |
| 945 | 945 | .processInstanceId(currentTask.getProcessInstanceId()) |
| 946 | 946 | .moveExecutionsToSingleActivityId(runExecutionIds, reqVO.getTargetTaskDefinitionKey()) |
| 947 | - // 设置需要预测的任务流程变量,用于辅助预测 | |
| 948 | - .processVariables(needSimulateVariables) | |
| 949 | - // 设置流程变量(local)节点退回标记, 用于退回到节点,不执行 BpmUserTaskAssignStartUserHandlerTypeEnum 策略,导致自动通过 | |
| 947 | + // 设置需要预测的任务 ids 的流程变量,用于辅助预测 | |
| 948 | + .processVariable(PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_TASK_IDS, needSimulateTaskDefinitionKeys) | |
| 949 | + // 设置流程变量(local)节点退回标记, 用于退回到节点,不执行 BpmUserTaskAssignStartUserHandlerTypeEnum 策略,导致自动通过 | |
| 950 | 950 | .localVariable(reqVO.getTargetTaskDefinitionKey(), |
| 951 | 951 | String.format(PROCESS_INSTANCE_VARIABLE_RETURN_FLAG, reqVO.getTargetTaskDefinitionKey()), Boolean.TRUE) |
| 952 | 952 | .changeState(); | ... | ... |