Procházet zdrojové kódy

抄送/跳转自定义事件

caixiaofeng před 6 měsíci
rodič
revize
f168dac285

+ 13 - 5
flow-common/flow-common-flowable-starter/src/main/java/com/flow/flowable/behavior/CopyActivityBehavior.java

@@ -1,18 +1,20 @@
 package com.flow.flowable.behavior;
 
 import com.flow.flowable.cmd.CopyProcessInstanceCmd;
+import com.flow.flowable.event.CustomFlowableEngineEvent;
+import com.flow.flowable.event.CustomFlowableEventType;
 import com.flow.flowable.model.CopyServiceTask;
 import org.flowable.bpmn.model.MultiInstanceLoopCharacteristics;
+import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
 import org.flowable.engine.ManagementService;
 import org.flowable.engine.delegate.DelegateExecution;
 import org.flowable.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior;
-import org.flowable.engine.impl.persistence.entity.ActivityInstanceEntity;
-import org.flowable.engine.impl.persistence.entity.ActivityInstanceEntityManager;
-import org.flowable.engine.impl.persistence.entity.HistoricActivityInstanceEntity;
-import org.flowable.engine.impl.persistence.entity.HistoricActivityInstanceEntityManager;
+import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
+import org.flowable.engine.impl.persistence.entity.*;
 import org.flowable.engine.impl.util.CommandContextUtil;
 
 import java.util.List;
+import java.util.Objects;
 
 public class CopyActivityBehavior extends AbstractBpmnActivityBehavior {
 
@@ -34,8 +36,14 @@ public class CopyActivityBehavior extends AbstractBpmnActivityBehavior {
             historicActivityInstanceEntity.setAssignee(assignee);
             historicActivityInstanceEntityManager.update(historicActivityInstanceEntity);
         }
-        ManagementService managementService = CommandContextUtil.getProcessEngineConfiguration().getManagementService();
+        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
+        ManagementService managementService = processEngineConfiguration.getManagementService();
         managementService.executeCommand(new CopyProcessInstanceCmd(execution.getProcessInstanceId(), assignee));
+        FlowableEventDispatcher eventDispatcher = processEngineConfiguration.getEventDispatcher();
+        if (Objects.nonNull(eventDispatcher) && eventDispatcher.isEnabled()) {
+            CustomFlowableEngineEvent customFlowableEngineEvent = new CustomFlowableEngineEvent((ExecutionEntityImpl) execution, CustomFlowableEventType.PROCESS_COPY);
+            eventDispatcher.dispatchEvent(customFlowableEngineEvent, processEngineConfiguration.getEngineCfgKey());
+        }
         leave(execution);
     }
 }

+ 14 - 2
flow-common/flow-common-flowable-starter/src/main/java/com/flow/flowable/behavior/JumpActivityBehavior.java

@@ -1,30 +1,42 @@
 package com.flow.flowable.behavior;
 
 import com.flow.flowable.cmd.JumpActivityCmd;
+import com.flow.flowable.event.CustomFlowableEngineEvent;
+import com.flow.flowable.event.CustomFlowableEventType;
 import com.flow.flowable.model.JumpServiceTask;
 import org.flowable.common.engine.api.delegate.Expression;
+import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
 import org.flowable.common.engine.impl.el.ExpressionManager;
 import org.flowable.engine.ManagementService;
 import org.flowable.engine.delegate.DelegateExecution;
 import org.flowable.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior;
+import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
+import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
 import org.flowable.engine.impl.util.CommandContextUtil;
 import org.springframework.util.StringUtils;
 
+import java.util.Objects;
+
 public class JumpActivityBehavior extends AbstractBpmnActivityBehavior {
 
     @Override
     public void execute(DelegateExecution execution) {
         JumpServiceTask jumpServiceTask = (JumpServiceTask) execution.getCurrentFlowElement();
+        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
         String skipExpression = jumpServiceTask.getSkipExpression();
         if (!StringUtils.isEmpty(skipExpression)) {
-            ExpressionManager expressionManager = CommandContextUtil.getProcessEngineConfiguration().getExpressionManager();
+            ExpressionManager expressionManager = processEngineConfiguration.getExpressionManager();
             Expression expression = expressionManager.createExpression(skipExpression);
             Object result = expression.getValue(execution);
             if ((result instanceof Boolean && (Boolean) result)) {
-                leave(execution);
                 return;
             }
         }
+        FlowableEventDispatcher eventDispatcher = processEngineConfiguration.getEventDispatcher();
+        if (Objects.nonNull(eventDispatcher) && eventDispatcher.isEnabled()) {
+            CustomFlowableEngineEvent customFlowableEngineEvent = new CustomFlowableEngineEvent((ExecutionEntityImpl) execution, CustomFlowableEventType.ACTIVITY_JUMP);
+            eventDispatcher.dispatchEvent(customFlowableEngineEvent, processEngineConfiguration.getEngineCfgKey());
+        }
         ManagementService managementService = CommandContextUtil.getProcessEngineConfiguration().getManagementService();
         managementService.executeCommand(new JumpActivityCmd(execution.getProcessInstanceId(), jumpServiceTask.getTargetNode()));
         leave(execution);

+ 35 - 0
flow-common/flow-common-flowable-starter/src/main/java/com/flow/flowable/event/CustomFlowableEngineEvent.java

@@ -0,0 +1,35 @@
+package com.flow.flowable.event;
+
+import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
+import org.flowable.common.engine.impl.event.FlowableEngineEventImpl;
+import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
+
+public class CustomFlowableEngineEvent extends FlowableEngineEventImpl {
+    protected Object entity;
+    protected CustomFlowableEventType customFlowableEventType;
+
+    public CustomFlowableEngineEvent(ExecutionEntityImpl entity, CustomFlowableEventType type) {
+        super(FlowableEngineEventType.CUSTOM);
+        this.entity = entity;
+        this.customFlowableEventType = type;
+        super.setExecutionId(entity.getId());
+        super.setProcessInstanceId(entity.getProcessInstanceId());
+        super.setProcessDefinitionId(entity.getProcessDefinitionId());
+    }
+
+    public Object getEntity() {
+        return entity;
+    }
+
+    public void setEntity(Object entity) {
+        this.entity = entity;
+    }
+
+    public CustomFlowableEventType getCustomFlowableEventType() {
+        return customFlowableEventType;
+    }
+
+    public void setCustomFlowableEventType(CustomFlowableEventType customFlowableEventType) {
+        this.customFlowableEventType = customFlowableEventType;
+    }
+}

+ 13 - 0
flow-common/flow-common-flowable-starter/src/main/java/com/flow/flowable/event/CustomFlowableEventType.java

@@ -0,0 +1,13 @@
+package com.flow.flowable.event;
+
+import org.flowable.common.engine.api.delegate.event.FlowableEventType;
+
+public enum CustomFlowableEventType implements FlowableEventType {
+    // 节点跳转
+    ACTIVITY_JUMP,
+    // 节点跳转-取消
+    ACTIVITY_JUMP_CANCEL,
+    // 抄送流程
+    PROCESS_COPY
+
+}

+ 2 - 1
flow-workflow/flow-workflow-biz/src/main/java/com/flow/listener/FlowableGlobListener.java

@@ -26,7 +26,8 @@ public class FlowableGlobListener implements ApplicationListener<ContextRefreshe
                 FlowableEngineEventType.PROCESS_COMPLETED,
                 FlowableEngineEventType.PROCESS_CANCELLED,
                 FlowableEngineEventType.TASK_CREATED,
-                FlowableEngineEventType.TASK_COMPLETED
+                FlowableEngineEventType.TASK_COMPLETED,
+                FlowableEngineEventType.CUSTOM
         );
     }
 }

+ 28 - 3
flow-workflow/flow-workflow-biz/src/main/java/com/flow/listener/GlobalActivityEventListener.java

@@ -11,6 +11,7 @@ import com.flow.enums.ApprovalNobodyEnum;
 import com.flow.enums.AssigneeTypeEnum;
 import com.flow.enums.NotifyEnum;
 import com.flow.enums.ProcessStatus;
+import com.flow.flowable.event.CustomFlowableEngineEvent;
 import com.flow.flowable.utils.ProcessElementUtil;
 import com.flow.service.FlowDefineService;
 import com.flow.service.FlowInstanceService;
@@ -19,7 +20,7 @@ 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.RuntimeService;
+import org.flowable.common.engine.api.delegate.event.FlowableEngineEvent;
 import org.flowable.engine.TaskService;
 import org.flowable.engine.delegate.DelegateExecution;
 import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
@@ -35,6 +36,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
 
 import java.time.LocalDateTime;
 import java.util.Map;
+import java.util.Objects;
 
 @Component
 @Slf4j
@@ -44,8 +46,6 @@ public class GlobalActivityEventListener extends AbstractFlowableEngineEventList
     @Autowired
     private FlowTaskService flowTaskService;
     @Autowired
-    private RuntimeService runtimeService;
-    @Autowired
     private TaskService taskService;
     @Autowired
     private NotifyService notifyService;
@@ -161,4 +161,29 @@ public class GlobalActivityEventListener extends AbstractFlowableEngineEventList
         System.out.println("variables = " + variables);
     }
 
+    @Override
+    protected void custom(FlowableEngineEvent event) {
+        CustomFlowableEngineEvent entityEvent = (CustomFlowableEngineEvent) event;
+        if (Objects.nonNull(entityEvent)) {
+            switch (entityEvent.getCustomFlowableEventType()) {
+                case PROCESS_COPY:
+                    processCopy(entityEvent);
+                    break;
+                case ACTIVITY_JUMP:
+                    activityJump(entityEvent);
+                    break;
+                default:
+                    break;
+            }
+        }
+    }
+
+    protected void processCopy(CustomFlowableEngineEvent event) {
+
+    }
+
+    protected void activityJump(CustomFlowableEngineEvent event) {
+
+    }
+
 }