Commit 26c1a10b0c0dfb4a2cd042114765f3310cd260a2

Authored by 芋道源码
Committed by Gitee
2 parents 67e548d5 629bf284

!1297 fix: 修复simple设计器第一个发起人节点,审批时校验是否存在审批人导致流程异常

Merge pull request !1297 from SamllNorth_Lee/feature/bpm
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
@@ -267,7 +267,6 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService @@ -267,7 +267,6 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
267 FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey()); 267 FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
268 List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, processVariables); 268 List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, processVariables);
269 269
270 - // TODO @小北:还是可以优化下哈;“4. 组装节点信息” 只拼接出 candidateUserIds;之后,再第二次循环,查询用户和部门信息,进行拼接  
271 // 2. 收集所有节点的候选用户 ID 270 // 2. 收集所有节点的候选用户 ID
272 Set<Long> allCandidateUsers = new HashSet<>(); 271 Set<Long> allCandidateUsers = new HashSet<>();
273 for (FlowNode node : nextFlowNodes) { 272 for (FlowNode node : nextFlowNodes) {
@@ -287,13 +286,13 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService @@ -287,13 +286,13 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
287 loginUserId, historicProcessInstance.getProcessDefinitionId(), processVariables); 286 loginUserId, historicProcessInstance.getProcessDefinitionId(), processVariables);
288 287
289 // 4.2 组装候选用户信息 288 // 4.2 组装候选用户信息
290 - List<UserSimpleBaseVO> candidateUsers = new ArrayList<>();  
291 - for (Long userId : candidateUserIds) {  
292 - UserSimpleBaseVO user = BpmProcessInstanceConvert.INSTANCE.buildUser(userId, userMap, deptMap); 289 + List<UserSimpleBaseVO> candidateUsers = convertList(candidateUserIds, userId -> {
  290 + AdminUserRespDTO user = userMap.get(userId);
293 if (user != null) { 291 if (user != null) {
294 - candidateUsers.add(user); 292 + return BpmProcessInstanceConvert.INSTANCE.buildUser(userId, userMap, deptMap);
295 } 293 }
296 - } 294 + return null;
  295 + });
297 296
298 // 4.3 构建节点信息 297 // 4.3 构建节点信息
299 return new ActivityNode() 298 return new ActivityNode()
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
@@ -599,6 +599,10 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -599,6 +599,10 @@ public class BpmTaskServiceImpl implements BpmTaskService {
599 */ 599 */
600 private Map<String, Object> validateAndSetNextAssignees(String taskDefinitionKey, Map<String, Object> variables, BpmnModel bpmnModel, 600 private Map<String, Object> validateAndSetNextAssignees(String taskDefinitionKey, Map<String, Object> variables, BpmnModel bpmnModel,
601 Map<String, List<Long>> nextAssignees, ProcessInstance processInstance) { 601 Map<String, List<Long>> nextAssignees, ProcessInstance processInstance) {
  602 + // Simple设计器第一个节点默认为发起人节点,不校验是否存在审批人
  603 + if (taskDefinitionKey.equals(START_USER_NODE_ID)) {
  604 + return variables;
  605 + }
602 // 1. 获取下一个将要执行的节点集合 606 // 1. 获取下一个将要执行的节点集合
603 FlowElement flowElement = bpmnModel.getFlowElement(taskDefinitionKey); 607 FlowElement flowElement = bpmnModel.getFlowElement(taskDefinitionKey);
604 List<FlowNode> nextFlowNodes = getNextFlowNodes(flowElement, bpmnModel, variables); 608 List<FlowNode> nextFlowNodes = getNextFlowNodes(flowElement, bpmnModel, variables);
@@ -609,16 +613,17 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -609,16 +613,17 @@ public class BpmTaskServiceImpl implements BpmTaskService {
609 Integer candidateStrategy = parseCandidateStrategy(nextFlowNode); 613 Integer candidateStrategy = parseCandidateStrategy(nextFlowNode);
610 // 2.1 情况一:如果节点中的审批人策略为 发起人自选 614 // 2.1 情况一:如果节点中的审批人策略为 发起人自选
611 if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy())) { 615 if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy())) {
612 - // 如果节点存在,但未配置审批人  
613 - List<Long> assignees = nextAssignees != null ? nextAssignees.get(nextFlowNode.getId()) : null;  
614 - if (CollUtil.isEmpty(assignees)) {  
615 - throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName());  
616 - } 616 + // 先从历史中获取审批人,在发起人会把所有的审批人保存到历史中,这里从历史中获取
617 processVariables = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables()); 617 processVariables = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables());
618 // 特殊:如果当前节点已经存在审批人,则不允许覆盖 618 // 特殊:如果当前节点已经存在审批人,则不允许覆盖
619 if (processVariables != null && CollUtil.isNotEmpty(processVariables.get(nextFlowNode.getId()))) { 619 if (processVariables != null && CollUtil.isNotEmpty(processVariables.get(nextFlowNode.getId()))) {
620 continue; 620 continue;
621 } 621 }
  622 + // 如果节点存在,但未配置审批人
  623 + List<Long> assignees = nextAssignees != null ? nextAssignees.get(nextFlowNode.getId()) : null;
  624 + if (CollUtil.isEmpty(assignees)) {
  625 + throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName());
  626 + }
622 // 设置 PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES 627 // 设置 PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES
623 if (processVariables == null) { 628 if (processVariables == null) {
624 processVariables = new HashMap<>(); 629 processVariables = new HashMap<>();
@@ -628,12 +633,13 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -628,12 +633,13 @@ public class BpmTaskServiceImpl implements BpmTaskService {
628 } 633 }
629 // 2.2 情况二:如果节点中的审批人策略为 审批人,在审批时选择下一个节点的审批人,并且该节点的审批人为空 634 // 2.2 情况二:如果节点中的审批人策略为 审批人,在审批时选择下一个节点的审批人,并且该节点的审批人为空
630 if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.APPROVE_USER_SELECT.getStrategy())) { 635 if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.APPROVE_USER_SELECT.getStrategy())) {
  636 + // 获取审批人自选的历史变量
  637 + processVariables = FlowableUtils.getApproveUserSelectAssignees(processInstance.getProcessVariables());
631 // 如果节点存在,但未配置审批人 638 // 如果节点存在,但未配置审批人
632 List<Long> assignees = nextAssignees != null ? nextAssignees.get(nextFlowNode.getId()) : null; 639 List<Long> assignees = nextAssignees != null ? nextAssignees.get(nextFlowNode.getId()) : null;
633 if (CollUtil.isEmpty(assignees)) { 640 if (CollUtil.isEmpty(assignees)) {
634 throw exception(PROCESS_INSTANCE_APPROVE_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName()); 641 throw exception(PROCESS_INSTANCE_APPROVE_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName());
635 } 642 }
636 - processVariables = FlowableUtils.getApproveUserSelectAssignees(processInstance.getProcessVariables());  
637 if (processVariables == null) { 643 if (processVariables == null) {
638 processVariables = new HashMap<>(); 644 processVariables = new HashMap<>();
639 } 645 }