Jelajahi Sumber

解决向前跳转失败问题

caixiaofeng 6 bulan lalu
induk
melakukan
eb6e3d5194

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

@@ -34,7 +34,7 @@ public class JumpActivityBehavior extends AbstractBpmnActivityBehavior {
             }
         }
         ManagementService managementService = CommandContextUtil.getProcessEngineConfiguration().getManagementService();
-        managementService.executeCommand(new JumpActivityCmd(execution.getProcessInstanceId(), jumpServiceTask.getTargetNode()));
+        managementService.executeCommand(new JumpActivityCmd(execution.getProcessInstanceId(), execution.getCurrentActivityId(), jumpServiceTask.getTargetNode()));
         FlowableEventDispatcher eventDispatcher = processEngineConfiguration.getEventDispatcher();
         if (Objects.nonNull(eventDispatcher) && eventDispatcher.isEnabled()) {
             CustomFlowableEngineEvent customFlowableEngineEvent = new CustomFlowableEngineEvent((ExecutionEntityImpl) execution, CustomFlowableEventType.ACTIVITY_JUMP);

+ 10 - 7
flow-common/flow-common-flowable-starter/src/main/java/com/flow/flowable/cmd/JumpActivityCmd.java

@@ -2,8 +2,8 @@ package com.flow.flowable.cmd;
 
 
 import com.flow.flowable.utils.ProcessElementUtil;
-import org.flowable.bpmn.model.BpmnModel;
 import org.flowable.bpmn.model.FlowElement;
+import org.flowable.bpmn.model.Process;
 import org.flowable.common.engine.api.FlowableException;
 import org.flowable.common.engine.impl.interceptor.Command;
 import org.flowable.common.engine.impl.interceptor.CommandContext;
@@ -21,11 +21,13 @@ import java.util.stream.Collectors;
 
 public class JumpActivityCmd implements Command<List<String>> {
     protected String processInstanceId;
-    protected String activityId;
+    protected String sourceId;
+    protected String targetId;
 
-    public JumpActivityCmd(String processInstanceId, String activityId) {
+    public JumpActivityCmd(String processInstanceId, String sourceId, String targetId) {
         this.processInstanceId = processInstanceId;
-        this.activityId = activityId;
+        this.sourceId = sourceId;
+        this.targetId = targetId;
     }
 
     @Override
@@ -35,10 +37,11 @@ public class JumpActivityCmd implements Command<List<String>> {
         if (Objects.isNull(processInstance)) {
             throw new FlowableException("流程实例不存在");
         }
-        BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(processInstance.getProcessDefinitionId());
-        FlowElement flowElement = bpmnModel.getFlowElement(activityId);
+        Process process = ProcessDefinitionUtil.getProcess(processInstance.getProcessDefinitionId());
+        FlowElement flowElement = process.getFlowElement(this.targetId);
         Set<FlowElement> childElements = ProcessElementUtil.findChildElements(flowElement);
         Set<String> nodeIds = childElements.stream().map(FlowElement::getId).collect(Collectors.toSet());
+        nodeIds.add(this.sourceId);
         // 获取要跳转执行
         List<ExecutionEntity> executions = executionManager.findChildExecutionsByParentExecutionId(processInstanceId);
         List<String> executionIds = executions.stream()
@@ -56,7 +59,7 @@ public class JumpActivityCmd implements Command<List<String>> {
                     .getRuntimeService()
                     .createChangeActivityStateBuilder()
                     .processInstanceId(processInstanceId)
-                    .moveExecutionsToSingleActivityId(executionIds, activityId)
+                    .moveExecutionsToSingleActivityId(executionIds, this.targetId)
                     .changeState();
         }
         return executionIds;

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

@@ -19,7 +19,7 @@ public class ProcessElementUtil {
      * @return
      */
     public static Set<FlowElement> findChildElements(FlowElement flowElement) {
-        LinkedHashSet<FlowElement> elements = new LinkedHashSet<>();
+        Set<FlowElement> elements = new LinkedHashSet<>();
 
         if (flowElement instanceof FlowNode) {
             FlowNode flowNode = (FlowNode) flowElement;

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

@@ -194,6 +194,7 @@ public class FlowTaskServiceImpl extends BaseServiceImpl<FlowTaskDao, FlowTask>
             redisService.del(task.getProcessInstanceId());
             managementService.executeCommand(new JumpActivityCmd(
                     task.getProcessInstanceId(),
+                    task.getTaskDefinitionKey(),
                     taskForm.getTargetNode()
             ));
         } catch (Exception e) {