activiti学习--10 并行网关

parallelGateWay.bpmn

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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/test">
  <process id="parallelGateWay" name="parallelGateWayProcess" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <userTask id="usertask1" name="付款" activiti:assignee="买家"></userTask>
    <userTask id="usertask2" name="发货" activiti:assignee="商家"></userTask>
    <userTask id="usertask3" name="收款" activiti:assignee="商家"></userTask>
    <userTask id="usertask4" name="收货" activiti:assignee="买家"></userTask>
    <parallelGateway id="parallelgateway1" name="Parallel Gateway"></parallelGateway>
    <parallelGateway id="parallelgateway2" name="Parallel Gateway"></parallelGateway>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="parallelgateway1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="parallelgateway1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="usertask1" targetRef="usertask3"></sequenceFlow>
    <sequenceFlow id="flow4" sourceRef="usertask3" targetRef="parallelgateway2"></sequenceFlow>
    <sequenceFlow id="flow5" sourceRef="parallelgateway2" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="flow6" sourceRef="parallelgateway1" targetRef="usertask2"></sequenceFlow>
    <sequenceFlow id="flow7" sourceRef="usertask2" targetRef="usertask4"></sequenceFlow>
    <sequenceFlow id="flow8" sourceRef="usertask4" targetRef="parallelgateway2"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_parallelGateWay">
    <bpmndi:BPMNPlane bpmnElement="parallelGateWay" id="BPMNPlane_parallelGateWay">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="323.0" y="20.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55.0" width="105.0" x="150.0" y="180.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
        <omgdc:Bounds height="55.0" width="105.0" x="450.0" y="180.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="330.0" y="460.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
        <omgdc:Bounds height="55.0" width="105.0" x="150.0" y="280.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
        <omgdc:Bounds height="55.0" width="105.0" x="450.0" y="280.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="parallelgateway1" id="BPMNShape_parallelgateway1">
        <omgdc:Bounds height="40.0" width="40.0" x="320.0" y="100.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="parallelgateway2" id="BPMNShape_parallelgateway2">
        <omgdc:Bounds height="40.0" width="40.0" x="330.0" y="380.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="340.0" y="55.0"></omgdi:waypoint>
        <omgdi:waypoint x="340.0" y="100.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="340.0" y="140.0"></omgdi:waypoint>
        <omgdi:waypoint x="202.0" y="180.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="202.0" y="235.0"></omgdi:waypoint>
        <omgdi:waypoint x="202.0" y="280.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="202.0" y="335.0"></omgdi:waypoint>
        <omgdi:waypoint x="350.0" y="380.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="350.0" y="420.0"></omgdi:waypoint>
        <omgdi:waypoint x="347.0" y="460.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
        <omgdi:waypoint x="340.0" y="140.0"></omgdi:waypoint>
        <omgdi:waypoint x="502.0" y="180.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
        <omgdi:waypoint x="502.0" y="235.0"></omgdi:waypoint>
        <omgdi:waypoint x="502.0" y="280.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
        <omgdi:waypoint x="502.0" y="335.0"></omgdi:waypoint>
        <omgdi:waypoint x="350.0" y="380.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

这里写图片描述
这里写图片描述

测试数据

   /**部署流程定义(从inputStream)*/
  @Test
  public void deploymentProcessDefinition_inputStream(){
      InputStream inputStreamBpmn = this.getClass().getResourceAsStream("parallelGateWay.bpmn");
      InputStream inputStreamPng = this.getClass().getResourceAsStream("parallelGateWay.png");
      Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署对象相关的Service
                      .createDeployment()//创建一个部署对象
                      .name("并行网关")//添加部署的名称
                      .addInputStream("parallelGateWay.bpmn", inputStreamBpmn)//
                      .addInputStream("parallelGateWay.png", inputStreamPng)//
                      .deploy();//完成部署
      System.out.println("部署ID:"+deployment.getId());
      System.out.println("部署名称:"+deployment.getName());  
      System.out.println("部署时间:"+deployment.getDeploymentTime()); 
//      部署ID:3201
//      部署名称:并行网关
//      部署时间:Wed Sep 06 21:02:53 CST 2017

  }

  /**启动流程实例*/
     @Test
  public void startProcessInstance(){
      //流程定义的key.,key对应helloworld.bpmn文件中id的属性值,使用key值启动,默认是按照最新版本的流程定义启动
      String processDefinitionKey = "parallelGateWay";
      ProcessInstance pi = processEngine.getRuntimeService()//与正在执行的流程实例和执行对象相关的Service
                      .startProcessInstanceByKey(processDefinitionKey);//使用流程定义的key启动流程实例,
      System.out.println("流程实例ID:"+pi.getId());// 
      System.out.println("流程定义ID:"+pi.getProcessDefinitionId());// 
//      流程实例ID:3301
//      流程定义ID:parallelGateWay:1:3204
  }

    /**查询当前人的个人任务*/
    @Test
    public void findMyPersonalTask(){
        String assignee = "商家";
        List<Task> list = processEngine.getTaskService()//与正在执行的任务管理相关的Service
                        .createTaskQuery()//创建任务查询对象
                        /**查询条件(where部分)*/
                        .taskAssignee(assignee)//指定个人任务查询,指定办理人
//                      .taskCandidateUser(candidateUser)//组任务的办理人查询
//                      .processDefinitionId(processDefinitionId)//使用流程定义ID查询
//                      .processInstanceId(processInstanceId)//使用流程实例ID查询
//                      .executionId(executionId)//使用执行对象ID查询
                        /**排序*/
                        .orderByTaskCreateTime().asc()//使用创建时间的升序排列
                        /**返回结果集*/
//                      .singleResult()//返回惟一结果集
//                      .count()//返回结果集的数量
//                      .listPage(firstResult, maxResults);//分页查询
                        .list();//返回列表
        if(list!=null && list.size()>0){
            System.out.println("--关联表:  ACT_RU_TASK----");
            for(Task task:list){
                   System.out.println("--------"+task.getAssignee()+"任务:"+task.getName()+"-----------------");
                    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());
                    System.out.println("执行对象ID:"+task.getExecutionId());
                    System.out.println("流程定义ID:"+task.getProcessDefinitionId());
//                    --关联表:  ACT_RU_TASK----
//                    --------商家任务:发货-----------------
//                    任务ID:3310
//                    任务名称:发货
//                    任务的创建时间:Wed Sep 06 21:03:06 CST 2017
//                    任务的办理人:商家
//                    流程实例ID:3301
//                    执行对象ID:3305
//                    流程定义ID:parallelGateWay:1:3204
            }
        }
    }

分析:
1用户已经开启实例,流程走到付款节点和发货节点,这时商家和买家都要相应的任务,上面的测试数据只打印了商家数据

2下面的流程是不管商家还是买家,他们都要一步一步走下去,知道商家或买家走到聚合节点,他们相应的任务才走完,也只有商家和买家都走到聚合几点,才能通过聚合节点继续走下去,否者,都要等待对方走到聚合节点。

数据库正在执行的任务情况
这里写图片描述
当商家买家任务都执行完,数据库任务历史情况

这里写图片描述
历史活动节点情况
这里写图片描述

转载于:https://www.cnblogs.com/feiZhou/p/9344110.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值