Commit 979485027dcc414183811e1dccd04535c7302383

Authored by 芋道源码
Committed by Gitee
2 parents b2dd2148 7ed96c4c

!1291 review: 重构组装下一个节点审批人方法

Merge pull request !1291 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,24 +267,41 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService @@ -267,24 +267,41 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
267 // 3.1 获取下一个将要执行的节点集合 267 // 3.1 获取下一个将要执行的节点集合
268 FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey()); 268 FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
269 List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, processVariables); 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 return convertList(nextFlowNodes, node -> { 284 return convertList(nextFlowNodes, node -> {
  285 + // 4.1 获取当前节点的候选用户 ID
271 List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(), 286 List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(),
272 loginUserId, historicProcessInstance.getProcessDefinitionId(), processVariables); 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 List<UserSimpleBaseVO> candidateUsers = new ArrayList<>(); 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 + UserSimpleBaseVO user = BpmProcessInstanceConvert.INSTANCE.buildUser(userId, userMap, deptMap);
  293 + if (user != null){
  294 + candidateUsers.add(user);
  295 + }
  296 + }
  297 +
  298 + // 4.3 构建节点信息
  299 + return new ActivityNode()
  300 + .setNodeType(BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType())
281 .setId(node.getId()) 301 .setId(node.getId())
282 .setName(node.getName()) 302 .setName(node.getName())
283 .setStatus(BpmTaskStatusEnum.RUNNING.getStatus()) 303 .setStatus(BpmTaskStatusEnum.RUNNING.getStatus())
284 .setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(node)) 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 .setCandidateUsers(candidateUsers); 305 .setCandidateUsers(candidateUsers);
289 }); 306 });
290 } 307 }