Activiti网关--并行网关

时间:2024-01-26 17:27:54

1、么是并行网关

  并行网关允许将流程分成多条分支,也可以把多条分支汇聚到一起,并行网关的功能是基于进 入和外出顺序流的:

  fork 分支:

    并行后的所有外出顺序流,为每个顺序流都创建一个并发分支。

  join 汇聚:

    所有到达并行网关,在此等待的进入分支, 直到所有进入顺序流的分支都到达以后,  流程就会通过汇聚网关。

  注意:

    如果同一个并行网关有多个进入和多个外出顺序流, 它就同时具有分支和汇聚功能。 这时, 网关会先汇聚所有进入的顺序流,然后再切分成多个并行分支。

  与其他网关的主要区别:

    并行网关不会解析条件。 即使顺序流中定义了条件,也会被忽略。

2、流程定义

  

 

  

3、部署流程

package com.zn;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class ActivitiParallelGateway {
    /**
     * 流程部署
     */
    @Test
    public void deployment() {
        //获取ProcessEngine对象   默认配置文件名称:activiti.cfg.xml  并且configuration的Bean实例ID为processEngineConfiguration
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //获取RepositoryService对象进行流程部署
        RepositoryService repositoryService = processEngine.getRepositoryService();
        //进行部署,将对应的流程定义文件生成到数据库当中,作为记录进行保存
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource("bmpnfiles/holidayParallelGateway .bpmn")     //加载流程文件
                .name("请假流程-并行网关")       //设置流程名称
                .key("holiday")
                .deploy();                      //部署

        //输出部署信息
        System.out.println("流程名称:" + deployment.getName());
        System.out.println("流程ID:" + deployment.getId());
        System.out.println("流程Key:" + deployment.getKey());
    }
}

控制台:

  

数据库:

  

4、启动流程实例

package com.zn;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class ActivitiParallelGateway {

    /**
     * 启动流程实例
     */
    @Test
    public void startInstance() {
        //获取ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //获取RuntimeService
        RuntimeService runtimeService = processEngine.getRuntimeService();
        //设置流程变量
        Map<String, Object> assMap = new HashMap<>();
        assMap.put("num", 3);
        //启动流程实例
        ProcessInstance holidayGroup = runtimeService.startProcessInstanceByKey("holidayPar", assMap);
        System.out.println("流程实例:" + holidayGroup.getId());
    }
}

数据库:

  

5、任务处理

package com.zn;

import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class ActivitiParallelGateway {

    /*
     *任务处理
     */
    @Test
    public void completeTask(){
        //获取ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //获取TaskService对象
        TaskService taskService = processEngine.getTaskService();
        //查询到自己的任务,然后通过任务ID进行提交
        Task task = taskService.createTaskQuery().processDefinitionKey("holidayPar").taskAssignee("zhangsan").singleResult();
        //任务处理
        taskService.complete(task.getId());
    }
}

数据库:

  

6、任务处理

package com.zn;

import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class ActivitiParallelGateway {

    /*
     *任务处理
     */
    @Test
    public void completeTask(){
        //获取ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //获取TaskService对象
        TaskService taskService = processEngine.getTaskService();
        //查询到自己的任务,然后通过任务ID进行提交
        Task task = taskService.createTaskQuery().processDefinitionKey("holidayPar").taskAssignee("lisi").singleResult();
        //任务处理
        taskService.complete(task.getId());
    }
}

数据库:

  

7、任务处理

package com.zn;

import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class ActivitiParallelGateway {

    /*
     *任务处理
     */
    @Test
    public void completeTask(){
        //获取ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //获取TaskService对象
        TaskService taskService = processEngine.getTaskService();
        //查询到自己的任务,然后通过任务ID进行提交
        Task task = taskService.createTaskQuery().processDefinitionKey("holidayPar").taskAssignee("zhaoliu").singleResult();
        //任务处理
        taskService.complete(task.getId());
    }
}

数据库:

  

  当执行到并行网关时,说明当前流程实例有多个分支在运行;

  并行任务不执行不分前后,有任务的负责人去执行即可;

  当所有分支达到汇聚结点,并行网关就执行完成了;

8、任务处理

package com.zn;

import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class ActivitiParallelGateway {

    /*
     *任务处理
     */
    @Test
    public void completeTask(){
        //获取ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //获取TaskService对象
        TaskService taskService = processEngine.getTaskService();
        //查询到自己的任务,然后通过任务ID进行提交
        Task task = taskService.createTaskQuery().processDefinitionKey("holidayPar").taskAssignee("sunqi").singleResult();
        //任务处理
        taskService.complete(task.getId());
    }
}

数据库:

  

9、任务处理

package com.zn;

import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class ActivitiParallelGateway {

    /*
     *任务处理
     */
    @Test
    public void completeTask(){
        //获取ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //获取TaskService对象
        TaskService taskService = processEngine.getTaskService();
        //查询到自己的任务,然后通过任务ID进行提交
        Task task = taskService.createTaskQuery().processDefinitionKey("holidayPar").taskAssignee("zhouba").singleResult();
        //任务处理
        taskService.complete(task.getId());
    }
}

数据库:

  

执行完成后,整个流程就结束:

  

 

posted on 2020-04-08 14:02  关耳er  阅读(...)  评论(...编辑  收藏