From 6b13839488edcd06046e26a41fe897358176689c Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期五, 13 十二月 2024 17:56:41 +0800
Subject: [PATCH] 采集质量

---
 iailab-module-bpm/iailab-module-bpm-biz/src/main/java/com/iailab/module/bpm/framework/flowable/core/candidate/strategy/other/BpmTaskCandidateAssignEmptyStrategy.java |   73 ++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/iailab-module-bpm/iailab-module-bpm-biz/src/main/java/com/iailab/module/bpm/framework/flowable/core/candidate/strategy/other/BpmTaskCandidateAssignEmptyStrategy.java b/iailab-module-bpm/iailab-module-bpm-biz/src/main/java/com/iailab/module/bpm/framework/flowable/core/candidate/strategy/other/BpmTaskCandidateAssignEmptyStrategy.java
new file mode 100644
index 0000000..e32a9f5
--- /dev/null
+++ b/iailab-module-bpm/iailab-module-bpm-biz/src/main/java/com/iailab/module/bpm/framework/flowable/core/candidate/strategy/other/BpmTaskCandidateAssignEmptyStrategy.java
@@ -0,0 +1,73 @@
+package com.iailab.module.bpm.framework.flowable.core.candidate.strategy.other;
+
+import cn.hutool.core.lang.Assert;
+import com.iailab.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO;
+import com.iailab.module.bpm.enums.definition.BpmUserTaskAssignEmptyHandlerTypeEnum;
+import com.iailab.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
+import com.iailab.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
+import com.iailab.module.bpm.framework.flowable.core.util.BpmnModelUtils;
+import com.iailab.module.bpm.service.definition.BpmProcessDefinitionService;
+import org.flowable.bpmn.model.BpmnModel;
+import org.flowable.bpmn.model.FlowElement;
+import org.flowable.engine.delegate.DelegateExecution;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * 审批人为空 {@link BpmTaskCandidateStrategy} 实现类
+ *
+ * @author hou
+ */
+@Component
+public class BpmTaskCandidateAssignEmptyStrategy implements BpmTaskCandidateStrategy {
+
+    @Resource
+    @Lazy // 延迟加载,避免循环依赖
+    private BpmProcessDefinitionService processDefinitionService;
+
+    @Override
+    public BpmTaskCandidateStrategyEnum getStrategy() {
+        return BpmTaskCandidateStrategyEnum.ASSIGN_EMPTY;
+    }
+
+    @Override
+    public void validateParam(String param) {
+    }
+
+    @Override
+    public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) {
+        return getCandidateUsers(execution.getProcessDefinitionId(), execution.getCurrentFlowElement());
+    }
+
+    @Override
+    public Set<Long> calculateUsersByActivity(BpmnModel bpmnModel, String activityId, String param,
+                                              Long startUserId, String processDefinitionId, Map<String, Object> processVariables) {
+        FlowElement flowElement = BpmnModelUtils.getFlowElementById(bpmnModel, activityId);
+        return getCandidateUsers(processDefinitionId, flowElement);
+    }
+
+    private Set<Long> getCandidateUsers(String processDefinitionId, FlowElement flowElement) {
+        // 情况一:指定人员审批
+        Integer assignEmptyHandlerType = BpmnModelUtils.parseAssignEmptyHandlerType(flowElement);
+        if (Objects.equals(assignEmptyHandlerType, BpmUserTaskAssignEmptyHandlerTypeEnum.ASSIGN_USER.getType())) {
+            return new HashSet<>(BpmnModelUtils.parseAssignEmptyHandlerUserIds(flowElement));
+        }
+
+        // 情况二:流程管理员
+        if (Objects.equals(assignEmptyHandlerType, BpmUserTaskAssignEmptyHandlerTypeEnum.ASSIGN_ADMIN.getType())) {
+            BpmProcessDefinitionInfoDO processDefinition = processDefinitionService.getProcessDefinitionInfo(processDefinitionId);
+            Assert.notNull(processDefinition, "流程定义({})不存在", processDefinitionId);
+            return new HashSet<>(processDefinition.getManagerUserIds());
+        }
+
+        // 都不满足,还是返回空
+        return new HashSet<>();
+    }
+
+}
\ No newline at end of file

--
Gitblit v1.9.3