Commit 5f993c6a9fb75887f751531c30a1041c4815e215

Authored by YunaiV
2 parents 539746d1 dace9cfe

Merge branch 'develop' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into master-jdk17

# Conflicts:
#	yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
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,6 @@ 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;
76 75 import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils.parseNodeType;
77 76 import static java.util.Arrays.asList;
78 77 import static java.util.Collections.singletonList;
... ... @@ -227,11 +226,8 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
227 226 // 3.2 获取由于退回操作,需要预测的节点。从流程变量中获取,回退操作会设置这些变量
228 227 Set<String> needSimulateTaskDefKeysByReturn = new HashSet<>();
229 228 if (StrUtil.isNotEmpty(reqVO.getProcessInstanceId())) {
230   - Map<String, Object> variables = runtimeService.getVariables(reqVO.getProcessInstanceId());
231   - Map<String, Object> simulateTaskVariables = MapUtil.filter(variables,
232   - item -> item.getKey().startsWith(PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_PREFIX));
233   - simulateTaskVariables.forEach((key, value) ->
234   - needSimulateTaskDefKeysByReturn.add(StrUtil.removePrefix(key, PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_PREFIX)));
  229 + Object needSimulateTaskIds = runtimeService.getVariable(reqVO.getProcessInstanceId(), BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_TASK_IDS);
  230 + needSimulateTaskDefKeysByReturn.addAll(Convert.toSet(String.class, needSimulateTaskIds));
235 231 }
236 232 // 移除运行中的节点,运行中的节点无需预测
237 233 if (CollUtil.isNotEmpty(runActivityNodes)) {
... ...
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
... ... @@ -69,7 +69,6 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
69 69 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
70 70 import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
71 71 import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.START_USER_NODE_ID;
72   -//import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants.*;
73 72 import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils.*;
74 73  
75 74 /**
... ... @@ -604,11 +603,13 @@ public class BpmTaskServiceImpl implements BpmTaskService {
604 603 bpmnModel, reqVO.getNextAssignees(), instance);
605 604 runtimeService.setVariables(task.getProcessInstanceId(), variables);
606 605  
607   - // 5. 移除辅助预测的流程变量,这些变量在回退操作中设置
608   - // todo @jason:可以直接 + 拼接哈
609   - String simulateVariableName = StrUtil.concat(false,
610   - BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_PREFIX, task.getTaskDefinitionKey());
611   - runtimeService.removeVariable(task.getProcessInstanceId(), simulateVariableName);
  606 + // 5. 如果当前节点 Id 存在于需要预测的流程节点中,从中移除。 流程变量在回退操作中设置
  607 + Object needSimulateTaskIds = runtimeService.getVariable(task.getProcessInstanceId(), BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_TASK_IDS);
  608 + Set<String> needSimulateTaskIdsByReturn = Convert.toSet(String.class, needSimulateTaskIds);
  609 + if (needSimulateTaskIdsByReturn.contains(task.getTaskDefinitionKey())) {
  610 + needSimulateTaskIdsByReturn.remove(task.getTaskDefinitionKey());
  611 + runtimeService.setVariable(task.getProcessInstanceId(), BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_TASK_IDS, needSimulateTaskIdsByReturn);
  612 + }
612 613  
613 614 // 6. 调用 BPM complete 去完成任务
614 615 taskService.complete(task.getId(), variables, true);
... ... @@ -937,11 +938,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
937 938 });
938 939  
939 940 // 3. 构建需要预测的任务流程变量
940   - // TODO @jason:【驳回预测相关】是不是搞成一个变量,里面是 set 更简洁一点呀?
941 941 Set<String> needSimulateTaskDefinitionKeys = getNeedSimulateTaskDefinitionKeys(bpmnModel, currentTask, targetElement);
942   - Map<String, Object> needSimulateVariables = convertMap(needSimulateTaskDefinitionKeys,
943   - key -> StrUtil.concat(false, BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_PREFIX, key), item -> Boolean.TRUE);
944   -
945 942  
946 943 // 4. 执行驳回
947 944 // 使用 moveExecutionsToSingleActivityId 替换 moveActivityIdsToSingleActivityId 原因:
... ... @@ -949,12 +946,11 @@ public class BpmTaskServiceImpl implements BpmTaskService {
949 946 runtimeService.createChangeActivityStateBuilder()
950 947 .processInstanceId(currentTask.getProcessInstanceId())
951 948 .moveExecutionsToSingleActivityId(runExecutionIds, reqVO.getTargetTaskDefinitionKey())
952   - // 设置需要预测的任务流程变量,用于辅助预测
953   - .processVariables(needSimulateVariables)
954   - // 设置流程变量(local)节点退回标记, 用于退回到节点,不执行 BpmUserTaskAssignStartUserHandlerTypeEnum 策略,导致自动通过
  949 + // 设置需要预测的任务 ids 的流程变量,用于辅助预测
  950 + .processVariable(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_NEED_SIMULATE_TASK_IDS, needSimulateTaskDefinitionKeys)
  951 + // 设置流程变量(local)节点退回标记, 用于退回到节点,不执行 BpmUserTaskAssignStartUserHandlerTypeEnum 策略,导致自动通过
955 952 .localVariable(reqVO.getTargetTaskDefinitionKey(),
956   - String.format(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_RETURN_FLAG, reqVO.getTargetTaskDefinitionKey()),
957   - Boolean.TRUE)
  953 + String.format(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_RETURN_FLAG, reqVO.getTargetTaskDefinitionKey()), Boolean.TRUE)
958 954 .changeState();
959 955 }
960 956  
... ...