Commit 575e7a38f37e32d28e0488c523cf55801f2a694f
1 parent
149cab1d
fix: 解决审批节点表单无可编辑字段时,variables流程变量值为空,流程节点流转异常问题
Showing
2 changed files
with
18 additions
and
22 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
| @@ -907,17 +907,9 @@ public class BpmnModelUtils { | @@ -907,17 +907,9 @@ public class BpmnModelUtils { | ||
| 907 | * @return 符合条件的路径 | 907 | * @return 符合条件的路径 |
| 908 | */ | 908 | */ |
| 909 | private static SequenceFlow findMatchSequenceFlowByExclusiveGateway(Gateway gateway, Map<String, Object> variables) { | 909 | private static SequenceFlow findMatchSequenceFlowByExclusiveGateway(Gateway gateway, Map<String, Object> variables) { |
| 910 | - // TODO 表单无可编辑字段时variables为空,流程走向会出现问题,比如流程审批过程中无需要修改的字段值, | ||
| 911 | - // TODO @小北:是不是还是保证,编辑的时候,如果计算下一个节点,还是 variables 是完整体?而不是空的!!!(可以微信讨论下) | ||
| 912 | - SequenceFlow matchSequenceFlow; | ||
| 913 | - if (CollUtil.isNotEmpty(variables)) { | ||
| 914 | - matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), | 910 | + SequenceFlow matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), |
| 915 | flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()) | 911 | flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()) |
| 916 | && (evalConditionExpress(variables, flow.getConditionExpression()))); | 912 | && (evalConditionExpress(variables, flow.getConditionExpression()))); |
| 917 | - } else { | ||
| 918 | - matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), | ||
| 919 | - flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId())); | ||
| 920 | - } | ||
| 921 | if (matchSequenceFlow == null) { | 913 | if (matchSequenceFlow == null) { |
| 922 | matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), | 914 | matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), |
| 923 | flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId())); | 915 | flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId())); |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| @@ -557,11 +557,24 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -557,11 +557,24 @@ 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 校验并处理 APPROVE_USER_SELECT 当前审批人,选择下一节点审批人的逻辑 | ||
| 561 | - Map<String, Object> variables = validateAndSetNextAssignees(task.getTaskDefinitionKey(), reqVO.getVariables(), | 560 | + // 如果流程变量前端传空,需要从历史实例中获取,原因:前端表单如果在当前节点无可编辑的字段时variables一定会为空 |
| 561 | + // 场景一:A节点发起,B节点表单无可编辑字段,审批通过时,C节点需要流程变量获取下一个执行节点,但因为B节点无可编辑的字段,variables为空,流程可能出现问题 | ||
| 562 | + // 场景二:A节点发起,B节点只有某一个字段可编辑(比如day),但C节点需要多个节点(比如workday,在发起时填写,因为B节点只有day的编辑权限,在审批后。variables会缺少work的值) | ||
| 563 | + // 3.1 设置流程变量 | ||
| 564 | + Map<String, Object> processVariables = new HashMap<>(); | ||
| 565 | + // 3.2 获取历史中流程变量 | ||
| 566 | + if (CollUtil.isNotEmpty(instance.getProcessVariables())) { | ||
| 567 | + processVariables.putAll(instance.getProcessVariables()); | ||
| 568 | + } | ||
| 569 | + // 3.3 合并前端传递的流程变量,以前端为准 | ||
| 570 | + if (CollUtil.isNotEmpty(reqVO.getVariables())) { | ||
| 571 | + processVariables.putAll(reqVO.getVariables()); | ||
| 572 | + } | ||
| 573 | + // 3.4 校验并处理 APPROVE_USER_SELECT 当前审批人,选择下一节点审批人的逻辑 | ||
| 574 | + Map<String, Object> variables = validateAndSetNextAssignees(task.getTaskDefinitionKey(), processVariables, | ||
| 562 | bpmnModel, reqVO.getNextAssignees(), instance); | 575 | bpmnModel, reqVO.getNextAssignees(), instance); |
| 563 | runtimeService.setVariables(task.getProcessInstanceId(), variables); | 576 | runtimeService.setVariables(task.getProcessInstanceId(), variables); |
| 564 | - // 2.4 调用 BPM complete 去完成任务 | 577 | + // 4 调用 BPM complete 去完成任务 |
| 565 | taskService.complete(task.getId(), variables, true); | 578 | taskService.complete(task.getId(), variables, true); |
| 566 | 579 | ||
| 567 | // 【加签专属】处理加签任务 | 580 | // 【加签专属】处理加签任务 |
| @@ -600,9 +613,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -600,9 +613,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 600 | } | 613 | } |
| 601 | processVariables = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables()); | 614 | processVariables = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables()); |
| 602 | // 特殊:如果当前节点已经存在审批人,则不允许覆盖 | 615 | // 特殊:如果当前节点已经存在审批人,则不允许覆盖 |
| 603 | - // TODO @小北:【不用改】通过 if return,让逻辑更简洁一点;虽然会多判断一次 processVariables,但是 if else 层级更少。 | ||
| 604 | - if (processVariables != null | ||
| 605 | - && CollUtil.isNotEmpty(processVariables.get(nextFlowNode.getId()))) { | 616 | + if (processVariables != null && CollUtil.isNotEmpty(processVariables.get(nextFlowNode.getId()))) { |
| 606 | continue; | 617 | continue; |
| 607 | } | 618 | } |
| 608 | // 设置 PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES | 619 | // 设置 PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES |
| @@ -622,13 +633,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -622,13 +633,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 622 | processVariables = FlowableUtils.getApproveUserSelectAssignees(processInstance.getProcessVariables()); | 633 | processVariables = FlowableUtils.getApproveUserSelectAssignees(processInstance.getProcessVariables()); |
| 623 | if (processVariables == null) { | 634 | if (processVariables == null) { |
| 624 | processVariables = new HashMap<>(); | 635 | processVariables = new HashMap<>(); |
| 625 | - } else { | ||
| 626 | - List<Long> approveUserSelectAssignee = processVariables.get(nextFlowNode.getId()); | ||
| 627 | - // 特殊:如果当前节点已经存在审批人,则不允许覆盖 | ||
| 628 | - // TODO @小北:这种,应该可以覆盖呢。 | ||
| 629 | - if (CollUtil.isNotEmpty(approveUserSelectAssignee)) { | ||
| 630 | - continue; | ||
| 631 | - } | ||
| 632 | } | 636 | } |
| 633 | // 设置 PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES | 637 | // 设置 PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES |
| 634 | processVariables.put(nextFlowNode.getId(), assignees); | 638 | processVariables.put(nextFlowNode.getId(), assignees); |