flowable网关


网关(gateway)用于控制执行的流向。

网关用其中带有图标的菱形表示。该图标显示了网关的类型。

不用网关也可以实现分支,比如之前通过流程变量,在连线的条件上设置分支条件,但这样有个缺点:如果条件都不满足,流程就结束了(并且是异常结束)。

而从网关出去的条件都不满足是直接抛出异常。

排他网关

排他网关(exclusive gateway)。当执行到达这个网关时,会按照所有出口顺序流定义的顺序对它们进行计算。选择第一个条件计算为true的顺序流(当没有设置条件时,认为顺序流为true)继续流程。

请注意这里出口顺序流的含义与BPMN 2.0中的一般情况不一样。一般情况下,会选择所有条件计算为true的顺序流,并行执行。而使用排他网关时,只会选择一条顺序流。当多条顺序流的条件都计算为true时,会且仅会选择在XML中最先定义的顺序流继续流程。如果没有可选的顺序流,会抛出异常。

排他网关用内部带有’X’图标的标准网关(菱形)表示,'X’图标代表异或的含义。请注意内部没有图标的网关默认为排他网关。BPMN 2.0规范不允许在同一个流程中混合使用有及没有X的菱形标志。

案例:

为了简单,各个处理人流程变量写死了,使用了固定的。请假天数使用了流程变量,动态赋值。

<?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="排他网关" name="排他网关" isExecutable="true"><startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent><userTask id="sid-FED5EEDE-6A46-427C-BB8E-5FDBC31CB59A" 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-AF7392D2-9B1B-44C8-972A-73E0E7BE2693" sourceRef="startEvent1" targetRef="sid-FED5EEDE-6A46-427C-BB8E-5FDBC31CB59A"></sequenceFlow><exclusiveGateway id="sid-F2A909DD-3624-493C-9607-AE4B0BDEA5B8" name="请假天数判断"></exclusiveGateway><sequenceFlow id="sid-82D32AB7-5011-466A-B17F-C1D58124E794" sourceRef="sid-FED5EEDE-6A46-427C-BB8E-5FDBC31CB59A" targetRef="sid-F2A909DD-3624-493C-9607-AE4B0BDEA5B8"></sequenceFlow><userTask id="sid-EE4DAD5F-F5EA-45E8-AC42-D562882B2D4D" 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><userTask id="sid-DA731FC7-1898-4271-9832-00409571A50A" 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><userTask id="sid-03281F54-C75A-48FD-8D37-E1ABBB5D889D" 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-0F6D6585-5C0A-4639-A39F-24F7BA3E0665" sourceRef="sid-DA731FC7-1898-4271-9832-00409571A50A" targetRef="sid-03281F54-C75A-48FD-8D37-E1ABBB5D889D"></sequenceFlow><sequenceFlow id="sid-3AEB90D3-560C-4168-B0D3-F1338409E987" sourceRef="sid-EE4DAD5F-F5EA-45E8-AC42-D562882B2D4D" targetRef="sid-03281F54-C75A-48FD-8D37-E1ABBB5D889D"></sequenceFlow><sequenceFlow id="sid-BF408642-6FA3-4611-8D00-80BF33D156A6" name="请假小于3天" sourceRef="sid-F2A909DD-3624-493C-9607-AE4B0BDEA5B8" targetRef="sid-EE4DAD5F-F5EA-45E8-AC42-D562882B2D4D"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${num<3}]]></conditionExpression></sequenceFlow><sequenceFlow id="sid-410408AB-8A3C-402E-82BA-FDE371571C2A" name="请假大于等于3天" sourceRef="sid-F2A909DD-3624-493C-9607-AE4B0BDEA5B8" targetRef="sid-DA731FC7-1898-4271-9832-00409571A50A"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${num>=3}]]></conditionExpression></sequenceFlow></process><bpmndi:BPMNDiagram id="BPMNDiagram_排他网关"><bpmndi:BPMNPlane bpmnElement="排他网关" id="BPMNPlane_排他网关"><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-FED5EEDE-6A46-427C-BB8E-5FDBC31CB59A" id="BPMNShape_sid-FED5EEDE-6A46-427C-BB8E-5FDBC31CB59A"><omgdc:Bounds height="80.0" width="100.0" x="175.0" y="138.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-F2A909DD-3624-493C-9607-AE4B0BDEA5B8" id="BPMNShape_sid-F2A909DD-3624-493C-9607-AE4B0BDEA5B8"><omgdc:Bounds height="40.0" width="40.0" x="320.0" y="158.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-EE4DAD5F-F5EA-45E8-AC42-D562882B2D4D" id="BPMNShape_sid-EE4DAD5F-F5EA-45E8-AC42-D562882B2D4D"><omgdc:Bounds height="80.0" width="100.0" x="405.00000000000006" y="45.00000000000001"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-DA731FC7-1898-4271-9832-00409571A50A" id="BPMNShape_sid-DA731FC7-1898-4271-9832-00409571A50A"><omgdc:Bounds height="79.99999999999997" width="99.99999999999994" x="405.0000000000001" y="255.00000000000003"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-03281F54-C75A-48FD-8D37-E1ABBB5D889D" id="BPMNShape_sid-03281F54-C75A-48FD-8D37-E1ABBB5D889D"><omgdc:Bounds height="80.0" width="100.0" x="630.0000000000001" y="138.00000000000003"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNEdge bpmnElement="sid-410408AB-8A3C-402E-82BA-FDE371571C2A" id="BPMNEdge_sid-410408AB-8A3C-402E-82BA-FDE371571C2A"><omgdi:waypoint x="340.5" y="197.44187392795888"></omgdi:waypoint><omgdi:waypoint x="340.5" y="295.0"></omgdi:waypoint><omgdi:waypoint x="404.99999999999943" y="295.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-AF7392D2-9B1B-44C8-972A-73E0E7BE2693" id="BPMNEdge_sid-AF7392D2-9B1B-44C8-972A-73E0E7BE2693"><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-BF408642-6FA3-4611-8D00-80BF33D156A6" id="BPMNEdge_sid-BF408642-6FA3-4611-8D00-80BF33D156A6"><omgdi:waypoint x="340.5" y="158.5"></omgdi:waypoint><omgdi:waypoint x="340.5" y="85.0"></omgdi:waypoint><omgdi:waypoint x="405.00000000000006" y="85.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-82D32AB7-5011-466A-B17F-C1D58124E794" id="BPMNEdge_sid-82D32AB7-5011-466A-B17F-C1D58124E794"><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-0F6D6585-5C0A-4639-A39F-24F7BA3E0665" id="BPMNEdge_sid-0F6D6585-5C0A-4639-A39F-24F7BA3E0665"><omgdi:waypoint x="504.9499999999979" y="295.0"></omgdi:waypoint><omgdi:waypoint x="560.0" y="295.0"></omgdi:waypoint><omgdi:waypoint x="560.0" y="178.00000000000003"></omgdi:waypoint><omgdi:waypoint x="630.0000000000001" y="178.00000000000003"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-3AEB90D3-560C-4168-B0D3-F1338409E987" id="BPMNEdge_sid-3AEB90D3-560C-4168-B0D3-F1338409E987"><omgdi:waypoint x="504.94999999998856" y="85.0"></omgdi:waypoint><omgdi:waypoint x="564.0" y="85.0"></omgdi:waypoint><omgdi:waypoint x="564.0" y="178.00000000000003"></omgdi:waypoint><omgdi:waypoint x="630.0000000000001" y="178.00000000000003"></omgdi:waypoint></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>

部署流程和启动流程

 /*** 部署流程*/@Testpublic void deployment() {ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();RepositoryService repositoryService = processEngine.getRepositoryService();repositoryService.createDeployment().name("排他网关流程").addClasspathResource("排他网关.bpmn20.xml").deploy();}/*** 启动流程实例*/@Testpublic void startProcess() {ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();RuntimeService runtimeService = processEngine.getRuntimeService();runtimeService.startProcessInstanceById("排他网关:1:47504");}

流程启动后,第一个任务是由员工受理:

/*** 员工任务*/@Testpublic void task1() {//获取流程引擎ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();//获取TaskService完成流程任务TaskService taskService = processEngine.getTaskService();//员工发起请假申请,所以这里设置下排他网关里面的请假天数流程变量//这里num=2,按照排他网关的条件设计,员工完成任务后,该任务流转到经理Map<String, Object> variables = new HashMap<>();variables.put("num", 2);//查询员工的任务Task task = taskService.createTaskQuery().processInstanceId("50001").taskAssignee("员工").singleResult();if (task != null) {taskService.complete(task.getId(), variables);}}

员工完成后,任务流转到经理,排他网关生效

需要注意:如果从网关出去的线所有条件都不满足的情况下会抛出系统异常

并行网关

网关也可以建模流程中的并行执行。在流程模型中引入并行的最简单的网关,就是并行网关(parallel gateway)。它可以将执行*分支(fork)为多条路径,也可以合并(join)*多条入口路径的执行。

并行网关的功能取决于其入口与出口顺序流:

  • **分支:**所有的出口顺序流都并行执行,为每一条顺序流创建一个并行执行。
  • **合并:**所有到达并行网关的并行执行都会在网关处等待,直到每一条入口顺序流都到达了有个执行。然后流程经过该合并网关继续。

请注意,如果并行网关同时具有多条入口与出口顺序流,可以同时具有分支与合并的行为。在这种情况下,网关首先合并所有入口顺序流,然后分裂为多条并行执行路径。

与其他网关类型有一个重要区别:并行网关不计算条件。如果连接到并行网关的顺序流上定义了条件,也会直接忽略该条件。

请注意并行网关不需要“平衡”(也就是说,前后对应的两个并行网关,其入口/出口顺序流的数量不需要一致)。每个并行网关都会简单地等待所有入口顺序流,并为每一条出口顺序流创建并行执行,而不受流程模型中的其他结构影响。

并行网关,用内部带有’加号’图标的网关(菱形)表示,代表*与(AND)*的含义。

案例:

为了简单,各个处理人流程变量写死了,使用了固定的。请假天数使用了流程变量,动态赋值。

<?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="并行网关" name="并行网关" isExecutable="true"><startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent><userTask id="sid-B2215B26-29A7-4843-8E36-55290D515BAB" 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-DA073FDE-7717-490A-BCDC-C45FDAC2C667" sourceRef="startEvent1" targetRef="sid-B2215B26-29A7-4843-8E36-55290D515BAB"></sequenceFlow><parallelGateway id="sid-F8BD9FC0-F355-4829-8CE8-CEF341E36E79"></parallelGateway><sequenceFlow id="sid-CF3F92AC-2C29-42BA-AEBC-667E29F1196D" sourceRef="sid-B2215B26-29A7-4843-8E36-55290D515BAB" targetRef="sid-F8BD9FC0-F355-4829-8CE8-CEF341E36E79"></sequenceFlow><userTask id="sid-CEA60ED2-6EEC-4EE1-B0B4-72E7AE37E53A" 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><userTask id="sid-DA80A4C4-2F97-45F7-A51E-6FAE367C1761" 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-2CA45C90-704C-4997-8B40-86035D7C621A" sourceRef="sid-F8BD9FC0-F355-4829-8CE8-CEF341E36E79" targetRef="sid-CEA60ED2-6EEC-4EE1-B0B4-72E7AE37E53A"></sequenceFlow><sequenceFlow id="sid-74F05C08-50E4-46A1-BAA8-AD00A296B3C2" sourceRef="sid-F8BD9FC0-F355-4829-8CE8-CEF341E36E79" targetRef="sid-DA80A4C4-2F97-45F7-A51E-6FAE367C1761"></sequenceFlow><parallelGateway id="sid-1FCF8776-9B64-4C0D-AE0F-BDEF9CC68B25"></parallelGateway><sequenceFlow id="sid-85281FCE-FD40-4407-80A3-D03098778472" sourceRef="sid-CEA60ED2-6EEC-4EE1-B0B4-72E7AE37E53A" targetRef="sid-1FCF8776-9B64-4C0D-AE0F-BDEF9CC68B25"></sequenceFlow><exclusiveGateway id="sid-D8459C3E-A2D6-4520-80A5-5EEAEB92E90C"></exclusiveGateway><sequenceFlow id="sid-16D20EE3-771C-4661-9263-866A5CCF3810" sourceRef="sid-1FCF8776-9B64-4C0D-AE0F-BDEF9CC68B25" targetRef="sid-D8459C3E-A2D6-4520-80A5-5EEAEB92E90C"></sequenceFlow><userTask id="sid-106E199C-BAE0-4A5E-A252-A251E970C970" 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><endEvent id="sid-36B64E5F-EF46-45E9-9C7B-CB85302815CE" name="流程结束"></endEvent><sequenceFlow id="sid-5B8F7208-A124-4109-8F19-494A30960517" sourceRef="sid-106E199C-BAE0-4A5E-A252-A251E970C970" targetRef="sid-36B64E5F-EF46-45E9-9C7B-CB85302815CE"></sequenceFlow><sequenceFlow id="sid-1CD70A74-857F-4337-88D3-E1E5DBC792AA" sourceRef="sid-DA80A4C4-2F97-45F7-A51E-6FAE367C1761" targetRef="sid-1FCF8776-9B64-4C0D-AE0F-BDEF9CC68B25"></sequenceFlow><sequenceFlow id="sid-A80136A4-F0B6-4D44-8FE2-5A90222B4098" name="请假天数大于3天" sourceRef="sid-D8459C3E-A2D6-4520-80A5-5EEAEB92E90C" targetRef="sid-106E199C-BAE0-4A5E-A252-A251E970C970"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${num > 3}]]></conditionExpression></sequenceFlow><sequenceFlow id="sid-CFE54A2B-9F6F-464B-B7F9-D38C4DD34A6E" name="请假天数小于等于3天" sourceRef="sid-D8459C3E-A2D6-4520-80A5-5EEAEB92E90C" targetRef="sid-36B64E5F-EF46-45E9-9C7B-CB85302815CE"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${num <= 3}]]></conditionExpression></sequenceFlow></process><bpmndi:BPMNDiagram id="BPMNDiagram_并行网关"><bpmndi:BPMNPlane bpmnElement="并行网关" id="BPMNPlane_并行网关"><bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1"><omgdc:Bounds height="30.0" width="29.999999999999993" x="60.00000000000001" y="190.00000000000003"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-B2215B26-29A7-4843-8E36-55290D515BAB" id="BPMNShape_sid-B2215B26-29A7-4843-8E36-55290D515BAB"><omgdc:Bounds height="79.99999999999997" width="99.99999999999997" x="150.00000000000003" y="165.00000000000003"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-F8BD9FC0-F355-4829-8CE8-CEF341E36E79" id="BPMNShape_sid-F8BD9FC0-F355-4829-8CE8-CEF341E36E79"><omgdc:Bounds height="40.0" width="40.0" x="360.0000000000001" y="185.00000000000003"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-CEA60ED2-6EEC-4EE1-B0B4-72E7AE37E53A" id="BPMNShape_sid-CEA60ED2-6EEC-4EE1-B0B4-72E7AE37E53A"><omgdc:Bounds height="80.0" width="100.0" x="445.0000000000001" y="60.00000000000001"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-DA80A4C4-2F97-45F7-A51E-6FAE367C1761" id="BPMNShape_sid-DA80A4C4-2F97-45F7-A51E-6FAE367C1761"><omgdc:Bounds height="80.0" width="99.99999999999994" x="445.00000000000017" y="270.0000000000002"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-1FCF8776-9B64-4C0D-AE0F-BDEF9CC68B25" id="BPMNShape_sid-1FCF8776-9B64-4C0D-AE0F-BDEF9CC68B25"><omgdc:Bounds height="40.0" width="40.0" x="680.9999896685282" y="185.00000000000003"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-D8459C3E-A2D6-4520-80A5-5EEAEB92E90C" id="BPMNShape_sid-D8459C3E-A2D6-4520-80A5-5EEAEB92E90C"><omgdc:Bounds height="40.0" width="40.0" x="765.9999896685282" y="185.00000000000003"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-106E199C-BAE0-4A5E-A252-A251E970C970" id="BPMNShape_sid-106E199C-BAE0-4A5E-A252-A251E970C970"><omgdc:Bounds height="80.0" width="99.99999999999989" x="930.0000000000001" y="165.00000000000003"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-36B64E5F-EF46-45E9-9C7B-CB85302815CE" id="BPMNShape_sid-36B64E5F-EF46-45E9-9C7B-CB85302815CE"><omgdc:Bounds height="28.0" width="28.0" x="966.0000000000001" y="330.0000000000001"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNEdge bpmnElement="sid-CF3F92AC-2C29-42BA-AEBC-667E29F1196D" id="BPMNEdge_sid-CF3F92AC-2C29-42BA-AEBC-667E29F1196D"><omgdi:waypoint x="249.94999999999627" y="205.13836565096955"></omgdi:waypoint><omgdi:waypoint x="360.44444444444457" y="205.4444444444445"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-5B8F7208-A124-4109-8F19-494A30960517" id="BPMNEdge_sid-5B8F7208-A124-4109-8F19-494A30960517"><omgdi:waypoint x="980.0" y="244.95000000000005"></omgdi:waypoint><omgdi:waypoint x="980.0000000000001" y="330.0000000000001"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-A80136A4-F0B6-4D44-8FE2-5A90222B4098" id="BPMNEdge_sid-A80136A4-F0B6-4D44-8FE2-5A90222B4098"><omgdi:waypoint x="805.4941507226092" y="205.4507772047075"></omgdi:waypoint><omgdi:waypoint x="930.0000000000001" y="205.1290697605505"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-16D20EE3-771C-4661-9263-866A5CCF3810" id="BPMNEdge_sid-16D20EE3-771C-4661-9263-866A5CCF3810"><omgdi:waypoint x="720.4388557084811" y="205.50000000000003"></omgdi:waypoint><omgdi:waypoint x="766.4999896685282" y="205.50000000000003"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-1CD70A74-857F-4337-88D3-E1E5DBC792AA" id="BPMNEdge_sid-1CD70A74-857F-4337-88D3-E1E5DBC792AA"><omgdi:waypoint x="544.9500000000002" y="309.3365078929854"></omgdi:waypoint><omgdi:waypoint x="689.4770892197312" y="213.45715680232504"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-2CA45C90-704C-4997-8B40-86035D7C621A" id="BPMNEdge_sid-2CA45C90-704C-4997-8B40-86035D7C621A"><omgdi:waypoint x="380.5000000000001" y="185.50000000000006"></omgdi:waypoint><omgdi:waypoint x="380.5000000000001" y="100.0"></omgdi:waypoint><omgdi:waypoint x="444.999999999983" y="100.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-CFE54A2B-9F6F-464B-B7F9-D38C4DD34A6E" id="BPMNEdge_sid-CFE54A2B-9F6F-464B-B7F9-D38C4DD34A6E"><omgdi:waypoint x="786.4999896685282" y="224.44316378066384"></omgdi:waypoint><omgdi:waypoint x="786.4999896685282" y="344.0000000000001"></omgdi:waypoint><omgdi:waypoint x="966.0000000000001" y="344.0000000000001"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-74F05C08-50E4-46A1-BAA8-AD00A296B3C2" id="BPMNEdge_sid-74F05C08-50E4-46A1-BAA8-AD00A296B3C2"><omgdi:waypoint x="380.5000000000001" y="224.44094168260042"></omgdi:waypoint><omgdi:waypoint x="380.5000000000001" y="310.0000000000002"></omgdi:waypoint><omgdi:waypoint x="444.9999999999995" y="310.0000000000002"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-DA073FDE-7717-490A-BCDC-C45FDAC2C667" id="BPMNEdge_sid-DA073FDE-7717-490A-BCDC-C45FDAC2C667"><omgdi:waypoint x="89.94999883049303" y="205.00000000000003"></omgdi:waypoint><omgdi:waypoint x="150.00000000000003" y="205.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-85281FCE-FD40-4407-80A3-D03098778472" id="BPMNEdge_sid-85281FCE-FD40-4407-80A3-D03098778472"><omgdi:waypoint x="544.9500000000002" y="100.63535036028094"></omgdi:waypoint><omgdi:waypoint x="689.006094526336" y="196.98473250836068"></omgdi:waypoint></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>

部署流程并启动流程

/*** 部署流程*/@Testpublic void deployment() {//获取流程引擎ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();//获取RepositoryService部署流程RepositoryService repositoryService = processEngine.getRepositoryService();repositoryService.createDeployment().name("并行网关流程").addClasspathResource("并行网关.bpmn20.xml").deploy();}/*** 启动流程*/@Testpublic void startProcess() {//获取流程引擎ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();//获取RuntimeService启动流程实例RuntimeService runtimeService = processEngine.getRuntimeService();//参数是act_re_procdef表的主键runtimeService.startProcessInstanceById("并行网关:1:55004");}

执行完成后,会有一条员工的任务:

员工完成任务

/*** 员工完成任务*/@Testpublic void completeTask() {//获取流程引擎ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();//获取TaskService完成任务TaskService taskService = processEngine.getTaskService();//直接查询 "员工"的任务Task task = taskService.createTaskQuery().processInstanceId("57501").taskAssignee("员工").singleResult();//在后面总经理审批前端排他网关有个 请假天数的流程变量,这里也同步设置下//这里设置的num=2.也就是最后不需要总经理审批,流程就结束了。Map<String, Object> variables = new HashMap<>();variables.put("num", 2);if (task != null) {taskService.setVariables(task.getId(), variables);taskService.complete(task.getId());}}

查看act_ru_task表:

在员工完成任务后,任务表生成了两条记录,即并行网关有几个分支,就会生成几个任务记录。并且,必须要等多个分支任务都完成后汇聚到一起,再流转到下一节点任务

还有一点:即使我们并行网关设置了条件,且代码中设置的流程变量只满足了一个条件,但依旧产生了两条任务,也就是并行网关并不会去解析我们设置的条件的

现在完成项目经理和技术经理的

/*** 项目经理完成任务*/@Testpublic void completeTask2() {//获取流程引擎ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();//获取TaskService完成任务TaskService taskService = processEngine.getTaskService();//直接查询 "项目经理"的任务Task task = taskService.createTaskQuery().processInstanceId("57501").taskAssignee("项目经理").singleResult();if (task != null) {taskService.complete(task.getId());}}

项目经理任务完成后,表中还有一条技术经理的任务,所以还需要把技术经理的任务完成

/*** 技术经理完成任务*/@Testpublic void completeTask3() {//获取流程引擎ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();//获取TaskService完成任务TaskService taskService = processEngine.getTaskService();//直接查询 "技术经理"的任务Task task = taskService.createTaskQuery().processInstanceId("57501").taskAssignee("技术经理").singleResult();if (task != null) {taskService.complete(task.getId());}}

等技术经理完成任务后,流程就结束了,因为在员工任务的那一步,num设置为2,不需要由总经理审批。act_ru_task表汇总已经没有该流程记录了。

这里的项目经理和技术经理审批没有前后顺序,不管哪个先执行完,都要等对方执行完后,流程才会走到下一个节点。

包容网关

可以把**包容网关(inclusive gateway)**看做排他网关与并行网关的组合。与排他网关一样,可以在包容网关的出口顺序流上定义条件,包容网关会计算条件。然而主要的区别是,包容网关与并行网关一样,可以同时选择多于一条出口顺序流。

包容网关的功能取决于其入口与出口顺序流:

  • **分支:**流程会计算所有出口顺序流的条件。对于每一条计算为true的顺序流,流程都会创建一个并行执行。
  • **合并:**所有到达包容网关的并行执行,都会在网关处等待。直到每一条具有流程标志(process token)的入口顺序流,都有一个执行到达。这是与并行网关的重要区别。换句话说,包容网关只会等待可以被执行的入口顺序流。在合并后,流程穿过合并并行网关继续。

并行网关不计算连线条件,包容网关计算连线条件

案例:

为了简单,各个处理人流程变量写死了,使用了固定的。请假天数使用了流程变量,动态赋值。

<?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="包容网关" name="包容网关" isExecutable="true"><startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent><userTask id="sid-0DCBDEE3-B939-457F-81E6-14E6E0A6D1AE" 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-3B8158BD-B863-4354-A77B-DCD8BD1BF8F5" sourceRef="startEvent1" targetRef="sid-0DCBDEE3-B939-457F-81E6-14E6E0A6D1AE"></sequenceFlow><inclusiveGateway id="sid-DB0D31B0-7BB9-42F9-BCA2-DBEC809D4BB4"></inclusiveGateway><sequenceFlow id="sid-53ADAEED-2483-4108-BD89-CF9918C3B5EB" sourceRef="sid-0DCBDEE3-B939-457F-81E6-14E6E0A6D1AE" targetRef="sid-DB0D31B0-7BB9-42F9-BCA2-DBEC809D4BB4"></sequenceFlow><userTask id="sid-71845E25-6DDB-44FD-B75A-577B5B5A1258" 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-1FC17612-09D0-4556-AC18-C6AA82237B0D" sourceRef="sid-DB0D31B0-7BB9-42F9-BCA2-DBEC809D4BB4" targetRef="sid-71845E25-6DDB-44FD-B75A-577B5B5A1258"></sequenceFlow><userTask id="sid-A33CB996-CB7C-41ED-9E47-6F8D5D66EE0B" 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><userTask id="sid-5B285DC0-F880-4BCC-96A7-C62A1E4788BC" 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><inclusiveGateway id="sid-A13889FC-DA2F-4129-A30E-C326F2EEC622"></inclusiveGateway><sequenceFlow id="sid-9496724F-66CB-4A4B-8640-806DFD35ADB9" sourceRef="sid-71845E25-6DDB-44FD-B75A-577B5B5A1258" targetRef="sid-A13889FC-DA2F-4129-A30E-C326F2EEC622"></sequenceFlow><sequenceFlow id="sid-5CED40BA-6EB0-41FF-9362-1493F58E82C0" sourceRef="sid-A33CB996-CB7C-41ED-9E47-6F8D5D66EE0B" targetRef="sid-A13889FC-DA2F-4129-A30E-C326F2EEC622"></sequenceFlow><sequenceFlow id="sid-0F650643-CA7A-43B8-AD04-05E8E54931AF" sourceRef="sid-5B285DC0-F880-4BCC-96A7-C62A1E4788BC" targetRef="sid-A13889FC-DA2F-4129-A30E-C326F2EEC622"></sequenceFlow><exclusiveGateway id="sid-0198D14F-B09E-4350-AEAC-9292F294A0D8"></exclusiveGateway><sequenceFlow id="sid-78A66DA3-FE93-4D73-8260-DC5FAB377774" sourceRef="sid-A13889FC-DA2F-4129-A30E-C326F2EEC622" targetRef="sid-0198D14F-B09E-4350-AEAC-9292F294A0D8"></sequenceFlow><userTask id="sid-949CF3A5-656E-4954-A4F7-FAEC52B5EB88" 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><endEvent id="sid-E3CE8A59-62F6-456A-BE08-F4720D0229B2"></endEvent><sequenceFlow id="sid-BE51CF9A-DD82-4310-B6C2-C1416F59C8FF" sourceRef="sid-949CF3A5-656E-4954-A4F7-FAEC52B5EB88" targetRef="sid-E3CE8A59-62F6-456A-BE08-F4720D0229B2"></sequenceFlow><sequenceFlow id="sid-EB24D5B1-D33A-4434-B723-1B482463F814" name="请假天数小于等于3天" sourceRef="sid-DB0D31B0-7BB9-42F9-BCA2-DBEC809D4BB4" targetRef="sid-5B285DC0-F880-4BCC-96A7-C62A1E4788BC"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${num<=3}]]></conditionExpression></sequenceFlow><sequenceFlow id="sid-940D20A4-CC02-467C-976A-205A0C54E646" name="请假天数大于3天" sourceRef="sid-0198D14F-B09E-4350-AEAC-9292F294A0D8" targetRef="sid-949CF3A5-656E-4954-A4F7-FAEC52B5EB88"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${num>3}]]></conditionExpression></sequenceFlow><sequenceFlow id="sid-8194D419-4AD3-45DF-99B0-A9DA9F7F1AB2" name="请假天数小于等于3天" sourceRef="sid-0198D14F-B09E-4350-AEAC-9292F294A0D8" targetRef="sid-E3CE8A59-62F6-456A-BE08-F4720D0229B2"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${num<=3}]]></conditionExpression></sequenceFlow><sequenceFlow id="sid-FB2ACF7F-47DD-4D66-99C4-32496B190D23" name="请假天数大于3天" sourceRef="sid-DB0D31B0-7BB9-42F9-BCA2-DBEC809D4BB4" targetRef="sid-A33CB996-CB7C-41ED-9E47-6F8D5D66EE0B"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${num > 3}]]></conditionExpression></sequenceFlow></process><bpmndi:BPMNDiagram id="BPMNDiagram_包容网关"><bpmndi:BPMNPlane bpmnElement="包容网关" id="BPMNPlane_包容网关"><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-0DCBDEE3-B939-457F-81E6-14E6E0A6D1AE" id="BPMNShape_sid-0DCBDEE3-B939-457F-81E6-14E6E0A6D1AE"><omgdc:Bounds height="80.0" width="100.0" x="175.0" y="138.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-DB0D31B0-7BB9-42F9-BCA2-DBEC809D4BB4" id="BPMNShape_sid-DB0D31B0-7BB9-42F9-BCA2-DBEC809D4BB4"><omgdc:Bounds height="40.0" width="40.0" x="360.00000000000006" y="158.00000000000003"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-71845E25-6DDB-44FD-B75A-577B5B5A1258" id="BPMNShape_sid-71845E25-6DDB-44FD-B75A-577B5B5A1258"><omgdc:Bounds height="80.0" width="99.99999999999994" x="495.00000000000006" y="138.00000000000003"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-A33CB996-CB7C-41ED-9E47-6F8D5D66EE0B" id="BPMNShape_sid-A33CB996-CB7C-41ED-9E47-6F8D5D66EE0B"><omgdc:Bounds height="80.0" width="99.99999999999994" x="495.00000000000006" y="15.000000000000002"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-5B285DC0-F880-4BCC-96A7-C62A1E4788BC" id="BPMNShape_sid-5B285DC0-F880-4BCC-96A7-C62A1E4788BC"><omgdc:Bounds height="79.99999999999997" width="99.99999999999994" x="495.00000000000006" y="255.00000000000003"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-A13889FC-DA2F-4129-A30E-C326F2EEC622" id="BPMNShape_sid-A13889FC-DA2F-4129-A30E-C326F2EEC622"><omgdc:Bounds height="40.0" width="40.0" x="720.0000000000001" y="158.99999735090472"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-0198D14F-B09E-4350-AEAC-9292F294A0D8" id="BPMNShape_sid-0198D14F-B09E-4350-AEAC-9292F294A0D8"><omgdc:Bounds height="40.0" width="40.0" x="810.0000000000001" y="158.99999735090475"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-949CF3A5-656E-4954-A4F7-FAEC52B5EB88" id="BPMNShape_sid-949CF3A5-656E-4954-A4F7-FAEC52B5EB88"><omgdc:Bounds height="80.0" width="99.99999999999989" x="975.0000000000001" y="138.99999735090478"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-E3CE8A59-62F6-456A-BE08-F4720D0229B2" id="BPMNShape_sid-E3CE8A59-62F6-456A-BE08-F4720D0229B2"><omgdc:Bounds height="28.0" width="27.999999999999886" x="1011.0000000000001" y="300.0000000000002"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNEdge bpmnElement="sid-FB2ACF7F-47DD-4D66-99C4-32496B190D23" id="BPMNEdge_sid-FB2ACF7F-47DD-4D66-99C4-32496B190D23"><omgdi:waypoint x="380.5" y="158.50000000000006"></omgdi:waypoint><omgdi:waypoint x="380.5" y="55.0"></omgdi:waypoint><omgdi:waypoint x="495.00000000000006" y="55.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-53ADAEED-2483-4108-BD89-CF9918C3B5EB" id="BPMNEdge_sid-53ADAEED-2483-4108-BD89-CF9918C3B5EB"><omgdi:waypoint x="274.95000000000005" y="178.00000000000003"></omgdi:waypoint><omgdi:waypoint x="360.00000000000006" y="178.00000000000003"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-0F650643-CA7A-43B8-AD04-05E8E54931AF" id="BPMNEdge_sid-0F650643-CA7A-43B8-AD04-05E8E54931AF"><omgdi:waypoint x="594.95" y="294.2054794339103"></omgdi:waypoint><omgdi:waypoint x="728.8549619447492" y="187.83282189079196"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-5CED40BA-6EB0-41FF-9362-1493F58E82C0" id="BPMNEdge_sid-5CED40BA-6EB0-41FF-9362-1493F58E82C0"><omgdi:waypoint x="594.95" y="55.80684929783127"></omgdi:waypoint><omgdi:waypoint x="729.1814141844062" y="169.81481227182869"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-940D20A4-CC02-467C-976A-205A0C54E646" id="BPMNEdge_sid-940D20A4-CC02-467C-976A-205A0C54E646"><omgdi:waypoint x="849.4939335394128" y="179.4510282787398"></omgdi:waypoint><omgdi:waypoint x="974.9999999999909" y="179.12840352057057"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-78A66DA3-FE93-4D73-8260-DC5FAB377774" id="BPMNEdge_sid-78A66DA3-FE93-4D73-8260-DC5FAB377774"><omgdi:waypoint x="759.4394839067457" y="179.49999735090472"></omgdi:waypoint><omgdi:waypoint x="810.5000000000001" y="179.49999735090472"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-9496724F-66CB-4A4B-8640-806DFD35ADB9" id="BPMNEdge_sid-9496724F-66CB-4A4B-8640-806DFD35ADB9"><omgdi:waypoint x="594.9499999999969" y="178.2561531675779"></omgdi:waypoint><omgdi:waypoint x="720.0576233913223" y="178.8979568035149"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-BE51CF9A-DD82-4310-B6C2-C1416F59C8FF" id="BPMNEdge_sid-BE51CF9A-DD82-4310-B6C2-C1416F59C8FF"><omgdi:waypoint x="1025.0" y="218.9499973509048"></omgdi:waypoint><omgdi:waypoint x="1025.0" y="300.0000000000002"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-EB24D5B1-D33A-4434-B723-1B482463F814" id="BPMNEdge_sid-EB24D5B1-D33A-4434-B723-1B482463F814"><omgdi:waypoint x="380.5" y="197.4418739279589"></omgdi:waypoint><omgdi:waypoint x="380.5" y="295.0"></omgdi:waypoint><omgdi:waypoint x="495.00000000000006" y="295.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-8194D419-4AD3-45DF-99B0-A9DA9F7F1AB2" id="BPMNEdge_sid-8194D419-4AD3-45DF-99B0-A9DA9F7F1AB2"><omgdi:waypoint x="830.5000000000001" y="198.44295797511467"></omgdi:waypoint><omgdi:waypoint x="830.5000000000001" y="314.0000000000002"></omgdi:waypoint><omgdi:waypoint x="1011.0000000000001" y="314.0000000000002"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-1FC17612-09D0-4556-AC18-C6AA82237B0D" id="BPMNEdge_sid-1FC17612-09D0-4556-AC18-C6AA82237B0D"><omgdi:waypoint x="399.50196526508" y="178.44207317073173"></omgdi:waypoint><omgdi:waypoint x="494.9999999999919" y="178.15182370820668"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-3B8158BD-B863-4354-A77B-DCD8BD1BF8F5" id="BPMNEdge_sid-3B8158BD-B863-4354-A77B-DCD8BD1BF8F5"><omgdi:waypoint x="129.9499984899576" y="178.0"></omgdi:waypoint><omgdi:waypoint x="174.9999999999917" y="178.0"></omgdi:waypoint></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>

部署流程并启动流程

/*** 部署流程*/@Testpublic void deployment() {//获取流程引擎ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();//获取RepositoryService部署流程RepositoryService repositoryService = processEngine.getRepositoryService();repositoryService.createDeployment().name("包容网关").addClasspathResource("包容网关.bpmn20.xml").deploy();}/*** 启动流程定义*/@Testpublic void startProcess() {//获取流程引擎ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();//获取RuntimeService启动流程RuntimeService runtimeService = processEngine.getRuntimeService();//参数是act_re_procdef表的主键runtimeService.startProcessInstanceById("包容网关:1:67504");}

启动完成后,第一个任务由员工完成

查看act_ru_task表:

员工完成任务

在员工完成任务通向的下一个任务节点是包容网关,有请假天数的流程变量,需要设置下

之后根据请假天数的流程变量,包容网关判断条件并走向下一个任务节点。

/*** 员工完成任务*/@Testpublic void completeTask() {//获取流程引擎ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();TaskService taskService = processEngine.getTaskService();Task task = taskService.createTaskQuery().processInstanceId("70001").taskAssignee("员工").singleResult();if (task != null) {//设置请假天数流程变量Map<String, Object> variables = new HashMap<>();variables.put("num", 2);/*** 这里员工完成任务后,请假天数是2,按照包容网关的流程设计,该流程后续需要由项目经理过和人事经理审批。* 项目经理:连线未设置条件,本身就要执行* 人事经理:请假天数小于等于3天,满足* 技术经理:请假天数大于3天,不满足*/taskService.complete(task.getId(), variables);}}

刷新act_ru_task表:包容网关流程出现了两个待处理的流程任务,包容网关生效

项目经理和人事经理完成任务

/*** 项目经理和人事经理完成任务*/@Testpublic void completeTask2() {//获取流程引擎ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();TaskService taskService = processEngine.getTaskService();/*** 项目经理和人事经理任务完成后,流程要么由总经理审批要么就直接结束了。* 通过排他网关判断,流程变量num不更新了,还是用开始员工申请的。*/Task task = taskService.createTaskQuery().processInstanceId("70001").taskAssignee("项目经理").singleResult();taskService.complete(task.getId());Task task2 = taskService.createTaskQuery().processInstanceId("70001").taskAssignee("人事经理").singleResult();taskService.complete(task2.getId());}

根据条件,项目经理和人事经理完成任务后,流程直接结束。

事件网关

基于事件的网关(event-based gateway)提供了根据事件做选择的方式。网关的每一条出口顺序流都需要连接至一个捕获中间事件。当流程执行到达基于事件的网关时,与等待状态类似,网关会暂停执行,并且为每一条出口顺序流创建一个事件订阅。

请注意:基于事件的网关的出口顺序流与一般的顺序流不同。这些顺序流从不实际执行。相反,它们用于告知流程引擎:当执行到达一个基于事件的网关时,需要订阅什么事件。有以下限制:

  • 一个基于事件的网关,必须有两条或更多的出口顺序流。
  • 基于事件的网关,只能连接至intermediateCatchEvent(捕获中间事件)类型的元素(Flowable不支持在基于事件的网关之后连接“接收任务 Receive Task”)。
  • 连接至基于事件的网关的intermediateCatchEvent,必须只有一个入口顺序流。

事件网关的执行原理?

网关的每一条出口顺序流,都需要连接至一个捕获中间事件。当流程执行到达基于事件的网关时,网关类似等待状态地动作:执行被暂停。并且,为每一条出口顺序流,创建一个事件订阅。流程的走向完全是由于中间事件的选择。而由哪一个事件来决定流程的走向则是由最先触发的事件来决定的。

案例:

定时器事件:

信号事件:

<?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="事件网关" name="事件网关" isExecutable="true"><startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent><sequenceFlow id="sid-E204C4A5-F9B7-48B5-88FF-B6325DCA0769" sourceRef="startEvent1" targetRef="sid-43904403-79A9-4FE7-9FFD-5FEB257ADDCB"></sequenceFlow><eventBasedGateway id="sid-43904403-79A9-4FE7-9FFD-5FEB257ADDCB"></eventBasedGateway><sequenceFlow id="sid-6906925E-B2EE-4976-A64E-109A9E111259" sourceRef="sid-43904403-79A9-4FE7-9FFD-5FEB257ADDCB" targetRef="sid-765C195E-D36E-4E61-9964-D0662AF8CF1C"></sequenceFlow><intermediateCatchEvent id="sid-765C195E-D36E-4E61-9964-D0662AF8CF1C" name="信号事件"><extensionElements><flowable:executionListener event="start" class="org.flowable.SignalListener"></flowable:executionListener></extensionElements><signalEventDefinition flowable:signalExpression="signal"></signalEventDefinition></intermediateCatchEvent><sequenceFlow id="sid-F81DE925-5C59-408A-8BDC-AEF6CF083291" sourceRef="sid-43904403-79A9-4FE7-9FFD-5FEB257ADDCB" targetRef="sid-6F3A9DE5-393A-47F8-ABB7-1BE95B235682"></sequenceFlow><intermediateCatchEvent id="sid-6F3A9DE5-393A-47F8-ABB7-1BE95B235682" name="定时器事件"><extensionElements><flowable:executionListener event="start" class="org.flowable.TimerListener"></flowable:executionListener></extensionElements><timerEventDefinition><timeDuration>PT5M</timeDuration></timerEventDefinition></intermediateCatchEvent><userTask id="sid-6F5EC168-C69A-481F-B42C-BE4BF455B369" 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-3286967C-437E-4E2B-9FFC-8CE12C97D873" sourceRef="sid-6F3A9DE5-393A-47F8-ABB7-1BE95B235682" targetRef="sid-6F5EC168-C69A-481F-B42C-BE4BF455B369"></sequenceFlow><userTask id="sid-05EA646F-4C32-417F-97CE-A6994C669423" 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-BFC9E70F-40FD-4511-811D-EF2FE00276CA" sourceRef="sid-765C195E-D36E-4E61-9964-D0662AF8CF1C" targetRef="sid-05EA646F-4C32-417F-97CE-A6994C669423"></sequenceFlow><exclusiveGateway id="sid-0DDD1C8E-2F1D-411F-8526-67BE4429AA36"></exclusiveGateway><sequenceFlow id="sid-5D37B051-283A-46B1-A805-D6CF3D780519" sourceRef="sid-05EA646F-4C32-417F-97CE-A6994C669423" targetRef="sid-0DDD1C8E-2F1D-411F-8526-67BE4429AA36"></sequenceFlow><sequenceFlow id="sid-E8E4C682-4568-4F9A-A822-4D5303790E54" sourceRef="sid-6F5EC168-C69A-481F-B42C-BE4BF455B369" targetRef="sid-0DDD1C8E-2F1D-411F-8526-67BE4429AA36"></sequenceFlow><endEvent id="sid-153F6F8A-A65D-4361-B2B5-A41D07F7A916"></endEvent><sequenceFlow id="sid-C0F86710-98FC-4A36-BD6F-B7D31525B3D8" sourceRef="sid-0DDD1C8E-2F1D-411F-8526-67BE4429AA36" targetRef="sid-153F6F8A-A65D-4361-B2B5-A41D07F7A916"></sequenceFlow></process><bpmndi:BPMNDiagram id="BPMNDiagram_事件网关"><bpmndi:BPMNPlane bpmnElement="事件网关" id="BPMNPlane_事件网关"><bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1"><omgdc:Bounds height="30.0" width="29.999999999999986" x="105.00000000000001" y="307.25"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-43904403-79A9-4FE7-9FFD-5FEB257ADDCB" id="BPMNShape_sid-43904403-79A9-4FE7-9FFD-5FEB257ADDCB"><omgdc:Bounds height="40.0" width="40.0" x="180.0" y="302.25"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-765C195E-D36E-4E61-9964-D0662AF8CF1C" id="BPMNShape_sid-765C195E-D36E-4E61-9964-D0662AF8CF1C"><omgdc:Bounds height="29.999999999999943" width="30.0" x="350.93750000000057" y="394.25000000000006"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-6F3A9DE5-393A-47F8-ABB7-1BE95B235682" id="BPMNShape_sid-6F3A9DE5-393A-47F8-ABB7-1BE95B235682"><omgdc:Bounds height="31.0" width="31.0" x="350.4375000000005" y="189.50000000000003"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-6F5EC168-C69A-481F-B42C-BE4BF455B369" id="BPMNShape_sid-6F5EC168-C69A-481F-B42C-BE4BF455B369"><omgdc:Bounds height="80.0" width="99.99999999999994" x="486.4375000000005" y="165.00000000000003"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-05EA646F-4C32-417F-97CE-A6994C669423" id="BPMNShape_sid-05EA646F-4C32-417F-97CE-A6994C669423"><omgdc:Bounds height="79.99999999999994" width="99.99999999999994" x="485.00000000000006" y="369.25000000000006"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-0DDD1C8E-2F1D-411F-8526-67BE4429AA36" id="BPMNShape_sid-0DDD1C8E-2F1D-411F-8526-67BE4429AA36"><omgdc:Bounds height="40.0" width="40.0" x="695.0000000000001" y="302.25000000000006"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-153F6F8A-A65D-4361-B2B5-A41D07F7A916" id="BPMNShape_sid-153F6F8A-A65D-4361-B2B5-A41D07F7A916"><omgdc:Bounds height="28.0" width="28.0" x="800.0000000000001" y="308.25000000000006"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNEdge bpmnElement="sid-E8E4C682-4568-4F9A-A822-4D5303790E54" id="BPMNEdge_sid-E8E4C682-4568-4F9A-A822-4D5303790E54"><omgdi:waypoint x="586.3875000000005" y="237.79880994049714"></omgdi:waypoint><omgdi:waypoint x="702.9176593587632" y="314.32268117473063"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-E204C4A5-F9B7-48B5-88FF-B6325DCA0769" id="BPMNEdge_sid-E204C4A5-F9B7-48B5-88FF-B6325DCA0769"><omgdi:waypoint x="134.9496588110467" y="322.34285545292164"></omgdi:waypoint><omgdi:waypoint x="180.375" y="322.625"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-F81DE925-5C59-408A-8BDC-AEF6CF083291" id="BPMNEdge_sid-F81DE925-5C59-408A-8BDC-AEF6CF083291"><omgdi:waypoint x="200.5" y="302.75"></omgdi:waypoint><omgdi:waypoint x="200.5" y="205.76229508196724"></omgdi:waypoint><omgdi:waypoint x="350.4375000000005" y="205.76229508196724"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-BFC9E70F-40FD-4511-811D-EF2FE00276CA" id="BPMNEdge_sid-BFC9E70F-40FD-4511-811D-EF2FE00276CA"><omgdi:waypoint x="380.8874993605693" y="409.25"></omgdi:waypoint><omgdi:waypoint x="484.99999999982083" y="409.25"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-C0F86710-98FC-4A36-BD6F-B7D31525B3D8" id="BPMNEdge_sid-C0F86710-98FC-4A36-BD6F-B7D31525B3D8"><omgdi:waypoint x="734.536926605502" y="322.6530612244898"></omgdi:waypoint><omgdi:waypoint x="800.0001739538704" y="322.3208114867363"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-3286967C-437E-4E2B-9FFC-8CE12C97D873" id="BPMNEdge_sid-3286967C-437E-4E2B-9FFC-8CE12C97D873"><omgdi:waypoint x="382.3874324391424" y="205.45294137580157"></omgdi:waypoint><omgdi:waypoint x="486.4374999999986" y="205.1469117647059"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-5D37B051-283A-46B1-A805-D6CF3D780519" id="BPMNEdge_sid-5D37B051-283A-46B1-A805-D6CF3D780519"><omgdi:waypoint x="584.95" y="408.59220532319387"></omgdi:waypoint><omgdi:waypoint x="703.4357798165138" y="330.6659403669725"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-6906925E-B2EE-4976-A64E-109A9E111259" id="BPMNEdge_sid-6906925E-B2EE-4976-A64E-109A9E111259"><omgdi:waypoint x="200.5" y="341.68915237511607"></omgdi:waypoint><omgdi:waypoint x="200.5" y="409.9963094587207"></omgdi:waypoint><omgdi:waypoint x="350.93750000000057" y="409.99630945872065"></omgdi:waypoint></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>

监听器

//信号监听器
public class SignalListener implements TaskListener, ExecutionListener {@Overridepublic void notify(DelegateExecution execution) {System.out.println("信号事件:执行监听器执行了...");}@Overridepublic void notify(DelegateTask delegateTask) {System.out.println("信号事件:任务监听器执行了...");}
}
//定时监听器
public class TimerListener implements TaskListener, ExecutionListener {@Overridepublic void notify(DelegateExecution execution) {System.out.println("定时事件:执行监听器执行了...");}@Overridepublic void notify(DelegateTask delegateTask) {System.out.println("定时事件:任务监听器执行了...");}
}

技术经理和项目经理的分配人就在流程固定设置为技术经理项目经理

部署流程和启动流程

/*** 部署流程*/@Testpublic void deployment() {//获取流程引擎ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();//获取RepositoryService部署流程RepositoryService repositoryService = processEngine.getRepositoryService();repositoryService.createDeployment().name("事件网关").addClasspathResource("事件网关.bpmn20.xml").deploy();}/*** 启动流程定义*/@Testpublic void startProcess() {//获取流程引擎ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();//获取RuntimeService启动流程RuntimeService runtimeService = processEngine.getRuntimeService();//参数是act_re_procdef表的主键runtimeService.startProcessInstanceById("事件网关:1:77504");}

流程启动后,act_ru_task中不会有任务生成,只有定时或者信号事件任意一个触发后才会生成任务。

通过代码主动触发信号任务:

/*** 触发信号*/@Testpublic void createSign() {ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();RuntimeService runtimeService = processEngine.getRuntimeService();List<Execution> executions = runtimeService.createExecutionQuery().signalEventSubscriptionName("signal").list();for (Execution execution : executions) {//发送信号runtimeService.signalEventReceived("signal", execution.getId());}}

之后,查看act_ru_task表,可以看到流程任务为项目经理,按照流程设计,信号事件的下一个节点就是项目经理审批。

如果什么都不操作,按照流程设计,五分钟后触发定时事件,流程会走到技术经理审批节点。

【flowable】十、flowable网关相关推荐

  1. 小白学流程引擎-FLowable(一) —FLowable是什么

    小白学流程引擎-FLowable(一) | FLowable是什么 一.什么是流程引擎? 通俗的说,流程引擎就是多种业务对象在一起合作完成某件事情的步骤,把步骤变成计算机能理解的形式就是流程引擎. 流 ...

  2. 体验一把 Flowable 三种常见网关

    Flowable 中网关类型其实也不少,常见的主要有三种类型,分别是: 排他网关 并行网关 包容网关 这三个里边最常用的当然就是排他网关了,今天松哥就来和小伙伴们聊一聊这三种网关,一起来体验一把这三种 ...

  3. flowable php,flowable demo

    [实例简介] 开发工具:idea,环境:jdk.maven.rocketmq,技术:spring boot + flowable 实现简单的工作流程,希望能有所帮助. [实例截图] [核心代码] fl ...

  4. 【Flowable】Flowable流程设计器

    Flowable流程设计器有两种实现方式 Eclipse Designer Flowable UI应用 1.Eclipse Designer Flowable提供了名为Flowable Eclipse ...

  5. 【Flowable】Flowable候选人和候选人组

    在流程定义中在任务结点的 assignee 固定设置任务负责人,在流程定义时将参与者固定设置在.bpmn 文件中,如果临时任务负责人变更则需要修改流程定义,系统可扩展性差.针对这种情况可以给任务设置多 ...

  6. Flowable入门系列文章41 - 网关 03

    基于事件的网关 描述 基于事件的网关提供了一种基于事件做出决定的方式.网关的每个出站序列流都需要连接到中间捕获事件.当进程执行到达一个基于事件的网关时,网关就像一个等待状态:暂停执行.另外,对于每个外 ...

  7. 学习记录605@flowable之moveExecutionsToSingleActivityId并行网关或者包容网关回退

    遇到网关的回退场景,记录一下,部分内容是推测的. 流程图 bpmn <?xml version="1.0" encoding="UTF-8"?> & ...

  8. Flowable学习笔记(二、BPMN 2.0-基础 )

    转载自  Flowable学习笔记(二.BPMN 2.0-基础 ) 1.BPMN简介 业务流程模型和标记法(BPMN, Business Process Model and Notation)是一套图 ...

  9. flowable,199boge,基础

    一 Flowable介绍 BPMN 一个软件协议,此协议用于约定了流程框架的开发规范.比如说,我们去绘制流程图的图标的规范. 基于这个规范,很方便地学习基于此规范的其它的流程框架. flowable是 ...

最新文章

  1. fx5u模拟量如何读取_FX5U系列三菱产品 使用模拟量时的注意事项
  2. Android开发——异步任务中Activity销毁时的问题
  3. 这 8 份「Paper + Code」,你一定用得上 | PaperDaily #08
  4. OCP考试052考试,新的考题还有答案整理-23题
  5. python路线选择试题_python例题练习
  6. Python+pandas使用交叉表分析超市营业额数据
  7. 前端—每天5道面试题(7)
  8. Python不能做游戏?游戏实战之-----《ink spill》(附游戏完整源码)
  9. React :caniuse-lite is outdated. please run next command
  10. ILSPY反编译工具下载代替收费的Reflector工具
  11. windowsR2(流媒体服务器)
  12. Vivado下使用Microblaze控制LED(vcu118,HLS级开发)
  13. 安装mysql数据库出现问题_安装mysql数据库及问题解决方法
  14. 推荐算法架构3:精排
  15. Adnroid Studio kotlin 报错AssertionError: Could not delete caches xxx kotlin\compileKotlin文件名太长
  16. python三菱fx3u通讯_【案例】三菱FX3UPLC的无线通讯讲解
  17. layui文件上传等待动画
  18. java集合入门和深入学习,看这篇就差不多了
  19. 2017.08.10小结
  20. Datawhale组队学习-NLP新闻文本分类-TASK06

热门文章

  1. 创新实训——飞讯(七)
  2. fping安装包linux,Linux系统--CentOS 7.6.1810 安装 fping 3.15
  3. 微信小程序api概述
  4. 获取手机设备号及存在的问题
  5. 2020高压电工证考试及高压电工模拟考试软件
  6. 带你了解一下reac框架
  7. wwise移植到linux平台,设立Wwise项目 - Lumberyard 用户指南
  8. 水泥混凝土摊铺机的作业中促进施工进度的措施
  9. 如何通过软件定义方案轻松实现卫星通信干扰测试?
  10. NLP学习笔记一(语言模型+NLM+Word2Vec)