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

Merge pull request !1291 from SamllNorth_Lee/feature/bpm
This commit is contained in:
芋道源码 2025-03-17 13:28:25 +00:00 committed by Gitee
commit 979485027d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 28 additions and 11 deletions

View File

@ -267,24 +267,41 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
// 3.1 获取下一个将要执行的节点集合
FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, processVariables);
return convertList(nextFlowNodes, node -> {
// 2. 收集所有节点的候选用户 ID
Set<Long> allCandidateUsers = new HashSet<>();
for (FlowNode node : nextFlowNodes) {
List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(),
loginUserId, historicProcessInstance.getProcessDefinitionId(), processVariables);
// 3.2 获取节点的审批人信息
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(candidateUserIds);
// 3.3 获取节点的审批人部门信息
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
// 3.4 存在一个节点多人审批的情况组装审批人信息
allCandidateUsers.addAll(candidateUserIds);
}
// 3. 批量查询用户和部门信息
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(new ArrayList<>(allCandidateUsers));
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
// 4. 组装节点信息
return convertList(nextFlowNodes, node -> {
// 4.1 获取当前节点的候选用户 ID
List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(),
loginUserId, historicProcessInstance.getProcessDefinitionId(), processVariables);
// 4.2 组装候选用户信息
List<UserSimpleBaseVO> candidateUsers = new ArrayList<>();
userMap.forEach((key, value) -> candidateUsers.add(BpmProcessInstanceConvert.INSTANCE.buildUser(key, userMap, deptMap)));
return new ActivityNode().setNodeType(BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType())
for (Long userId : candidateUserIds) {
UserSimpleBaseVO user = BpmProcessInstanceConvert.INSTANCE.buildUser(userId, userMap, deptMap);
if (user != null){
candidateUsers.add(user);
}
}
// 4.3 构建节点信息
return new ActivityNode()
.setNodeType(BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType())
.setId(node.getId())
.setName(node.getName())
.setStatus(BpmTaskStatusEnum.RUNNING.getStatus())
.setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(node))
// TODO @小北先把 candidateUserIds 设置完然后最后拼接 candidateUsers 信息这样如果有多个节点就不用重复查询啦类似 buildApprovalDetail 思路
// TODO 先拼接处 List ActivityNode
// TODO 接着再起一段处理 adminUserApi.getUserMap(candidateUserIds)deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId))
.setCandidateUsers(candidateUsers);
});
}