瀏覽代碼

审批人重复处理

caixiaofeng 6 月之前
父節點
當前提交
d72b805348

+ 18 - 0
flow-common/flow-common-flowable-starter/src/main/java/com/flow/flowable/utils/ProcessElementUtil.java

@@ -81,6 +81,24 @@ public class ProcessElementUtil {
         return elements;
     }
 
+    public static <T extends FlowElement> T findParentElement(FlowElement flowElement, Class<T> clazz) {
+        if (flowElement instanceof FlowNode) {
+            FlowNode flowNode = (FlowNode) flowElement;
+            List<SequenceFlow> incomingFlows = flowNode.getIncomingFlows();
+            if (CollectionUtils.isNotEmpty(incomingFlows)) {
+                for (SequenceFlow sequenceFlow : incomingFlows) {
+                    FlowElement sourceElement = sequenceFlow.getSourceFlowElement();
+                    if (sourceElement instanceof FlowNode) {
+                        if (clazz.isInstance(sourceElement)) {
+                            return clazz.cast(sourceElement);
+                        }
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
     /**
      * 获取扩展元素值
      *

+ 26 - 0
flow-workflow/flow-workflow-biz/src/main/java/com/flow/listener/GlobalActivityEventListener.java

@@ -18,8 +18,10 @@ import com.flow.service.FlowTaskService;
 import com.flow.service.NotifyService;
 import lombok.extern.slf4j.Slf4j;
 import org.flowable.bpmn.model.FlowElement;
+import org.flowable.bpmn.model.UserTask;
 import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
 import org.flowable.common.engine.api.delegate.event.FlowableEngineEvent;
+import org.flowable.engine.HistoryService;
 import org.flowable.engine.RuntimeService;
 import org.flowable.engine.TaskService;
 import org.flowable.engine.delegate.DelegateExecution;
@@ -52,6 +54,8 @@ public class GlobalActivityEventListener extends AbstractFlowableEngineEventList
     @Autowired
     private RuntimeService runtimeService;
     @Autowired
+    private HistoryService historyService;
+    @Autowired
     private NotifyService notifyService;
     @Autowired
     private FlowInstanceService flowInstanceService;
@@ -95,6 +99,28 @@ public class GlobalActivityEventListener extends AbstractFlowableEngineEventList
                 return;
             }
         }
+
+        // 审批人重复处理
+        String duplicate = execution.getVariable("_DUPLICATE_APPROVAL", String.class);
+        if (StringUtils.isNotBlank(duplicate)) {
+            String taskDefinitionKey = runtimeService.getVariable(event.getProcessInstanceId(), String.format("_%s_", entity.getAssignee()), String.class);
+            if (duplicate.equals(DuplicateApprovalEnum.ONCE.getType())) {
+                if (StringUtils.isNotBlank(taskDefinitionKey)) {
+                    flowTaskService.autoComplete(entity.getId(), " 审批人重复");
+                    return;
+                }
+            } else if (duplicate.equals(DuplicateApprovalEnum.ADJACENT.getType())) {
+                if (StringUtils.isNotBlank(taskDefinitionKey)) {
+                    UserTask userTask = ProcessElementUtil.findParentElement(currentFlowElement, UserTask.class);
+                    if (Objects.nonNull(userTask)) {
+                        if (userTask.getId().equals(taskDefinitionKey)) {
+                            flowTaskService.autoComplete(entity.getId(), " 审批人重复");
+                            return;
+                        }
+                    }
+                }
+            }
+        }
         // 消息通知
         TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
             @Override

+ 5 - 0
flow-workflow/flow-workflow-biz/src/main/java/com/flow/service/impl/FlowDefineServiceImpl.java

@@ -10,6 +10,7 @@ import com.flow.entity.FlowDefine;
 import com.flow.entity.node.*;
 import com.flow.entity.settings.Settings;
 import com.flow.entity.settings.TitleConfig;
+import com.flow.enums.DuplicateApprovalEnum;
 import com.flow.enums.ProcessStatus;
 import com.flow.model.FormInfo;
 import com.flow.model.StartProcess;
@@ -106,6 +107,10 @@ public class FlowDefineServiceImpl extends BaseServiceImpl<FlowDefineDao, FlowDe
         if ("custom".equals(titleConfig.getType())) {
             instanceName = StrUtil.format(titleConfig.getValue(), values);
         }
+        DuplicateApprovalEnum duplicate = settings.getDuplicate();
+        if (Objects.nonNull(duplicate)) {
+            values.put("_DUPLICATE_APPROVAL", duplicate.getType());
+        }
         Authentication.setAuthenticatedUserId(SecurityContextUtil.getUserId());
         runtimeService.createProcessInstanceBuilder()
                 .processDefinitionId(startProcess.getDefineId())

+ 4 - 0
flow-workflow/flow-workflow-biz/src/main/java/com/flow/service/impl/FlowTaskServiceImpl.java

@@ -299,6 +299,10 @@ public class FlowTaskServiceImpl extends BaseServiceImpl<FlowTaskDao, FlowTask>
                     }
                 }
             });
+            String assignee = SecurityContextUtil.getUserId();
+            if (StringUtils.isNotBlank(assignee)) {
+                values.put(String.format("_%s_", assignee), task.getTaskDefinitionKey());
+            }
         }
         if (Objects.nonNull(delegationState) && delegationState == DelegationState.PENDING) {
             taskService.resolveTask(

+ 2 - 0
flow-workflow/flow-workflow-entity/src/main/java/com/flow/entity/settings/Settings.java

@@ -1,5 +1,6 @@
 package com.flow.entity.settings;
 
+import com.flow.enums.DuplicateApprovalEnum;
 import lombok.Data;
 
 @Data
@@ -7,4 +8,5 @@ public class Settings {
     private CancelConfig cancel;
     private PrintConfig print;
     private TitleConfig title;
+    private DuplicateApprovalEnum duplicate;
 }

+ 17 - 0
flow-workflow/flow-workflow-entity/src/main/java/com/flow/enums/DuplicateApprovalEnum.java

@@ -0,0 +1,17 @@
+package com.flow.enums;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor
+public enum DuplicateApprovalEnum {
+    REPEAT("repeat", "重复审批"),
+    ONCE("once", "只审批一次"),
+    ADJACENT("adjacent", "相邻节点审批自动通过");
+
+    @JsonValue
+    private final String type;
+    private final String description;
+}