持续创作,加速成长!这是我参与「掘金日新计划 · 6 月更文挑战」的第16天,点击查看活动详情
什么是网关
网关(gateway)用于控制执行的流向,网关可以消费(consuming) 与生成(generating) 标志。 网关用其中带有图标的菱形表示。
1.排他网关
1.1 什么是排他网关
排他网关(exclusive gateway)(也叫异或网关 XOR gateway,或者更专业的,基于数据的排他网关 exclusive data-based gateway),用于对流程中的决策建模。当执行到达这个网关时,会按照所有出口顺序流定义的顺序对它们进行计算。选择第一个条件计算为true的顺序流(当没有设置条件时,认为顺序流为true)继续流程。
1.2 在Flowable UI 中创建 排他网关流程图
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:flowable="http://flowable.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.flowable.org/processdef">
<process id="_noKey" name="排他网关" isExecutable="true">
<startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
<userTask id="sid-B2E817F9-34BC-4881-99DC-B2A476C1297D" name="员工请假" flowable:assignee="张三" flowable:formFieldValidation="true">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="sid-3F70F9B9-3CC0-496D-A661-B4A14ACD7922" sourceRef="startEvent1" targetRef="sid-B2E817F9-34BC-4881-99DC-B2A476C1297D"></sequenceFlow>
<exclusiveGateway id="sid-959A60DB-C2E1-4328-A50E-2BEFA452D6D0" name="请假天数"></exclusiveGateway>
<sequenceFlow id="sid-C39ACE1E-850B-40F3-9FD3-F7DFD405FD8A" sourceRef="sid-B2E817F9-34BC-4881-99DC-B2A476C1297D" targetRef="sid-959A60DB-C2E1-4328-A50E-2BEFA452D6D0"></sequenceFlow>
<userTask id="sid-821ECFE2-BBB2-47A8-8B78-650160885689" name="组长审批" flowable:assignee="lisi" flowable:formFieldValidation="true">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<userTask id="sid-F1842FE3-B837-4772-9544-24A13E33E3CE" name="经理审批" flowable:assignee="wangwu" flowable:formFieldValidation="true">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<userTask id="sid-56640F50-EB5D-4740-812D-AFB8E57A0E0A" name="人事审批" flowable:assignee="xk" flowable:formFieldValidation="true">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="sid-8C182810-9869-4D6E-B50A-5E23DE8A44C0" sourceRef="sid-821ECFE2-BBB2-47A8-8B78-650160885689" targetRef="sid-56640F50-EB5D-4740-812D-AFB8E57A0E0A"></sequenceFlow>
<sequenceFlow id="sid-DF3C852A-1923-42C0-997C-E618217F64CD" sourceRef="sid-F1842FE3-B837-4772-9544-24A13E33E3CE" targetRef="sid-56640F50-EB5D-4740-812D-AFB8E57A0E0A"></sequenceFlow>
<endEvent id="sid-DA2376B7-6D0F-4874-A10F-BA9E895F25C1"></endEvent>
<sequenceFlow id="sid-09E305E3-15AD-427A-BB7A-5FA533D72C48" sourceRef="sid-56640F50-EB5D-4740-812D-AFB8E57A0E0A" targetRef="sid-DA2376B7-6D0F-4874-A10F-BA9E895F25C1"></sequenceFlow>
<sequenceFlow id="sid-C88F5F35-744A-4A05-9B77-7EDF9A5BA9FE" sourceRef="sid-959A60DB-C2E1-4328-A50E-2BEFA452D6D0" targetRef="sid-F1842FE3-B837-4772-9544-24A13E33E3CE">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${num>3}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="sid-3BEDB840-A02F-4FE3-BB18-6072510E7081" sourceRef="sid-959A60DB-C2E1-4328-A50E-2BEFA452D6D0" targetRef="sid-821ECFE2-BBB2-47A8-8B78-650160885689">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${num<3}]]></conditionExpression>
</sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram__noKey">
<bpmndi:BPMNPlane bpmnElement="_noKey" id="BPMNPlane__noKey">
<bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
<omgdc:Bounds height="30.0" width="30.0" x="100.0" y="163.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-B2E817F9-34BC-4881-99DC-B2A476C1297D" id="BPMNShape_sid-B2E817F9-34BC-4881-99DC-B2A476C1297D">
<omgdc:Bounds height="80.0" width="100.0" x="175.0" y="138.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-959A60DB-C2E1-4328-A50E-2BEFA452D6D0" id="BPMNShape_sid-959A60DB-C2E1-4328-A50E-2BEFA452D6D0">
<omgdc:Bounds height="40.0" width="40.0" x="320.0" y="158.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-821ECFE2-BBB2-47A8-8B78-650160885689" id="BPMNShape_sid-821ECFE2-BBB2-47A8-8B78-650160885689">
<omgdc:Bounds height="80.0" width="100.0" x="375.0" y="45.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-F1842FE3-B837-4772-9544-24A13E33E3CE" id="BPMNShape_sid-F1842FE3-B837-4772-9544-24A13E33E3CE">
<omgdc:Bounds height="80.0" width="100.0" x="375.0" y="240.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-56640F50-EB5D-4740-812D-AFB8E57A0E0A" id="BPMNShape_sid-56640F50-EB5D-4740-812D-AFB8E57A0E0A">
<omgdc:Bounds height="80.0" width="100.0" x="570.0" y="138.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-DA2376B7-6D0F-4874-A10F-BA9E895F25C1" id="BPMNShape_sid-DA2376B7-6D0F-4874-A10F-BA9E895F25C1">
<omgdc:Bounds height="28.0" width="28.0" x="715.0" y="164.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-3F70F9B9-3CC0-496D-A661-B4A14ACD7922" id="BPMNEdge_sid-3F70F9B9-3CC0-496D-A661-B4A14ACD7922">
<omgdi:waypoint x="129.9499984899576" y="178.0"></omgdi:waypoint>
<omgdi:waypoint x="174.9999999999917" y="178.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-09E305E3-15AD-427A-BB7A-5FA533D72C48" id="BPMNEdge_sid-09E305E3-15AD-427A-BB7A-5FA533D72C48">
<omgdi:waypoint x="669.9499999999999" y="178.0"></omgdi:waypoint>
<omgdi:waypoint x="715.0" y="178.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-3BEDB840-A02F-4FE3-BB18-6072510E7081" id="BPMNEdge_sid-3BEDB840-A02F-4FE3-BB18-6072510E7081">
<omgdi:waypoint x="340.5" y="158.5"></omgdi:waypoint>
<omgdi:waypoint x="340.5" y="85.0"></omgdi:waypoint>
<omgdi:waypoint x="375.0" y="85.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-8C182810-9869-4D6E-B50A-5E23DE8A44C0" id="BPMNEdge_sid-8C182810-9869-4D6E-B50A-5E23DE8A44C0">
<omgdi:waypoint x="474.9499999999852" y="85.0"></omgdi:waypoint>
<omgdi:waypoint x="530.0" y="85.0"></omgdi:waypoint>
<omgdi:waypoint x="530.0" y="178.0"></omgdi:waypoint>
<omgdi:waypoint x="570.0" y="178.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-C88F5F35-744A-4A05-9B77-7EDF9A5BA9FE" id="BPMNEdge_sid-C88F5F35-744A-4A05-9B77-7EDF9A5BA9FE">
<omgdi:waypoint x="340.5" y="197.44067421259845"></omgdi:waypoint>
<omgdi:waypoint x="340.5" y="280.0"></omgdi:waypoint>
<omgdi:waypoint x="374.9999999999826" y="280.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-C39ACE1E-850B-40F3-9FD3-F7DFD405FD8A" id="BPMNEdge_sid-C39ACE1E-850B-40F3-9FD3-F7DFD405FD8A">
<omgdi:waypoint x="274.94999999999806" y="178.21623376623378"></omgdi:waypoint>
<omgdi:waypoint x="320.4130434782609" y="178.4130434782609"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-DF3C852A-1923-42C0-997C-E618217F64CD" id="BPMNEdge_sid-DF3C852A-1923-42C0-997C-E618217F64CD">
<omgdi:waypoint x="474.9499999997919" y="280.0"></omgdi:waypoint>
<omgdi:waypoint x="530.0" y="280.0"></omgdi:waypoint>
<omgdi:waypoint x="530.0" y="197.0"></omgdi:waypoint>
<omgdi:waypoint x="569.9999999999905" y="197.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
1.3 进行部署和启动流程
部署流程:
@Test
public void DeployProcess(){
Deployment holiday = repositoryService.createDeployment()
.addClasspathResource("排他网关.bpmn20.xml")
.name("排他网关")
.deploy();
}
启动流程:
@Test
public void StatrProcess(){
//先查到流程
ProcessDefinition leave_key = repositoryService.createProcessDefinitionQuery().processDefinitionKey("_noKey").singleResult();
//启动流程并分配给
ProcessInstance processInstance = runtimeService.startProcessInstanceById(leave_key.getId());
}
我们可以看到流程已经流转到了张三
1.4 张三完成流程
public void comleteProcess(){
Task task = taskService.createTaskQuery()
//ACT_RU_TASK 表中 PROC_INST_ID_
.processInstanceId("5726e327-e49c-11ec-ae0f-666ee0fc370d")
.taskAssignee("张三")
.singleResult();
if (task!=null){
Map<String,Object> map=new HashMap<>();
map.put("num",2);//发起人
taskService.complete(task.getId(),map);
System.out.println("完成");
//去 历史表中查看
}
}
张三请假两天完成后任务应该流转到 组长审批(请假天数大于3天是经理审批 小于 3天是组长审批)
1.5 下面我们让组长和人事都完成任务
组长完成任务:
public void comleteProcess(){
Task task = taskService.createTaskQuery()
//ACT_RU_TASK 表中 PROC_INST_ID_
.processInstanceId("5726e327-e49c-11ec-ae0f-666ee0fc370d")
.taskAssignee("lisi")
.singleResult();
if (task!=null){
Map<String,Object> map=new HashMap<>();
//map.put("num",2);//发起人
taskService.complete(task.getId());
System.out.println("完成");
//去 历史表中查看
}
}
流转到人事
人事完成任务:
public void comleteProcess(){
Task task = taskService.createTaskQuery()
//ACT_RU_TASK 表中 PROC_INST_ID_
.processInstanceId("5726e327-e49c-11ec-ae0f-666ee0fc370d")
.taskAssignee("xk")
.singleResult();
if (task!=null){
Map<String,Object> map=new HashMap<>();
//map.put("num",2);//发起人
taskService.complete(task.getId());
System.out.println("完成");
//去 历史表中查看
}
}
在历史数据中可以看到流程已经结束
1.6 这里我们要说一个问题当 排他网关的条件 两边都不能 完善时会出现异常
我们现在的体检时 请假天数< 3 是组长 >3 是经理 但是等于3 并没有做处理 我们继续启动(和上面代码一样就不重复贴了)一个新的流程测试一下这种情况,这里使用张三完成下任务。
public void comleteProcess(){
Task task = taskService.createTaskQuery()
//ACT_RU_TASK 表中 PROC_INST_ID_
.processInstanceId("95636ebe-e49e-11ec-af52-666ee0fc370d")
.taskAssignee("张三")
.singleResult();
if (task!=null){
Map<String,Object> map=new HashMap<>();
map.put("num",3);
taskService.complete(task.getId(),map);
System.out.println("完成");
//去 历史表中查看
}
}
输出结果:
org.flowable.common.engine.api.FlowableException: No outgoing sequence flow of the exclusive
gateway 'sid-959A60DB-C2E1-4328-A50E-2BEFA452D6D0' could be selected for continuing the process
注意:虽然异常了但是任务还在继续,将条件num 重新调整继续让流程流转
测试:
public void comleteProcess(){
Task task = taskService.createTaskQuery()
//ACT_RU_TASK 表中 PROC_INST_ID_
.processInstanceId("95636ebe-e49e-11ec-af52-666ee0fc370d")
.taskAssignee("张三")
.singleResult();
if (task!=null){
Map<String,Object> map=new HashMap<>();
map.put("num",2);
taskService.complete(task.getId(),map);
System.out.println("完成");
//去 历史表中查看
}
}
结果我们返现 流程继续往下正常流转了
并行网关
1. 什么是并行网关
网关也可以建模流程中的并行执行。在流程模型中引入并行的最简单的网关,就是并行网关(parallel gateway) 。它可以将执行分支(fork) 为多条路径,也可以合并(join) 多条入口路径的执行。并行网关的功能取决于其入口与出口顺序流:
- 分支: 所有的出口顺序流都并行执行,为每一条顺序流创建一个并行执行。
- 合并: 所有到达并行网关的并行执行都会在网关处等待,直到每一条入口顺序流都到达了有个执行。然后流程经过该合并网关继续。 注意:如果并行网关同时具有多条入口与出口顺序流,可以同时具有分支与合并的行为。在这种情况下,网关首先合并所有入口顺序流,然后分裂为多条并行执行路径。
与其他网关类型有一个重要区别:并行网关不会解析条件。即使流程中定义了条件,会直接忽略该条件。
1.1 画 并行网关 流程图
<?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:flowable="http://flowable.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.flowable.org/processdef">
<process id="parallel_gateway" name="并行网关" isExecutable="true">
<startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
<userTask id="sid-723E52FF-FDB7-48FA-94D4-BDFB8E0222AC" name="员工请假" flowable:assignee="zhangsan" flowable:formFieldValidation="true">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="sid-75D5ABE5-3244-4F73-9562-A41D5A46B9FD" sourceRef="startEvent1" targetRef="sid-723E52FF-FDB7-48FA-94D4-BDFB8E0222AC"></sequenceFlow>
<parallelGateway id="sid-225C2509-27C9-4EEA-BB52-8BA4C77A5B88"></parallelGateway>
<sequenceFlow id="sid-1EF2A131-802C-4B3C-899E-DAFB70665562" sourceRef="sid-723E52FF-FDB7-48FA-94D4-BDFB8E0222AC" targetRef="sid-225C2509-27C9-4EEA-BB52-8BA4C77A5B88"></sequenceFlow>
<userTask id="sid-A74AFF16-C143-4F70-9963-BBAF215ABEE2" name="组长审批" flowable:assignee="lisi" flowable:formFieldValidation="true">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<userTask id="sid-EBA69F19-0C9B-4052-8F4D-BD1B2DB67726" name="经理审批" flowable:assignee="wangwu" flowable:formFieldValidation="true">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="sid-566E5FD4-9C63-4718-8E64-1CF17655AE37" sourceRef="sid-225C2509-27C9-4EEA-BB52-8BA4C77A5B88" targetRef="sid-EBA69F19-0C9B-4052-8F4D-BD1B2DB67726"></sequenceFlow>
<parallelGateway id="sid-4BCBDD0C-0EF3-47CC-B114-7575DB628AE6"></parallelGateway>
<sequenceFlow id="sid-AF81BC67-92FD-4D78-A9AA-2E2163697D79" sourceRef="sid-EBA69F19-0C9B-4052-8F4D-BD1B2DB67726" targetRef="sid-4BCBDD0C-0EF3-47CC-B114-7575DB628AE6"></sequenceFlow>
<sequenceFlow id="sid-86A24FC6-2DD6-4CDB-B320-B7AAAF1E9157" sourceRef="sid-A74AFF16-C143-4F70-9963-BBAF215ABEE2" targetRef="sid-4BCBDD0C-0EF3-47CC-B114-7575DB628AE6"></sequenceFlow>
<userTask id="sid-D201831B-EAA8-4E1B-A3A3-982A28A8263E" name="人事审批" flowable:formFieldValidation="true"></userTask>
<sequenceFlow id="sid-9B23E4B9-66A5-442F-8532-56859DF2945F" sourceRef="sid-4BCBDD0C-0EF3-47CC-B114-7575DB628AE6" targetRef="sid-D201831B-EAA8-4E1B-A3A3-982A28A8263E"></sequenceFlow>
<endEvent id="sid-6AE7DB21-2B22-4B04-8692-6ABF521EA4F8"></endEvent>
<sequenceFlow id="sid-28D40E4E-81D1-466B-AD02-6208EB611EF2" sourceRef="sid-D201831B-EAA8-4E1B-A3A3-982A28A8263E" targetRef="sid-6AE7DB21-2B22-4B04-8692-6ABF521EA4F8"></sequenceFlow>
<sequenceFlow id="sid-41F4BFCA-20E3-419E-B3F8-0DA524F5B93D" sourceRef="sid-225C2509-27C9-4EEA-BB52-8BA4C77A5B88" targetRef="sid-A74AFF16-C143-4F70-9963-BBAF215ABEE2"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_parallel_gateway">
<bpmndi:BPMNPlane bpmnElement="parallel_gateway" id="BPMNPlane_parallel_gateway">
<bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
<omgdc:Bounds height="30.0" width="30.0" x="100.0" y="163.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-723E52FF-FDB7-48FA-94D4-BDFB8E0222AC" id="BPMNShape_sid-723E52FF-FDB7-48FA-94D4-BDFB8E0222AC">
<omgdc:Bounds height="80.0" width="100.0" x="165.0" y="135.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-225C2509-27C9-4EEA-BB52-8BA4C77A5B88" id="BPMNShape_sid-225C2509-27C9-4EEA-BB52-8BA4C77A5B88">
<omgdc:Bounds height="40.0" width="40.0" x="405.0" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-A74AFF16-C143-4F70-9963-BBAF215ABEE2" id="BPMNShape_sid-A74AFF16-C143-4F70-9963-BBAF215ABEE2">
<omgdc:Bounds height="80.0" width="100.0" x="480.0" y="45.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-EBA69F19-0C9B-4052-8F4D-BD1B2DB67726" id="BPMNShape_sid-EBA69F19-0C9B-4052-8F4D-BD1B2DB67726">
<omgdc:Bounds height="80.0" width="100.0" x="480.0" y="225.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-4BCBDD0C-0EF3-47CC-B114-7575DB628AE6" id="BPMNShape_sid-4BCBDD0C-0EF3-47CC-B114-7575DB628AE6">
<omgdc:Bounds height="40.0" width="40.0" x="690.0" y="151.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-D201831B-EAA8-4E1B-A3A3-982A28A8263E" id="BPMNShape_sid-D201831B-EAA8-4E1B-A3A3-982A28A8263E">
<omgdc:Bounds height="80.0" width="100.0" x="775.0" y="131.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-6AE7DB21-2B22-4B04-8692-6ABF521EA4F8" id="BPMNShape_sid-6AE7DB21-2B22-4B04-8692-6ABF521EA4F8">
<omgdc:Bounds height="28.0" width="28.0" x="920.0" y="157.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-566E5FD4-9C63-4718-8E64-1CF17655AE37" id="BPMNEdge_sid-566E5FD4-9C63-4718-8E64-1CF17655AE37">
<omgdi:waypoint x="425.5" y="189.43998414376327"></omgdi:waypoint>
<omgdi:waypoint x="425.5" y="265.0"></omgdi:waypoint>
<omgdi:waypoint x="479.99999999993804" y="265.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-AF81BC67-92FD-4D78-A9AA-2E2163697D79" id="BPMNEdge_sid-AF81BC67-92FD-4D78-A9AA-2E2163697D79">
<omgdi:waypoint x="579.9499999999999" y="238.88888888888889"></omgdi:waypoint>
<omgdi:waypoint x="696.8613138686131" y="177.84416058394163"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-28D40E4E-81D1-466B-AD02-6208EB611EF2" id="BPMNEdge_sid-28D40E4E-81D1-466B-AD02-6208EB611EF2">
<omgdi:waypoint x="874.949999999996" y="171.0"></omgdi:waypoint>
<omgdi:waypoint x="920.0" y="171.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-41F4BFCA-20E3-419E-B3F8-0DA524F5B93D" id="BPMNEdge_sid-41F4BFCA-20E3-419E-B3F8-0DA524F5B93D">
<omgdi:waypoint x="425.5" y="150.5"></omgdi:waypoint>
<omgdi:waypoint x="425.5" y="85.0"></omgdi:waypoint>
<omgdi:waypoint x="480.0" y="85.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-75D5ABE5-3244-4F73-9562-A41D5A46B9FD" id="BPMNEdge_sid-75D5ABE5-3244-4F73-9562-A41D5A46B9FD">
<omgdi:waypoint x="129.94340692927761" y="177.55019845363262"></omgdi:waypoint>
<omgdi:waypoint x="164.99999999999906" y="176.4985"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-9B23E4B9-66A5-442F-8532-56859DF2945F" id="BPMNEdge_sid-9B23E4B9-66A5-442F-8532-56859DF2945F">
<omgdi:waypoint x="729.5247370727427" y="171.41666666666666"></omgdi:waypoint>
<omgdi:waypoint x="774.9999999999952" y="171.21812227074236"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-86A24FC6-2DD6-4CDB-B320-B7AAAF1E9157" id="BPMNEdge_sid-86A24FC6-2DD6-4CDB-B320-B7AAAF1E9157">
<omgdi:waypoint x="579.95" y="111.84462384462702"></omgdi:waypoint>
<omgdi:waypoint x="690.0" y="170.9927054156706"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-1EF2A131-802C-4B3C-899E-DAFB70665562" id="BPMNEdge_sid-1EF2A131-802C-4B3C-899E-DAFB70665562">
<omgdi:waypoint x="264.95000000000005" y="173.8095238095238"></omgdi:waypoint>
<omgdi:waypoint x="405.46511627906943" y="170.46395348837208"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
1.2 我们进行流程部署和启动
部署流程:
@Test
public void DeployProcess(){
Deployment holiday = repositoryService.createDeployment()
.addClasspathResource("并行网关.bpmn20.xml")
.name("并行网关")
.deploy();
}
启动流程:
@Test
public void StatrProcess(){
//先查到流程
ProcessDefinition leave_key = repositoryService.createProcessDefinitionQuery().processDefinitionKey("parallel_gateway").singleResult();
//启动流程并分配给
ProcessInstance processInstance = runtimeService.startProcessInstanceById(leave_key.getId());
}
1.3 张三完成以一下任务
完成张三的任务
@Test
public void comleteProcess(){
Task task = taskService.createTaskQuery()
//ACT_RU_TASK 表中 PROC_INST_ID_
.processInstanceId("7d763907-e4a1-11ec-a298-666ee0fc370d")
.taskAssignee("zhangsan")
.singleResult();
if (task!=null){
// Map<String,Object> map=new HashMap<>();
// map.put("num",2);
taskService.complete(task.getId());
System.out.println("完成");
//去 历史表中查看
}
}
在数据库中可以看到两个并行的任务
1.4 lisi 和 wangwu 分别完成任务
这里就不一一贴了
@Test
public void comleteProcess(){
Task task = taskService.createTaskQuery()
//ACT_RU_TASK 表中 PROC_INST_ID_
.processInstanceId("7d763907-e4a1-11ec-a298-666ee0fc370d")
.taskAssignee("lisi")//wangwu
.singleResult();
if (task!=null){
// Map<String,Object> map=new HashMap<>();
// map.put("num",2);
taskService.complete(task.getId());
System.out.println("完成");
//去 历史表中查看
}
}
可以看到已经流转到了人事审批(注意:并行网关需要等待所有并行任务都完成才会流转到洗一个任务节点,且并行网关即使设置了条件也会自动过滤掉)
这里后续就是人事完成审批结束流程和上面的排他网关一样的就不多啰嗦啦。
实践是检验真理的唯一方法! 明天见🥰🥰🥰