浏览代码

监听器优化

caixiaofeng 6 月之前
父节点
当前提交
42ee873b0b

+ 29 - 1
flow-common/flow-common-flowable-starter/src/main/java/com/flow/flowable/utils/ProcessElementUtil.java

@@ -2,6 +2,8 @@ package com.flow.flowable.utils;
 
 import org.flowable.bpmn.model.*;
 import org.flowable.editor.language.json.converter.util.CollectionUtils;
+import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
+import org.springframework.util.StringUtils;
 
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -79,7 +81,13 @@ public class ProcessElementUtil {
         return elements;
     }
 
-
+    /**
+     * 获取扩展元素值
+     *
+     * @param element
+     * @param extensionElementName
+     * @return
+     */
     public static String getExtensionElementValue(BaseElement element, String extensionElementName) {
         Map<String, List<ExtensionElement>> extensionElementMap = element.getExtensionElements();
         List<ExtensionElement> extensionElements = extensionElementMap.get(extensionElementName);
@@ -93,4 +101,24 @@ public class ProcessElementUtil {
         return null;
     }
 
+    /**
+     * 递归获取父执行
+     *
+     * @param executionEntity
+     * @param id
+     * @return
+     */
+    public static ExecutionEntity findParentExecution(ExecutionEntity executionEntity, String id) {
+        if (!StringUtils.isEmpty(id)) {
+            if (id.equals(executionEntity.getId())) {
+                return executionEntity;
+            }
+            ExecutionEntity parent = executionEntity.getParent();
+            if (parent != null) {
+                return findParentExecution(parent, id);
+            }
+        }
+        return null;
+    }
+
 }

+ 4 - 15
flow-workflow/flow-workflow-biz/src/main/java/com/flow/listener/GlobalActivityEventListener.java

@@ -19,13 +19,14 @@ import com.flow.service.NotifyService;
 import lombok.extern.slf4j.Slf4j;
 import org.flowable.bpmn.model.FlowElement;
 import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
+import org.flowable.engine.ManagementService;
+import org.flowable.engine.RuntimeService;
 import org.flowable.engine.TaskService;
 import org.flowable.engine.delegate.DelegateExecution;
 import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
 import org.flowable.engine.delegate.event.FlowableCancelledEvent;
 import org.flowable.engine.delegate.event.FlowableProcessStartedEvent;
 import org.flowable.engine.delegate.event.impl.FlowableProcessCancelledEventImpl;
-import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
 import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
 import org.flowable.task.service.impl.persistence.entity.TaskEntityImpl;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -44,13 +45,13 @@ public class GlobalActivityEventListener extends AbstractFlowableEngineEventList
     @Autowired
     private FlowTaskService flowTaskService;
     @Autowired
+    private RuntimeService runtimeService;
+    @Autowired
     private TaskService taskService;
     @Autowired
     private NotifyService notifyService;
     @Autowired
     private FlowInstanceService flowInstanceService;
-    @Autowired
-    private ProcessEngineConfigurationImpl processEngineConfiguration;
 
     // 任务创建监听器
     @Override
@@ -63,7 +64,6 @@ public class GlobalActivityEventListener extends AbstractFlowableEngineEventList
         FlowElement currentFlowElement = execution.getCurrentFlowElement();
         String nobody = ProcessElementUtil.getExtensionElementValue(currentFlowElement, "nobody");
         String assigneeType = ProcessElementUtil.getExtensionElementValue(currentFlowElement, "assigneeType");
-        String nobodyUsers = ProcessElementUtil.getExtensionElementValue(currentFlowElement, "nobodyUsers");
 
         if (StringUtils.isNotBlank(assigneeType)) {
             if (assigneeType.equals(AssigneeTypeEnum.AUTO_PASS.getType())) {
@@ -84,17 +84,6 @@ public class GlobalActivityEventListener extends AbstractFlowableEngineEventList
                     flowTaskService.autoComplete(entity.getId(), " 审批人为空");
                 } else if (nobody.equals(ApprovalNobodyEnum.REFUSE.getNobody())) {
                     flowTaskService.autoRefuse(entity.getId(), " 审批人为空");
-                } else if (nobody.equals(ApprovalNobodyEnum.ASSIGN.getNobody())) {
-                    if (StringUtils.isNotBlank(nobodyUsers)) {
-                        String[] split = nobodyUsers.split(",");
-                        if(split.length > 0){
-                            entity.setAssignee(split[0]);
-                        }
-
-                    }
-                } else if (nobody.equals(ApprovalNobodyEnum.ADMIN.getNobody())) {
-                    DelegateExecution parent = execution.getParent();
-
                 }
                 return;
             }

+ 2 - 1
flow-workflow/flow-workflow-entity/src/main/java/com/flow/entity/node/ApprovalNode.java

@@ -83,8 +83,9 @@ public class ApprovalNode extends AssigneeNode {
         sameElement.setElementText(this.same.getSame());
         userTask.addExtensionElement(sameElement);
         ExtensionElement nobodyUsersElement = new ExtensionElement();
-        nobodyUsersElement.setNamespace("https://flowable.org/model");
         nobodyUsersElement.setName("nobodyUsers");
+        nobodyUsersElement.setNamespace("https://flowable.org/model");
+        nobodyUsersElement.setNamespacePrefix("flowable");
         if (CollectionUtils.isNotEmpty(this.nobodyUsers)) {
             nobodyUsersElement.setElementText(String.join(",", this.nobodyUsers));
         }