Camunda工作流网关(三)-Inclusive Gateway(包容性网关)

包容性网关允许根据流程实例变量做出多个决策,所有满足条件的序列流都会执行。在进入网关时,会评估条件并采取所有符合条件的流。这种网关适用于复杂的决策逻辑,如文中提到的公司用章流程,涉及多个审批层级的判断。


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

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

每一个网关都有自己独特的功能,本章主要介绍Inclusive Gateway(包容性网关)的使用方式。

1、Inclusive Gateway(包容性网关)

在这里插入图片描述

The inclusive gateway (or OR-gateway) allows for making multiple decisions based on data (i.e. on process instance variables).
包容性网关(或or网关)允许根据数据(即流程实例变量)做出多个决策。

If an inclusive gateway has multiple outgoing sequence flows, all sequence flows must have a condition to define when the flow is taken. If the inclusive gateway only has one outgoing sequence flow, then it does not need to have a condition.
如果包含网关具有多个传出序列流,则所有序列流都必须有一个条件来定义何时采用该流。如果包含网关只有一个传出序列流,那么它不需要有条件。

Optionally, one of the sequence flows can be marked as the default flow. This sequence flow should not have a condition, because its behavior depends on the other conditions.
可以选择将其中一个序列流标记为默认流。这个序列流不应该有条件,因为它的行为取决于其他条件。

When an inclusive gateway is entered, the conditions are evaluated. The process instance takes all sequence flows where the condition is fulfilled.
当进入包容性网关时,将评估条件。流程实例获取满足条件的所有序列流。

包容网关两个重要的特性

分支(fork):所有出口顺序流都会被计算,对于计算为true的分支都会被执行。

聚合(join):所有到达包容网关的并行执行,都会在网关处等待,直到每一条具有流程标志的入口顺序流,都有一个执行到达。这是与并行网关的重要区别。换句话说,包容网关只会等待将会被执行的入口顺序流。在合并后,流程穿过合并并行网关继续

重点1:
排他网关只有一条分支被执行,如果有多条符合条件的分支,流程会默认走第一条
并行网关至少有一条分支被执行,而且所有的分支都会被执行。
包容网关有多条或者一条分支会被执行。

重点2:
包容网关包括了并行网关和排他网关的所有功能。

2、业务场景

公司里有个用章的流程,先是部门主任审批,然后判断使用天数如果小于1天的需要后勤行政审批,判断使用天数如果大于1天的需要项目经理审批,而对大于2天的需要综合办审批 。

在这里插入图片描述
同时满足两个条件时,需要所有条件多审批完成电子流才继续往下走,如下,判断同时符合【项目经理审批】和【综合办审批】,则项目经理和综合办审批完成后,电子流会流转到【HR审批】环节。
在这里插入图片描述

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_14x7iqb" 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_tylc03" name="通用流程03" isExecutable="true" camunda:historyTimeToLive="100">
    <bpmn:sequenceFlow id="flow_emg_flag01" name="判断" sourceRef="Gateway_1hrtclm" targetRef="task_xmjl">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${amount&gt;1}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="flow_emg_flag03" name="判断" sourceRef="Gateway_1hrtclm" targetRef="task_zhb">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${amount&gt;2}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_0oqjdy0" sourceRef="task_xmjl" targetRef="Gateway_13u1zae" />
    <bpmn:sequenceFlow id="Flow_07f6i9q" sourceRef="task_zhb" targetRef="Gateway_13u1zae" />
    <bpmn:inclusiveGateway id="Gateway_13u1zae">
      <bpmn:incoming>Flow_0oqjdy0</bpmn:incoming>
      <bpmn:incoming>Flow_07f6i9q</bpmn:incoming>
      <bpmn:incoming>Flow_1h9dpm3</bpmn:incoming>
      <bpmn:outgoing>Flow_0rsdjw3</bpmn:outgoing>
    </bpmn:inclusiveGateway>
    <bpmn:sequenceFlow id="Flow_0rsdjw3" sourceRef="Gateway_13u1zae" targetRef="task_hr" />
    <bpmn:inclusiveGateway id="Gateway_1hrtclm" name="包容性网关">
      <bpmn:incoming>Flow_1q25zh3</bpmn:incoming>
      <bpmn:outgoing>flow_emg_flag01</bpmn:outgoing>
      <bpmn:outgoing>flow_emg_flag03</bpmn:outgoing>
      
### BPMN 网关的功能区别与使用场景 #### 排他网关 (Exclusive Gateway) 排他网关用于在多个可能路径之间做出单一选择。当流程到达此网关时,只会有一条符合条件的路径被执行,其他路径则不会被激活。 ```mermaid graph TD; A(Start) --> B{Exclusive<br>Gateway}; B -->|Condition True| C(Task 1); B -->|Else Condition| D(Task 2); ``` 这种类型的网关适用于需要基于特定条件来决定后续处理逻辑的情况[^1]。 #### 并行网关 (Parallel Gateway) 并行网关允许同时启动多条路径,在遇到此类网关时,所有连接到其后的活动都将并发执行。这意味着所有的分支会被立即触发而无需任何前置条件评估。 ```mermaid graph TD; E(Start) --> F{Parallel<br>Gateway}; F --- G(Task 3); F --- H(Task 4); I(Task 5) <-- F; ``` 对于那些希望同步推进多项任务的应用程序来说非常有用,比如在一个业务过程中同时发送电子邮件通知给多位相关人员[^2]。 #### 包容网关 (Inclusive Gateway) 包容网关结合了排他网关和并行网关的特点。它不仅能够根据条件筛选出合适的路径,而且还可以支持多条路径的同时运行。具体而言: - **分支**:所有外出顺序流中的条件都会被解析;如果某个条件的结果为 `true` ,那么对应的顺序流就会以并行方式继续执行,并为此创建新的分支。 - **汇聚**:所有参与的分支都需要抵达该网关才能使整个过程向前发展。换句话说,只有当所有选定的进入顺序流均已到达时,才会离开这个网关。 ```mermaid graph TD; J(Start) --> K{Inclusive<br>Gateway}; K -->|Cond 1 True| L(Task 6); K -->|Cond 2 True| M(Task 7); N(Task 8) <-- K; ``` 这样的机制非常适合用来管理复杂的工作流,其中某些操作可能是可选性的或者是有条件依赖关系的存在。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

hardworkl

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

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

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

打赏作者

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

抵扣说明:

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

余额充值