zoukankan      html  css  js  c++  java
  • Activiti网关-排他网关

    排他网关

    1、什么是排他网关

      排他网关(也叫异或(XOR)网关,或叫基于数据的排他网关),用来在流程中实现决策。 当流程执行到这个网关,所有分支都会判断条件是否为true,如果为 true 则执行该分支,

      注意,排他网关只会选择一个为 true 的分支执行。(即使有两个分支条件都为 true,排他网关也会只选择一条分支去执行)

    不使用排他网关也可以实现分支:

        

      上图中,在连线的condition条件上设置分支条件;

      缺点:如果条件都不满足,不使用排他网关,流程就结束了(是异常结束);

      如果使用排他网关决定分支的走向:

        

      如果从网关出去的线所有条件都不满足则系统抛出org.activiti.engine.ActivitiException异常;

      说明:经过排他网关必须要有一条且只有一条分支走;

    2、流程定义

      

    3、部署流程

    package com.zn;
    
    import com.zn.entity.Holiday;
    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 ActivitiExclusiveGateway {
        /**
         * 流程部署
         */
        @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/holidayExclusiveGateway.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 com.zn.entity.Holiday;
    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 ActivitiExclusiveGateway {
    
        /**
         * 启动流程实例
         */
        @Test
        public void getInstance() {
            //获取ProcessEngine对象   默认配置文件名称:activiti.cfg.xml  并且configuration的Bean实例ID为processEngineConfiguration
            ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
            //获取RuntimeService
            RuntimeService runtimeService = processEngine.getRuntimeService();
            //设置流程变量  启动流程时设置
            Holiday holiday=new Holiday();
            holiday.setNum(3);
            //定义一个map集合,存放assignee的值
            Map<String ,Object> assMap=new HashMap<>();
            assMap.put("holiday",holiday);
            //启动一个流程实例
            ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holidayWay", assMap);
            System.out.println("流程启动成功~");
        }
    
    }

    数据库:

      

    5、任务处理

    package com.zn;
    
    import com.zn.entity.Holiday;
    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 ActivitiExclusiveGateway {
    
        /*
         *任务处理
         */
        @Test
        public void completeTask(){
            //获取ProcessEngine
            ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
            //获取TaskService对象
            TaskService taskService = processEngine.getTaskService();
            //查询到自己的任务,然后通过任务ID进行提交
            Task task = taskService.createTaskQuery().processDefinitionKey("holidayWay").taskAssignee("zhangsan").singleResult();
            //任务处理
            taskService.complete(task.getId());
        }
        
    }

    数据库:

      

    6、任务处理

    package com.zn;
    
    import com.zn.entity.Holiday;
    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 ActivitiExclusiveGateway {
    
        /*
         *任务处理
         */
        @Test
        public void completeTask(){
            //获取ProcessEngine
            ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
            //获取TaskService对象
            TaskService taskService = processEngine.getTaskService();
            //查询到自己的任务,然后通过任务ID进行提交
            Task task = taskService.createTaskQuery().processDefinitionKey("holidayWay").taskAssignee("lisi").singleResult();
            //任务处理
            taskService.complete(task.getId());
        }
    
    
    }

    数据库:

      

  • 相关阅读:
    FloatingActionButton
    OpenWrt for WR720N
    OpenWrt
    shell修改文件名(二)
    shell修改文件名(一)
    POJ 1300 Door Man(欧拉通路)
    USACO zerosum DFS 1A
    hadoop源代码解读namenode高可靠:HA;web方式查看namenode下信息;dfs/data决定datanode存储位置
    Leetcode-subsets
    单链表的各种操作 笔试 面试
  • 原文地址:https://www.cnblogs.com/F017/p/12656363.html
Copyright © 2011-2022 走看看