review: 278 281行

This commit is contained in:
smallNorthLee 2025-03-04 22:28:25 +08:00
parent 4e57bd157f
commit 9e151b3966
1 changed files with 60 additions and 55 deletions

View File

@ -232,57 +232,62 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
@Override @Override
public List<ActivityNode> getNextFlowNodes(Long loginUserId, BpmApprovalDetailReqVO reqVO) { public List<ActivityNode> getNextFlowNodes(Long loginUserId, BpmApprovalDetailReqVO reqVO) {
// 1 校验任务存在 // 1.1 校验任务存在
Task task = taskService.getTask(reqVO.getTaskId()); Task task = taskService.getTask(reqVO.getTaskId());
if (task == null) { if (task == null) {
throw exception(TASK_NOT_EXISTS); throw exception(TASK_NOT_EXISTS);
} }
// 2 校验任务是否由当前用户审批 // 1.2 校验任务是否由当前用户审批
if (StrUtil.isNotBlank(task.getAssignee()) if (StrUtil.isNotBlank(task.getAssignee())
&& ObjectUtil.notEqual(loginUserId, NumberUtils.parseLong(task.getAssignee()))) { && ObjectUtil.notEqual(loginUserId, NumberUtils.parseLong(task.getAssignee()))) {
throw exception(TASK_OPERATE_FAIL_ASSIGN_NOT_SELF); throw exception(TASK_OPERATE_FAIL_ASSIGN_NOT_SELF);
} }
// 3 校验流程实例存在 // 1.3 校验流程实例存在
ProcessInstance instance = getProcessInstance(task.getProcessInstanceId()); ProcessInstance instance = getProcessInstance(task.getProcessInstanceId());
if (instance == null) { if (instance == null) {
throw exception(PROCESS_INSTANCE_NOT_EXISTS); throw exception(PROCESS_INSTANCE_NOT_EXISTS);
} }
// 4 获取 BpmnModel // 1.4 校验BpmnModel
BpmnModel bpmnModel = processDefinitionService.getProcessDefinitionBpmnModel(task.getProcessDefinitionId()); BpmnModel bpmnModel = processDefinitionService.getProcessDefinitionBpmnModel(task.getProcessDefinitionId());
if (bpmnModel == null) { if (bpmnModel == null) {
return null; return null;
} }
//1.5 流程实例是否存在
HistoricProcessInstance historicProcessInstance = getHistoricProcessInstance(task.getProcessInstanceId()); HistoricProcessInstance historicProcessInstance = getHistoricProcessInstance(task.getProcessInstanceId());
if (historicProcessInstance == null) { if (historicProcessInstance == null) {
throw exception(ErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS); throw exception(ErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS);
} }
// 2 设置流程变量
Map<String, Object> processVariables = new HashMap<>(); Map<String, Object> processVariables = new HashMap<>();
// 获取历史中流程变量 // 2.1 获取历史中流程变量
Map<String, Object> historicVariables = historicProcessInstance.getProcessVariables(); Map<String, Object> historicVariables = historicProcessInstance.getProcessVariables();
if (CollUtil.isNotEmpty(historicVariables)) { if (CollUtil.isNotEmpty(historicVariables)) {
processVariables.putAll(historicVariables); processVariables.putAll(historicVariables);
} }
// 合并前端传递的流程变量以前端为准 // 2.2 合并前端传递的流程变量以前端为准
if (CollUtil.isNotEmpty(reqVO.getProcessVariables())) { if (CollUtil.isNotEmpty(reqVO.getProcessVariables())) {
processVariables.putAll(reqVO.getProcessVariables()); processVariables.putAll(reqVO.getProcessVariables());
} }
// 获取流程定义信息 // 3 获取当前任务节点的信息
BpmProcessDefinitionInfoDO processDefinitionInfo = processDefinitionService
.getProcessDefinitionInfo(task.getProcessDefinitionId());
// 获取当前任务节点的信息
FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey()); FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
// 获取下一个将要执行的节点集合 // 3.1 获取下一个将要执行的节点集合
List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, processVariables); List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, processVariables);
return convertList(nextFlowNodes, node -> { return convertList(nextFlowNodes, node -> {
List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(), List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(),
loginUserId, processDefinitionInfo.getProcessDefinitionId(), processVariables); loginUserId, historicProcessInstance.getProcessDefinitionId(), processVariables);
//存在一个节点多人审批的情况 // 3.2 获取节点的审批人信息
List<UserSimpleBaseVO> candidateUsers = new ArrayList<>();
for (Long candidateUserId : candidateUserIds) {
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(candidateUserIds); Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(candidateUserIds);
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId)); if (CollUtil.isEmpty(userMap)) {
candidateUsers.add(BpmProcessInstanceConvert.INSTANCE.buildUser(candidateUserId, userMap, deptMap)); return null;
} }
// 3.3 获取节点的审批人部门信息
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
// 3.4 存在一个节点多人审批的情况组装审批人信息
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()) return new ActivityNode().setNodeType(BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType())
.setId(node.getId()) .setId(node.getId())
.setName(node.getName()) .setName(node.getName())