Commit 1023afda4051db10d7a3198a067a0b55461b7b1b

Authored by lizhixian
1 parent 3d20ce1a

fix: 修复流程分支节点预测问题

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
... ... @@ -32,7 +32,7 @@ import static org.flowable.bpmn.constants.BpmnXMLConstants.FLOWABLE_EXTENSIONS_P
32 32  
33 33 /**
34 34 * BPMN Model 操作工具类。目前分成三部分:
35   - *
  35 + * <p>
36 36 * 1. BPMN 修改 + 解析元素相关的方法
37 37 * 2. BPMN 简单查找相关的方法
38 38 * 3. BPMN 复杂遍历相关的方法
... ... @@ -105,8 +105,8 @@ public class BpmnModelUtils {
105 105 * 给节点添加候选人元素
106 106 *
107 107 * @param candidateStrategy 候选人策略
108   - * @param candidateParam 候选人参数,允许空
109   - * @param flowElement 节点
  108 + * @param candidateParam 候选人参数,允许空
  109 + * @param flowElement 节点
110 110 */
111 111 public static void addCandidateElements(Integer candidateStrategy, String candidateParam, FlowElement flowElement) {
112 112 addExtensionElement(flowElement, BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY,
... ... @@ -150,9 +150,9 @@ public class BpmnModelUtils {
150 150 /**
151 151 * 解析审批类型
152 152 *
153   - * @see BpmUserTaskApproveTypeEnum
154 153 * @param userTask 任务节点
155 154 * @return 审批类型
  155 + * @see BpmUserTaskApproveTypeEnum
156 156 */
157 157 public static Integer parseApproveType(FlowElement userTask) {
158 158 return NumberUtils.parseInt(parseExtensionElement(userTask, BpmnModelConstants.USER_TASK_APPROVE_TYPE));
... ... @@ -162,7 +162,7 @@ public class BpmnModelUtils {
162 162 * 添加任务拒绝处理元素
163 163 *
164 164 * @param rejectHandler 任务拒绝处理
165   - * @param userTask 任务节点
  165 + * @param userTask 任务节点
166 166 */
167 167 public static void addTaskRejectElements(BpmSimpleModelNodeVO.RejectHandler rejectHandler, UserTask userTask) {
168 168 if (rejectHandler == null) {
... ... @@ -196,9 +196,9 @@ public class BpmnModelUtils {
196 196 /**
197 197 * 给节点添加用户任务的审批人与发起人相同时,处理类型枚举
198 198 *
199   - * @see BpmUserTaskAssignStartUserHandlerTypeEnum
200 199 * @param assignStartUserHandlerType 发起人处理类型
201   - * @param userTask 任务节点
  200 + * @param userTask 任务节点
  201 + * @see BpmUserTaskAssignStartUserHandlerTypeEnum
202 202 */
203 203 public static void addAssignStartUserHandlerType(Integer assignStartUserHandlerType, UserTask userTask) {
204 204 if (assignStartUserHandlerType == null) {
... ... @@ -210,9 +210,9 @@ public class BpmnModelUtils {
210 210 /**
211 211 * 给节点添加用户任务的审批人为空时,处理类型枚举
212 212 *
213   - * @see BpmUserTaskAssignEmptyHandlerTypeEnum
214 213 * @param emptyHandler 空处理
215   - * @param userTask 任务节点
  214 + * @param userTask 任务节点
  215 + * @see BpmUserTaskAssignEmptyHandlerTypeEnum
216 216 */
217 217 public static void addAssignEmptyHandlerType(BpmSimpleModelNodeVO.AssignEmptyHandler emptyHandler, UserTask userTask) {
218 218 if (emptyHandler == null) {
... ... @@ -256,7 +256,7 @@ public class BpmnModelUtils {
256 256 * 给节点添加表单字段权限元素
257 257 *
258 258 * @param fieldsPermissions 表单字段权限
259   - * @param flowElement 节点
  259 + * @param flowElement 节点
260 260 */
261 261 public static void addFormFieldsPermission(List<Map<String, String>> fieldsPermissions, FlowElement flowElement) {
262 262 if (CollUtil.isNotEmpty(fieldsPermissions)) {
... ... @@ -267,7 +267,7 @@ public class BpmnModelUtils {
267 267 /**
268 268 * 解析表单字段权限
269 269 *
270   - * @param bpmnModel bpmnModel 对象
  270 + * @param bpmnModel bpmnModel 对象
271 271 * @param flowElementId 元素 ID
272 272 * @return 表单字段权限
273 273 */
... ... @@ -313,7 +313,7 @@ public class BpmnModelUtils {
313 313 /**
314 314 * 解析操作按钮设置
315 315 *
316   - * @param bpmnModel bpmnModel 对象
  316 + * @param bpmnModel bpmnModel 对象
317 317 * @param flowElementId 元素 ID
318 318 * @return 操作按钮设置
319 319 */
... ... @@ -762,9 +762,9 @@ public class BpmnModelUtils {
762 762  
763 763 // 情况:StartEvent/EndEvent/UserTask/ServiceTask
764 764 if (currentElement instanceof StartEvent
765   - || currentElement instanceof EndEvent
766   - || currentElement instanceof UserTask
767   - || currentElement instanceof ServiceTask) {
  765 + || currentElement instanceof EndEvent
  766 + || currentElement instanceof UserTask
  767 + || currentElement instanceof ServiceTask) {
768 768 // 添加元素
769 769 FlowNode flowNode = (FlowNode) currentElement;
770 770 resultElements.add(flowNode);
... ... @@ -778,10 +778,16 @@ public class BpmnModelUtils {
778 778 if (currentElement instanceof ExclusiveGateway) {
779 779 // 查找满足条件的 SequenceFlow 路径
780 780 Gateway gateway = (Gateway) currentElement;
781   - SequenceFlow matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(),
782   - flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId())
783   - //流程第一次发起时,variables条件值一定为空,发生异常会导致后续分支节点无法预测,
784   - || (null != variables && evalConditionExpress(variables, flow.getConditionExpression())));
  781 + SequenceFlow matchSequenceFlow;
  782 + //流程首次发起时,variables值一定为空,会导致条件表达式解析错误导致预测节点缺失
  783 + if (null == variables) {
  784 + matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(),
  785 + flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()));
  786 + } else {
  787 + matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(),
  788 + flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId())
  789 + && (evalConditionExpress(variables, flow.getConditionExpression())));
  790 + }
785 791 if (matchSequenceFlow == null) {
786 792 matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(),
787 793 flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId()));
... ... @@ -831,7 +837,7 @@ public class BpmnModelUtils {
831 837 * 计算条件表达式是否为 true 满足条件
832 838 *
833 839 * @param variables 流程实例
834   - * @param express 条件表达式
  840 + * @param express 条件表达式
835 841 * @return 是否满足条件
836 842 */
837 843 public static boolean evalConditionExpress(Map<String, Object> variables, String express) {
... ...