ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

使用Camunda流程引擎,关于独占网关(Exclusive Gateway)使用

2022-03-02 14:02:59  阅读:277  来源: 互联网

标签:Exclusive 网关 独占 flow Flow Camunda true Gateway


在使用开源Camunda流程引擎做二次开发时,网关是必须要接触的。在Camunda的 Modeler工具中提供了4种类型的网关:Exclusive Gateway(独占网关)、Parallel Gateway(并行网关)、Inclusive Gateway(包容性网关)、Event-based Gateway(基于事件的网关),每一个网关都有自己独特的功能,这一篇就先介绍Exclusive Gateway(独占网关)。 Exclusive Gateway(独占网关)
An exclusive gateway (also called the XOR gateway or, in more technical terms, the exclusive data-based gateway), is used to model a decision in the process. When the execution arrives at this gateway, all outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to ‘true’ (or which doesn’t have a condition set, conceptually having a ‘true’ value defined on the sequence flow) is selected for continuing the process.
大概意思就是:独占网关(也称为XOR网关,或者更技术性的独占数据网关)用于建模过程中的决策。当执行到达此网关时,所有传出序列流都按照定义顺序进行评估。选择条件评估为“true”(或没有条件集,在概念上在序列流上定义“true”值)的序列流以继续该过程。 其中需要特别注意的一点就是下面这句话:
Note that only one sequence flow is selected when using the exclusive gateway. In case multiple sequence flow have a condition that evaluates to ‘true’, the first one defined in the XML is exclusively selected for continuing the process. If no sequence flow can be selected (no condition evaluates to ‘true’) this will result in a runtime exception, unless you have a default flow defined. One default flow can be set on the gateway itself in case no other condition matches - like an ‘else’ in programming languages.
大概意思就是:请注意,使用独占网关时只能选择一个序列流。如果多个序列流具有计算为“true”的条件,则XML中定义的第一个序列流将仅用于继续该过程。 如果无法选择序列流(没有条件计算为“true”),除非您定义了默认流,否则这将导致运行时异常。可以在网关本身上设置一个默认流,以防没有其他条件匹配——例如编程语言中的“其他”。 流程实例 场景:公司里有请假的流程,先是组长审批,如果请假大于3天就是经理审批,然后结束,如果是小于等于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: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_0qmx9bd" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.11.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0">
  <bpmn:process id="Process_0a6brl4" isExecutable="true">
    <bpmn:startEvent id="StartEvent_1" name="开始">
      <bpmn:outgoing>Flow_0bsat4s</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:userTask id="Activity_1rsws2h" name="组长审批">
      <bpmn:incoming>Flow_0bsat4s</bpmn:incoming>
      <bpmn:outgoing>Flow_14b6zp2</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:sequenceFlow id="Flow_0bsat4s" sourceRef="StartEvent_1" targetRef="Activity_1rsws2h" />
    <bpmn:exclusiveGateway id="Gateway_1njikuz">
      <bpmn:incoming>Flow_14b6zp2</bpmn:incoming>
      <bpmn:outgoing>Flow_0nag1ay</bpmn:outgoing>
      <bpmn:outgoing>Flow_1vwc1bq</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:sequenceFlow id="Flow_0nag1ay" name="小于等于3天" sourceRef="Gateway_1njikuz" targetRef="Activity_07vris1">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${isDays&lt;=3}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_1vwc1bq" name="大于3天" sourceRef="Gateway_1njikuz" targetRef="Activity_1nm1jj3">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${isDays&gt;3}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_14b6zp2" sourceRef="Activity_1rsws2h" targetRef="Gateway_1njikuz" />
    <bpmn:userTask id="Activity_07vris1" name="人事审批">
      <bpmn:incoming>Flow_0nag1ay</bpmn:incoming>
      <bpmn:outgoing>Flow_1kex2f5</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:userTask id="Activity_1nm1jj3" name="经理审批">
      <bpmn:incoming>Flow_1vwc1bq</bpmn:incoming>
      <bpmn:outgoing>Flow_03hj1us</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:endEvent id="Event_14pjuff" name="结束">
      <bpmn:incoming>Flow_03hj1us</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_03hj1us" sourceRef="Activity_1nm1jj3" targetRef="Event_14pjuff" />
    <bpmn:endEvent id="Event_08elgeq" name="结束">
      <bpmn:incoming>Flow_1kex2f5</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_1kex2f5" sourceRef="Activity_07vris1" targetRef="Event_08elgeq" />
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0a6brl4">
      <bpmndi:BPMNEdge id="Flow_0bsat4s_di" bpmnElement="Flow_0bsat4s">
        <di:waypoint x="198" y="210" />
        <di:waypoint x="340" y="210" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0nag1ay_di" bpmnElement="Flow_0nag1ay">
        <di:waypoint x="560" y="235" />
        <di:waypoint x="560" y="280" />
        <di:waypoint x="660" y="280" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="549" y="283" width="62" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1vwc1bq_di" bpmnElement="Flow_1vwc1bq">
        <di:waypoint x="560" y="185" />
        <di:waypoint x="560" y="120" />
        <di:waypoint x="660" y="120" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="570" y="103" width="40" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_14b6zp2_di" bpmnElement="Flow_14b6zp2">
        <di:waypoint x="440" y="210" />
        <di:waypoint x="535" y="210" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_03hj1us_di" bpmnElement="Flow_03hj1us">
        <di:waypoint x="760" y="120" />
        <di:waypoint x="862" y="120" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1kex2f5_di" bpmnElement="Flow_1kex2f5">
        <di:waypoint x="760" y="280" />
        <di:waypoint x="862" y="280" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="162" y="192" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="169" y="235" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_0fdhp45_di" bpmnElement="Activity_1rsws2h">
        <dc:Bounds x="340" y="170" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Gateway_1njikuz_di" bpmnElement="Gateway_1njikuz" isMarkerVisible="true">
        <dc:Bounds x="535" y="185" width="50" height="50" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_0gxt3kl_di" bpmnElement="Activity_07vris1">
        <dc:Bounds x="660" y="240" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_08elgeq_di" bpmnElement="Event_08elgeq">
        <dc:Bounds x="862" y="262" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="869" y="305" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_0gj23e9_di" bpmnElement="Activity_1nm1jj3">
        <dc:Bounds x="660" y="80" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_14pjuff_di" bpmnElement="Event_14pjuff">
        <dc:Bounds x="862" y="102" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="869" y="145" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

部署流程并测试验证

流程发起后,第一个节点是组长审批。

 

在组长审批后,就会走到独占网关节点,它会根据请假天数是走经理审批,还是人事审批,所以这一步需要提交参数:isDays

 

对独占网关就介绍到这里,下一篇是并行网关介绍

标签:Exclusive,网关,独占,flow,Flow,Camunda,true,Gateway
来源: https://blog.csdn.net/weixin_44878554/article/details/123226336

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有