Commit 33ab9616291bd49cbbf82d5fde5c0ff184d05baf

Authored by lizhixian
1 parent 1b08e682

feat:审批通过时,查询下一个执行的任务节点

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
@@ -15,6 +15,7 @@ import cn.iocoder.yudao.framework.common.util.number.NumberUtils; @@ -15,6 +15,7 @@ import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
15 import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; 15 import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
16 import cn.iocoder.yudao.framework.common.util.object.PageUtils; 16 import cn.iocoder.yudao.framework.common.util.object.PageUtils;
17 import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; 17 import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
  18 +import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
18 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO; 19 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
19 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; 20 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
20 import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.*; 21 import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.*;
@@ -249,24 +250,43 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService @@ -249,24 +250,43 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
249 if (bpmnModel == null) { 250 if (bpmnModel == null) {
250 return null; 251 return null;
251 } 252 }
252 - // 5. 获取当前任务节点的信息 253 + HistoricProcessInstance historicProcessInstance = getHistoricProcessInstance(task.getProcessInstanceId());
  254 + if (historicProcessInstance == null) {
  255 + throw exception(ErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS);
  256 + }
  257 + Map<String, Object> processVariables = new HashMap<>();
  258 + // 获取历史中流程变量
  259 + Map<String, Object> historicVariables = historicProcessInstance.getProcessVariables();
  260 + if (CollUtil.isNotEmpty(historicVariables)) {
  261 + processVariables.putAll(historicVariables);
  262 + }
  263 + // 合并前端传递的流程变量,以前端为准
  264 + if (CollUtil.isNotEmpty(reqVO.getProcessVariables())){
  265 + processVariables.putAll(reqVO.getProcessVariables());
  266 + }
  267 + // 获取流程定义信息
  268 + BpmProcessDefinitionInfoDO processDefinitionInfo = processDefinitionService
  269 + .getProcessDefinitionInfo(task.getProcessDefinitionId());
  270 + // 获取当前任务节点的信息
253 FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey()); 271 FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
254 - List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, reqVO.getProcessVariables());  
255 - return convertList(nextFlowNodes, nodes -> {  
256 - FlowElement flowNode = BpmnModelUtils.getFlowElementById(bpmnModel, nodes.getId());  
257 - ActivityNode activityNode = new ActivityNode().setId(nodes.getId()).setName(nodes.getName())  
258 - .setNodeType(START_USER_NODE_ID.equals(nodes.getId())  
259 - ? BpmSimpleModelNodeTypeEnum.START_USER_NODE.getType()  
260 - : ObjUtil.defaultIfNull(parseNodeType(flowNode), // 目的:解决“办理节点”的识别  
261 - BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType()))  
262 - .setStatus(FlowableUtils.getTaskStatus(task))  
263 - .setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(flowNode));  
264 -  
265 - // 如果是取消状态,则跳过  
266 - if (BpmTaskStatusEnum.isCancelStatus(activityNode.getStatus())) {  
267 - return null; 272 + // 获取下一个将要执行的节点集合
  273 + List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, processVariables);
  274 + return convertList(nextFlowNodes, node -> {
  275 + List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(),
  276 + loginUserId, processDefinitionInfo.getProcessDefinitionId(), processVariables);
  277 + //存在一个节点多人审批的情况
  278 + List<UserSimpleBaseVO> candidateUsers = new ArrayList<>();
  279 + for (Long candidateUserId : candidateUserIds) {
  280 + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(candidateUserIds);
  281 + Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
  282 + candidateUsers.add(BpmProcessInstanceConvert.INSTANCE.buildUser(candidateUserId, userMap, deptMap));
268 } 283 }
269 - return activityNode; 284 + return new ActivityNode().setNodeType(BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType())
  285 + .setId(node.getId())
  286 + .setName(node.getName())
  287 + .setStatus(BpmTaskStatusEnum.RUNNING.getStatus())
  288 + .setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(node))
  289 + .setCandidateUsers(candidateUsers);
270 }); 290 });
271 } 291 }
272 292
@@ -725,8 +745,12 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService @@ -725,8 +745,12 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
725 // true,不影响没配置 745 // true,不影响没配置
726 // skipExpression 的节点 746 // skipExpression 的节点
727 if (CollUtil.isNotEmpty(startUserSelectAssignees)) { 747 if (CollUtil.isNotEmpty(startUserSelectAssignees)) {
  748 + // 设置流程变量,发起人自选审批人
728 variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, 749 variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES,
729 startUserSelectAssignees); 750 startUserSelectAssignees);
  751 + // 设置流程变量,审批人自选审批人
  752 + variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES,
  753 + startUserSelectAssignees);
730 } 754 }
731 755
732 // 3. 创建流程 756 // 3. 创建流程
@@ -768,9 +792,10 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService @@ -768,9 +792,10 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
768 return; 792 return;
769 } 793 }
770 794
771 - // 2.1 移除掉不是发起人自选审批人节点 795 + // 2.1 移除掉不是发起人或者审批人自选审批人节点
772 activityNodes.removeIf(task -> 796 activityNodes.removeIf(task ->
773 - ObjectUtil.notEqual(BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy(), task.getCandidateStrategy())); 797 + ObjectUtil.notEqual(BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy(), task.getCandidateStrategy())
  798 + && ObjectUtil.notEqual(BpmTaskCandidateStrategyEnum.APPROVE_USER_SELECT.getStrategy(), task.getCandidateStrategy()));
774 // 2.2 流程发起时要先获取当前流程的预测走向节点,发起时只校验预测的节点发起人自选审批人的审批人和抄送人是否都配置了 799 // 2.2 流程发起时要先获取当前流程的预测走向节点,发起时只校验预测的节点发起人自选审批人的审批人和抄送人是否都配置了
775 activityNodes.forEach(task -> { 800 activityNodes.forEach(task -> {
776 List<Long> assignees = startUserSelectAssignees != null ? startUserSelectAssignees.get(task.getId()) : null; 801 List<Long> assignees = startUserSelectAssignees != null ? startUserSelectAssignees.get(task.getId()) : null;