# 调用子流程

调用子流程是指子流程在主流程的外面。子流程一般是多个流程可重用的流程,也可以独立调用子流程。 可以对比编程中的方法抽取。子流程运行时,主流程也是等待状态。子流程结束,主流程继续。

# BPMN设计

# 主流程

foo

全局配置

foo

上传视频

foo

处理单个视频

foo

确认上传

# XML内容

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
  <bpmn:process id="Process_called_activity" name="调用子流程" isExecutable="true">
    <bpmn:startEvent id="StartEvent_1">
      <bpmn:outgoing>Flow_17do2o9</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:sequenceFlow id="Flow_17do2o9" sourceRef="StartEvent_1" targetRef="Activity_0hvc1zt" />
    <bpmn:userTask id="Activity_0hvc1zt" name="上传视频" camunda:assignee="${customer}">
      <bpmn:extensionElements>
        <camunda:formData>
          <camunda:formField id="num" label="数量" type="long" defaultValue="1" />
        </camunda:formData>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_17do2o9</bpmn:incoming>
      <bpmn:outgoing>Flow_1g4a6nc</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:sequenceFlow id="Flow_1g4a6nc" sourceRef="Activity_0hvc1zt" targetRef="Activity_0rb7n5o" />
    <bpmn:sequenceFlow id="Flow_08kb2ee" sourceRef="Activity_0rb7n5o" targetRef="Activity_11s7j95" />
    <bpmn:userTask id="Activity_11s7j95" name="确认上传" camunda:assignee="aaa">
      <bpmn:incoming>Flow_08kb2ee</bpmn:incoming>
      <bpmn:outgoing>Flow_0udt21b</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:endEvent id="Event_0pgl9h9">
      <bpmn:incoming>Flow_0udt21b</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_0udt21b" sourceRef="Activity_11s7j95" targetRef="Event_0pgl9h9" />
    <bpmn:callActivity id="Activity_0rb7n5o" name="处理单个视频" calledElement="process_sub_process_vedio">
      <bpmn:extensionElements>
        <camunda:inputOutput />
        <camunda:out sourceExpression="${targetResult}" target="result" />
        <camunda:in sourceExpression="${videoName}" target="targetVideoName" />
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_1g4a6nc</bpmn:incoming>
      <bpmn:outgoing>Flow_08kb2ee</bpmn:outgoing>
      <bpmn:multiInstanceLoopCharacteristics camunda:collection="${videoNameList}" camunda:elementVariable="videoName" />
    </bpmn:callActivity>
  </bpmn:process>
</bpmn:definitions>

# 子流程

foo

视频格式检验。视频内容检查也是同养设置,不赘述。

foo

监听器将处理结果进行设置

# XML内容

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
  <bpmn:process id="process_sub_process_vedio" name="处理单个视频" isExecutable="true">
    <bpmn:startEvent id="StartEvent_1">
      <bpmn:outgoing>Flow_1uxffv9</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:sequenceFlow id="Flow_1uxffv9" sourceRef="StartEvent_1" targetRef="Gateway_07vpeap" />
    <bpmn:parallelGateway id="Gateway_07vpeap">
      <bpmn:incoming>Flow_1uxffv9</bpmn:incoming>
      <bpmn:outgoing>Flow_1705jbd</bpmn:outgoing>
      <bpmn:outgoing>Flow_1v6afyz</bpmn:outgoing>
    </bpmn:parallelGateway>
    <bpmn:sequenceFlow id="Flow_1705jbd" sourceRef="Gateway_07vpeap" targetRef="Activity_1djbbmd" />
    <bpmn:serviceTask id="Activity_1djbbmd" name="视频格式" camunda:delegateExpression="${videoFormatTask}">
      <bpmn:incoming>Flow_1705jbd</bpmn:incoming>
      <bpmn:outgoing>Flow_1fpwrea</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:sequenceFlow id="Flow_1v6afyz" sourceRef="Gateway_07vpeap" targetRef="Activity_1ap7i3h" />
    <bpmn:serviceTask id="Activity_1ap7i3h" name="内容审查" camunda:delegateExpression="${videoContentCheckTask}">
      <bpmn:incoming>Flow_1v6afyz</bpmn:incoming>
      <bpmn:outgoing>Flow_06q9myy</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:parallelGateway id="Gateway_0r05r0g">
      <bpmn:incoming>Flow_1fpwrea</bpmn:incoming>
      <bpmn:incoming>Flow_06q9myy</bpmn:incoming>
      <bpmn:outgoing>Flow_1q8g3uy</bpmn:outgoing>
    </bpmn:parallelGateway>
    <bpmn:sequenceFlow id="Flow_1fpwrea" sourceRef="Activity_1djbbmd" targetRef="Gateway_0r05r0g" />
    <bpmn:sequenceFlow id="Flow_06q9myy" sourceRef="Activity_1ap7i3h" targetRef="Gateway_0r05r0g" />
    <bpmn:endEvent id="Event_0cycxs7">
      <bpmn:incoming>Flow_1q8g3uy</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_1q8g3uy" sourceRef="Gateway_0r05r0g" targetRef="Event_0cycxs7">
      <bpmn:extensionElements>
        <camunda:executionListener event="take">
          <camunda:script scriptFormat="groovy">def result="正常";
execution.setVariable("targetResult",result);</camunda:script>
        </camunda:executionListener>
      </bpmn:extensionElements>
    </bpmn:sequenceFlow>
  </bpmn:process>

</bpmn:definitions>

# 测试验证

foo

使用关羽的账号,登陆camunda演示站点 (opens new window),并且发起流程

foo

点击预览,可以看到流程运行轨迹

foo

点击上一步的[处理单个视频]节点,可以看到多实例运行的情况。可以看到有2次运行记录。至此完成调用子流程的演示。