Camunda工作流网关(一)-Exclusive Gateway(独占网关或排他网关)


在Camunda的 Modeler工具中提供了5种类型的网关:

  1. Exclusive Gateway(独占网关或排他网关)
  2. Parallel Gateway(并行网关)
  3. Inclusive Gateway(包容性网关)
  4. Complex Gateway(复杂网关)
  5. Event-based Gateway(基于事件的网关)

每一个网关都有自己独特的功能,本章主要介绍Exclusive Gateway(独占网关或排他网关)的使用方式。

1、Exclusive Gateway(独占网关或排他网关)

在这里插入图片描述

An exclusive gateway (or XOR-gateway) allows you to make a decision based on data (i.e. on process instance variables).
独占网关(也称为XOR网关或排他网关)允许您根据数据(即流程实例变量)做出决策。

If an exclusive gateway has multiple outgoing sequence flows, all sequence flows except one must have a conditionExpression to define when the flow is taken. The gateway can have one sequence flow without conditionExpression, which must be defined as the default flow.
如果一个独占网关具有多个传出序列流,则除一个序列流外的所有序列流都必须具有一个条件表达式来定义何时获取该流。网关可以有一个不带conditionExpression的序列流,必须将其定义为默认流。

When an exclusive gateway is entered, the conditionExpression is evaluated. The process instance takes the first sequence flow where the condition is fulfilled.
当输入独占网关时,将计算条件表达式。如果同时满足多个条件时,流程实例采用满足条件的第一个序列流

If no condition is fulfilled, it takes the default flow of the gateway. If the gateway has no default flow, an incident is created.
如果不满足任何条件,则采用网关的默认流。如果网关没有默认流,则会创建一个偶发事件。

An exclusive gateway can also be used to join multiple incoming flows together and improve the readability of the BPMN. A joining gateway has a pass-through semantic and doesn’t merge the incoming concurrent flows like a parallel gateway.
独占网关还可以用于将多个传入流连接在一起,并提高BPMN的可读性。加入网关具有传递语义,不会像并行网关那样合并传入的并发流。

排他网关的重要特性

  1. 一个排他网关对应一个以上的顺序流。

  2. 由排他网关流出的顺序流都有个conditionExpression元素,在内部维护返回boolean类型的决策结果。

  3. 决策网关只会返回一条结果。当流程执行到排他网关时,流程引擎会自动检索网关出口,从上到下检索如果发现第一条决策结果为true或者没有设置条件的(默认为成立),则流出。

  4. 如果没有任何一个出口符合条件,则抛出异常。

  5. 使用流程变量,设置连线的条件,并按照连线的条件执行工作流,如果没有条件符合的条件,则以默认的连线离开。

重点:
排他网关只有一条分支被执行,如果有多条符合条件的分支,流程会默认走第一条
如果没有任何一个出口符合条件,则抛出异常。

2、业务场景

如物资审批流程,部门主任审批通过后,根据紧急情况判断走哪条路,紧急情况emergencyFlag =3,项目经理审批,重要情况emergencyFlag=2,后勤行政主管审批,正常情况emergencyFlag =1,综合办审批
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3、BPMN流程模型文件

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1ehmd6d" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.12.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.19.0">
  <bpmn:process id="flow_xmgs_tylc01" name="通用流程01" isExecutable="true" camunda:historyTimeToLive="100">
    <bpmn:startEvent id="StartEvent_1">
      <bpmn:outgoing>Flow_08830mr</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:sequenceFlow id="Flow_08830mr" sourceRef="StartEvent_1" targetRef="task_bmzr" />
    <bpmn:userTask id="task_bmzr" name="部门主任审批" camunda:assignee="${bmzr_approver}">
      <bpmn:incoming>Flow_08830mr</bpmn:incoming>
      <bpmn:outgoing>Flow_1rbm3s8</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:exclusiveGateway id="Gateway_05fznwk">
      <bpmn:incoming>Flow_1rbm3s8</bpmn:incoming>
      <bpmn:outgoing>flow_emg_flag01</bpmn:outgoing>
      <bpmn:outgoing>flow_emg_flag02</bpmn:outgoing>
      <bpmn:outgoing>flow_emg_flag03</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:sequenceFlow id="Flow_1rbm3s8" sourceRef="task_bmzr" targetRef="Gateway_05fznwk" />
    <bpmn:sequenceFlow id="flow_emg_flag01" name="紧急情况:emergencyFlag==3" sourceRef="Gateway_05fznwk" targetRef="task_xmjl">
      <bpmn:documentation>紧急</bpmn:documentation>
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${emergencyFlag==3}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="flow_emg_flag02" name="重要:emergencyFlag==2" sourceRef="Gateway_05fznwk" targetRef="task_zhbgs">
      <bpmn:documentation>重要</bpmn:documentation>
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${emergencyFlag==2}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="flow_emg_flag03" name="正常情况:emergencyFlag==1" sourceRef="Gateway_05fznwk" targetRef="task_zhb">
      <bpmn:documentation>正常</bpmn:documentation>
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${emergencyFlag==1}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:userTask id="task_xmjl" name="项目经理审批" camunda:assignee="${xmjl_approver}">
      <bpmn:incoming>flow_emg_flag01</bpmn:incoming>
      <bpmn:outgoing>Flow_0oyeye8</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:userTask id="task_zhbgs" name="后勤行政主管" camunda:assignee="${hqxzzg_approver}">
      <bpmn:incoming>flow_emg_flag02</bpmn:incoming>
      <bpmn:outgoing>Flow_0eeb2ci</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:userTask id="task_zhb" name="综合办审批" camunda:assignee="${zhb_approver}">
      <bpmn:incoming>flow_emg_flag03</bpmn:incoming>
      <bpmn:outgoing>Flow_08x9l8v</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:sequenceFlow id="Flow_0oyeye8" sourceRef="task_xmjl" targetRef="task_hr" />
    <bpmn:userTask id="task_hr" name="HR审批" camunda:assignee="${hr_approver}">
      <bpmn:incoming>Flow_0oyeye8</bpmn:incoming>
      <bpmn:incoming>Flow_0eeb2ci</bpmn:incoming>
      <bpmn:incoming>Flow_08x9l8v</bpmn:incoming>
      <bpmn:outgoing>Flow_0czusdm</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:sequenceFlow id="Flow_0eeb2ci" sourceRef="task_zhbgs" targetRef="task_hr" />
    <bpmn:sequenceFlow id="Flow_08x9l8v" sourceRef="task_zhb" targetRef="task_hr" />
    <bpmn:endEvent id="Event_1oa1ubo">
      <bpmn:incoming>Flow_0czusdm</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_0czusdm" sourceRef="task_hr" targetRef="Event_1oa1ubo" />
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="flow_xmgs_tylc01">
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="152" y="242" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_1r3n5f4_di" bpmnElement="task_bmzr">
        <dc:Bounds x="240" y="220" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Gateway_05fznwk_di" bpmnElement="Gateway_05fznwk" isMarkerVisible="true">
        <dc:Bounds x="395" y="235" width="50" height="50" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_0amuv66_di" bpmnElement="task_zhb">
        <dc:Bounds x="490" y="350" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_0134myg_di" bpmnElement="task_zhbgs">
        <dc:Bounds x="490" y="220" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_1q7iwxl_di" bpmnElement="task_xmjl">
        <dc:Bounds x="490" y="80" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_17b31zq_di" bpmnElement="task_hr">
        <dc:Bounds x="730" y="220" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_1oa1ubo_di" bpmnElement="Event_1oa1ubo">
        <dc:Bounds x="922" y="242" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_08830mr_di" bpmnElement="Flow_08830mr">
        <di:waypoint x="188" y="260" />
        <di:waypoint x="240" y="260" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1rbm3s8_di" bpmnElement="Flow_1rbm3s8">
        <di:waypoint x="340" y="260" />
        <di:waypoint x="395" y="260" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0mk4f2p_di" bpmnElement="flow_emg_flag01">
        <di:waypoint x="420" y="235" />
        <di:waypoint x="420" y="120" />
        <di:waypoint x="490" y="120" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="394" y="175" width="87" height="27" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1xonyk2_di" bpmnElement="flow_emg_flag02">
        <di:waypoint x="445" y="260" />
        <di:waypoint x="490" y="260" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="425" y="242" width="87" height="27" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1vsi7j7_di" bpmnElement="flow_emg_flag03">
        <di:waypoint x="420" y="285" />
        <di:waypoint x="420" y="390" />
        <di:waypoint x="490" y="390" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="395" y="335" width="86" height="27" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_08x9l8v_di" bpmnElement="Flow_08x9l8v">
        <di:waypoint x="590" y="390" />
        <di:waypoint x="660" y="390" />
        <di:waypoint x="660" y="260" />
        <di:waypoint x="730" y="260" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0eeb2ci_di" bpmnElement="Flow_0eeb2ci">
        <di:waypoint x="590" y="260" />
        <di:waypoint x="730" y="260" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0oyeye8_di" bpmnElement="Flow_0oyeye8">
        <di:waypoint x="590" y="120" />
        <di:waypoint x="660" y="120" />
        <di:waypoint x="660" y="260" />
        <di:waypoint x="730" y="260" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0czusdm_di" bpmnElement="Flow_0czusdm">
        <di:waypoint x="830" y="260" />
        <di:waypoint x="922" y="260" />
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hardworkl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值