【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关

文章目录

    • 1. 连线
      • 1.1 流程设计
      • 1.2 测试类
      • 1.3 运行
        • 1.3.1 查询任务
        • 1.3.2 完成任务
    • 2. 排他网关
      • 2.1 流程设计
      • 2.2 测试类
      • 2.3 运行
        • 2.3.1 查询任务
        • 2.3.2 完成任务
    • 3. 并行网关
      • 3.1 流程设计
      • 3.2 测试类
      • 3.3 运行
        • 3.3.1 查询任务
        • 3.3.2 完成任务
        • 3.3.3 完成班长任务
        • 3.3.4 完成班主任任务
    • 4. 兼容网关
      • 4.1 流程设计
      • 4.2 测试类
      • 4.3 运行
        • 4.3.1 查询任务
        • 4.3.2 完成任务
    • 5. 事件网关
    • 源码地址
    • 项目推荐

Activiti中网关分为连线,排他网关,并行网关,兼容网关,事件网关,接下来我们分别介绍他们的使用方式。

*后台服务基于Springboot2 + Activiti6,整合文章请参考:https://blog.csdn.net/yy756127197/article/details/101211510 不需要流程设计器就排除3,4步骤 *

1. 连线

连线就是可以设置多条线路,如果有多条连线符合条件,那就选择第一条在流程文件中出现的连线,如果没有符合条件的,就是用默认线路。

1.1 流程设计

连线设置
设置同意线路为默认线路
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第1张图片
流程图
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第2张图片
流程文件bpmn


<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
  <process id="line" name="连线" isExecutable="true">
    <startEvent id="startEvent1">startEvent>
    <userTask id="userTask1" name="指定处理人" default="sid-EDDC5664-19C0-4020-A36D-11F20A1E6962" activiti:assignee="admin">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">modeler:initiator-can-complete>
      extensionElements>
    userTask>
    <userTask id="userTask3" name="监听器" activiti:assignee="test">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">modeler:initiator-can-complete>
      extensionElements>
    userTask>
    <sequenceFlow id="sid-13B085EF-2E80-43D1-BEDF-8950B2A9B783" sourceRef="startEvent1" targetRef="userTask1">sequenceFlow>
    <endEvent id="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">endEvent>
    <sequenceFlow id="sid-DCE668F0-BD17-4EC2-8C65-0334163C1767" sourceRef="userTask3" targetRef="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">sequenceFlow>
    <sequenceFlow id="sid-AE551128-BF5C-4F31-89B5-E90744E1C7D9" name="拒绝" sourceRef="userTask1" targetRef="userTask3">
      <conditionExpression xsi:type="tFormalExpression">conditionExpression>
    sequenceFlow>
    <sequenceFlow id="sid-EDDC5664-19C0-4020-A36D-11F20A1E6962" name="同意" sourceRef="userTask1" targetRef="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">
      <conditionExpression xsi:type="tFormalExpression">conditionExpression>
    sequenceFlow>
  process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_line">
    <bpmndi:BPMNPlane bpmnElement="line" id="BPMNPlane_line">
      <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
        <omgdc:Bounds height="30.0" width="30.0" x="480.0" y="45.0">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="userTask1" id="BPMNShape_userTask1">
        <omgdc:Bounds height="80.0" width="100.0" x="445.0" y="180.0">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="userTask3" id="BPMNShape_userTask3">
        <omgdc:Bounds height="80.0" width="100.0" x="630.0" y="285.0">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD" id="BPMNShape_sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">
        <omgdc:Bounds height="28.0" width="28.0" x="481.0" y="454.0">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-13B085EF-2E80-43D1-BEDF-8950B2A9B783" id="BPMNEdge_sid-13B085EF-2E80-43D1-BEDF-8950B2A9B783">
        <omgdi:waypoint x="495.0" y="75.0">omgdi:waypoint>
        <omgdi:waypoint x="495.0" y="180.0">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-DCE668F0-BD17-4EC2-8C65-0334163C1767" id="BPMNEdge_sid-DCE668F0-BD17-4EC2-8C65-0334163C1767">
        <omgdi:waypoint x="630.0" y="363.64864864864865">omgdi:waypoint>
        <omgdi:waypoint x="506.076673127176" y="459.43803104223696">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-AE551128-BF5C-4F31-89B5-E90744E1C7D9" id="BPMNEdge_sid-AE551128-BF5C-4F31-89B5-E90744E1C7D9">
        <omgdi:waypoint x="545.0" y="248.3783783783784">omgdi:waypoint>
        <omgdi:waypoint x="630.0" y="296.6216216216216">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-EDDC5664-19C0-4020-A36D-11F20A1E6962" id="BPMNEdge_sid-EDDC5664-19C0-4020-A36D-11F20A1E6962">
        <omgdi:waypoint x="495.0" y="260.0">omgdi:waypoint>
        <omgdi:waypoint x="495.0" y="454.0">omgdi:waypoint>
      bpmndi:BPMNEdge>
    bpmndi:BPMNPlane>
  bpmndi:BPMNDiagram>
definitions>

1.2 测试类

LineTest.java

import com.it.cloud.modules.activiti.service.IActReModelService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricVariableInstance;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 连线测试
 */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class LineTest {

    @Autowired
    private IActReModelService actReModelService;

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private TaskService taskService;

    @Autowired
    private HistoryService historyService;

    /**
     * 部署流程定义
     */
    @Test
    public void deploy() {
        Deployment deployment = repositoryService.createDeployment() // 创建部署
                .addClasspathResource("diagrams/line.bpmn20.xml") // 加载流程资源文件
                .name("line流程") // 流程名称
                .deploy(); // 部署
        System.out.println("流程部署ID:" + deployment.getId());
        System.out.println("流程部署Name:" + deployment.getName());
    }

    /**
     * 启动流程实例
     */
    @Test
    public void start() {
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("line"); // 流程定义表的KEY字段值
        System.out.println("流程实例ID:" + pi.getId());
        System.out.println("流程定义ID:" + pi.getProcessDefinitionId());
    }

    /**
     * 查看任务
     */
    @Test
    public void queryTask() {
        List<Task> taskList = taskService.createTaskQuery() // 创建任务查询
                .taskAssignee("admin") // 指定某个人
                .list();
        for (Task task : taskList) {
            System.out.println("任务ID:" + task.getId());
            System.out.println("任务名称:" + task.getName());
            System.out.println("任务创建时间:" + task.getCreateTime());
            System.out.println("任务委派人:" + task.getAssignee());
            System.out.println("流程实例ID:" + task.getProcessInstanceId());
        }
    }

    /**
     * 完成任务
     */
    @Test
    public void completeTask() {
        taskService.complete("85005");
    }

    /**
     * 完成任务2
     */
    @Test
    public void completeTask2() {
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("msg", "拒绝");
        taskService.complete("157505", variables);
    }
}

1.3 运行

运行deploy(), start()

1.3.1 查询任务

运行queryTask()

效果:
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第3张图片

1.3.2 完成任务

运行completeTask2(),设置参数msg==‘拒绝’

效果:
数据库ACT_RU_TASK, 任务到达监听器节点
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第4张图片

2. 排他网关

排他网关好像一个人在分岔路口,只会选择一条线路前进,如果有多条连线符合条件,那就选择第一条在流程文件中出现的连线,如果没有符合条件的,就是用默认线路。

2.1 流程设计

连线设置
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第5张图片

流程图
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第6张图片
流程文件bpmn


<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
  <process id="exclusiveGateway" name="排他网关" isExecutable="true">
    <startEvent id="startEvent1">startEvent>
    <userTask id="student" name="请假" activiti:assignee="admin">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">modeler:initiator-can-complete>
      extensionElements>
    userTask>
    <sequenceFlow id="sid-13B085EF-2E80-43D1-BEDF-8950B2A9B783" sourceRef="startEvent1" targetRef="student">sequenceFlow>
    <endEvent id="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">endEvent>
    <sequenceFlow id="sid-DCE668F0-BD17-4EC2-8C65-0334163C1767" sourceRef="userTask3" targetRef="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">sequenceFlow>
    <exclusiveGateway id="sid-8B31D4EF-20E6-41A7-951E-1BAD308BE658">exclusiveGateway>
    <userTask id="userTask1" name="分路1" activiti:assignee="test">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">modeler:initiator-can-complete>
      extensionElements>
    userTask>
    <userTask id="userTask2" name="分路2" activiti:assignee="test2">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">modeler:initiator-can-complete>
      extensionElements>
    userTask>
    <userTask id="userTask3" name="分路3" activiti:assignee="test3">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">modeler:initiator-can-complete>
      extensionElements>
    userTask>
    <sequenceFlow id="sid-B6BDAB4C-31D7-4C0D-A691-5B1B0BA45CD5" sourceRef="student" targetRef="sid-8B31D4EF-20E6-41A7-951E-1BAD308BE658">sequenceFlow>
    <sequenceFlow id="sid-BBFB84EF-D0E4-4033-BABF-C6EAAB6D5A2D" sourceRef="userTask1" targetRef="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">sequenceFlow>
    <sequenceFlow id="sid-519E63CA-62C7-4960-974C-344EC3507E4B" sourceRef="userTask2" targetRef="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">sequenceFlow>
    <sequenceFlow id="sid-6B065627-2360-48BE-85C0-D323A4C7145C" name="小于10" sourceRef="sid-8B31D4EF-20E6-41A7-951E-1BAD308BE658" targetRef="userTask2">
      <conditionExpression xsi:type="tFormalExpression">=5}]]>conditionExpression>
    sequenceFlow>
    <sequenceFlow id="sid-90E72D0D-C484-49AB-A535-CE690D4D552A" name="小于5" sourceRef="sid-8B31D4EF-20E6-41A7-951E-1BAD308BE658" targetRef="userTask1">
      <conditionExpression xsi:type="tFormalExpression">conditionExpression>
    sequenceFlow>
    <sequenceFlow id="sid-AE551128-BF5C-4F31-89B5-E90744E1C7D9" name="大于10" sourceRef="sid-8B31D4EF-20E6-41A7-951E-1BAD308BE658" targetRef="userTask3">
      <conditionExpression xsi:type="tFormalExpression">10}]]>conditionExpression>
    sequenceFlow>
  process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_exclusiveGateway">
    <bpmndi:BPMNPlane bpmnElement="exclusiveGateway" id="BPMNPlane_exclusiveGateway">
      <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
        <omgdc:Bounds height="30.0" width="30.0" x="480.0" y="30.0">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="student" id="BPMNShape_student">
        <omgdc:Bounds height="80.0" width="100.0" x="445.0" y="90.0">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD" id="BPMNShape_sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">
        <omgdc:Bounds height="28.0" width="28.0" x="481.0" y="505.05052045693685">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-8B31D4EF-20E6-41A7-951E-1BAD308BE658" id="BPMNShape_sid-8B31D4EF-20E6-41A7-951E-1BAD308BE658">
        <omgdc:Bounds height="40.00000000000003" width="40.0" x="475.0" y="218.8552255313393">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="userTask1" id="BPMNShape_userTask1">
        <omgdc:Bounds height="80.0" width="100.0" x="270.0" y="345.0">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="userTask2" id="BPMNShape_userTask2">
        <omgdc:Bounds height="80.0" width="100.0" x="445.0" y="345.0">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="userTask3" id="BPMNShape_userTask3">
        <omgdc:Bounds height="80.0" width="100.0" x="630.0" y="345.0">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-BBFB84EF-D0E4-4033-BABF-C6EAAB6D5A2D" id="BPMNEdge_sid-BBFB84EF-D0E4-4033-BABF-C6EAAB6D5A2D">
        <omgdi:waypoint x="370.0" y="423.300148701982">omgdi:waypoint>
        <omgdi:waypoint x="483.88595022255396" y="510.5371252737886">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-13B085EF-2E80-43D1-BEDF-8950B2A9B783" id="BPMNEdge_sid-13B085EF-2E80-43D1-BEDF-8950B2A9B783">
        <omgdi:waypoint x="495.0" y="60.0">omgdi:waypoint>
        <omgdi:waypoint x="495.0" y="90.0">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-519E63CA-62C7-4960-974C-344EC3507E4B" id="BPMNEdge_sid-519E63CA-62C7-4960-974C-344EC3507E4B">
        <omgdi:waypoint x="495.0" y="425.0">omgdi:waypoint>
        <omgdi:waypoint x="495.0" y="505.05052045693685">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-90E72D0D-C484-49AB-A535-CE690D4D552A" id="BPMNEdge_sid-90E72D0D-C484-49AB-A535-CE690D4D552A">
        <omgdi:waypoint x="484.57034995102333" y="248.42557548236266">omgdi:waypoint>
        <omgdi:waypoint x="368.1994635620143" y="345.0">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-6B065627-2360-48BE-85C0-D323A4C7145C" id="BPMNEdge_sid-6B065627-2360-48BE-85C0-D323A4C7145C">
        <omgdi:waypoint x="495.43454810870884" y="258.4206774226305">omgdi:waypoint>
        <omgdi:waypoint x="495.13732040900857" y="345.0">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-DCE668F0-BD17-4EC2-8C65-0334163C1767" id="BPMNEdge_sid-DCE668F0-BD17-4EC2-8C65-0334163C1767">
        <omgdi:waypoint x="639.9100433989835" y="425.0">omgdi:waypoint>
        <omgdi:waypoint x="506.743429442482" y="511.42871850927077">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-AE551128-BF5C-4F31-89B5-E90744E1C7D9" id="BPMNEdge_sid-AE551128-BF5C-4F31-89B5-E90744E1C7D9">
        <omgdi:waypoint x="506.1180690142432" y="247.7371565170961">omgdi:waypoint>
        <omgdi:waypoint x="630.0" y="345.5298714177071">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-B6BDAB4C-31D7-4C0D-A691-5B1B0BA45CD5" id="BPMNEdge_sid-B6BDAB4C-31D7-4C0D-A691-5B1B0BA45CD5">
        <omgdi:waypoint x="495.0" y="170.0">omgdi:waypoint>
        <omgdi:waypoint x="495.0" y="218.8552255313393">omgdi:waypoint>
      bpmndi:BPMNEdge>
    bpmndi:BPMNPlane>
  bpmndi:BPMNDiagram>
definitions>

2.2 测试类

ExclusiveGatewayTest.java

package com.it.cloud.activiti.gateway;

import com.it.cloud.modules.activiti.service.IActReModelService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 排他网关测试
 */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class ExclusiveGatewayTest {

    @Autowired
    private IActReModelService actReModelService;

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private TaskService taskService;

    @Autowired
    private HistoryService historyService;

    /**
     * 部署流程定义
     */
    @Test
    public void deploy() {
        Deployment deployment = repositoryService.createDeployment() // 创建部署
                .addClasspathResource("diagrams/exclusiveGateway.bpmn20.xml") // 加载流程资源文件
                .name("exclusiveGateway流程") // 流程名称
                .deploy(); // 部署
        System.out.println("流程部署ID:" + deployment.getId());
        System.out.println("流程部署Name:" + deployment.getName());
    }

    /**
     * 启动流程实例
     */
    @Test
    public void start() {
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("exclusiveGateway"); // 流程定义表的KEY字段值
        System.out.println("流程实例ID:" + pi.getId());
        System.out.println("流程定义ID:" + pi.getProcessDefinitionId());
    }

    /**
     * 查看任务
     */
    @Test
    public void queryTask() {
        List<Task> taskList = taskService.createTaskQuery() // 创建任务查询
                .taskAssignee("admin") // 指定某个人
                .list();
        for (Task task : taskList) {
            System.out.println("任务ID:" + task.getId());
            System.out.println("任务名称:" + task.getName());
            System.out.println("任务创建时间:" + task.getCreateTime());
            System.out.println("任务委派人:" + task.getAssignee());
            System.out.println("流程实例ID:" + task.getProcessInstanceId());
        }
    }

    /**
     * 完成任务
     */
    @Test
    public void completeTask() {
        taskService.complete("85005");
    }

    /**
     * 完成任务2
     */
    @Test
    public void completeTask2() {
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("days", 7);
        taskService.complete("165005", variables);
    }
}

2.3 运行

运行deploy(), start()

2.3.1 查询任务

运行queryTask()

效果:
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第7张图片

2.3.2 完成任务

运行completeTask2(),设置参数days==7

效果:
数据库ACT_RU_TASK, 任务到达分路2节点
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第8张图片

3. 并行网关

并行网关用于表述流程的并发,并行网关可以让一个执行流变成多个同时进行的并发执行流,也可以让多个执行流合并为一个执行流,因此并行网关会有两种行为,分岔和合并。

3.1 流程设计

流程图
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第9张图片

流程文件bpmn


<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
  <process id="parallelGateway" name="并行网关" isExecutable="true">
    <startEvent id="startEvent1">startEvent>
    <userTask id="student" name="请假" activiti:assignee="admin">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">modeler:initiator-can-complete>
      extensionElements>
    userTask>
    <sequenceFlow id="sid-13B085EF-2E80-43D1-BEDF-8950B2A9B783" sourceRef="startEvent1" targetRef="student">sequenceFlow>
    <endEvent id="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">endEvent>
    <userTask id="userTask1" name="班长" activiti:assignee="test">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">modeler:initiator-can-complete>
      extensionElements>
    userTask>
    <userTask id="userTask2" name="班主任" activiti:assignee="test2">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">modeler:initiator-can-complete>
      extensionElements>
    userTask>
    <userTask id="userTask3" name="校长" activiti:assignee="test3">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">modeler:initiator-can-complete>
      extensionElements>
    userTask>
    <parallelGateway id="sid-5DDB2499-4CB7-46F5-BD50-455312B93033">parallelGateway>
    <sequenceFlow id="sid-B6BDAB4C-31D7-4C0D-A691-5B1B0BA45CD5" sourceRef="student" targetRef="sid-5DDB2499-4CB7-46F5-BD50-455312B93033">sequenceFlow>
    <parallelGateway id="sid-8B8D887B-14FC-4766-A0AA-558874F3ACD1">parallelGateway>
    <sequenceFlow id="sid-7DFC8B7A-5B14-4B29-BA7A-04A8A796045D" sourceRef="sid-5DDB2499-4CB7-46F5-BD50-455312B93033" targetRef="userTask1">sequenceFlow>
    <sequenceFlow id="sid-DCD4E730-E07A-4233-92B1-20F8902AFEC2" sourceRef="sid-5DDB2499-4CB7-46F5-BD50-455312B93033" targetRef="userTask2">sequenceFlow>
    <sequenceFlow id="sid-9CEADDDB-3F74-41E6-AE39-58026D4C77E8" sourceRef="userTask2" targetRef="sid-8B8D887B-14FC-4766-A0AA-558874F3ACD1">sequenceFlow>
    <sequenceFlow id="sid-68C89AA3-AC62-4F8F-9539-4F3743EAB039" sourceRef="userTask1" targetRef="sid-8B8D887B-14FC-4766-A0AA-558874F3ACD1">sequenceFlow>
    <sequenceFlow id="sid-AA6BAF4E-2895-4B1F-9779-3F8B4B0529D2" sourceRef="sid-8B8D887B-14FC-4766-A0AA-558874F3ACD1" targetRef="userTask3">sequenceFlow>
    <sequenceFlow id="sid-7D9A40CD-A52A-468F-87EB-1F8FB1C1045C" sourceRef="userTask3" targetRef="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">sequenceFlow>
  process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_parallelGateway">
    <bpmndi:BPMNPlane bpmnElement="parallelGateway" id="BPMNPlane_parallelGateway">
      <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
        <omgdc:Bounds height="30.000000000000004" width="30.0" x="468.3333161142144" y="16.666666004392862">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="student" id="BPMNShape_student">
        <omgdc:Bounds height="80.0" width="100.0" x="433.3333161142144" y="83.33333002196431">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD" id="BPMNShape_sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">
        <omgdc:Bounds height="28.000000000000114" width="28.0" x="469.3333161142144" y="549.9999781449644">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="userTask1" id="BPMNShape_userTask1">
        <omgdc:Bounds height="80.0" width="100.0" x="316.6666540834644" y="266.6666560702858">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="userTask2" id="BPMNShape_userTask2">
        <omgdc:Bounds height="80.0" width="100.0" x="566.6666441493574" y="266.6666560702858">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="userTask3" id="BPMNShape_userTask3">
        <omgdc:Bounds height="80.0" width="100.00000000000011" x="433.3333161142144" y="433.3333161142144">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-5DDB2499-4CB7-46F5-BD50-455312B93033" id="BPMNShape_sid-5DDB2499-4CB7-46F5-BD50-455312B93033">
        <omgdc:Bounds height="40.0" width="40.0" x="463.3333161142145" y="216.6666580571072">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-8B8D887B-14FC-4766-A0AA-558874F3ACD1" id="BPMNShape_sid-8B8D887B-14FC-4766-A0AA-558874F3ACD1">
        <omgdc:Bounds height="40.0" width="40.0" x="463.3333161142144" y="366.66665209664296">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-13B085EF-2E80-43D1-BEDF-8950B2A9B783" id="BPMNEdge_sid-13B085EF-2E80-43D1-BEDF-8950B2A9B783">
        <omgdi:waypoint x="483.3333161142144" y="46.666666004392866">omgdi:waypoint>
        <omgdi:waypoint x="483.3333161142144" y="83.33333002196431">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-DCD4E730-E07A-4233-92B1-20F8902AFEC2" id="BPMNEdge_sid-DCD4E730-E07A-4233-92B1-20F8902AFEC2">
        <omgdi:waypoint x="496.30695692247645" y="243.69301724884525">omgdi:waypoint>
        <omgdi:waypoint x="566.6666441493574" y="280.5060535162372">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-9CEADDDB-3F74-41E6-AE39-58026D4C77E8" id="BPMNEdge_sid-9CEADDDB-3F74-41E6-AE39-58026D4C77E8">
        <omgdi:waypoint x="566.6666441493574" y="336.6666557722626">omgdi:waypoint>
        <omgdi:waypoint x="495.83331616078056" y="379.1666521432091">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-AA6BAF4E-2895-4B1F-9779-3F8B4B0529D2" id="BPMNEdge_sid-AA6BAF4E-2895-4B1F-9779-3F8B4B0529D2">
        <omgdi:waypoint x="483.72242116915095" y="406.27754704170644">omgdi:waypoint>
        <omgdi:waypoint x="483.56542443856506" y="433.3333161142144">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-7D9A40CD-A52A-468F-87EB-1F8FB1C1045C" id="BPMNEdge_sid-7D9A40CD-A52A-468F-87EB-1F8FB1C1045C">
        <omgdi:waypoint x="483.3333161142144" y="513.3333161142144">omgdi:waypoint>
        <omgdi:waypoint x="483.3333161142144" y="549.9999781449644">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-68C89AA3-AC62-4F8F-9539-4F3743EAB039" id="BPMNEdge_sid-68C89AA3-AC62-4F8F-9539-4F3743EAB039">
        <omgdi:waypoint x="416.6666540834644" y="340.9523700154021">omgdi:waypoint>
        <omgdi:waypoint x="471.4689092866094" y="378.531058924248">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-7DFC8B7A-5B14-4B29-BA7A-04A8A796045D" id="BPMNEdge_sid-7DFC8B7A-5B14-4B29-BA7A-04A8A796045D">
        <omgdi:waypoint x="471.2797447369608" y="244.61308667985355">omgdi:waypoint>
        <omgdi:waypoint x="416.6666540834644" y="277.00804977025376">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-B6BDAB4C-31D7-4C0D-A691-5B1B0BA45CD5" id="BPMNEdge_sid-B6BDAB4C-31D7-4C0D-A691-5B1B0BA45CD5">
        <omgdi:waypoint x="483.5090115835925" y="163.33333002196431">omgdi:waypoint>
        <omgdi:waypoint x="483.74508081597196" y="217.07842275886466">omgdi:waypoint>
      bpmndi:BPMNEdge>
    bpmndi:BPMNPlane>
  bpmndi:BPMNDiagram>
definitions>

3.2 测试类

ParallelGatewayTest.java

package com.it.cloud.activiti.gateway;

import com.it.cloud.modules.activiti.service.IActReModelService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 并行网关测试
 */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class ParallelGatewayTest {

    @Autowired
    private IActReModelService actReModelService;

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private TaskService taskService;

    @Autowired
    private HistoryService historyService;

    /**
     * 部署流程定义
     */
    @Test
    public void deploy() {
        Deployment deployment = repositoryService.createDeployment() // 创建部署
                .addClasspathResource("diagrams/parallelGateway.bpmn20.xml") // 加载流程资源文件
                .name("parallelGateway流程") // 流程名称
                .deploy(); // 部署
        System.out.println("流程部署ID:" + deployment.getId());
        System.out.println("流程部署Name:" + deployment.getName());
    }

    /**
     * 启动流程实例
     */
    @Test
    public void start() {
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("parallelGateway"); // 流程定义表的KEY字段值
        System.out.println("流程实例ID:" + pi.getId());
        System.out.println("流程定义ID:" + pi.getProcessDefinitionId());
    }

    /**
     * 查看任务
     */
    @Test
    public void queryTask() {
        List<Task> taskList = taskService.createTaskQuery() // 创建任务查询
                .taskAssignee("admin") // 指定某个人
                .list();
        for (Task task : taskList) {
            System.out.println("任务ID:" + task.getId());
            System.out.println("任务名称:" + task.getName());
            System.out.println("任务创建时间:" + task.getCreateTime());
            System.out.println("任务委派人:" + task.getAssignee());
            System.out.println("流程实例ID:" + task.getProcessInstanceId());
        }
    }

    /**
     * 完成任务
     */
    @Test
    public void completeTask() {
        taskService.complete("172505");
    }
}

3.3 运行

运行deploy(), start()

3.3.1 查询任务

运行queryTask()

效果:
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第10张图片

3.3.2 完成任务

运行completeTask()

效果:
数据库ACT_RU_TASK, 任务到达班长和班主任节点
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第11张图片

3.3.3 完成班长任务

运行completeTask()

效果:
数据库ACT_RU_TASK, 只剩下班主任节点
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第12张图片

3.3.4 完成班主任任务

运行completeTask()

效果:
数据库ACT_RU_TASK, 任务到达校长节点

【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第13张图片

4. 兼容网关

兼容网关就好像排他网关和并行网关的结合体,与排他网关不同的是,兼容网关可以创建多条执行流,换言之,如果多个条件成立,那么此时可以将它看做并行网关,而排他网关,多个条件成立时,只会选择第一个定义的顺序流。

4.1 流程设计

连线设置
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第14张图片
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第15张图片

流程图
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第16张图片
流程文件bpmn


<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
  <process id="inclusiveGateway" name="兼容网关" isExecutable="true">
    <startEvent id="startEvent1">startEvent>
    <userTask id="student" name="请假" activiti:assignee="admin">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">modeler:initiator-can-complete>
      extensionElements>
    userTask>
    <sequenceFlow id="sid-13B085EF-2E80-43D1-BEDF-8950B2A9B783" sourceRef="startEvent1" targetRef="student">sequenceFlow>
    <endEvent id="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">endEvent>
    <userTask id="userTask1" name="班长" activiti:assignee="test">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">modeler:initiator-can-complete>
      extensionElements>
    userTask>
    <userTask id="userTask2" name="班主任" activiti:assignee="test2">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">modeler:initiator-can-complete>
      extensionElements>
    userTask>
    <sequenceFlow id="sid-B6BDAB4C-31D7-4C0D-A691-5B1B0BA45CD5" sourceRef="student" targetRef="sid-861418F9-D9DD-43B2-B504-FB959C2B2717">sequenceFlow>
    <inclusiveGateway id="sid-861418F9-D9DD-43B2-B504-FB959C2B2717">inclusiveGateway>
    <inclusiveGateway id="sid-A4689DF5-AF9B-4C06-83B8-DEE3FE54B707">inclusiveGateway>
    <sequenceFlow id="sid-68C89AA3-AC62-4F8F-9539-4F3743EAB039" sourceRef="userTask1" targetRef="sid-A4689DF5-AF9B-4C06-83B8-DEE3FE54B707">sequenceFlow>
    <sequenceFlow id="sid-9CEADDDB-3F74-41E6-AE39-58026D4C77E8" sourceRef="userTask2" targetRef="sid-A4689DF5-AF9B-4C06-83B8-DEE3FE54B707">sequenceFlow>
    <sequenceFlow id="sid-7DFC8B7A-5B14-4B29-BA7A-04A8A796045D" name="大于5" sourceRef="sid-861418F9-D9DD-43B2-B504-FB959C2B2717" targetRef="userTask1">
      <conditionExpression xsi:type="tFormalExpression">5}]]>conditionExpression>
    sequenceFlow>
    <sequenceFlow id="sid-DCD4E730-E07A-4233-92B1-20F8902AFEC2" name="大于10" sourceRef="sid-861418F9-D9DD-43B2-B504-FB959C2B2717" targetRef="userTask2">
      <conditionExpression xsi:type="tFormalExpression">10}]]>conditionExpression>
    sequenceFlow>
    <sequenceFlow id="sid-AA6BAF4E-2895-4B1F-9779-3F8B4B0529D2" sourceRef="sid-A4689DF5-AF9B-4C06-83B8-DEE3FE54B707" targetRef="userTask3">sequenceFlow>
    <sequenceFlow id="sid-7D9A40CD-A52A-468F-87EB-1F8FB1C1045C" sourceRef="userTask3" targetRef="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">sequenceFlow>
    <userTask id="userTask3" name="校长" activiti:assignee="test3">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://activiti.com/modeler">modeler:initiator-can-complete>
      extensionElements>
    userTask>
  process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_inclusiveGateway">
    <bpmndi:BPMNPlane bpmnElement="inclusiveGateway" id="BPMNPlane_inclusiveGateway">
      <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
        <omgdc:Bounds height="30.000000000000004" width="30.0" x="468.3333161142144" y="16.666666004392862">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="student" id="BPMNShape_student">
        <omgdc:Bounds height="80.0" width="100.0" x="433.3333161142144" y="83.33333002196431">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD" id="BPMNShape_sid-9AFEE86D-C779-494A-8ACD-D2AC0E96C5AD">
        <omgdc:Bounds height="28.0" width="28.0" x="469.3333161142144" y="549.9999781449644">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="userTask1" id="BPMNShape_userTask1">
        <omgdc:Bounds height="80.0" width="100.0" x="316.6666540834644" y="266.6666560702858">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="userTask2" id="BPMNShape_userTask2">
        <omgdc:Bounds height="80.0" width="100.0" x="566.6666441493574" y="266.6666560702858">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-861418F9-D9DD-43B2-B504-FB959C2B2717" id="BPMNShape_sid-861418F9-D9DD-43B2-B504-FB959C2B2717">
        <omgdc:Bounds height="40.0" width="40.0" x="463.3333161142145" y="199.99999205271433">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-A4689DF5-AF9B-4C06-83B8-DEE3FE54B707" id="BPMNShape_sid-A4689DF5-AF9B-4C06-83B8-DEE3FE54B707">
        <omgdc:Bounds height="40.0" width="40.00000000000006" x="463.3333161142144" y="366.66665209664296">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="userTask3" id="BPMNShape_userTask3">
        <omgdc:Bounds height="80.0" width="100.00000000000011" x="433.3333161142144" y="433.3333161142144">omgdc:Bounds>
      bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-13B085EF-2E80-43D1-BEDF-8950B2A9B783" id="BPMNEdge_sid-13B085EF-2E80-43D1-BEDF-8950B2A9B783">
        <omgdi:waypoint x="483.3333161142144" y="46.666666004392866">omgdi:waypoint>
        <omgdi:waypoint x="483.3333161142144" y="83.33333002196431">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-DCD4E730-E07A-4233-92B1-20F8902AFEC2" id="BPMNEdge_sid-DCD4E730-E07A-4233-92B1-20F8902AFEC2">
        <omgdi:waypoint x="495.3576691930046" y="227.9756389739242">omgdi:waypoint>
        <omgdi:waypoint x="566.6666441493574" y="274.2325277938434">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-9CEADDDB-3F74-41E6-AE39-58026D4C77E8" id="BPMNEdge_sid-9CEADDDB-3F74-41E6-AE39-58026D4C77E8">
        <omgdi:waypoint x="566.6666441493574" y="336.96778501778147">omgdi:waypoint>
        <omgdi:waypoint x="496.2864411587433" y="379.6197771411718">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-AA6BAF4E-2895-4B1F-9779-3F8B4B0529D2" id="BPMNEdge_sid-AA6BAF4E-2895-4B1F-9779-3F8B4B0529D2">
        <omgdi:waypoint x="483.72242116915095" y="406.27754704170644">omgdi:waypoint>
        <omgdi:waypoint x="483.56542443856506" y="433.3333161142144">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-7D9A40CD-A52A-468F-87EB-1F8FB1C1045C" id="BPMNEdge_sid-7D9A40CD-A52A-468F-87EB-1F8FB1C1045C">
        <omgdi:waypoint x="483.3333161142144" y="513.3333161142144">omgdi:waypoint>
        <omgdi:waypoint x="483.3333161142144" y="549.9999781449644">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-68C89AA3-AC62-4F8F-9539-4F3743EAB039" id="BPMNEdge_sid-68C89AA3-AC62-4F8F-9539-4F3743EAB039">
        <omgdi:waypoint x="416.6666540834644" y="341.01942956025266">omgdi:waypoint>
        <omgdi:waypoint x="471.38559262442436" y="378.614375586433">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-7DFC8B7A-5B14-4B29-BA7A-04A8A796045D" id="BPMNEdge_sid-7DFC8B7A-5B14-4B29-BA7A-04A8A796045D">
        <omgdi:waypoint x="472.3087259933697" y="228.97540193186953">omgdi:waypoint>
        <omgdi:waypoint x="416.6666540834644" y="269.89567423803163">omgdi:waypoint>
      bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-B6BDAB4C-31D7-4C0D-A691-5B1B0BA45CD5" id="BPMNEdge_sid-B6BDAB4C-31D7-4C0D-A691-5B1B0BA45CD5">
        <omgdi:waypoint x="483.53914802798" y="163.33333002196431">omgdi:waypoint>
        <omgdi:waypoint x="483.72986783339127" y="200.39654377189112">omgdi:waypoint>
      bpmndi:BPMNEdge>
    bpmndi:BPMNPlane>
  bpmndi:BPMNDiagram>
definitions>

4.2 测试类

InclusiveGatewayTest .java

import com.it.cloud.modules.activiti.service.IActReModelService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 兼容网关测试
 */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class InclusiveGatewayTest {

    @Autowired
    private IActReModelService actReModelService;

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private TaskService taskService;

    @Autowired
    private HistoryService historyService;

    /**
     * 部署流程定义
     */
    @Test
    public void deploy() {
        Deployment deployment = repositoryService.createDeployment() // 创建部署
                .addClasspathResource("diagrams/inclusiveGateway.bpmn20.xml") // 加载流程资源文件
                .name("inclusiveGateway流程") // 流程名称
                .deploy(); // 部署
        System.out.println("流程部署ID:" + deployment.getId());
        System.out.println("流程部署Name:" + deployment.getName());
    }

    /**
     * 启动流程实例
     */
    @Test
    public void start() {
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("inclusiveGateway"); // 流程定义表的KEY字段值
        System.out.println("流程实例ID:" + pi.getId());
        System.out.println("流程定义ID:" + pi.getProcessDefinitionId());
    }

    /**
     * 查看任务
     */
    @Test
    public void queryTask() {
        List<Task> taskList = taskService.createTaskQuery() // 创建任务查询
                .taskAssignee("admin") // 指定某个人
                .list();
        for (Task task : taskList) {
            System.out.println("任务ID:" + task.getId());
            System.out.println("任务名称:" + task.getName());
            System.out.println("任务创建时间:" + task.getCreateTime());
            System.out.println("任务委派人:" + task.getAssignee());
            System.out.println("流程实例ID:" + task.getProcessInstanceId());
        }
    }

    /**
     * 完成任务
     */
    @Test
    public void completeTask() {
        taskService.complete("175007");
    }

    /**
     * 完成任务2
     */
    @Test
    public void completeTask2() {
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("days", 7);
        taskService.complete("185005", variables);
    }
}

4.3 运行

运行deploy(), start()

4.3.1 查询任务

运行queryTask()

效果:【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第17张图片

4.3.2 完成任务

运行completeTask2(),设置参数days==7

效果:
数据库ACT_RU_TASK, 任务到达班长节点
【弄nèng - Activiti6】Activiti6入门篇(五)—— 流程网关_第18张图片

5. 事件网关

当流程经过事件网关时,如果某一事件先触发,流程就往这一事件所处方向执行。
不太常用,感兴趣的额外看下。


源码地址

IT-CLOUD-ACTIVITI6
开源项目,持续更新中,喜欢请 Star~

项目推荐

IT-CLOUD :IT服务管理平台,集成基础服务,中间件服务,监控告警服务等。
开源项目,持续更新中,喜欢请 Star~

你可能感兴趣的:(Activiti6,activiti)