Эх сурвалжийг харах

【代码评审】BPM:子流程的多实例

YunaiV 5 сар өмнө
parent
commit
e892dcabac

+ 1 - 0
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmChildProcessMultiInstanceSourceTypeEnum.java

@@ -33,4 +33,5 @@ public enum BpmChildProcessMultiInstanceSourceTypeEnum implements ArrayValuable<
     public Integer[] array() {
         return ARRAYS;
     }
+
 }

+ 2 - 2
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/simple/BpmSimpleModelNodeVO.java

@@ -394,7 +394,7 @@ public class BpmSimpleModelNodeVO {
              */
             @Schema(description = "回调任务 Key", example = "xxx", hidden = true)
             private String callbackTaskDefineKey;
-            
+
         }
 
         @Schema(description = "流程表单触发器设置", example = "{}")
@@ -509,7 +509,7 @@ public class BpmSimpleModelNodeVO {
 
             @Schema(description = "完成比例", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
             @NotNull(message = "完成比例不能为空")
-            private Integer completeRatio;
+            private Integer completeRatio; // TODO @lesan:approveRatio 要不这个,和上面保持一致?
 
             @Schema(description = "多实例来源类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
             @NotNull(message = "多实例来源类型不能为空")

+ 2 - 0
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/BpmParallelMultiInstanceBehavior.java

@@ -48,6 +48,7 @@ public class BpmParallelMultiInstanceBehavior extends ParallelMultiInstanceBehav
      */
     @Override
     protected int resolveNrOfInstances(DelegateExecution execution) {
+        // 情况一:UserTask 节点
         if (execution.getCurrentFlowElement() instanceof UserTask) {
             // 第一步,设置 collectionVariable 和 CollectionVariable
             // 从  execution.getVariable() 读取所有任务处理人的 key
@@ -72,6 +73,7 @@ public class BpmParallelMultiInstanceBehavior extends ParallelMultiInstanceBehav
             return assigneeUserIds.size();
         }
 
+        // 情况二:CallActivity 节点
         if (execution.getCurrentFlowElement() instanceof CallActivity) {
             FlowElement flowElement = execution.getCurrentFlowElement();
             Integer sourceType = BpmnModelUtils.parseMultiInstanceSourceType(flowElement);

+ 2 - 0
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/BpmSequentialMultiInstanceBehavior.java

@@ -41,6 +41,7 @@ public class BpmSequentialMultiInstanceBehavior extends SequentialMultiInstanceB
      */
     @Override
     protected int resolveNrOfInstances(DelegateExecution execution) {
+        // 情况一:UserTask 节点
         if (execution.getCurrentFlowElement() instanceof UserTask) {
             // 第一步,设置 collectionVariable 和 CollectionVariable
             // 从  execution.getVariable() 读取所有任务处理人的 key
@@ -66,6 +67,7 @@ public class BpmSequentialMultiInstanceBehavior extends SequentialMultiInstanceB
             return assigneeUserIds.size();
         }
 
+        // 情况二:CallActivity 节点
         if (execution.getCurrentFlowElement() instanceof CallActivity) {
             FlowElement flowElement = execution.getCurrentFlowElement();
             Integer sourceType = BpmnModelUtils.parseMultiInstanceSourceType(flowElement);

+ 6 - 5
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java

@@ -721,6 +721,8 @@ public class SimpleModelUtils {
                 } else if (node.getDelaySetting().getDelayType().equals(BpmDelayTimerTypeEnum.FIXED_TIME_DURATION.getType())) {
                     boundaryEvent = buildTimeoutBoundaryEvent(receiveTask, BpmBoundaryEventTypeEnum.DELAY_TIMER_TIMEOUT.getType(),
                             null, null, node.getDelaySetting().getDelayTime());
+                } else {
+                    throw new UnsupportedOperationException("不支持的延迟类型:" + node.getDelaySetting());
                 }
                 flowElements.add(boundaryEvent);
             }
@@ -751,7 +753,7 @@ public class SimpleModelUtils {
                 // 重要:设置 callbackTaskDefineKey,用于 HTTP 回调
                 node.getTriggerSetting().getHttpRequestSetting().setCallbackTaskDefineKey(receiveTask.getId());
             }
-            
+
             // 触发器使用 ServiceTask 来实现
             ServiceTask serviceTask = new ServiceTask();
             serviceTask.setId(node.getId());
@@ -877,6 +879,7 @@ public class SimpleModelUtils {
                         childProcessSetting.getMultiInstanceSetting().getSourceType().equals(BpmChildProcessMultiInstanceSourceTypeEnum.MULTI_FORM.getType())) {
                     multiInstanceCharacteristics.setInputDataItem(childProcessSetting.getMultiInstanceSetting().getSource());
                 }
+//              TODO @lesan:String.format(approveMethodEnum.getCompletionCondition(), String.format("%.2f", approveRatio / 100D)));
                 multiInstanceCharacteristics.setCompletionCondition(String.format("${ nrOfCompletedInstances/nrOfInstances >= %s}",
                         String.format("%.2f", childProcessSetting.getMultiInstanceSetting().getCompleteRatio() / 100D)));
                 callActivity.setLoopCharacteristics(multiInstanceCharacteristics);
@@ -901,9 +904,7 @@ public class SimpleModelUtils {
     }
 
     private static BoundaryEvent buildTimeoutBoundaryEvent(Activity attachedToRef, Integer type,
-                                                           String timeDuration,
-                                                           String timeCycle,
-                                                           String timeDate) {
+                                                           String timeDuration, String timeCycle, String timeDate) {
         // 1.1 定时器边界事件
         BoundaryEvent boundaryEvent = new BoundaryEvent();
         boundaryEvent.setId("Event-" + IdUtil.fastUUID());
@@ -922,7 +923,7 @@ public class SimpleModelUtils {
         }
         boundaryEvent.addEventDefinition(eventDefinition);
 
-        // 2.1 添加定时器边界事件类型
+        // 2. 添加定时器边界事件类型
         addExtensionElement(boundaryEvent, BOUNDARY_EVENT_TYPE, type);
         return boundaryEvent;
     }

+ 2 - 1
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java

@@ -414,7 +414,8 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
             // 处理每个任务的 tasks 属性
             for (HistoricActivityInstance activity : taskActivities) {
                 HistoricTaskInstance task = taskMap.get(activity.getTaskId());
-                // ChildProcess 子流程节点仅存在于 activity 中,并且没有自身的 task ,需要跳过执行
+                // 特殊情况:子流程节点 ChildProcess 仅存在于 activity 中,并且没有自身的 task,需要跳过执行
+                // TODO @芋艿:后续看看怎么优化!
                 if (task == null) {
                     continue;
                 }