0
点赞
收藏
分享

微信扫一扫

【第二十篇】Flowable中的任务回退

【第二十篇】Flowable中的任务回退_Flowable

Flowable中的任务回退

1.串行的回退

  我们先从最简单的串行流程来分析,案例如下

【第二十篇】Flowable中的任务回退_xml_02

完整的xml文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="用户任务1" activiti:assignee="user1"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<userTask id="usertask2" name="用户任务2" activiti:assignee="user2"></userTask>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
<userTask id="usertask3" name="用户任务3" activiti:assignee="user3"></userTask>
<sequenceFlow id="flow3" sourceRef="usertask2" targetRef="usertask3"></sequenceFlow>
<userTask id="usertask4" name="用户任务4" activiti:assignee="user4"></userTask>
<sequenceFlow id="flow4" sourceRef="usertask3" targetRef="usertask4"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow5" sourceRef="usertask4" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
<bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="390.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="470.0" y="250.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="620.0" y="250.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="55.0" width="105.0" x="770.0" y="250.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
<omgdc:Bounds height="55.0" width="105.0" x="920.0" y="250.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="1070.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="425.0" y="277.0"></omgdi:waypoint>
<omgdi:waypoint x="470.0" y="277.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="575.0" y="277.0"></omgdi:waypoint>
<omgdi:waypoint x="620.0" y="277.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="725.0" y="277.0"></omgdi:waypoint>
<omgdi:waypoint x="770.0" y="277.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="875.0" y="277.0"></omgdi:waypoint>
<omgdi:waypoint x="920.0" y="277.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="1025.0" y="277.0"></omgdi:waypoint>
<omgdi:waypoint x="1070.0" y="277.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>

  上面的流程就是一个非常简单的串行任务,定义了4个用户任务,指派的处理人分别是​​user1​​​,​​user2​​​,​​user3​​​,​​user4​​.在流程的执行过程中我们可以通过回退来演示具体的效果。首先来部署流程

/**
* 部署流程
*/
@Test
void testDeploy() throws Exception {
Deployment deploy = repositoryService.createDeployment()
.addClasspathResource("任务回退01.bpmn20.xml")
.name("任务回退01")
.deploy();
System.out.println("deploy.getId() = " + deploy.getId());
System.out.println("deploy.getName() = " + deploy.getName());
System.out.println("部署开始的时间:" + new Date());
//TimeUnit.MINUTES.sleep(3);
}

然后我们启动一个流程实例。

/**
* 启动流程实例
*/
@Test
void startProcess(){
ProcessInstance processInstance = runtimeService
.startProcessInstanceById("myProcess:1:4");
System.out.println("processInstance.getId() = " + processInstance.getId());
}

【第二十篇】Flowable中的任务回退_xml_03

然后我们通过user1完成任务,直到user3完成任务,到user4来处理任务。

/**
* 完成任务
*/
@Test
void completeTask(){
Task task = taskService.createTaskQuery()
.processDefinitionId("myProcess:1:4")
.taskAssignee("user1")
.singleResult();
taskService.complete(task.getId());
}

通过上面的多个Task完成操作,现在已经到了user4来处理的节点了

【第二十篇】Flowable中的任务回退_工作流_04

【第二十篇】Flowable中的任务回退_Flowable_05

我们先看下从​​用户任务4​​​回退到​​用户任务3​​的操作。

/**
* 回退操作
*/
@Test
void rollbackTask(){
// 当前的Task对应的用户任务的Id
List<String> currentActivityIds = new ArrayList<>();
currentActivityIds.add("usertask4");
// 需要回退的目标节点的用户任务Id
String newActivityId = "usertask3";
// 回退操作
runtimeService.createChangeActivityStateBuilder()
.processInstanceId("2501")
.moveActivityIdsToSingleActivityId(currentActivityIds,newActivityId)
.changeState();

}

操作后我们可以在对应的历史表中看到相关的信息

【第二十篇】Flowable中的任务回退_工作流_06

【第二十篇】Flowable中的任务回退_xml_07

然后我们通过user3来完成任务继续到user4处理,然后我们可以测试回退到user1处。

【第二十篇】Flowable中的任务回退_驳回_08

/**
* 回退操作
*/
@Test
void rollbackTask(){
// 当前的Task对应的用户任务的Id
List<String> currentActivityIds = new ArrayList<>();
currentActivityIds.add("usertask4");
// 需要回退的目标节点的用户任务Id
String newActivityId = "usertask1";
// 回退操作
runtimeService.createChangeActivityStateBuilder()
.processInstanceId("2501")
.moveActivityIdsToSingleActivityId(currentActivityIds,newActivityId)
.changeState();
}

【第二十篇】Flowable中的任务回退_xml_09

  可以看到任务又回到了user1处。也就是在串行的流程中,我们可以回退到任意的用户节点,当然这个串行也包括多人会签和排他网关节点。当然在回退的时候我们还可以使用​​moveActivityIdTo(String currentActivityId,String newActivityId)​​这个方法来处理。

2.并行的回退

  接下来我们在并行的场景中来看看各种回退的场景。具体案例流程如下:

【第二十篇】Flowable中的任务回退_驳回_10

详细的xml文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="用户审批01" activiti:assignee="user1"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="parallelgateway1"></sequenceFlow>
<parallelGateway id="parallelgateway1" name="Exclusive Gateway"></parallelGateway>
<userTask id="usertask2" name="业务负责人" activiti:assignee="user2"></userTask>
<sequenceFlow id="flow3" sourceRef="parallelgateway1" targetRef="usertask2"></sequenceFlow>
<userTask id="usertask3" name="行政副总" activiti:assignee="user4"></userTask>
<sequenceFlow id="flow4" sourceRef="parallelgateway1" targetRef="usertask3"></sequenceFlow>
<userTask id="usertask4" name="业务副总" activiti:assignee="user3"></userTask>
<sequenceFlow id="flow5" sourceRef="usertask2" targetRef="usertask4"></sequenceFlow>
<sequenceFlow id="flow6" sourceRef="usertask4" targetRef="parallelgateway2"></sequenceFlow>
<parallelGateway id="parallelgateway2" name="Exclusive Gateway"></parallelGateway>
<sequenceFlow id="flow7" sourceRef="usertask3" targetRef="parallelgateway2"></sequenceFlow>
<userTask id="usertask5" name="总经理" activiti:assignee="user5"></userTask>
<sequenceFlow id="flow8" sourceRef="parallelgateway2" targetRef="usertask5"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow9" sourceRef="usertask5" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
<bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="370.0" y="300.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="450.0" y="290.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="parallelgateway1" id="BPMNShape_parallelgateway1">
<omgdc:Bounds height="40.0" width="40.0" x="600.0" y="298.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="740.0" y="180.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="55.0" width="105.0" x="740.0" y="370.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
<omgdc:Bounds height="55.0" width="105.0" x="930.0" y="180.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="parallelgateway2" id="BPMNShape_parallelgateway2">
<omgdc:Bounds height="40.0" width="40.0" x="1140.0" y="297.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask5" id="BPMNShape_usertask5">
<omgdc:Bounds height="55.0" width="105.0" x="1225.0" y="290.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="1375.0" y="300.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="405.0" y="317.0"></omgdi:waypoint>
<omgdi:waypoint x="450.0" y="317.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="555.0" y="317.0"></omgdi:waypoint>
<omgdi:waypoint x="600.0" y="318.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="620.0" y="298.0"></omgdi:waypoint>
<omgdi:waypoint x="620.0" y="207.0"></omgdi:waypoint>
<omgdi:waypoint x="740.0" y="207.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="620.0" y="338.0"></omgdi:waypoint>
<omgdi:waypoint x="620.0" y="397.0"></omgdi:waypoint>
<omgdi:waypoint x="740.0" y="397.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="845.0" y="207.0"></omgdi:waypoint>
<omgdi:waypoint x="930.0" y="207.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
<omgdi:waypoint x="1035.0" y="207.0"></omgdi:waypoint>
<omgdi:waypoint x="1159.0" y="207.0"></omgdi:waypoint>
<omgdi:waypoint x="1160.0" y="297.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
<omgdi:waypoint x="845.0" y="397.0"></omgdi:waypoint>
<omgdi:waypoint x="1160.0" y="397.0"></omgdi:waypoint>
<omgdi:waypoint x="1160.0" y="337.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
<omgdi:waypoint x="1180.0" y="317.0"></omgdi:waypoint>
<omgdi:waypoint x="1225.0" y="317.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
<omgdi:waypoint x="1330.0" y="317.0"></omgdi:waypoint>
<omgdi:waypoint x="1375.0" y="317.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>

  先部署流程,然后启动并运行到并行流程的节点如下的位置
【第二十篇】Flowable中的任务回退_xml_11

  然后我们可以尝试从​​业务副总​​​处回退到​​用户审批01​​处,看看该处理应该要如何实现。

【第二十篇】Flowable中的任务回退_回退_12

回退逻辑代码的实现

/**
* 回退操作
* 业务副总驳回到到用户审批处 那么行政审批的也应该要返回
*/
@Test
void rollbackTask(){
// 当前的Task对应的用户任务的Id
List<String> currentActivityIds = new ArrayList<>();
currentActivityIds.add("usertask4"); // 行政副总
currentActivityIds.add("usertask3"); // 业务副总
// 需要回退的目标节点的用户任务Id
String newActivityId = "usertask1"; // 用户审批01
// 回退操作
runtimeService.createChangeActivityStateBuilder()
.processInstanceId("22501")
.moveActivityIdsToSingleActivityId(currentActivityIds,newActivityId)
.changeState();
}

查看ACT_RU_TASK可以看到回到了​​用户审批01​​了

【第二十篇】Flowable中的任务回退_Flowable_13

同时在ACT_HI_ACTINS中也可以看到回退的历史操作
【第二十篇】Flowable中的任务回退_回退_14

然后再来看看 行政副总的 并行分支执行完成了,然后在 业务副总处审批要驳回的处理

【第二十篇】Flowable中的任务回退_Flowable_15

【第二十篇】Flowable中的任务回退_驳回_16

@Test
void rollbackTask(){
// 当前的Task对应的用户任务的Id
List<String> currentActivityIds = new ArrayList<>();
currentActivityIds.add("usertask4"); // 行政副总
//currentActivityIds.add("usertask3"); // 业务副总
// 需要回退的目标节点的用户任务Id
String newActivityId = "usertask1"; // 用户审批01
// 回退操作
runtimeService.createChangeActivityStateBuilder()
.processInstanceId("22501")
.moveActivityIdsToSingleActivityId(currentActivityIds,newActivityId)
.changeState();
}

一样的效果

3.子流程回退

  最后我们来看看带有子流程的场景下如果有回退的情况应该要如何来处理,案例如下:

【第二十篇】Flowable中的任务回退_Flowable_17

完整的xml内容为:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="主任务1" activiti:assignee="user1"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<subProcess id="subprocess1" name="Sub Process">
<startEvent id="startevent2" name="Start"></startEvent>
<userTask id="usertask2" name="子任务1" activiti:assignee="user2"></userTask>
<sequenceFlow id="flow3" sourceRef="startevent2" targetRef="usertask2"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow4" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
</subProcess>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="subprocess1"></sequenceFlow>
<userTask id="usertask3" name="主任务2" activiti:assignee="user3"></userTask>
<sequenceFlow id="flow5" sourceRef="subprocess1" targetRef="usertask3"></sequenceFlow>
<endEvent id="endevent2" name="End"></endEvent>
<sequenceFlow id="flow6" sourceRef="usertask3" targetRef="endevent2"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
<bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="320.0" y="290.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="400.0" y="280.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="subprocess1" id="BPMNShape_subprocess1">
<omgdc:Bounds height="291.0" width="481.0" x="620.0" y="168.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="startevent2" id="BPMNShape_startevent2">
<omgdc:Bounds height="35.0" width="35.0" x="680.0" y="298.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="760.0" y="288.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="910.0" y="298.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="55.0" width="105.0" x="1146.0" y="286.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent2" id="BPMNShape_endevent2">
<omgdc:Bounds height="35.0" width="35.0" x="1296.0" y="296.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="355.0" y="307.0"></omgdi:waypoint>
<omgdi:waypoint x="400.0" y="307.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="715.0" y="315.0"></omgdi:waypoint>
<omgdi:waypoint x="760.0" y="315.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="865.0" y="315.0"></omgdi:waypoint>
<omgdi:waypoint x="910.0" y="315.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="505.0" y="307.0"></omgdi:waypoint>
<omgdi:waypoint x="620.0" y="313.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="1101.0" y="313.0"></omgdi:waypoint>
<omgdi:waypoint x="1146.0" y="313.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
<omgdi:waypoint x="1251.0" y="313.0"></omgdi:waypoint>
<omgdi:waypoint x="1296.0" y="313.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>

部署流程后并启动流程,我们先来看第一个场景,从子流程回退到主流程,也就是如下图:

【第二十篇】Flowable中的任务回退_驳回_18

Task进入到了子流程的Task处

【第二十篇】Flowable中的任务回退_驳回_19

然后我们来处理回退到主流程:直接跳转即可

/**
* 回退操作
* 从子流程回退到主流程操作
*/
@Test
void rollbackMainTask(){

// 回退操作
runtimeService.createChangeActivityStateBuilder()
.processInstanceId("2501")
.moveActivityIdTo("usertask2","usertask1")
.changeState();
}

}

/**
* 回退操作
* 从子流程回退到主流程操作:moveExecutionToActivityId不关心当前的节点
*/
@Test
void rollbackMainTask(){

// 回退操作
runtimeService.createChangeActivityStateBuilder()
.processInstanceId("2501")
.moveExecutionToActivityId("5003","usertask1")
.changeState();
}

然后从主流程回退到子流程操作

【第二十篇】Flowable中的任务回退_xml_20

【第二十篇】Flowable中的任务回退_回退_21

同样的直接跳转即可

/**
* 回退操作
*/
@Test
void rollbackSubTask(){

// 回退操作
runtimeService.createChangeActivityStateBuilder()
.processInstanceId("2501")
.moveActivityIdTo("usertask3","usertask2")
.changeState();
}


举报

相关推荐

0 条评论