Commit 9c9f2812e9dc95095be0dc5bece7ad9417b1310c

Authored by Lesan
1 parent 0d886dc4

fix: 添加buildTimeoutBoundaryEvent方法

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java
... ... @@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.B
10 10 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.ConditionGroups;
11 11 import cn.iocoder.yudao.module.bpm.enums.definition.*;
12 12 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
13   -import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants;
14 13 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants;
15 14 import cn.iocoder.yudao.module.bpm.framework.flowable.core.listener.BpmCopyTaskDelegate;
16 15 import cn.iocoder.yudao.module.bpm.framework.flowable.core.listener.BpmTriggerTaskDelegate;
... ... @@ -84,7 +83,7 @@ public class SimpleModelUtils {
84 83 traverseNodeToBuildFlowNode(startNode, process);
85 84  
86 85 // 3. 构建并添加节点之间的连线 Sequence Flow
87   - EndEvent endEvent = BpmnModelUtils.getEndEvent(bpmnModel);
  86 + EndEvent endEvent = getEndEvent(bpmnModel);
88 87 traverseNodeToBuildSequenceFlow(process, startNode, endEvent.getId());
89 88  
90 89 // 4. 自动布局
... ... @@ -364,7 +363,7 @@ public class SimpleModelUtils {
364 363 userTask.setName(node.getName());
365 364  
366 365 // 人工审批
367   - addExtensionElement(userTask, BpmnModelConstants.USER_TASK_APPROVE_TYPE, BpmUserTaskApproveTypeEnum.USER.getType());
  366 + addExtensionElement(userTask, USER_TASK_APPROVE_TYPE, BpmUserTaskApproveTypeEnum.USER.getType());
368 367 // 候选人策略为发起人自己
369 368 addCandidateElements(BpmTaskCandidateStrategyEnum.START_USER.getStrategy(), null, userTask);
370 369 // 添加表单字段权限属性元素
... ... @@ -415,25 +414,17 @@ public class SimpleModelUtils {
415 414 */
416 415 private BoundaryEvent buildUserTaskTimeoutBoundaryEvent(UserTask userTask,
417 416 BpmSimpleModelNodeVO.TimeoutHandler timeoutHandler) {
418   - // 1.1 定时器边界事件
419   - // TODO @lesan:一些 BoundaryEvent timeout 的,可以做一些基础的设置么?
420   - BoundaryEvent boundaryEvent = new BoundaryEvent();
421   - boundaryEvent.setId("Event-" + IdUtil.fastUUID());
422   - boundaryEvent.setCancelActivity(false); // 设置关联的任务为不会被中断
423   - boundaryEvent.setAttachedToRef(userTask);
424   - // 1.2 定义超时时间、最大提醒次数
425   - TimerEventDefinition eventDefinition = new TimerEventDefinition();
426   - eventDefinition.setTimeDuration(timeoutHandler.getTimeDuration());
  417 + // 1. 创建 Timeout Boundary Event
  418 + String timeCycle = null;
427 419 if (Objects.equals(BpmUserTaskTimeoutHandlerTypeEnum.REMINDER.getType(), timeoutHandler.getType()) &&
428 420 timeoutHandler.getMaxRemindCount() != null && timeoutHandler.getMaxRemindCount() > 1) {
429   - eventDefinition.setTimeCycle(String.format("R%d/%s",
430   - timeoutHandler.getMaxRemindCount(), timeoutHandler.getTimeDuration()));
  421 + timeCycle = String.format("R%d/%s",
  422 + timeoutHandler.getMaxRemindCount(), timeoutHandler.getTimeDuration());
431 423 }
432   - boundaryEvent.addEventDefinition(eventDefinition);
  424 + BoundaryEvent boundaryEvent = buildTimeoutBoundaryEvent(userTask, BpmBoundaryEventTypeEnum.USER_TASK_TIMEOUT.getType(),
  425 + timeoutHandler.getTimeDuration(), timeCycle, null);
433 426  
434   - // 2.1 添加定时器边界事件类型
435   - addExtensionElement(boundaryEvent, BOUNDARY_EVENT_TYPE, BpmBoundaryEventTypeEnum.USER_TASK_TIMEOUT.getType());
436   - // 2.2 添加超时执行动作元素
  427 + // 2 添加超时执行动作元素
437 428 addExtensionElement(boundaryEvent, USER_TASK_TIMEOUT_HANDLER_TYPE, timeoutHandler.getType());
438 429 return boundaryEvent;
439 430 }
... ... @@ -516,7 +507,7 @@ public class SimpleModelUtils {
516 507 BpmUserTaskApproveMethodEnum approveMethodEnum = BpmUserTaskApproveMethodEnum.valueOf(approveMethod);
517 508 Assert.notNull(approveMethodEnum, "审批方式({})不能为空", approveMethodEnum);
518 509 // 添加审批方式的扩展属性
519   - addExtensionElement(userTask, BpmnModelConstants.USER_TASK_APPROVE_METHOD, approveMethod);
  510 + addExtensionElement(userTask, USER_TASK_APPROVE_METHOD, approveMethod);
520 511 if (approveMethodEnum == BpmUserTaskApproveMethodEnum.RANDOM) {
521 512 // 随机审批,不需要设置多实例属性
522 513 return;
... ... @@ -723,21 +714,14 @@ public class SimpleModelUtils {
723 714  
724 715 // 2. 添加接收任务的 Timer Boundary Event
725 716 if (node.getDelaySetting() != null) {
726   - // 2.1 定时器边界事件
727   - // TODO @lesan:一些 BoundaryEvent timeout 的,可以做一些基础的设置么?
728   - BoundaryEvent boundaryEvent = new BoundaryEvent();
729   - boundaryEvent.setId("Event-" + IdUtil.fastUUID());
730   - boundaryEvent.setCancelActivity(false);
731   - boundaryEvent.setAttachedToRef(receiveTask);
732   - // 2.2 定义超时时间
733   - TimerEventDefinition eventDefinition = new TimerEventDefinition();
  717 + BoundaryEvent boundaryEvent = null;
734 718 if (node.getDelaySetting().getDelayType().equals(BpmDelayTimerTypeEnum.FIXED_DATE_TIME.getType())) {
735   - eventDefinition.setTimeDuration(node.getDelaySetting().getDelayTime());
  719 + boundaryEvent = buildTimeoutBoundaryEvent(receiveTask, BpmBoundaryEventTypeEnum.DELAY_TIMER_TIMEOUT.getType(),
  720 + node.getDelaySetting().getDelayTime(), null, null);
736 721 } else if (node.getDelaySetting().getDelayType().equals(BpmDelayTimerTypeEnum.FIXED_TIME_DURATION.getType())) {
737   - eventDefinition.setTimeDate(node.getDelaySetting().getDelayTime());
  722 + boundaryEvent = buildTimeoutBoundaryEvent(receiveTask, BpmBoundaryEventTypeEnum.DELAY_TIMER_TIMEOUT.getType(),
  723 + null, null, node.getDelaySetting().getDelayTime());
738 724 }
739   - boundaryEvent.addEventDefinition(eventDefinition);
740   - addExtensionElement(boundaryEvent, BOUNDARY_EVENT_TYPE, BpmBoundaryEventTypeEnum.DELAY_TIMER_TIMEOUT.getType());
741 725 flowElements.add(boundaryEvent);
742 726 }
743 727 return flowElements;
... ... @@ -870,19 +854,14 @@ public class SimpleModelUtils {
870 854  
871 855 // 7. 超时设置
872 856 if (childProcessSetting.getTimeoutSetting() != null) {
873   - // TODO @lesan:一些 BoundaryEvent timeout 的,可以做一些基础的设置么?
874   - BoundaryEvent boundaryEvent = new BoundaryEvent();
875   - boundaryEvent.setId("Event-" + IdUtil.fastUUID());
876   - boundaryEvent.setCancelActivity(false);
877   - boundaryEvent.setAttachedToRef(callActivity);
878   - TimerEventDefinition eventDefinition = new TimerEventDefinition();
879   - if (childProcessSetting.getTimeoutSetting().getType().equals(BpmDelayTimerTypeEnum.FIXED_DATE_TIME.getType())) {
880   - eventDefinition.setTimeDuration(childProcessSetting.getTimeoutSetting().getTimeExpression());
881   - } else if (childProcessSetting.getTimeoutSetting().getType().equals(BpmDelayTimerTypeEnum.FIXED_TIME_DURATION.getType())) {
882   - eventDefinition.setTimeDate(childProcessSetting.getTimeoutSetting().getTimeExpression());
  857 + BoundaryEvent boundaryEvent = null;
  858 + if (node.getDelaySetting().getDelayType().equals(BpmDelayTimerTypeEnum.FIXED_DATE_TIME.getType())) {
  859 + boundaryEvent = buildTimeoutBoundaryEvent(callActivity, BpmBoundaryEventTypeEnum.DELAY_TIMER_TIMEOUT.getType(),
  860 + node.getDelaySetting().getDelayTime(), null, null);
  861 + } else if (node.getDelaySetting().getDelayType().equals(BpmDelayTimerTypeEnum.FIXED_TIME_DURATION.getType())) {
  862 + boundaryEvent = buildTimeoutBoundaryEvent(callActivity, BpmBoundaryEventTypeEnum.CHILD_PROCESS_TIMEOUT.getType(),
  863 + null, null, node.getDelaySetting().getDelayTime());
883 864 }
884   - boundaryEvent.addEventDefinition(eventDefinition);
885   - addExtensionElement(boundaryEvent, BOUNDARY_EVENT_TYPE, BpmBoundaryEventTypeEnum.CHILD_PROCESS_TIMEOUT.getType());
886 865 flowElements.add(boundaryEvent);
887 866 }
888 867  
... ... @@ -903,6 +882,33 @@ public class SimpleModelUtils {
903 882 return id + "_join";
904 883 }
905 884  
  885 + private static BoundaryEvent buildTimeoutBoundaryEvent(Activity attachedToRef, Integer type,
  886 + String timeDuration,
  887 + String timeCycle,
  888 + String timeDate) {
  889 + // 1.1 定时器边界事件
  890 + BoundaryEvent boundaryEvent = new BoundaryEvent();
  891 + boundaryEvent.setId("Event-" + IdUtil.fastUUID());
  892 + boundaryEvent.setCancelActivity(false); // 设置关联的任务为不会被中断
  893 + boundaryEvent.setAttachedToRef(attachedToRef);
  894 + // 1.2 定义超时时间表达式
  895 + TimerEventDefinition eventDefinition = new TimerEventDefinition();
  896 + if (ObjUtil.isNotNull(timeDuration)) {
  897 + eventDefinition.setTimeDuration(timeDuration);
  898 + }
  899 + if (ObjUtil.isNotNull(timeDuration)) {
  900 + eventDefinition.setTimeCycle(timeCycle);
  901 + }
  902 + if (ObjUtil.isNotNull(timeDate)) {
  903 + eventDefinition.setTimeDate(timeDate);
  904 + }
  905 + boundaryEvent.addEventDefinition(eventDefinition);
  906 +
  907 + // 2.1 添加定时器边界事件类型
  908 + addExtensionElement(boundaryEvent, BOUNDARY_EVENT_TYPE, type);
  909 + return boundaryEvent;
  910 + }
  911 +
906 912 // ========== SIMPLE 流程预测相关的方法 ==========
907 913  
908 914 public static List<BpmSimpleModelNodeVO> simulateProcess(BpmSimpleModelNodeVO rootNode, Map<String, Object> variables) {
... ...