连线:

新建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="sequenceFlow" name="sequenceFlowProcess" isExecutable="true"><startEvent id="startevent1" name="Start"></startEvent><userTask id="usertask1" name="审批【部门经理】" activiti:assignee="赵六"></userTask><sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow><userTask id="usertask2" name="审批【总经理】" activiti:assignee="田七"></userTask><sequenceFlow id="flow2" name="重要" sourceRef="usertask1" targetRef="usertask2"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${message=='重要'}]]></conditionExpression></sequenceFlow><endEvent id="endevent1" name="End"></endEvent><sequenceFlow id="flow3" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow><sequenceFlow id="flow4" name="不重要" sourceRef="usertask1" targetRef="endevent1"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${message=='不重要'}]]></conditionExpression></sequenceFlow></process><bpmndi:BPMNDiagram id="BPMNDiagram_sequenceFlow"><bpmndi:BPMNPlane bpmnElement="sequenceFlow" id="BPMNPlane_sequenceFlow"><bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"><omgdc:Bounds height="35.0" width="35.0" x="340.0" y="50.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1"><omgdc:Bounds height="55.0" width="105.0" x="305.0" y="140.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2"><omgdc:Bounds height="55.0" width="105.0" x="460.0" y="240.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"><omgdc:Bounds height="35.0" width="35.0" x="340.0" y="320.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1"><omgdi:waypoint x="357.0" y="85.0"></omgdi:waypoint><omgdi:waypoint x="357.0" y="140.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2"><omgdi:waypoint x="357.0" y="195.0"></omgdi:waypoint><omgdi:waypoint x="512.0" y="240.0"></omgdi:waypoint><bpmndi:BPMNLabel><omgdc:Bounds height="14.0" width="24.0" x="6.0" y="-17.0"></omgdc:Bounds></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3"><omgdi:waypoint x="512.0" y="295.0"></omgdi:waypoint><omgdi:waypoint x="357.0" y="320.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4"><omgdi:waypoint x="357.0" y="195.0"></omgdi:waypoint><omgdi:waypoint x="357.0" y="320.0"></omgdi:waypoint><bpmndi:BPMNLabel><omgdc:Bounds height="14.0" width="36.0" x="10.0" y="0.0"></omgdc:Bounds></bpmndi:BPMNLabel></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>

注意:如果将流程图放置在和java类相同的路径,需要配置

public class SequenceFlowTest {ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();/**部署流程定义(从inputStream)*/@Testpublic void deploymentProcessDefinition_inputStream(){InputStream inputStreamBpmn = this.getClass().getResourceAsStream("sequenceFlow.bpmn");InputStream inputStreamPng = this.getClass().getResourceAsStream("sequenceFlow.png");Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署对象相关的Service.createDeployment()//创建一个部署对象.name("连线")//添加部署的名称.addInputStream("sequenceFlow.bpmn", inputStreamBpmn)//.addInputStream("sequenceFlow.png", inputStreamPng)//.deploy();//完成部署System.out.println("部署ID:"+deployment.getId());//System.out.println("部署名称:"+deployment.getName());//}/**启动流程实例*/@Testpublic void startProcessInstance(){//流程定义的keyString processDefinitionKey = "sequenceFlow";ProcessInstance pi = processEngine.getRuntimeService()//与正在执行的流程实例和执行对象相关的Service.startProcessInstanceByKey(processDefinitionKey);//使用流程定义的key启动流程实例,key对应helloworld.bpmn文件中id的属性值,使用key值启动,默认是按照最新版本的流程定义启动System.out.println("流程实例ID:"+pi.getId());//流程实例ID    101System.out.println("流程定义ID:"+pi.getProcessDefinitionId());//流程定义ID   helloworld:1:4}/**查询当前人的个人任务*/@Testpublic 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){for(Task task:list){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());System.out.println("########################################################");}}}/**完成我的任务*/@Testpublic void completeMyPersonalTask(){//任务IDString taskId = "3103";//完成任务的同时,设置流程变量,使用流程变量用来指定完成任务后,下一个连线,对应sequenceFlow.bpmn文件中${message=='不重要'}Map<String, Object> variables = new HashMap<String, Object>();variables.put("message", "重要");processEngine.getTaskService()//与正在执行的任务管理相关的Service.complete(taskId,variables);System.out.println("完成任务:任务ID:"+taskId);}
}

说明:

1、一个活动中可以指定一个或多个SequenceFlow(Start中有一个,End中没有)。

* 开始活动中有一个SequenceFlow 。

* 结束活动中没有SequenceFlow 。

* 其他活动中有1条或多条SequenceFlow

2、如果只有一个,则可以不使用流程变量设置codition的名称;

如果有多个,则需要使用流程变量设置codition的名称。message表示流程变量的名称,‘不重要’表示流程变量的值,${}或#{}中间的内容要使用boolean类型的表达式,用来判断应该执行的连线。

排他网关:

新建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="exclusiveGateWay" name="exclusiveGateWayProcess" isExecutable="true"><startEvent id="startevent1" name="Start"></startEvent><userTask id="usertask1" name="费用报销申请" activiti:assignee="王小五"></userTask><sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow><userTask id="usertask2" name="审批【部门经理】" activiti:assignee="赵小六"></userTask><userTask id="usertask3" name="财务" activiti:assignee="胡小八"></userTask><userTask id="usertask4" name="审批【总经理】" activiti:assignee="田小七"></userTask><exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway" default="默认执行财务"></exclusiveGateway><sequenceFlow id="flow2" sourceRef="usertask1" targetRef="exclusivegateway1"></sequenceFlow><sequenceFlow id="flow3" name="金额小于等于1000,大于等于500" sourceRef="exclusivegateway1" targetRef="usertask2"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${money>=500 && money<=1000}]]></conditionExpression></sequenceFlow><sequenceFlow id="默认执行财务" name="默认执行财务" sourceRef="exclusivegateway1" targetRef="usertask3"></sequenceFlow><sequenceFlow id="flow5" name="金额大于1000元" sourceRef="exclusivegateway1" targetRef="usertask4"><conditionExpression xsi:type="tFormalExpression"><![CDATA[${money>1000}]]></conditionExpression></sequenceFlow><endEvent id="endevent1" name="End"></endEvent><sequenceFlow id="flow6" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow><sequenceFlow id="flow7" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow><sequenceFlow id="flow8" sourceRef="usertask4" targetRef="endevent1"></sequenceFlow></process><bpmndi:BPMNDiagram id="BPMNDiagram_exclusiveGateWay"><bpmndi:BPMNPlane bpmnElement="exclusiveGateWay" id="BPMNPlane_exclusiveGateWay"><bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"><omgdc:Bounds height="35.0" width="35.0" x="340.0" y="50.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1"><omgdc:Bounds height="55.0" width="105.0" x="305.0" y="140.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2"><omgdc:Bounds height="55.0" width="105.0" x="80.0" y="390.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"><omgdc:Bounds height="35.0" width="35.0" x="340.0" y="560.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3"><omgdc:Bounds height="55.0" width="105.0" x="305.0" y="390.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4"><omgdc:Bounds height="55.0" width="105.0" x="550.0" y="380.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1"><omgdc:Bounds height="40.0" width="40.0" x="337.0" y="260.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1"><omgdi:waypoint x="357.0" y="85.0"></omgdi:waypoint><omgdi:waypoint x="357.0" y="140.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2"><omgdi:waypoint x="357.0" y="195.0"></omgdi:waypoint><omgdi:waypoint x="357.0" y="260.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3"><omgdi:waypoint x="357.0" y="300.0"></omgdi:waypoint><omgdi:waypoint x="132.0" y="390.0"></omgdi:waypoint><bpmndi:BPMNLabel><omgdc:Bounds height="42.0" width="100.0" x="-117.0" y="-35.0"></omgdc:Bounds></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5"><omgdi:waypoint x="357.0" y="300.0"></omgdi:waypoint><omgdi:waypoint x="602.0" y="380.0"></omgdi:waypoint><bpmndi:BPMNLabel><omgdc:Bounds height="14.0" width="84.0" x="16.0" y="-15.0"></omgdc:Bounds></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6"><omgdi:waypoint x="132.0" y="445.0"></omgdi:waypoint><omgdi:waypoint x="357.0" y="560.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7"><omgdi:waypoint x="357.0" y="445.0"></omgdi:waypoint><omgdi:waypoint x="357.0" y="560.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8"><omgdi:waypoint x="602.0" y="435.0"></omgdi:waypoint><omgdi:waypoint x="357.0" y="560.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="默认执行财务" id="BPMNEdge_默认执行财务"><omgdi:waypoint x="357.0" y="300.0"></omgdi:waypoint><omgdi:waypoint x="357.0" y="390.0"></omgdi:waypoint><bpmndi:BPMNLabel><omgdc:Bounds height="14.0" width="72.0" x="10.0" y="0.0"></omgdc:Bounds></bpmndi:BPMNLabel></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>
public class ExclusiveGateWayTest {ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();/**部署流程定义(从inputStream)*/@Testpublic void deploymentProcessDefinition_inputStream(){InputStream inputStreamBpmn = this.getClass().getResourceAsStream("exclusiveGateWay.bpmn");InputStream inputStreamPng = this.getClass().getResourceAsStream("exclusiveGateWay.png");Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署对象相关的Service.createDeployment()//创建一个部署对象.name("排他网关")//添加部署的名称.addInputStream("exclusiveGateWay.bpmn", inputStreamBpmn)//.addInputStream("exclusiveGateWay.png", inputStreamPng)//.deploy();//完成部署System.out.println("部署ID:"+deployment.getId());//System.out.println("部署名称:"+deployment.getName());//}/**启动流程实例*/@Testpublic void startProcessInstance(){//流程定义的keyString processDefinitionKey = "exclusiveGateWay";ProcessInstance pi = processEngine.getRuntimeService()//与正在执行的流程实例和执行对象相关的Service.startProcessInstanceByKey(processDefinitionKey);//使用流程定义的key启动流程实例,key对应helloworld.bpmn文件中id的属性值,使用key值启动,默认是按照最新版本的流程定义启动System.out.println("流程实例ID:"+pi.getId());//流程实例ID    101System.out.println("流程定义ID:"+pi.getProcessDefinitionId());//流程定义ID   helloworld:1:4}/**查询当前人的个人任务*/@Testpublic 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){for(Task task:list){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());System.out.println("########################################################");}}}/**完成我的任务*/@Testpublic void completeMyPersonalTask(){//任务IDString taskId = "3904";//完成任务的同时,设置流程变量,使用流程变量用来指定完成任务后,下一个连线,对应exclusiveGateWay.bpmn文件中${money>1000}Map<String, Object> variables = new HashMap<String, Object>();variables.put("money", 200);processEngine.getTaskService()//与正在执行的任务管理相关的Service.complete(taskId,variables);System.out.println("完成任务:任务ID:"+taskId);}
}

说明:

  1. 一个排他网关对应一个以上的顺序流
  2. 由排他网关流出的顺序流都有个conditionExpression元素,在内部维护返回boolean类型的决策结果。
  3. 决策网关只会返回一条结果。当流程执行到排他网关时,流程引擎会自动检索网关出口,从上到下检索如果发现第一条决策结果为true或者没有设置条件的(默认为成立),则流出。
  4. 如果没有任何一个出口符合条件,则抛出异常
  5. 使用流程变量,设置连线的条件,并按照连线的条件执行工作流,如果没有条件符合的条件,则以默认的连线离开。例如:

则执行连线:

如果使用流程变量设置

则执行连线:

并行网关:

新建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>
public class ParallelGateWayTest {ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();/**部署流程定义(从inputStream)*/@Testpublic 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());//}/**启动流程实例*/@Testpublic void startProcessInstance(){//流程定义的keyString processDefinitionKey = "parallelGateWay";ProcessInstance pi = processEngine.getRuntimeService()//与正在执行的流程实例和执行对象相关的Service.startProcessInstanceByKey(processDefinitionKey);//使用流程定义的key启动流程实例,key对应helloworld.bpmn文件中id的属性值,使用key值启动,默认是按照最新版本的流程定义启动System.out.println("流程实例ID:"+pi.getId());//流程实例ID    101System.out.println("流程定义ID:"+pi.getProcessDefinitionId());//流程定义ID   helloworld:1:4}/**查询当前人的个人任务*/@Testpublic 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){for(Task task:list){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());System.out.println("########################################################");}}}/**完成我的任务*/@Testpublic void completeMyPersonalTask(){//任务IDString taskId = "4302";processEngine.getTaskService()//与正在执行的任务管理相关的Service.complete(taskId);System.out.println("完成任务:任务ID:"+taskId);}
}

说明:

  1. 一个流程中流程实例只有1个,执行对象有多个
  2. 并行网关的功能是基于进入和外出的顺序流的:

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

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

  1. 并行网关的进入和外出都是使用相同节点标识
  2. 如果同一个并行网关有多个进入和多个外出顺序流, 它就同时具有分支和汇聚功能。 这时,网关会先汇聚所有进入的顺序流,然后再切分成多个并行分支。
  3. 并行网关不会解析条件。 即使顺序流中定义了条件,也会被忽略。
  4. 并行网关不需要是“平衡的”(比如, 对应并行网关的进入和外出节点数目不一定相等)。如图中标示是合法的:

接收任务:

接收任务是一个简单任务,它会等待对应消息的到达。 当前,官方只实现了这个任务的java语义。 当流程达到接收任务,流程状态会保存到数据库中。

在任务创建后,意味着流程会进入等待状态, 直到引擎接收了一个特定的消息, 这会触发流程穿过接收任务继续执行。

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="receiveTask" name="receiveTaskProcess" isExecutable="true"><startEvent id="startevent1" name="Start"></startEvent><receiveTask id="receivetask1" name="汇总当日销售额"></receiveTask><receiveTask id="receivetask2" name="给老毕发送短信"></receiveTask><endEvent id="endevent1" name="End"></endEvent><sequenceFlow id="flow1" sourceRef="receivetask2" targetRef="endevent1"></sequenceFlow><sequenceFlow id="flow2" sourceRef="startevent1" targetRef="receivetask1"></sequenceFlow><sequenceFlow id="flow3" sourceRef="receivetask1" targetRef="receivetask2"></sequenceFlow></process><bpmndi:BPMNDiagram id="BPMNDiagram_receiveTask"><bpmndi:BPMNPlane bpmnElement="receiveTask" id="BPMNPlane_receiveTask"><bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"><omgdc:Bounds height="35.0" width="35.0" x="350.0" y="50.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"><omgdc:Bounds height="35.0" width="35.0" x="350.0" y="380.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="receivetask1" id="BPMNShape_receivetask1"><omgdc:Bounds height="55.0" width="105.0" x="315.0" y="150.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="receivetask2" id="BPMNShape_receivetask2"><omgdc:Bounds height="55.0" width="105.0" x="315.0" y="260.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1"><omgdi:waypoint x="367.0" y="315.0"></omgdi:waypoint><omgdi:waypoint x="367.0" y="380.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2"><omgdi:waypoint x="367.0" y="85.0"></omgdi:waypoint><omgdi:waypoint x="367.0" y="150.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3"><omgdi:waypoint x="367.0" y="205.0"></omgdi:waypoint><omgdi:waypoint x="367.0" y="260.0"></omgdi:waypoint></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>
public class ReceiveTaskTest {ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();/**部署流程定义(从inputStream)*/@Testpublic void deploymentProcessDefinition_inputStream(){InputStream inputStreamBpmn = this.getClass().getResourceAsStream("receiveTask.bpmn");InputStream inputStreamPng = this.getClass().getResourceAsStream("receiveTask.png");Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署对象相关的Service.createDeployment()//创建一个部署对象.name("接收活动任务")//添加部署的名称.addInputStream("receiveTask.bpmn", inputStreamBpmn)//.addInputStream("receiveTask.png", inputStreamPng)//.deploy();//完成部署System.out.println("部署ID:"+deployment.getId());//System.out.println("部署名称:"+deployment.getName());//}/**启动流程实例+设置流程变量+获取流程变量+向后执行一步*/@Testpublic void startProcessInstance(){//流程定义的keyString processDefinitionKey = "receiveTask";ProcessInstance pi = processEngine.getRuntimeService()//与正在执行的流程实例和执行对象相关的Service.startProcessInstanceByKey(processDefinitionKey);//使用流程定义的key启动流程实例,key对应helloworld.bpmn文件中id的属性值,使用key值启动,默认是按照最新版本的流程定义启动System.out.println("流程实例ID:"+pi.getId());//流程实例ID    101System.out.println("流程定义ID:"+pi.getProcessDefinitionId());//流程定义ID   helloworld:1:4/**查询执行对象ID*/Execution execution1 = processEngine.getRuntimeService()//.createExecutionQuery()//创建执行对象查询.processInstanceId(pi.getId())//使用流程实例ID查询.activityId("receivetask1")//当前活动的id,对应receiveTask.bpmn文件中的活动节点id的属性值.singleResult();/**使用流程变量设置当日销售额,用来传递业务参数*/processEngine.getRuntimeService()//.setVariable(execution1.getId(), "汇总当日销售额", 21000);/**向后执行一步,如果流程处于等待状态,使得流程继续执行*/processEngine.getRuntimeService().signal(execution1.getId());/**查询执行对象ID*/Execution execution2 = processEngine.getRuntimeService()//.createExecutionQuery()//创建执行对象查询.processInstanceId(pi.getId())//使用流程实例ID查询.activityId("receivetask2")//当前活动的id,对应receiveTask.bpmn文件中的活动节点id的属性值.singleResult();/**从流程变量中获取汇总当日销售额的值*/Integer value = (Integer)processEngine.getRuntimeService()//.getVariable(execution2.getId(), "汇总当日销售额");System.out.println("给老板发送短信:金额是:"+value);/**向后执行一步,如果流程处于等待状态,使得流程继续执行*/processEngine.getRuntimeService().signal(execution2.getId());}}

activity连线,排他网关和并行网关以及接收任务相关推荐

  1. Flowable进阶学习(六)网关(排他网关、并行网关、包容网关、事件网关)

    文章目录 排他网关 案例: 并行网关 案例: 包容网关 案例: 事件网关 1. 定时事件 1.1 定时器启动事件 案例 网关(gateway)用来控制流程的流向.来实现复杂的审批流程. 网关的分类包括 ...

  2. 学习记录555@flowable排他网关、并行网关、包容网关

    排他网关 排他网关(exclusive gateway)(也叫异或网关 XOR gateway,或者更专业的,基于数据的排他网关 exclusive data-based gateway),用于对流程 ...

  3. 【Activiti工作流】11.并行网关

    上一节我们讲解了排他网关,本节我们来讲解与排他网关类似的模式的一种网关---并行网关. 通过上一篇我们了解,排他网关是对一个事件流向线的分支决策节点,决定着任务的流向.而并行网关除了有分支以外,还有聚 ...

  4. flowable并行审批_Flowable6.4 – 并行网关和包容网关 | 字痕随行

    这个春节的节奏就是:吃喝睡.吃喝睡,手机都懒的刷了.今天开始提振一下心情,整理一下思路,开始缓慢更新. 这次补完一下之前的一篇<Flowable6.4-排他网关>,简单介绍一下并行网关和包 ...

  5. 【activiti 入门】activiti6.0之并行网关

    首先是环境搭建可参考之前的博客,而且有具体demo提供下载  https://download.csdn.net/download/qq_33333654/11790823 demo中仅涵盖了排他网关 ...

  6. Activiti工作并行网关和融合(包容)网关使用经验总结

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言 一.并行网关Parallel Gateway 二.包容网关(融合网关)Inclusive Gateway 总结 前言 ...

  7. activiti学习(十六)——并行网关、排他网关、包含网关

    网关和分支是流程图中相当重要的一环.毕竟不可能所有流程都是一条直线走到底的,可能需要并行处理,也可能需要根据条件的不同选择对应的路由,网关的作用正是在此.本文主要探索一下这几种网关的常用方法,以及一些 ...

  8. flowable6.4 并行网关 驳回 跳转 回退 多实例加签减签

    目录 前言 flowable6.4.2 不足之处 并行网关跳转驳回BUG 多实例加签减签BUG 解决之法 说明 用法 前言 flowable 优秀的工作流流程引擎框架,前身Activity 为什么要用 ...

  9. activiti并行网关(Parallel Gateway)

    1.什么是并行网关? 它可以将分支(fork)为多个路径,也可以合并(join)多个入口路径. 2.使用场景: 场景一:在一个政府机关的办公OA系统设计的时候,有这么一个需求:政府需要做一个财务呈批的 ...

最新文章

  1. ESP8266-SDK编写的TM1668程序驱动数码管
  2. 【星球知识卡片】残差网络家族10多个变种学习卡片,请收下!
  3. pytorch基础知识整理(二)数据加载
  4. easyui打开新的选项卡_Easyui Tabs 标签页/选项卡_EasyUI 插件
  5. java webservice https_WebService的HTTPS访问——解决PKIX错误 | 字痕随行
  6. 2021牛客暑期多校训练营2
  7. 5单个编译总会编译全部_JDBC【5】 JDBC预编译和拼接Sql对比
  8. nodeJs利用mongoose模块操作数据
  9. 广告文案被指侮辱女性 茶颜悦色道歉:立即召回相关产品
  10. SQL Server 2016 SP1中的新功能和增强功能
  11. 本地信息搜索php程序,PHP搜索引擎
  12. 数据结构上机实践第八周项目1- 建立顺序串的算法库
  13. 为程序员准备的英语学习资料
  14. PyTorch——device与cuda.device用法
  15. Mac显示桌面的快捷方式
  16. 所有的风只向她们吹 所有的日子都为她们破碎——査海生《四姐妹》
  17. mysql校对集工具_mysql字符集和校对规则(Mysql校对集)
  18. CMake来编译OpenCV,细致教程
  19. 第三届厦门国际银行数创金融杯金融营销建模大赛-BaseLine
  20. 最小公倍数c语言调用该函数,C语言中如何调用函数求最大公约数和最小公倍数...

热门文章

  1. qt执行定时结束任务的方法代码
  2. 用JS制作《飞机大作战》游戏_第4讲(创建敌方飞机、敌方飞机发射子弹、玩家子弹击中敌方小飞机,小飞机死亡)-陈远波...
  3. Word:插入指定颜色的矢量图
  4. 验证码信息验证(不区分大小写)
  5. 【MySQL】mysql区分大小写问题
  6. 最新emoji表情代码大全_2020父亲节快乐祝福语大全简短 最新温馨的父子节动态表情图片...
  7. 设计模式之观察者模式(1)
  8. 课堂练习2.1:外部中断
  9. java 16进制转64进制_Java进制概述及进制间的相互转换
  10. Ext文件上传总是返回.do