Commit 8ed3066506e3984e9f3ab4cfcf063e89de53e4e4
1 parent
fc8e4662
review: 重构组装下一个节点审批人方法
Showing
1 changed file
with
27 additions
and
10 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
| ... | ... | @@ -267,24 +267,41 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService |
| 267 | 267 | // 3.1 获取下一个将要执行的节点集合 |
| 268 | 268 | FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey()); |
| 269 | 269 | List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, processVariables); |
| 270 | + | |
| 271 | + // 2. 收集所有节点的候选用户 ID | |
| 272 | + Set<Long> allCandidateUsers = new HashSet<>(); | |
| 273 | + for (FlowNode node : nextFlowNodes) { | |
| 274 | + List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(), | |
| 275 | + loginUserId, historicProcessInstance.getProcessDefinitionId(), processVariables); | |
| 276 | + allCandidateUsers.addAll(candidateUserIds); | |
| 277 | + } | |
| 278 | + | |
| 279 | + // 3. 批量查询用户和部门信息 | |
| 280 | + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(new ArrayList<>(allCandidateUsers)); | |
| 281 | + Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId)); | |
| 282 | + | |
| 283 | + // 4. 组装节点信息 | |
| 270 | 284 | return convertList(nextFlowNodes, node -> { |
| 285 | + // 4.1 获取当前节点的候选用户 ID | |
| 271 | 286 | List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(), |
| 272 | 287 | loginUserId, historicProcessInstance.getProcessDefinitionId(), processVariables); |
| 273 | - // 3.2 获取节点的审批人信息 | |
| 274 | - Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(candidateUserIds); | |
| 275 | - // 3.3 获取节点的审批人部门信息 | |
| 276 | - Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId)); | |
| 277 | - // 3.4 存在一个节点多人审批的情况,组装审批人信息 | |
| 288 | + | |
| 289 | + // 4.2 组装候选用户信息 | |
| 278 | 290 | List<UserSimpleBaseVO> candidateUsers = new ArrayList<>(); |
| 279 | - userMap.forEach((key, value) -> candidateUsers.add(BpmProcessInstanceConvert.INSTANCE.buildUser(key, userMap, deptMap))); | |
| 280 | - return new ActivityNode().setNodeType(BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType()) | |
| 291 | + for (Long userId : candidateUserIds) { | |
| 292 | + AdminUserRespDTO user = userMap.get(userId); | |
| 293 | + if (user != null) { | |
| 294 | + candidateUsers.add(BpmProcessInstanceConvert.INSTANCE.buildUser(userId, userMap, deptMap)); | |
| 295 | + } | |
| 296 | + } | |
| 297 | + | |
| 298 | + // 4.3 构建节点信息 | |
| 299 | + return new ActivityNode() | |
| 300 | + .setNodeType(BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType()) | |
| 281 | 301 | .setId(node.getId()) |
| 282 | 302 | .setName(node.getName()) |
| 283 | 303 | .setStatus(BpmTaskStatusEnum.RUNNING.getStatus()) |
| 284 | 304 | .setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(node)) |
| 285 | - // TODO @小北:先把 candidateUserIds 设置完,然后最后拼接 candidateUsers 信息。这样,如果有多个节点,就不用重复查询啦;类似 buildApprovalDetail 思路; | |
| 286 | - // TODO 先拼接处 List ActivityNode | |
| 287 | - // TODO 接着,再起一段,处理 adminUserApi.getUserMap(candidateUserIds)、deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId)) | |
| 288 | 305 | .setCandidateUsers(candidateUsers); |
| 289 | 306 | }); |
| 290 | 307 | } | ... | ... |