Commit 0ab54a9fe42ddc72af31df119d5665fac3f6e2d8
1 parent
4e2ebe0c
【代码评审】BPM:fix: 解决审批节点表单无可编辑字段时,variables流程变量值为空,流程节点流转异常问题
Showing
4 changed files
with
14 additions
and
21 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/definition/BpmProcessDefinitionInfoDO.java
| ... | ... | @@ -191,12 +191,12 @@ public class BpmProcessDefinitionInfoDO extends BaseDO { |
| 191 | 191 | /** |
| 192 | 192 | * 流程前置通知设置 |
| 193 | 193 | */ |
| 194 | - @TableField(typeHandler = JacksonTypeHandler.class, exist = false) // TODO @芋艿:临时注释 exist,因为要合并 master-jdk17 | |
| 194 | + @TableField(typeHandler = JacksonTypeHandler.class) | |
| 195 | 195 | private BpmModelMetaInfoVO.HttpRequestSetting processBeforeTriggerSetting; |
| 196 | 196 | /** |
| 197 | 197 | * 流程后置通知设置 |
| 198 | 198 | */ |
| 199 | - @TableField(typeHandler = JacksonTypeHandler.class, exist = false) // TODO @芋艿:临时注释 exist,因为要合并 master-jdk17 | |
| 199 | + @TableField(typeHandler = JacksonTypeHandler.class) | |
| 200 | 200 | private BpmModelMetaInfoVO.HttpRequestSetting processAfterTriggerSetting; |
| 201 | 201 | |
| 202 | 202 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
| ... | ... | @@ -21,7 +21,6 @@ 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; | |
| 25 | 24 | import org.flowable.common.engine.impl.util.io.BytesStreamSource; |
| 26 | 25 | import org.flowable.engine.impl.el.FixedValue; |
| 27 | 26 | |
| ... | ... | @@ -1007,11 +1006,6 @@ public class BpmnModelUtils { |
| 1007 | 1006 | Object result = FlowableUtils.getExpressionValue(variables, expression); |
| 1008 | 1007 | return Boolean.TRUE.equals(result); |
| 1009 | 1008 | } 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 | - } | |
| 1015 | 1009 | // 为什么使用 info 日志?原因是,expression 如果从 variables 取不到值,会报错。实际这种情况下,可以忽略 |
| 1016 | 1010 | log.info("[evalConditionExpress][条件表达式({}) 变量({}) 解析报错]", expression, variables, ex); |
| 1017 | 1011 | return Boolean.FALSE; | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelServiceImpl.java
| ... | ... | @@ -250,8 +250,7 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 250 | 250 | }); |
| 251 | 251 | // 3. 校验第一个用户任务节点的规则类型是否为“审批人自选”,BPMN 设计器,校验第一个用户任务节点,SIMPLE 设计器,第一个节点固定为发起人所以校验第二个用户任务节点 |
| 252 | 252 | UserTask firUserTask = CollUtil.get(userTasks, BpmModelTypeEnum.BPMN.getType().equals(type) ? 0 : 1); |
| 253 | - // 4. 极端情况下无多个用户任务节点,比如发起人-抄送节点 | |
| 254 | - if (firUserTask == null){ | |
| 253 | + if (firUserTask == null) { | |
| 255 | 254 | return; |
| 256 | 255 | } |
| 257 | 256 | Integer candidateStrategy = parseCandidateStrategy(firUserTask); | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| ... | ... | @@ -557,31 +557,31 @@ 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 | - // 如果流程变量前端传空,需要从历史实例中获取,原因:前端表单如果在当前节点无可编辑的字段时variables一定会为空 | |
| 561 | - // 场景一:A节点发起,B节点表单无可编辑字段,审批通过时,C节点需要流程变量获取下一个执行节点,但因为B节点无可编辑的字段,variables为空,流程可能出现问题 | |
| 562 | - // 场景二:A节点发起,B节点只有某一个字段可编辑(比如day),但C节点需要多个节点(比如workday,在发起时填写,因为B节点只有day的编辑权限,在审批后。variables会缺少work的值) | |
| 563 | - // 3.1 设置流程变量 | |
| 560 | + | |
| 561 | + // 3. 设置流程变量。如果流程变量前端传空,需要从历史实例中获取,原因:前端表单如果在当前节点无可编辑的字段时 variables 一定会为空 | |
| 562 | + // 场景一:A 节点发起,B 节点表单无可编辑字段,审批通过时,C 节点需要流程变量获取下一个执行节点,但因为 B 节点无可编辑的字段,variables 为空,流程可能出现问题。 | |
| 563 | + // 场景二:A 节点发起,B 节点只有某一个字段可编辑(比如 day),但 C 节点需要多个节点。 | |
| 564 | + // (比如 work + day 变量,在发起时填写,因为 B 节点只有 day 的编辑权限,在审批后,variables 会缺少 work 的值) | |
| 564 | 565 | Map<String, Object> processVariables = new HashMap<>(); |
| 565 | - // 3.2 获取历史中流程变量 | |
| 566 | - if (CollUtil.isNotEmpty(instance.getProcessVariables())) { | |
| 566 | + if (CollUtil.isNotEmpty(instance.getProcessVariables())) { // 获取历史中流程变量 | |
| 567 | 567 | processVariables.putAll(instance.getProcessVariables()); |
| 568 | 568 | } |
| 569 | - // 3.3 合并前端传递的流程变量,以前端为准 | |
| 570 | - if (CollUtil.isNotEmpty(reqVO.getVariables())) { | |
| 569 | + if (CollUtil.isNotEmpty(reqVO.getVariables())) { // 合并前端传递的流程变量,以前端为准 | |
| 571 | 570 | processVariables.putAll(reqVO.getVariables()); |
| 572 | 571 | } |
| 573 | - // 3.4 校验并处理 APPROVE_USER_SELECT 当前审批人,选择下一节点审批人的逻辑 | |
| 572 | + | |
| 573 | + // 4. 校验并处理 APPROVE_USER_SELECT 当前审批人,选择下一节点审批人的逻辑 | |
| 574 | 574 | Map<String, Object> variables = validateAndSetNextAssignees(task.getTaskDefinitionKey(), processVariables, |
| 575 | 575 | bpmnModel, reqVO.getNextAssignees(), instance); |
| 576 | 576 | runtimeService.setVariables(task.getProcessInstanceId(), variables); |
| 577 | - // 4 调用 BPM complete 去完成任务 | |
| 577 | + | |
| 578 | + // 5. 调用 BPM complete 去完成任务 | |
| 578 | 579 | taskService.complete(task.getId(), variables, true); |
| 579 | 580 | |
| 580 | 581 | // 【加签专属】处理加签任务 |
| 581 | 582 | handleParentTaskIfSign(task.getParentTaskId()); |
| 582 | 583 | } |
| 583 | 584 | |
| 584 | - | |
| 585 | 585 | /** |
| 586 | 586 | * 校验选择的下一个节点的审批人,是否合法 |
| 587 | 587 | * | ... | ... |