Commit 4e2ebe0c66be9c73bf4a97ddd1b00f3e82234511
Committed by
Gitee
!1280 fix: 解决审批节点表单无可编辑字段时,variables流程变量值为空,流程节点流转异常问题
Merge pull request !1280 from SamllNorth_Lee/feature/bpm
Showing
3 changed files
with
32 additions
and
31 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
| ... | ... | @@ -21,6 +21,7 @@ import org.flowable.bpmn.converter.BpmnXMLConverter; |
| 21 | 21 | import org.flowable.bpmn.model.Process; |
| 22 | 22 | import org.flowable.bpmn.model.*; |
| 23 | 23 | import org.flowable.common.engine.api.FlowableException; |
| 24 | +import org.flowable.common.engine.impl.javax.el.PropertyNotFoundException; | |
| 24 | 25 | import org.flowable.common.engine.impl.util.io.BytesStreamSource; |
| 25 | 26 | import org.flowable.engine.impl.el.FixedValue; |
| 26 | 27 | |
| ... | ... | @@ -907,17 +908,9 @@ public class BpmnModelUtils { |
| 907 | 908 | * @return 符合条件的路径 |
| 908 | 909 | */ |
| 909 | 910 | 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(), | |
| 911 | + SequenceFlow matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), | |
| 915 | 912 | flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()) |
| 916 | 913 | && (evalConditionExpress(variables, flow.getConditionExpression()))); |
| 917 | - } else { | |
| 918 | - matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), | |
| 919 | - flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId())); | |
| 920 | - } | |
| 921 | 914 | if (matchSequenceFlow == null) { |
| 922 | 915 | matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), |
| 923 | 916 | flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId())); |
| ... | ... | @@ -1014,6 +1007,11 @@ public class BpmnModelUtils { |
| 1014 | 1007 | Object result = FlowableUtils.getExpressionValue(variables, expression); |
| 1015 | 1008 | return Boolean.TRUE.equals(result); |
| 1016 | 1009 | } catch (FlowableException ex) { |
| 1010 | + // TODO @芋艿 临时方案解决流程变量中不包含条件表达式时报错问题,如果expression 的计算,可能不依赖于 variables,getExpressionValue方法应该需要重构 | |
| 1011 | + if (ex.getCause() instanceof PropertyNotFoundException){ | |
| 1012 | + log.error("[evalConditionExpress][条件表达式({}) 变量({}) 解析报错]", expression, variables, ex); | |
| 1013 | + return Boolean.FALSE; | |
| 1014 | + } | |
| 1017 | 1015 | // 为什么使用 info 日志?原因是,expression 如果从 variables 取不到值,会报错。实际这种情况下,可以忽略 |
| 1018 | 1016 | log.info("[evalConditionExpress][条件表达式({}) 变量({}) 解析报错]", expression, variables, ex); |
| 1019 | 1017 | return Boolean.FALSE; | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelServiceImpl.java
| ... | ... | @@ -248,16 +248,15 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 248 | 248 | throw exception(MODEL_DEPLOY_FAIL_BPMN_USER_TASK_NAME_NOT_EXISTS, userTask.getId()); |
| 249 | 249 | } |
| 250 | 250 | }); |
| 251 | - // TODO @小北:是不是可以 UserTask firUserTask = CollUtil.get(userTasks, BpmModelTypeEnum.BPMN.getType().equals(type) ? 0 : 1);然后,最好判空。。。极端情况下,没 usertask ,哈哈哈哈。 | |
| 252 | - // 3. 校验第一个用户任务节点的规则类型是否为“审批人自选” | |
| 253 | - Map<Integer, UserTask> userTaskMap = new HashMap<>(); | |
| 254 | - // BPMN 设计器,校验第一个用户任务节点 | |
| 255 | - userTaskMap.put(BpmModelTypeEnum.BPMN.getType(), userTasks.get(0)); | |
| 256 | - // SIMPLE 设计器,第一个节点固定为发起人所以校验第二个用户任务节点 | |
| 257 | - userTaskMap.put(BpmModelTypeEnum.SIMPLE.getType(), userTasks.get(1)); | |
| 258 | - Integer candidateStrategy = parseCandidateStrategy(userTaskMap.get(type)); | |
| 251 | + // 3. 校验第一个用户任务节点的规则类型是否为“审批人自选”,BPMN 设计器,校验第一个用户任务节点,SIMPLE 设计器,第一个节点固定为发起人所以校验第二个用户任务节点 | |
| 252 | + UserTask firUserTask = CollUtil.get(userTasks, BpmModelTypeEnum.BPMN.getType().equals(type) ? 0 : 1); | |
| 253 | + // 4. 极端情况下无多个用户任务节点,比如发起人-抄送节点 | |
| 254 | + if (firUserTask == null){ | |
| 255 | + return; | |
| 256 | + } | |
| 257 | + Integer candidateStrategy = parseCandidateStrategy(firUserTask); | |
| 259 | 258 | if (Objects.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.APPROVE_USER_SELECT.getStrategy())) { |
| 260 | - throw exception(MODEL_DEPLOY_FAIL_FIRST_USER_TASK_CANDIDATE_STRATEGY_ERROR, userTaskMap.get(type).getName()); | |
| 259 | + throw exception(MODEL_DEPLOY_FAIL_FIRST_USER_TASK_CANDIDATE_STRATEGY_ERROR, firUserTask.getName()); | |
| 261 | 260 | } |
| 262 | 261 | } |
| 263 | 262 | ... | ... |
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 | 557 | // 2.2 添加评论 |
| 558 | 558 | taskService.addComment(task.getId(), task.getProcessInstanceId(), BpmCommentTypeEnum.APPROVE.getType(), |
| 559 | 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 | 575 | bpmnModel, reqVO.getNextAssignees(), instance); |
| 563 | 576 | runtimeService.setVariables(task.getProcessInstanceId(), variables); |
| 564 | - // 2.4 调用 BPM complete 去完成任务 | |
| 577 | + // 4 调用 BPM complete 去完成任务 | |
| 565 | 578 | taskService.complete(task.getId(), variables, true); |
| 566 | 579 | |
| 567 | 580 | // 【加签专属】处理加签任务 |
| ... | ... | @@ -600,9 +613,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 600 | 613 | } |
| 601 | 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 | 617 | continue; |
| 607 | 618 | } |
| 608 | 619 | // 设置 PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES |
| ... | ... | @@ -622,13 +633,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 622 | 633 | processVariables = FlowableUtils.getApproveUserSelectAssignees(processInstance.getProcessVariables()); |
| 623 | 634 | if (processVariables == null) { |
| 624 | 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 | 637 | // 设置 PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES |
| 634 | 638 | processVariables.put(nextFlowNode.getId(), assignees); | ... | ... |