Commit c2789f628c2c053b50986d25de057cb2efcc6953
1 parent
23844b93
fix: 解决审批节点表单无可编辑字段时,variables流程变量值为空,流程节点流转异常问题
Showing
1 changed file
with
13 additions
and
8 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| @@ -557,22 +557,27 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -557,22 +557,27 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 557 | // 2.2 添加评论 | 557 | // 2.2 添加评论 |
| 558 | taskService.addComment(task.getId(), task.getProcessInstanceId(), BpmCommentTypeEnum.APPROVE.getType(), | 558 | taskService.addComment(task.getId(), task.getProcessInstanceId(), BpmCommentTypeEnum.APPROVE.getType(), |
| 559 | BpmCommentTypeEnum.APPROVE.formatComment(reqVO.getReason())); | 559 | BpmCommentTypeEnum.APPROVE.formatComment(reqVO.getReason())); |
| 560 | - // 2.3 调用 BPM complete 去完成任务 | 560 | + |
| 561 | // 如果流程变量前端传空,需要从历史实例中获取,原因:前端表单如果在当前节点无可编辑的字段时variables一定会为空 | 561 | // 如果流程变量前端传空,需要从历史实例中获取,原因:前端表单如果在当前节点无可编辑的字段时variables一定会为空 |
| 562 | // 场景一:A节点发起,B节点表单无可编辑字段,审批通过时,C节点需要流程变量获取下一个执行节点,但因为B节点无可编辑的字段,variables为空,流程可能出现问题 | 562 | // 场景一:A节点发起,B节点表单无可编辑字段,审批通过时,C节点需要流程变量获取下一个执行节点,但因为B节点无可编辑的字段,variables为空,流程可能出现问题 |
| 563 | // 场景二:A节点发起,B节点只有某一个字段可编辑(比如day),但C节点需要多个节点(比如workday,在发起时填写,因为B节点只有day的编辑权限,在审批后。variables会缺少work的值) | 563 | // 场景二:A节点发起,B节点只有某一个字段可编辑(比如day),但C节点需要多个节点(比如workday,在发起时填写,因为B节点只有day的编辑权限,在审批后。variables会缺少work的值) |
| 564 | // 历史中的变量值 | 564 | // 历史中的变量值 |
| 565 | - Map<String, Object> variables = new HashMap<>(instance.getProcessVariables()); | ||
| 566 | - // 如果变量值不为空,则覆盖历史变量 | 565 | + // 3.1 设置流程变量 |
| 566 | + Map<String, Object> processVariables = new HashMap<>(); | ||
| 567 | + // 3.2 获取历史中流程变量 | ||
| 568 | + if (CollUtil.isNotEmpty(instance.getProcessVariables())) { | ||
| 569 | + processVariables.putAll(instance.getProcessVariables()); | ||
| 570 | + } | ||
| 571 | + // 3.3 合并前端传递的流程变量,以前端为准 | ||
| 567 | if (CollUtil.isNotEmpty(reqVO.getVariables())) { | 572 | if (CollUtil.isNotEmpty(reqVO.getVariables())) { |
| 568 | - variables.putAll(reqVO.getVariables()); | 573 | + processVariables.putAll(reqVO.getVariables()); |
| 569 | } | 574 | } |
| 570 | // 校验并处理 APPROVE_USER_SELECT 当前审批人,选择下一节点审批人的逻辑 | 575 | // 校验并处理 APPROVE_USER_SELECT 当前审批人,选择下一节点审批人的逻辑 |
| 571 | - Map<String, Object> resVariables = validateAndSetNextAssignees(task.getTaskDefinitionKey(), variables, | 576 | + Map<String, Object> variables = validateAndSetNextAssignees(task.getTaskDefinitionKey(), processVariables, |
| 572 | bpmnModel, reqVO.getNextAssignees(), instance); | 577 | bpmnModel, reqVO.getNextAssignees(), instance); |
| 573 | - // 完成任务 | ||
| 574 | - runtimeService.setVariables(task.getProcessInstanceId(), resVariables); | ||
| 575 | - taskService.complete(task.getId(), resVariables, true); | 578 | + // 3.4 调用 BPM complete 去完成任务 |
| 579 | + runtimeService.setVariables(task.getProcessInstanceId(), variables); | ||
| 580 | + taskService.complete(task.getId(), variables, true); | ||
| 576 | 581 | ||
| 577 | // 【加签专属】处理加签任务 | 582 | // 【加签专属】处理加签任务 |
| 578 | handleParentTaskIfSign(task.getParentTaskId()); | 583 | handleParentTaskIfSign(task.getParentTaskId()); |