文章目录
部分简介摘抄自官方文档
参考杨大仙的程序空间https://my.oschina.net/JavaLaw
*后台服务基于Springboot2 + Activiti6,整合文章请参考:https://blog.csdn.net/yy756127197/article/details/101211510 不需要流程设计器就排除3,4步骤 *
本文介绍错误结束事件和终止错误结束事件,取消结束事件等使用方式差不多。
1. 结束事件
1.1 简介
结束事件都是触发事件。 这是说当流程达到结束事件,会触发一个结果。
分为无指定结束事件,错误结束事件,取消结束事件,终止结束事件等。
2. 错误结束事件
2.1 简介
当流程到达错误结束事件时会结束执行流并且抛出错误,该错误可以被错误边界事件捕获,如果没有被捕获,那么他就相当于无指定结束事件。一般用在子流程中。
2.2 流程设计
场景:用户支付成功后等待一分钟,商家发货
设置消息定义
错误结束事件
流程图
流程文件bpmn
<?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/processdef">
<message id="msg" name="msg"></message>
<process id="errorEnd" name="errorEnd" isExecutable="true">
<documentation>errorEnd</documentation>
<startEvent id="sid-AE775DDE-5837-43B3-8290-44A9F5EE34ED"></startEvent>
<subProcess id="sid-579DEB01-C7C9-4704-8C73-070E99663C3E" name="子流程">
<startEvent id="sid-AC21AE14-E120-444F-A872-B6FF67687A59"></startEvent>
<exclusiveGateway id="sid-3AC8191C-07E4-428F-8AD1-145C36595C44"></exclusiveGateway>
<endEvent id="sid-BEBFA059-43EB-44B2-9161-EFCE5B5D4E56"></endEvent>
<endEvent id="sid-961DE02B-8651-4B3A-8C75-C39012E6ED52">
<errorEventDefinition errorRef="error"></errorEventDefinition>
</endEvent>
<userTask id="sid-00774FED-6029-4427-83B4-319A2B22BC4C" name="服务执行" activiti:assignee="errorEndUser">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="sid-A756FBC0-9AB5-464E-8A5F-DB23CAE03C22" sourceRef="sid-AC21AE14-E120-444F-A872-B6FF67687A59" targetRef="sid-00774FED-6029-4427-83B4-319A2B22BC4C"></sequenceFlow>
<sequenceFlow id="sid-C6396652-65DF-4C75-A11B-041A44E15F44" sourceRef="sid-00774FED-6029-4427-83B4-319A2B22BC4C" targetRef="sid-3AC8191C-07E4-428F-8AD1-145C36595C44"></sequenceFlow>
<sequenceFlow id="sid-9FE4C81C-85F2-4A35-86CA-EEC5E66E9880" sourceRef="sid-3AC8191C-07E4-428F-8AD1-145C36595C44" targetRef="sid-961DE02B-8651-4B3A-8C75-C39012E6ED52">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${flag == false}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="sid-C36A05AA-9547-44D0-89AD-21FC4C87AA5B" sourceRef="sid-3AC8191C-07E4-428F-8AD1-145C36595C44" targetRef="sid-BEBFA059-43EB-44B2-9161-EFCE5B5D4E56">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${flag == true}]]></conditionExpression>
</sequenceFlow>
</subProcess>
<sequenceFlow id="sid-C1D3F58A-4211-488D-AACF-A6165CDAE291" sourceRef="sid-AE775DDE-5837-43B3-8290-44A9F5EE34ED" targetRef="sid-579DEB01-C7C9-4704-8C73-070E99663C3E"></sequenceFlow>
<userTask id="sid-668CDEB1-5312-40FB-B20B-D815FD19C19D" name="错误任务" activiti:assignee="errorEndUser1">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="sid-13B4425D-E6F5-49E9-9000-FB4143D7D868" sourceRef="sid-CC662244-F29F-4BE3-990E-C30C3687274C" targetRef="sid-668CDEB1-5312-40FB-B20B-D815FD19C19D"></sequenceFlow>
<boundaryEvent id="sid-CC662244-F29F-4BE3-990E-C30C3687274C" attachedToRef="sid-579DEB01-C7C9-4704-8C73-070E99663C3E">
<errorEventDefinition errorRef="error"></errorEventDefinition>
</boundaryEvent>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_errorEnd">
<bpmndi:BPMNPlane bpmnElement="errorEnd" id="BPMNPlane_errorEnd">
<bpmndi:BPMNShape bpmnElement="sid-AE775DDE-5837-43B3-8290-44A9F5EE34ED" id="BPMNShape_sid-AE775DDE-5837-43B3-8290-44A9F5EE34ED">
<omgdc:Bounds height="30.0" width="30.0" x="135.0" y="115.375"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-579DEB01-C7C9-4704-8C73-070E99663C3E" id="BPMNShape_sid-579DEB01-C7C9-4704-8C73-070E99663C3E">
<omgdc:Bounds height="208.0" width="473.0" x="255.0" y="26.375"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-AC21AE14-E120-444F-A872-B6FF67687A59" id="BPMNShape_sid-AC21AE14-E120-444F-A872-B6FF67687A59">
<omgdc:Bounds height="30.0" width="30.0" x="300.0" y="115.375"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-3AC8191C-07E4-428F-8AD1-145C36595C44" id="BPMNShape_sid-3AC8191C-07E4-428F-8AD1-145C36595C44">
<omgdc:Bounds height="40.0" width="40.0" x="570.0" y="110.375"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-BEBFA059-43EB-44B2-9161-EFCE5B5D4E56" id="BPMNShape_sid-BEBFA059-43EB-44B2-9161-EFCE5B5D4E56">
<omgdc:Bounds height="28.0" width="28.0" x="655.0" y="60.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-961DE02B-8651-4B3A-8C75-C39012E6ED52" id="BPMNShape_sid-961DE02B-8651-4B3A-8C75-C39012E6ED52">
<omgdc:Bounds height="28.0" width="28.0" x="655.0" y="180.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-00774FED-6029-4427-83B4-319A2B22BC4C" id="BPMNShape_sid-00774FED-6029-4427-83B4-319A2B22BC4C">
<omgdc:Bounds height="80.0" width="100.0" x="405.0" y="90.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-668CDEB1-5312-40FB-B20B-D815FD19C19D" id="BPMNShape_sid-668CDEB1-5312-40FB-B20B-D815FD19C19D">
<omgdc:Bounds height="80.0" width="100.0" x="585.0" y="270.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-CC662244-F29F-4BE3-990E-C30C3687274C" id="BPMNShape_sid-CC662244-F29F-4BE3-990E-C30C3687274C">
<omgdc:Bounds height="30.0" width="30.0" x="469.62930100571805" y="219.62464435554702"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-C6396652-65DF-4C75-A11B-041A44E15F44" id="BPMNEdge_sid-C6396652-65DF-4C75-A11B-041A44E15F44">
<omgdi:waypoint x="505.0" y="130.3228782287823"></omgdi:waypoint>
<omgdi:waypoint x="570.3700092850511" y="130.74500928505108"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-C36A05AA-9547-44D0-89AD-21FC4C87AA5B" id="BPMNEdge_sid-C36A05AA-9547-44D0-89AD-21FC4C87AA5B">
<omgdi:waypoint x="590.5" y="110.875"></omgdi:waypoint>
<omgdi:waypoint x="590.5" y="74.0"></omgdi:waypoint>
<omgdi:waypoint x="655.0" y="74.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-13B4425D-E6F5-49E9-9000-FB4143D7D868" id="BPMNEdge_sid-13B4425D-E6F5-49E9-9000-FB4143D7D868">
<omgdi:waypoint x="484.62930100571805" y="249.62464435554702"></omgdi:waypoint>
<omgdi:waypoint x="484.62930100571805" y="310.0"></omgdi:waypoint>
<omgdi:waypoint x="585.0" y="310.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-9FE4C81C-85F2-4A35-86CA-EEC5E66E9880" id="BPMNEdge_sid-9FE4C81C-85F2-4A35-86CA-EEC5E66E9880">
<omgdi:waypoint x="590.5" y="149.875"></omgdi:waypoint>
<omgdi:waypoint x="590.5" y="194.31963470319636"></omgdi:waypoint>
<omgdi:waypoint x="655.0" y="194.31963470319636"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-A756FBC0-9AB5-464E-8A5F-DB23CAE03C22" id="BPMNEdge_sid-A756FBC0-9AB5-464E-8A5F-DB23CAE03C22">
<omgdi:waypoint x="329.9999461897028" y="130.33482157270615"></omgdi:waypoint>
<omgdi:waypoint x="405.0" y="130.13392857142856"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-C1D3F58A-4211-488D-AACF-A6165CDAE291" id="BPMNEdge_sid-C1D3F58A-4211-488D-AACF-A6165CDAE291">
<omgdi:waypoint x="165.0" y="130.375"></omgdi:waypoint>
<omgdi:waypoint x="255.0" y="130.375"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
2.3 测试类
ErrorEndTest.java
import com.it.cloud.modules.activiti.service.IActReModelService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 错误结束事件
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class ErrorEndTest {
@Autowired
private IActReModelService actReModelService;
@Autowired
private RuntimeService runtimeService;
@Autowired
private RepositoryService repositoryService;
@Autowired
private TaskService taskService;
@Autowired
private HistoryService historyService;
/**
* 部署流程定义
*/
@Test
public void deploy() {
Deployment deployment = repositoryService.createDeployment() // 创建部署
.addClasspathResource("diagrams/errorEnd.bpmn20.xml") // 加载流程资源文件
.name("errorEnd流程") // 流程名称
.deploy(); // 部署
System.out.println("流程部署ID:" + deployment.getId());
System.out.println("流程部署Name:" + deployment.getName());
}
/**
* 启动流程实例
*/
@Test
public void start() throws InterruptedException {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("errorEnd"); // 流程定义表的KEY字段值
System.out.println("流程实例ID:" + pi.getId());
System.out.println("流程定义ID:" + pi.getProcessDefinitionId());
System.out.println("----------------------一条有想法的分割线------------------------");
// 查询任务
List<Task> taskList1 = taskService.createTaskQuery() // 创建任务查询
.taskAssignee("errorEndUser") // 指定某个人
.list();
for (Task task : taskList1) {
System.out.println("任务ID:" + task.getId());
System.out.println("任务名称:" + task.getName());
System.out.println("任务创建时间:" + task.getCreateTime());
System.out.println("任务委派人:" + task.getAssignee());
System.out.println("流程实例ID:" + task.getProcessInstanceId());
// 完成任务
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("flag", false);
taskService.complete(task.getId(), variables);
}
// 睡一会
Thread.sleep(1000 * 3);
// 查询任务
List<Task> taskList2 = taskService.createTaskQuery() // 创建任务查询
.taskAssignee("errorEndUser1") // 指定某个人
.list();
for (Task task : taskList2) {
System.out.println("任务ID:" + task.getId());
System.out.println("任务名称:" + task.getName());
System.out.println("任务创建时间:" + task.getCreateTime());
System.out.println("任务委派人:" + task.getAssignee());
System.out.println("流程实例ID:" + task.getProcessInstanceId());
}
}
}
2.4 运行
运行deploy()
2.4.1 启动任务
运行start(), 设置flag=false
效果:
3. 终止结束事件
3.1 简介
当流程到达终止结束事件时会结束当前执行流,如果activiti:terminateAll属性设置成true,那么该流程实例的所有执行流全部终止。如可以用在子流程,嵌入式子流程,调用子流程,事务字流程中。
4.2 流程设计
场景:用户支付成功后等待一分钟,商家发货
终止结束事件
流程图
流程文件bpmn
<?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/processdef">
<message id="msg" name="msg"></message>
<process id="terminateEnd" name="terminateEnd" isExecutable="true">
<documentation>terminateEnd</documentation>
<startEvent id="sid-AE775DDE-5837-43B3-8290-44A9F5EE34ED"></startEvent>
<subProcess id="sid-579DEB01-C7C9-4704-8C73-070E99663C3E" name="子流程">
<startEvent id="sid-AC21AE14-E120-444F-A872-B6FF67687A59"></startEvent>
<endEvent id="sid-9C048B6A-13AD-42FA-A6E7-2FFBE2246B94">
<terminateEventDefinition activiti:terminateAll="true"></terminateEventDefinition>
</endEvent>
<serviceTask id="sid-EEFD9F2F-F1D9-4758-8E45-C89F7D6B05FF" name="服务执行" activiti:class="com.it.cloud.activiti.event.delegate.RunDelegate"></serviceTask>
<sequenceFlow id="sid-A756FBC0-9AB5-464E-8A5F-DB23CAE03C22" sourceRef="sid-AC21AE14-E120-444F-A872-B6FF67687A59" targetRef="sid-EEFD9F2F-F1D9-4758-8E45-C89F7D6B05FF"></sequenceFlow>
<sequenceFlow id="sid-C6396652-65DF-4C75-A11B-041A44E15F44" sourceRef="sid-EEFD9F2F-F1D9-4758-8E45-C89F7D6B05FF" targetRef="sid-9C048B6A-13AD-42FA-A6E7-2FFBE2246B94"></sequenceFlow>
</subProcess>
<sequenceFlow id="sid-D6EC03F3-1844-4CC7-89EC-27F423AF8B92" sourceRef="sid-AE775DDE-5837-43B3-8290-44A9F5EE34ED" targetRef="sid-6BC758FD-E152-434C-9923-D8D4B84EDA49"></sequenceFlow>
<parallelGateway id="sid-6BC758FD-E152-434C-9923-D8D4B84EDA49"></parallelGateway>
<userTask id="sid-2F5341EA-ADF8-4907-951E-CAB27364932D" name="用户任务1" activiti:assignee="terminateEndUser1">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="sid-C8E84514-2DB1-47A8-82D6-6CC2DA4D3143" sourceRef="sid-6BC758FD-E152-434C-9923-D8D4B84EDA49" targetRef="sid-2F5341EA-ADF8-4907-951E-CAB27364932D"></sequenceFlow>
<sequenceFlow id="sid-A4A0DE30-3A88-4EF4-BB28-BAA7A7ADFCAB" sourceRef="sid-6BC758FD-E152-434C-9923-D8D4B84EDA49" targetRef="sid-579DEB01-C7C9-4704-8C73-070E99663C3E"></sequenceFlow>
<userTask id="sid-14010A77-7E7E-4922-9622-0EB4F6CC7B0A" name="用户任务2" activiti:assignee="terminateEndUser2">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="sid-FDA58B1B-9170-468E-B357-9C5E6550F7B9" sourceRef="sid-579DEB01-C7C9-4704-8C73-070E99663C3E" targetRef="sid-14010A77-7E7E-4922-9622-0EB4F6CC7B0A"></sequenceFlow>
<sequenceFlow id="sid-28BE6A3D-18B0-4277-A51E-4BA39D40D314" sourceRef="sid-2F5341EA-ADF8-4907-951E-CAB27364932D" targetRef="sid-14010A77-7E7E-4922-9622-0EB4F6CC7B0A"></sequenceFlow>
<endEvent id="sid-179762E5-E6EE-4720-8112-F393C5484BF8"></endEvent>
<sequenceFlow id="sid-BE0CD8B8-CD08-469E-910F-0D0D557B6DD0" sourceRef="sid-14010A77-7E7E-4922-9622-0EB4F6CC7B0A" targetRef="sid-179762E5-E6EE-4720-8112-F393C5484BF8"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_terminateEnd">
<bpmndi:BPMNPlane bpmnElement="terminateEnd" id="BPMNPlane_terminateEnd">
<bpmndi:BPMNShape bpmnElement="sid-AE775DDE-5837-43B3-8290-44A9F5EE34ED" id="BPMNShape_sid-AE775DDE-5837-43B3-8290-44A9F5EE34ED">
<omgdc:Bounds height="30.0" width="30.0" x="45.0" y="205.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-579DEB01-C7C9-4704-8C73-070E99663C3E" id="BPMNShape_sid-579DEB01-C7C9-4704-8C73-070E99663C3E">
<omgdc:Bounds height="155.0" width="395.0" x="225.0" y="45.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-AC21AE14-E120-444F-A872-B6FF67687A59" id="BPMNShape_sid-AC21AE14-E120-444F-A872-B6FF67687A59">
<omgdc:Bounds height="30.0" width="30.0" x="270.0" y="107.5"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-9C048B6A-13AD-42FA-A6E7-2FFBE2246B94" id="BPMNShape_sid-9C048B6A-13AD-42FA-A6E7-2FFBE2246B94">
<omgdc:Bounds height="28.0" width="28.0" x="540.0" y="108.5"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-EEFD9F2F-F1D9-4758-8E45-C89F7D6B05FF" id="BPMNShape_sid-EEFD9F2F-F1D9-4758-8E45-C89F7D6B05FF">
<omgdc:Bounds height="80.0" width="100.0" x="375.0" y="82.5"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-6BC758FD-E152-434C-9923-D8D4B84EDA49" id="BPMNShape_sid-6BC758FD-E152-434C-9923-D8D4B84EDA49">
<omgdc:Bounds height="40.0" width="40.0" x="120.0" y="200.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-2F5341EA-ADF8-4907-951E-CAB27364932D" id="BPMNShape_sid-2F5341EA-ADF8-4907-951E-CAB27364932D">
<omgdc:Bounds height="80.0" width="100.0" x="372.5" y="300.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-14010A77-7E7E-4922-9622-0EB4F6CC7B0A" id="BPMNShape_sid-14010A77-7E7E-4922-9622-0EB4F6CC7B0A">
<omgdc:Bounds height="80.0" width="100.0" x="690.0" y="180.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-179762E5-E6EE-4720-8112-F393C5484BF8" id="BPMNShape_sid-179762E5-E6EE-4720-8112-F393C5484BF8">
<omgdc:Bounds height="28.0" width="28.0" x="855.0" y="206.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-D6EC03F3-1844-4CC7-89EC-27F423AF8B92" id="BPMNEdge_sid-D6EC03F3-1844-4CC7-89EC-27F423AF8B92">
<omgdi:waypoint x="74.99971066768252" y="220.0931659047682"></omgdi:waypoint>
<omgdi:waypoint x="120.375" y="220.375"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-C6396652-65DF-4C75-A11B-041A44E15F44" id="BPMNEdge_sid-C6396652-65DF-4C75-A11B-041A44E15F44">
<omgdi:waypoint x="475.0" y="122.5"></omgdi:waypoint>
<omgdi:waypoint x="540.0" y="122.5"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-BE0CD8B8-CD08-469E-910F-0D0D557B6DD0" id="BPMNEdge_sid-BE0CD8B8-CD08-469E-910F-0D0D557B6DD0">
<omgdi:waypoint x="790.0" y="220.0"></omgdi:waypoint>
<omgdi:waypoint x="855.0" y="220.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-A756FBC0-9AB5-464E-8A5F-DB23CAE03C22" id="BPMNEdge_sid-A756FBC0-9AB5-464E-8A5F-DB23CAE03C22">
<omgdi:waypoint x="300.0" y="122.5"></omgdi:waypoint>
<omgdi:waypoint x="375.0" y="122.5"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-C8E84514-2DB1-47A8-82D6-6CC2DA4D3143" id="BPMNEdge_sid-C8E84514-2DB1-47A8-82D6-6CC2DA4D3143">
<omgdi:waypoint x="140.5" y="239.5"></omgdi:waypoint>
<omgdi:waypoint x="140.5" y="340.0"></omgdi:waypoint>
<omgdi:waypoint x="372.5" y="340.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-A4A0DE30-3A88-4EF4-BB28-BAA7A7ADFCAB" id="BPMNEdge_sid-A4A0DE30-3A88-4EF4-BB28-BAA7A7ADFCAB">
<omgdi:waypoint x="140.5" y="200.5"></omgdi:waypoint>
<omgdi:waypoint x="140.5" y="122.5"></omgdi:waypoint>
<omgdi:waypoint x="225.0" y="122.5"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-FDA58B1B-9170-468E-B357-9C5E6550F7B9" id="BPMNEdge_sid-FDA58B1B-9170-468E-B357-9C5E6550F7B9">
<omgdi:waypoint x="620.0" y="122.5"></omgdi:waypoint>
<omgdi:waypoint x="740.0" y="122.5"></omgdi:waypoint>
<omgdi:waypoint x="740.0" y="180.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-28BE6A3D-18B0-4277-A51E-4BA39D40D314" id="BPMNEdge_sid-28BE6A3D-18B0-4277-A51E-4BA39D40D314">
<omgdi:waypoint x="472.5" y="340.0"></omgdi:waypoint>
<omgdi:waypoint x="740.0" y="340.0"></omgdi:waypoint>
<omgdi:waypoint x="740.0" y="260.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
3.3 测试类
TerminateEndTest.java
import com.it.cloud.modules.activiti.service.IActReModelService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 终止结束事件
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class TerminateEndTest {
@Autowired
private IActReModelService actReModelService;
@Autowired
private RuntimeService runtimeService;
@Autowired
private RepositoryService repositoryService;
@Autowired
private TaskService taskService;
@Autowired
private HistoryService historyService;
/**
* 部署流程定义
*/
@Test
public void deploy() {
Deployment deployment = repositoryService.createDeployment() // 创建部署
.addClasspathResource("diagrams/terminateEnd.bpmn20.xml") // 加载流程资源文件
.name("terminateEnd流程") // 流程名称
.deploy(); // 部署
System.out.println("流程部署ID:" + deployment.getId());
System.out.println("流程部署Name:" + deployment.getName());
}
/**
* 启动流程实例
*/
@Test
public void start() throws InterruptedException {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("terminateEnd"); // 流程定义表的KEY字段值
System.out.println("流程实例ID:" + pi.getId());
System.out.println("流程定义ID:" + pi.getProcessDefinitionId());
System.out.println("----------------------一条有想法的分割线------------------------");
// 睡一会
Thread.sleep(1000 * 3);
// 查询执行流
long exeCount = runtimeService.createExecutionQuery()
.processInstanceId(pi.getId())
.count();
System.out.println("执行流数量:" + exeCount);
}
}
3.4 运行
运行deploy()
3.4.1 启动任务
运行start()
效果:
源码地址
IT-CLOUD-ACTIVITI6
开源项目,持续更新中,喜欢请 Star~
项目推荐
IT-CLOUD :IT服务管理平台,集成基础服务,中间件服务,监控告警服务等。
开源项目,持续更新中,喜欢请 Star~