系列学习 SpringBoot + Activiti7 工作流之第 6 篇 —— 【进阶篇】网关

查看之前的博客可以点击顶部的【分类专栏】
 

网关

网关用来控制流程的流向

1、排他网关 ExclusiveGateway(×图标)

排他网关,用来在流程中实现决策。 当流程执行到这个网关,所有分支都会判断条件是否为true,如果为true则执行该分支。排他网关只会选择一个为true的分支执行。如果有两个分支条件都为true,排他网关会选择id值较小的一条分支去执行。

 

为什么要用排他网关?

不用排他网关也可以实现分支,如:在连线的 condition 条件上设置分支条件。在连线设置 condition 条件的缺点:如果条件都不满足,流程就结束了(是异常结束)。

如果从网关出去的线所有条件都不满足则系统抛出异常。

org.activiti.engine.ActivitiException: No outgoing sequence flow of the exclusive gateway 'exclusivegateway1' could be selected for continuing the process
   at org.activiti.engine.impl.bpmn.behavior.ExclusiveGatewayActivityBehavior.leave(ExclusiveGatewayActivityBehavior.java:85)

画图:

 

apply4.xml 代码:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" 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" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1623659982391" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
  <process id="apply4" isClosed="false" isExecutable="true" name="排他网关测试" processType="None">
    <startEvent id="_2" name="流程开启"/>
    <userTask activiti:exclusive="true" id="_3" name="发起请假申请">
      <extensionElements>
        <activiti:taskListener class="com.study.listener.MyListener" event="create"/>
      </extensionElements>
    </userTask>
    <userTask activiti:exclusive="true" id="_4" name="主管审批">
      <extensionElements>
        <activiti:taskListener class="com.study.listener.MyListener" event="create"/>
      </extensionElements>
    </userTask>
    <endEvent id="_5" name="流程结束"/>
    <exclusiveGateway gatewayDirection="Unspecified" id="_6" name="请假天数判断"/>
    <userTask activiti:exclusive="true" id="_7" name="经理审批">
      <extensionElements>
        <activiti:taskListener class="com.study.listener.MyListener" event="create"/>
      </extensionElements>
    </userTask>
    <sequenceFlow id="_8" sourceRef="_2" targetRef="_3"/>
    <sequenceFlow id="_9" sourceRef="_3" targetRef="_4"/>
    <sequenceFlow id="_10" sourceRef="_4" targetRef="_6"/>
    <sequenceFlow id="_11" sourceRef="_6" targetRef="_5">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${applyEntity.day<3}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="_12" sourceRef="_6" targetRef="_7">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${applyEntity.day>=3}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="_13" sourceRef="_7" targetRef="_5"/>
  </process>
  <bpmndi:BPMNDiagram documentation="background=#FFFFFF;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
    <bpmndi:BPMNPlane bpmnElement="apply4">
      <bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
        <omgdc:Bounds height="32.0" width="32.0" x="235.0" y="70.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3">
        <omgdc:Bounds height="55.0" width="85.0" x="215.0" y="170.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_4" id="Shape-_4">
        <omgdc:Bounds height="55.0" width="85.0" x="215.0" y="270.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_5" id="Shape-_5">
        <omgdc:Bounds height="32.0" width="32.0" x="235.0" y="570.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_6" id="Shape-_6" isMarkerVisible="false">
        <omgdc:Bounds height="32.0" width="32.0" x="240.0" y="375.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_7" id="Shape-_7">
        <omgdc:Bounds height="55.0" width="85.0" x="345.0" y="480.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="_13" id="BPMNEdge__13" sourceElement="_7" targetElement="_5">
        <omgdi:waypoint x="390.0" y="535.0"/>
        <omgdi:waypoint x="390.0" y="565.0"/>
        <omgdi:waypoint x="267.0" y="586.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_12" id="BPMNEdge__12" sourceElement="_6" targetElement="_7">
        <omgdi:waypoint x="268.0" y="395.0"/>
        <omgdi:waypoint x="390.0" y="395.0"/>
        <omgdi:waypoint x="390.0" y="480.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="-60.0" width="0.0" x="1.0" y="66.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_8" id="BPMNEdge__8" sourceElement="_2" targetElement="_3">
        <omgdi:waypoint x="251.0" y="102.0"/>
        <omgdi:waypoint x="251.0" y="170.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_9" id="BPMNEdge__9" sourceElement="_3" targetElement="_4">
        <omgdi:waypoint x="257.5" y="225.0"/>
        <omgdi:waypoint x="257.5" y="270.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_11" id="BPMNEdge__11" sourceElement="_6" targetElement="_5">
        <omgdi:waypoint x="253.5" y="404.5"/>
        <omgdi:waypoint x="253.5" y="570.1965193707209"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="-2.0" width="0.0" x="0.0" y="-58.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_10" id="BPMNEdge__10" sourceElement="_4" targetElement="_6">
        <omgdi:waypoint x="256.0" y="325.0"/>
        <omgdi:waypoint x="256.0" y="375.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

测试。自行测试。

 

2、并行网关 ParallelGateway(+图标)

并行网关允许将流程分成多条分支,也可以把多条分支汇聚到一起,并行网关的功能是基于进入和外出顺序流的:

fork分支:并行后的所有外出顺序流,为每个顺序流都创建一个并发分支。

join汇聚:所有到达并行网关,在此等待的进入分支, 直到所有进入顺序流的分支都到达以后, 流程就会通过汇聚网关

注意,如果同一个并行网关有多个进入和多个外出顺序流, 它就同时具有分支和汇聚功能。 这时,网关会先汇聚所有进入的顺序流,然后再切分成多个并行分支。

与其他网关的主要区别是,并行网关不会解析条件,即使顺序流中定义了条件,也会被忽略。

 

 

我们新建一个并行网关 + 排他网关的例子

 

说明:员工请假,需要经过主管A审批和主管B审批,两个主管都审批通过后,然后汇聚起来,接着进入一个排他网关:如果请假天数超过3天,还需要经理审批,否者请假就通过了。

代码:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" 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" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1623661445874" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
  <process id="apply5" isClosed="false" isExecutable="true" name="并行网关测试" processType="None">
    <startEvent id="_2" name="流程开始"/>
    <userTask activiti:exclusive="true" id="_3" name="创建请假申请">
      <extensionElements>
        <activiti:taskListener class="com.study.listener.MyListener" event="create"/>
      </extensionElements>
    </userTask>
    <endEvent id="_4" name="流程结束"/>
    <parallelGateway gatewayDirection="Unspecified" id="_5" name="并行网关1"/>
    <userTask activiti:exclusive="true" id="_6" name="主管A审批">
      <extensionElements>
        <activiti:taskListener class="com.study.listener.MyListener" event="create"/>
      </extensionElements>
    </userTask>
    <userTask activiti:exclusive="true" id="_7" name="主管B审批">
      <extensionElements>
        <activiti:taskListener class="com.study.listener.MyListener" event="create"/>
      </extensionElements>
    </userTask>
    <sequenceFlow id="_8" sourceRef="_2" targetRef="_3"/>
    <sequenceFlow id="_9" sourceRef="_3" targetRef="_5"/>
    <sequenceFlow id="_10" sourceRef="_5" targetRef="_6"/>
    <sequenceFlow id="_11" sourceRef="_5" targetRef="_7"/>
    <userTask activiti:exclusive="true" id="_12" name="经理审批">
      <extensionElements>
        <activiti:taskListener class="com.study.listener.MyListener" event="create"/>
      </extensionElements>
    </userTask>
    <parallelGateway gatewayDirection="Unspecified" id="_13" name="并行网关2"/>
    <sequenceFlow id="_14" sourceRef="_6" targetRef="_13"/>
    <sequenceFlow id="_15" sourceRef="_7" targetRef="_13"/>
    <exclusiveGateway gatewayDirection="Unspecified" id="_16" name="排他网关"/>
    <sequenceFlow id="_17" sourceRef="_13" targetRef="_16"/>
    <sequenceFlow id="_18" sourceRef="_16" targetRef="_12">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${applyEntity.day>3}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="_19" sourceRef="_12" targetRef="_4"/>
    <sequenceFlow id="_20" sourceRef="_16" targetRef="_4">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${applyEntity.day<=3}]]></conditionExpression>
    </sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram documentation="background=#FFFFFF;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
    <bpmndi:BPMNPlane bpmnElement="apply5">
      <bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
        <omgdc:Bounds height="32.0" width="32.0" x="220.0" y="25.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3">
        <omgdc:Bounds height="55.0" width="85.0" x="195.0" y="100.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_4" id="Shape-_4">
        <omgdc:Bounds height="32.0" width="32.0" x="225.0" y="570.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_5" id="Shape-_5">
        <omgdc:Bounds height="32.0" width="32.0" x="225.0" y="175.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_6" id="Shape-_6">
        <omgdc:Bounds height="55.0" width="85.0" x="95.0" y="245.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_7" id="Shape-_7">
        <omgdc:Bounds height="55.0" width="85.0" x="300.0" y="245.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_12" id="Shape-_12">
        <omgdc:Bounds height="55.0" width="85.0" x="85.0" y="490.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_13" id="Shape-_13">
        <omgdc:Bounds height="32.0" width="32.0" x="225.0" y="340.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_16" id="Shape-_16" isMarkerVisible="false">
        <omgdc:Bounds height="32.0" width="32.0" x="225.0" y="420.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="_15" id="BPMNEdge__15" sourceElement="_7" targetElement="_13">
        <omgdi:waypoint x="345.0" y="300.0"/>
        <omgdi:waypoint x="345.0" y="315.0"/>
        <omgdi:waypoint x="257.0" y="356.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_14" id="BPMNEdge__14" sourceElement="_6" targetElement="_13">
        <omgdi:waypoint x="135.0" y="300.0"/>
        <omgdi:waypoint x="135.0" y="320.0"/>
        <omgdi:waypoint x="225.0" y="356.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_17" id="BPMNEdge__17" sourceElement="_13" targetElement="_16">
        <omgdi:waypoint x="241.0" y="372.0"/>
        <omgdi:waypoint x="241.0" y="420.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_19" id="BPMNEdge__19" sourceElement="_12" targetElement="_4">
        <omgdi:waypoint x="125.0" y="545.0"/>
        <omgdi:waypoint x="125.0" y="565.0"/>
        <omgdi:waypoint x="225.0" y="586.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_18" id="BPMNEdge__18" sourceElement="_16" targetElement="_12">
        <omgdi:waypoint x="225.0" y="436.0"/>
        <omgdi:waypoint x="125.0" y="516.0"/>
        <omgdi:waypoint x="125.0" y="490.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="-83.0" x="0.0" y="19.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_8" id="BPMNEdge__8" sourceElement="_2" targetElement="_3">
        <omgdi:waypoint x="236.0" y="57.0"/>
        <omgdi:waypoint x="236.0" y="100.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_9" id="BPMNEdge__9" sourceElement="_3" targetElement="_5">
        <omgdi:waypoint x="241.0" y="155.0"/>
        <omgdi:waypoint x="241.0" y="175.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_20" id="BPMNEdge__20" sourceElement="_16" targetElement="_4">
        <omgdi:waypoint x="241.0" y="452.0"/>
        <omgdi:waypoint x="241.0" y="570.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="-1.0" width="0.0" x="0.0" y="69.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_11" id="BPMNEdge__11" sourceElement="_5" targetElement="_7">
        <omgdi:waypoint x="257.0" y="191.0"/>
        <omgdi:waypoint x="345.0" y="235.0"/>
        <omgdi:waypoint x="345.0" y="245.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_10" id="BPMNEdge__10" sourceElement="_5" targetElement="_6">
        <omgdi:waypoint x="225.0" y="191.0"/>
        <omgdi:waypoint x="135.0" y="225.0"/>
        <omgdi:waypoint x="135.0" y="245.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

并行任务执行不分前后,由任务的负责人去执行即可。

总结:所有分支到达汇聚结点,并行网关执行完成。并行网关在业务应用中常用于会签任务,会签任务即多个参与者共同办理的任务。

 

3、包含网关 InclusiveGateway(O图标)

包含网关可以看做是排他网关和并行网关的结合体。

和排他网关一样,你可以在外出顺序流上定义条件,包含网关会解析它们。 但是主要的区别是包含网关可以选择多于一条顺序流,这和并行网关一样。

包含网关的功能是基于进入和外出顺序流的:

分支:所有外出顺序流的条件都会被解析,结果为true的顺序流会以并行方式继续执行, 会为每个顺序流创建一个分支。

汇聚:所有并行分支到达包含网关,会进入等待状态, 直到每个包含流程token的进入顺序流的分支都到达。 这是与并行网关的最大不同。换句话说,包含网关只会等待被选中执行了的进入顺序流。 在汇聚之后,流程会穿过包含网关继续执行。

需求:员工请假,如果小于3天,主管和人资审批。如果超过3天,经理和人资审批。也就是人资都要审批。因此我们在包含网关上不设置人资审批的条件。

如果是2天,那么就是主管和人资审批,然后要等到2个人都审批结束,才到第二个包含网关。然后进入排他网关,超过3天的,需要总裁审批,否则直接通过。

apply6.xml 代码:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" 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" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1623662681206" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
  <process id="apply6" isClosed="false" isExecutable="true" name="包含网关测试" processType="None">
    <endEvent id="_2" name="流程结束"/>
    <startEvent id="_3" name="流程开始"/>
    <userTask activiti:exclusive="true" id="_4" name="发起申请">
      <extensionElements>
        <activiti:taskListener class="com.study.listener.MyListener" event="create"/>
      </extensionElements>
    </userTask>
    <inclusiveGateway gatewayDirection="Unspecified" id="_5" name="包含网关1"/>
    <userTask activiti:exclusive="true" id="_6" name="主管审批">
      <extensionElements>
        <activiti:taskListener class="com.study.listener.MyListener" event="create"/>
      </extensionElements>
    </userTask>
    <userTask activiti:exclusive="true" id="_7" name="人资审批">
      <extensionElements>
        <activiti:taskListener class="com.study.listener.MyListener" event="create"/>
      </extensionElements>
    </userTask>
    <userTask activiti:exclusive="true" id="_8" name="经理审批">
      <extensionElements>
        <activiti:taskListener class="com.study.listener.MyListener" event="create"/>
      </extensionElements>
    </userTask>
    <inclusiveGateway gatewayDirection="Unspecified" id="_9" name="包含网关2"/>
    <exclusiveGateway gatewayDirection="Unspecified" id="_10" name="排他网关"/>
    <userTask activiti:exclusive="true" id="_11" name="总裁审批">
      <extensionElements>
        <activiti:taskListener class="com.study.listener.MyListener" event="create"/>
      </extensionElements>
    </userTask>
    <sequenceFlow id="_12" sourceRef="_3" targetRef="_4"/>
    <sequenceFlow id="_13" sourceRef="_4" targetRef="_5"/>
    <sequenceFlow id="_14" sourceRef="_5" targetRef="_6">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${applyEntity.day<3}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="_15" sourceRef="_5" targetRef="_7"/>
    <sequenceFlow id="_16" sourceRef="_5" targetRef="_8">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${applyEntity.day>=3}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="_17" sourceRef="_7" targetRef="_9"/>
    <sequenceFlow id="_18" sourceRef="_6" targetRef="_9"/>
    <sequenceFlow id="_19" sourceRef="_8" targetRef="_9"/>
    <sequenceFlow id="_20" sourceRef="_9" targetRef="_10"/>
    <sequenceFlow id="_21" sourceRef="_10" targetRef="_2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${applyEntity.day<3}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="_22" sourceRef="_10" targetRef="_11">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${applyEntity.day>=3}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="_23" sourceRef="_11" targetRef="_2"/>
  </process>
  <bpmndi:BPMNDiagram documentation="background=#FFFFFF;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
    <bpmndi:BPMNPlane bpmnElement="apply6">
      <bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
        <omgdc:Bounds height="32.0" width="32.0" x="310.0" y="520.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3">
        <omgdc:Bounds height="32.0" width="32.0" x="300.0" y="-10.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_4" id="Shape-_4">
        <omgdc:Bounds height="55.0" width="85.0" x="275.0" y="60.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_5" id="Shape-_5">
        <omgdc:Bounds height="32.0" width="32.0" x="300.0" y="145.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_6" id="Shape-_6">
        <omgdc:Bounds height="55.0" width="85.0" x="155.0" y="235.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_7" id="Shape-_7">
        <omgdc:Bounds height="55.0" width="85.0" x="275.0" y="230.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_8" id="Shape-_8">
        <omgdc:Bounds height="55.0" width="85.0" x="410.0" y="235.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_9" id="Shape-_9">
        <omgdc:Bounds height="32.0" width="32.0" x="305.0" y="325.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_10" id="Shape-_10" isMarkerVisible="false">
        <omgdc:Bounds height="32.0" width="32.0" x="305.0" y="415.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_11" id="Shape-_11">
        <omgdc:Bounds height="55.0" width="85.0" x="455.0" y="455.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="_13" id="BPMNEdge__13" sourceElement="_4" targetElement="_5">
        <omgdi:waypoint x="316.0" y="115.0"/>
        <omgdi:waypoint x="316.0" y="145.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_12" id="BPMNEdge__12" sourceElement="_3" targetElement="_4">
        <omgdi:waypoint x="316.0" y="22.0"/>
        <omgdi:waypoint x="316.0" y="60.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_23" id="BPMNEdge__23" sourceElement="_11" targetElement="_2">
        <omgdi:waypoint x="500.0" y="510.0"/>
        <omgdi:waypoint x="500.0" y="535.0"/>
        <omgdi:waypoint x="341.9687194226713" y="535.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_15" id="BPMNEdge__15" sourceElement="_5" targetElement="_7">
        <omgdi:waypoint x="315.0" y="176.0"/>
        <omgdi:waypoint x="315.0" y="205.0"/>
        <omgdi:waypoint x="315.0" y="230.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_14" id="BPMNEdge__14" sourceElement="_5" targetElement="_6">
        <omgdi:waypoint x="300.0" y="161.0"/>
        <omgdi:waypoint x="195.0" y="200.0"/>
        <omgdi:waypoint x="195.0" y="235.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_17" id="BPMNEdge__17" sourceElement="_7" targetElement="_9">
        <omgdi:waypoint x="321.0" y="285.0"/>
        <omgdi:waypoint x="321.0" y="325.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_16" id="BPMNEdge__16" sourceElement="_5" targetElement="_8">
        <omgdi:waypoint x="332.0" y="161.0"/>
        <omgdi:waypoint x="450.0" y="205.0"/>
        <omgdi:waypoint x="450.0" y="235.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_19" id="BPMNEdge__19" sourceElement="_8" targetElement="_9">
        <omgdi:waypoint x="455.0" y="290.0"/>
        <omgdi:waypoint x="455.0" y="340.0"/>
        <omgdi:waypoint x="336.0" y="340.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_18" id="BPMNEdge__18" sourceElement="_6" targetElement="_9">
        <omgdi:waypoint x="190.0" y="290.0"/>
        <omgdi:waypoint x="190.0" y="340.0"/>
        <omgdi:waypoint x="306.0" y="340.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_20" id="BPMNEdge__20" sourceElement="_9" targetElement="_10">
        <omgdi:waypoint x="321.0" y="357.0"/>
        <omgdi:waypoint x="321.0" y="415.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_22" id="BPMNEdge__22" sourceElement="_10" targetElement="_11">
        <omgdi:waypoint x="337.0" y="431.0"/>
        <omgdi:waypoint x="495.0" y="455.0"/>
        <omgdi:waypoint x="495.0" y="455.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_21" id="BPMNEdge__21" sourceElement="_10" targetElement="_2">
        <omgdi:waypoint x="323.5" y="444.5"/>
        <omgdi:waypoint x="323.5" y="520.1965193707209"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

 

总结:包含网关,在分支时,需要判断条件,符合条件的分支,将会执行,符合条件的分支最终才进行汇聚。

 

4、事件网关 EventGateway

事件网关允许根据事件判断流向。网关的每个外出顺序流都要连接到一个中间捕获事件。 当流程到达一个基于事件网关,网关会进入等待状态:会暂停执行。与此同时,会为每个外出顺序流创建相对的事件订阅。

事件网关的外出顺序流和普通顺序流不同,这些顺序流不会真的"执行", 相反它们让流程引擎去决定执行到事件网关的流程需要订阅哪些事件。 要考虑以下条件:

1. 事件网关必须有两条或以上外出顺序流;
2. 事件网关后,只能使用intermediateCatchEvent类型(activiti不支持基于事件网关后连接ReceiveTask)
3. 连接到事件网关的中间捕获事件必须只有一个入口顺序流。

 

intermediateCatchEvent支持的事件类型:

Message Event: 消息事件

Singal Event:  信号事件

Timer Event:  定时事件

 

呃,事件网关用得少。网关的讲解到这。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值