Commit 6e2d00d561d5b7b866f90012da43d83eb8c7c911
1 parent
d41cce94
feat:审批通过时,查询下一个执行节点,校验流程执行正确与否
Showing
2 changed files
with
11 additions
and
6 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
| ... | ... | @@ -169,7 +169,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService |
| 169 | 169 | Long startUserId = loginUserId; // 流程发起人 |
| 170 | 170 | HistoricProcessInstance historicProcessInstance = null; // 流程实例 |
| 171 | 171 | Integer processInstanceStatus = BpmProcessInstanceStatusEnum.NOT_START.getStatus(); // 流程状态 |
| 172 | - Map<String, Object> processVariables = reqVO.getProcessVariables(); // 流程变量 | |
| 172 | + Map<String, Object> processVariables = new HashMap<>(); // 流程变量 | |
| 173 | 173 | // 1.2 如果是流程已发起的场景,则使用流程实例的数据 |
| 174 | 174 | if (reqVO.getProcessInstanceId() != null) { |
| 175 | 175 | historicProcessInstance = getHistoricProcessInstance(reqVO.getProcessInstanceId()); |
| ... | ... | @@ -180,10 +180,12 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService |
| 180 | 180 | processInstanceStatus = FlowableUtils.getProcessInstanceStatus(historicProcessInstance); |
| 181 | 181 | // 合并 DB 和前端传递的流量变量,以前端的为主 |
| 182 | 182 | Map<String, Object> historicVariables = historicProcessInstance.getProcessVariables(); |
| 183 | - if (CollUtil.isNotEmpty(processVariables)) { | |
| 184 | - historicVariables.putAll(processVariables); | |
| 183 | + if (CollUtil.isNotEmpty(historicVariables)) { | |
| 184 | + processVariables.putAll(historicVariables); | |
| 185 | 185 | } |
| 186 | - processVariables = historicVariables; | |
| 186 | + } | |
| 187 | + if (CollUtil.isNotEmpty(reqVO.getProcessVariables())) { | |
| 188 | + processVariables.putAll(reqVO.getProcessVariables()); | |
| 187 | 189 | } |
| 188 | 190 | // 1.3 读取其它相关数据 |
| 189 | 191 | ProcessDefinition processDefinition = processDefinitionService.getProcessDefinition( | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| ... | ... | @@ -531,6 +531,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 531 | 531 | // 校验传递的参数中是否为下一个将要执行的任务节点 |
| 532 | 532 | Map<String, Object> variables = validateAndSetNextAssignees(task.getTaskDefinitionKey(), reqVO.getVariables(), |
| 533 | 533 | bpmnModel, reqVO.getNextAssignees(), instance); |
| 534 | + runtimeService.setVariables(task.getProcessInstanceId(), variables); | |
| 534 | 535 | taskService.complete(task.getId(), variables, true); |
| 535 | 536 | } else { |
| 536 | 537 | taskService.complete(task.getId()); |
| ... | ... | @@ -555,6 +556,10 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 555 | 556 | */ |
| 556 | 557 | private Map<String, Object> validateAndSetNextAssignees(String taskDefinitionKey, Map<String, Object> variables, BpmnModel bpmnModel, |
| 557 | 558 | Map<String, List<Long>> nextAssignees, ProcessInstance processInstance) { |
| 559 | + // 下一个节点参数为空,不做处理,表示流程正常流转,无需选择下一个节点的审判人 | |
| 560 | + if (CollUtil.isEmpty(nextAssignees)){ | |
| 561 | + return variables; | |
| 562 | + } | |
| 558 | 563 | // 1. 获取当前任务节点的信息 |
| 559 | 564 | FlowElement flowElement = bpmnModel.getFlowElement(taskDefinitionKey); |
| 560 | 565 | // 2. 获取下一个将要执行的节点集合 |
| ... | ... | @@ -587,7 +592,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 587 | 592 | // 4.3.3 校验通过的全部节点和审批人 |
| 588 | 593 | allNextAssignees.put(nextFlowNode.getId(), nextAssignees.get(nextFlowNode.getId())); |
| 589 | 594 | } |
| 590 | - // TODO @小北:加一个“审批人选择”的校验; | |
| 591 | 595 | } |
| 592 | 596 | // variables 是存储动态表单到 local 任务级别。过滤一下,避免 ProcessInstance 系统级的变量被占用 |
| 593 | 597 | Map<String, Object> newVariables = FlowableUtils.filterTaskFormVariable(variables); |
| ... | ... | @@ -599,7 +603,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 599 | 603 | newVariables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES, hisProcessVariables); |
| 600 | 604 | // 设置流程变量,发起人自选,后续的节点或者回退后再或者驳回重新发起的场景可能存在发起人自选或者审批人自选,所以中两个变量值要保持一致,否则会查询不到审批人 |
| 601 | 605 | newVariables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, hisProcessVariables); |
| 602 | - runtimeService.setVariables(processInstance.getProcessInstanceId(), newVariables); | |
| 603 | 606 | } |
| 604 | 607 | return newVariables; |
| 605 | 608 | } | ... | ... |