Commit 1f9769a4329ad361b73ab6cb33595b01e29f0bd0
1 parent
1e3fd24d
review: 拆分发起人自选审批人 和 审批人选择下一个节点审批人
Showing
2 changed files
with
32 additions
and
34 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
| ... | ... | @@ -282,9 +282,6 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService |
| 282 | 282 | loginUserId, historicProcessInstance.getProcessDefinitionId(), processVariables); |
| 283 | 283 | // 3.2 获取节点的审批人信息 |
| 284 | 284 | Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(candidateUserIds); |
| 285 | - if (CollUtil.isEmpty(userMap)) { | |
| 286 | - return null; | |
| 287 | - } | |
| 288 | 285 | // 3.3 获取节点的审批人部门信息 |
| 289 | 286 | Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId)); |
| 290 | 287 | // 3.4 存在一个节点多人审批的情况,组装审批人信息 | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| ... | ... | @@ -564,47 +564,48 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 564 | 564 | FlowElement flowElement = bpmnModel.getFlowElement(taskDefinitionKey); |
| 565 | 565 | // 2. 获取下一个将要执行的节点集合 |
| 566 | 566 | List<FlowNode> nextFlowNodes = getNextFlowNodes(flowElement, bpmnModel, variables); |
| 567 | - // 获取流程实例中的审批人自选审批人 | |
| 568 | - Map<String, List<Long>> hisProcessVariables = FlowableUtils.getApproveUserSelectAssignees(processInstance.getProcessVariables()); | |
| 569 | - if (CollUtil.isEmpty(hisProcessVariables)){ | |
| 570 | - hisProcessVariables = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables()); | |
| 571 | - } | |
| 572 | - // 校验通过的全部节点和审批人 | |
| 573 | - Map<String, List<Long>> allNextAssignees = new HashMap<>(); | |
| 574 | 567 | // 3. 循环下一个将要执行的节点集合 |
| 575 | 568 | for (FlowNode nextFlowNode : nextFlowNodes) { |
| 576 | 569 | // 3.1 获取下一个将要执行节点中的审批人策略 |
| 577 | 570 | Integer candidateStrategy = parseCandidateStrategy(nextFlowNode); |
| 578 | - // 3.2 获取流程实例中的审批人自选审批人 | |
| 579 | - List<Long> approveUserSelectAssignee = hisProcessVariables.get(nextFlowNode.getId()); | |
| 580 | - // 3.3 如果节点中的审批人策略为 发起人自选或者审批人自选,并且该节点的审批人为空 | |
| 581 | - if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy()) | |
| 582 | - || ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.APPROVE_USER_SELECT.getStrategy()) | |
| 583 | - && CollUtil.isEmpty(approveUserSelectAssignee)) { | |
| 584 | - // 判断节点是否为执行节点,仅校验节点 | |
| 585 | - if (!nextAssignees.containsKey(nextFlowNode.getId())) { | |
| 586 | - throw exception(TASK_TARGET_NODE_NOT_EXISTS, nextFlowNode.getName()); | |
| 571 | + // 3.2 判断节点是否为执行节点,仅校验节点 | |
| 572 | + if (!nextAssignees.containsKey(nextFlowNode.getId())) { | |
| 573 | + throw exception(TASK_TARGET_NODE_NOT_EXISTS, nextFlowNode.getName()); | |
| 574 | + } | |
| 575 | + // 3.3 获取节点中的审批人 | |
| 576 | + List<Long> assignees = nextAssignees.get(nextFlowNode.getId()); | |
| 577 | + // 3.3 如果节点中的审批人策略为 发起人自选 | |
| 578 | + if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy())) { | |
| 579 | + Map<String, List<Long>> hisProcessVariables = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables()); | |
| 580 | + List<Long> startUserSelectAssignee = hisProcessVariables.get(nextFlowNode.getId()); | |
| 581 | + // 如果当前节点已经存在审批人,则不允许覆盖 | |
| 582 | + if (CollUtil.isNotEmpty(startUserSelectAssignee)) { | |
| 583 | + continue; | |
| 584 | + } | |
| 585 | + // 判断节点的审批人是否配置,节点存在,但未配置审批人 | |
| 586 | + if (CollUtil.isEmpty(assignees)){ | |
| 587 | + throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName()); | |
| 587 | 588 | } |
| 589 | + // 校验通过的全部节点和审批人 | |
| 590 | + hisProcessVariables.put(nextFlowNode.getId(), assignees); | |
| 591 | + variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, hisProcessVariables); | |
| 592 | + } | |
| 593 | + // 3.4 如果节点中的审批人策略为 审批人,在审批时选择下一个节点的审批人,并且该节点的审批人为空 | |
| 594 | + if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.APPROVE_USER_SELECT.getStrategy())){ | |
| 588 | 595 | // 判断节点的审批人是否配置,节点存在,但未配置审批人 |
| 589 | - if (CollUtil.isEmpty(nextAssignees.get(nextFlowNode.getId()))) { | |
| 596 | + if (CollUtil.isEmpty(assignees)) { | |
| 590 | 597 | throw exception(PROCESS_INSTANCE_APPROVE_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName()); |
| 591 | 598 | } |
| 592 | - // 4.3.3 校验通过的全部节点和审批人 | |
| 593 | - allNextAssignees.put(nextFlowNode.getId(), nextAssignees.get(nextFlowNode.getId())); | |
| 599 | + Map<String, List<Long>> hisProcessVariables = FlowableUtils.getApproveUserSelectAssignees(processInstance.getProcessVariables()); | |
| 600 | + if (hisProcessVariables == null) { | |
| 601 | + hisProcessVariables = new HashMap<>(); | |
| 602 | + // 校验通过的全部节点和审批人 | |
| 603 | + hisProcessVariables.put(nextFlowNode.getId(), assignees); | |
| 604 | + } | |
| 605 | + variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES, hisProcessVariables); | |
| 594 | 606 | } |
| 595 | 607 | } |
| 596 | - // variables 是存储动态表单到 local 任务级别。过滤一下,避免 ProcessInstance 系统级的变量被占用 | |
| 597 | - Map<String, Object> newVariables = FlowableUtils.filterTaskFormVariable(variables); | |
| 598 | - // 4. 如果下个节点审批参数不为空,则设置流程变量 | |
| 599 | - if (CollUtil.isNotEmpty(allNextAssignees)) { | |
| 600 | - // 获取实例中的全部节点数据,避免后续节点的审批人被覆盖 | |
| 601 | - hisProcessVariables.putAll(allNextAssignees); | |
| 602 | - // 设置流程变量,审批人自选 | |
| 603 | - newVariables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES, hisProcessVariables); | |
| 604 | - // 设置流程变量,发起人自选,后续的节点或者回退后再或者驳回重新发起的场景可能存在发起人自选或者审批人自选,所以中两个变量值要保持一致,否则会查询不到审批人 | |
| 605 | - newVariables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, hisProcessVariables); | |
| 606 | - } | |
| 607 | - return newVariables; | |
| 608 | + return variables; | |
| 608 | 609 | } |
| 609 | 610 | |
| 610 | 611 | /** | ... | ... |