Camunda 子流程实现示例Demo(嵌套子流程Embedded Subprocess)

       Camunda子流程有两种实现方式:嵌套子流程(Embedded Subprocess)和外部子流程(Call Activity)。以下介绍Camunda嵌套子流程(Embedded Subprocess)的实现方式。

一、什么是嵌套子流程

       子流程是包含其他活动、网关、事件等的活动,其本身形成的流程是更大流程的一部分。子流程完全在父流程中定义(这就是为什么它通常被称为嵌入式子流程)。

      嵌套子流程有什么用处?以下是官方的解释:

  • Subprocesses allow hierarchical modeling. Many modeling tools allow that subprocesses can be collapsed, hiding all the details of the subprocess and displaying a high-level, end-to-end overview of the business process.

       子流程允许分层建模。许多建模工具允许折叠子流程,隐藏子流程的所有细节,并显示业务流程的高级端到端概述。

  • A subprocess creates a new scope for events. Events that are thrown during execution of the subprocess can be caught by a boundary event on the boundary of the subprocess, thus creating a scope for that event, limited to the subprocess.

      子流程为事件创建一个新的范围。在子流程执行期间抛出的事件可以由子流程边界上的边界事件捕获,从而为该事件创建一个范围,限制在子流程。

示例流程图:

上面的流程模型表明: 如果我们被邀请去吃饭,我们会取消我们的烹饪过程。然而,如果我们已经在吃了,我们就不会再对邀请做出反应了。用更专业的术语来说,消息事件的范围是子流程,因此只能在子流程处于活动状态时接收消息。

二、流程模拟验证

模拟公文处理流程:拟稿人起草公文——》部门会签——》领导签发,其中部门会签通过嵌套子流程实现。

 

第一步、设计流程图

编辑

 

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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0pf7z9i" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.8.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0">

  <bpmn:process id="Process_0gricxz" name="嵌套子流程" isExecutable="true">

    <bpmn:startEvent id="StartEvent_1">

      <bpmn:outgoing>Flow_0rfd9kh</bpmn:outgoing>

    </bpmn:startEvent>

    <bpmn:sequenceFlow id="Flow_0rfd9kh" sourceRef="StartEvent_1" targetRef="Activity_1grmrle" />

    <bpmn:subProcess id="Activity_01d0fiw" name="部门会签子流程">

      <bpmn:incoming>Flow_1anv3xt</bpmn:incoming>

      <bpmn:outgoing>Flow_1c66957</bpmn:outgoing>

      <bpmn:multiInstanceLoopCharacteristics camunda:collection="assigneeList" camunda:elementVariable="assignee" />

      <bpmn:startEvent id="Event_1lqvv26">

        <bpmn:outgoing>Flow_0e1k6u7</bpmn:outgoing>

      </bpmn:startEvent>

      <bpmn:sequenceFlow id="Flow_0e1k6u7" sourceRef="Event_1lqvv26" targetRef="Activity_1ec2oya" />

      <bpmn:userTask id="Activity_1ec2oya" name="会签" camunda:assignee="${assignee}">

        <bpmn:incoming>Flow_0e1k6u7</bpmn:incoming>

        <bpmn:outgoing>Flow_0e6563y</bpmn:outgoing>

      </bpmn:userTask>

      <bpmn:sequenceFlow id="Flow_0e6563y" sourceRef="Activity_1ec2oya" targetRef="Event_1xjupth" />

      <bpmn:endEvent id="Event_1xjupth">

        <bpmn:incoming>Flow_0e6563y</bpmn:incoming>

      </bpmn:endEvent>

    </bpmn:subProcess>

    <bpmn:sequenceFlow id="Flow_1anv3xt" name="发起会签" sourceRef="Activity_1grmrle" targetRef="Activity_01d0fiw">

      <bpmn:extensionElements>

        <camunda:executionListener event="take">

          <camunda:script scriptFormat="groovy">def userList = ["user1","user2","user3"];

execution.setVariable("assigneeList", userList);</camunda:script>

        </camunda:executionListener>

      </bpmn:extensionElements>

    </bpmn:sequenceFlow>

    <bpmn:endEvent id="Event_1e5cfza">

      <bpmn:incoming>Flow_1l1q3kb</bpmn:incoming>

    </bpmn:endEvent>

    <bpmn:sequenceFlow id="Flow_1l1q3kb" sourceRef="Activity_0rlr3iz" targetRef="Event_1e5cfza" />

    <bpmn:sequenceFlow id="Flow_1c66957" name="会签完成" sourceRef="Activity_01d0fiw" targetRef="Activity_0rlr3iz" />

    <bpmn:userTask id="Activity_1grmrle" name="起草公文" camunda:assignee="demo">

      <bpmn:incoming>Flow_0rfd9kh</bpmn:incoming>

      <bpmn:outgoing>Flow_1anv3xt</bpmn:outgoing>

    </bpmn:userTask>

    <bpmn:userTask id="Activity_0rlr3iz" name="领导签发" camunda:assignee="demo">

      <bpmn:incoming>Flow_1c66957</bpmn:incoming>

      <bpmn:outgoing>Flow_1l1q3kb</bpmn:outgoing>

    </bpmn:userTask>

  </bpmn:process>

  <bpmndi:BPMNDiagram id="BPMNDiagram_1">

    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0gricxz">

      <bpmndi:BPMNEdge id="Flow_1c66957_di" bpmnElement="Flow_1c66957">

        <di:waypoint x="800" y="190" />

        <di:waypoint x="880" y="190" />

        <bpmndi:BPMNLabel>

          <dc:Bounds x="812.9999999999999" y="173" width="45" height="14" />

        </bpmndi:BPMNLabel>

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_1l1q3kb_di" bpmnElement="Flow_1l1q3kb">

        <di:waypoint x="980" y="190" />

        <di:waypoint x="1042" y="190" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_1anv3xt_di" bpmnElement="Flow_1anv3xt">

        <di:waypoint x="340" y="180" />

        <di:waypoint x="420" y="180" />

        <bpmndi:BPMNLabel>

          <dc:Bounds x="353" y="153" width="44" height="14" />

        </bpmndi:BPMNLabel>

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0rfd9kh_di" bpmnElement="Flow_0rfd9kh">

        <di:waypoint x="188" y="180" />

        <di:waypoint x="240" y="180" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNShape id="Activity_1xs84zt_di" bpmnElement="Activity_0rlr3iz">

        <dc:Bounds x="880" y="140" width="100" height="80" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_01n6dcy_di" bpmnElement="Activity_1grmrle">

        <dc:Bounds x="240" y="140" width="100" height="80" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Event_1e5cfza_di" bpmnElement="Event_1e5cfza">

        <dc:Bounds x="1042" y="172" width="36" height="36" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">

        <dc:Bounds x="152" y="162" width="36" height="36" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_01d0fiw_di" bpmnElement="Activity_01d0fiw" isExpanded="true">

        <dc:Bounds x="420" y="80" width="380" height="200" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNEdge id="Flow_0e1k6u7_di" bpmnElement="Flow_0e1k6u7">

        <di:waypoint x="496" y="180" />

        <di:waypoint x="570" y="180" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0e6563y_di" bpmnElement="Flow_0e6563y">

        <di:waypoint x="670" y="180" />

        <di:waypoint x="732" y="180" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNShape id="Event_1lqvv26_di" bpmnElement="Event_1lqvv26">

        <dc:Bounds x="460" y="162" width="36" height="36" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Event_1xjupth_di" bpmnElement="Event_1xjupth">

        <dc:Bounds x="732" y="162" width="36" height="36" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_0xbobyf_di" bpmnElement="Activity_1ec2oya">

        <dc:Bounds x="570" y="140" width="100" height="80" />

      </bpmndi:BPMNShape>

    </bpmndi:BPMNPlane>

  </bpmndi:BPMNDiagram>

</bpmn:definitions>

第二步、发起流程

通过demo用户登录camunda平台http://localhost:8080/camunda/app/tasklist/default/#/login,发起流程:

 

启动流程后,此时流程在主流程第一个活动节点,点击提交流程。


 

第三步、审批流程

提交流程后,流程自动进入嵌套子流程,该流程设置了3个用户模拟并行会签,所以收到3个待办任务,这3个任务是并行的,分别通过user1、user2、user3登录后处理,完成子流程会签。


 

 

user1、user2、user3会签完成后,流程自动进入主流程。

 

参考:

Embedded Subprocess | docs.camunda.org

http://www.yunchengxc.com

posted @ 2022-06-13 14:34  大龄码农有梦想  阅读(934)  评论(0编辑  收藏  举报