<?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: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/test">
<process id="parallelGateWay" name="parallelGateWay" 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="usertask2"></sequenceFlow>
<sequenceFlow id="flow4" sourceRef="usertask2" targetRef="parallelgateway2"></sequenceFlow>
<sequenceFlow id="flow5" sourceRef="parallelgateway1" targetRef="usertask3"></sequenceFlow>
<sequenceFlow id="flow6" sourceRef="usertask3" targetRef="usertask4"></sequenceFlow>
<sequenceFlow id="flow7" sourceRef="usertask4" targetRef="parallelgateway2"></sequenceFlow>
<sequenceFlow id="flow8" sourceRef="parallelgateway2" targetRef="endevent1"></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="410.0" y="10.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="410.0" y="480.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="230.0" y="140.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="230.0" y="274.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="55.0" width="105.0" x="510.0" y="140.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
<omgdc:Bounds height="55.0" width="105.0" x="510.0" y="274.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="parallelgateway1" id="BPMNShape_parallelgateway1">
<omgdc:Bounds height="40.0" width="40.0" x="407.0" y="90.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="parallelgateway2" id="BPMNShape_parallelgateway2">
<omgdc:Bounds height="40.0" width="40.0" x="407.0" y="380.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="427.0" y="45.0"></omgdi:waypoint>
<omgdi:waypoint x="427.0" y="90.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="407.0" y="110.0"></omgdi:waypoint>
<omgdi:waypoint x="282.0" y="140.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="282.0" y="195.0"></omgdi:waypoint>
<omgdi:waypoint x="282.0" y="274.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="282.0" y="329.0"></omgdi:waypoint>
<omgdi:waypoint x="427.0" y="380.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="447.0" y="110.0"></omgdi:waypoint>
<omgdi:waypoint x="562.0" y="140.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
<omgdi:waypoint x="562.0" y="195.0"></omgdi:waypoint>
<omgdi:waypoint x="562.0" y="274.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
<omgdi:waypoint x="562.0" y="329.0"></omgdi:waypoint>
<omgdi:waypoint x="427.0" y="380.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
<omgdi:waypoint x="427.0" y="420.0"></omgdi:waypoint>
<omgdi:waypoint x="427.0" y="480.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
图形如下:
package com.ljw.c_parallelGateWay;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
/**
* 并行网关
* @author lenovo
*
*/
public class ParallelGateWayTest {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
// 部署流程定义(classpath)
@Test
public void deploymentProcessDefinition_inputStream() {
InputStream bpmn = this.getClass().getResourceAsStream("parallelGateWay.bpmn");
InputStream png = this.getClass().getResourceAsStream("parallelGateWay.png");
Deployment deployment = processEngine.getRepositoryService()// 与流程定义和部署对象相关的sevices
.createDeployment()// 创建一个部署对象
.name("并行网关")// 添加部署名称
.addInputStream("parallelGateWay.bpmn", bpmn)
.addInputStream("parallelGateWay.png", png)
.deploy();
System.out.println("部署ID:" + deployment.getId());
System.out.println("部署名称:" + deployment.getName());
}
// 启动流程实例
@Test
public void deploymentProcessInstance() {
String key = "parallelGateWay";
ProcessInstance pi = processEngine.getRuntimeService()// 与正在执行的流程是咧和执行对象相关的services
.startProcessInstanceByKey(key);// 使用流程定义的key启动流程实例key对呀的helloworld.bnpm文件里的id的属性值
System.out.println("流程实例ID:" + pi.getId());
System.out.println("流程定义ID:" + pi.getProcessDefinitionId());
}
// 查询当前人的个人任务
@Test
public void findMyPersonalTask() {
String assingnee = "买家";
List<Task> list = processEngine.getTaskService()// 与正在执行的任务管理相关的services
.createTaskQuery()// 创建任务查询对象
/** 查询条件(where部分) */
.taskAssignee(assingnee)// 指定个人任务查询,指定
// .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());
}
}
}
// 完成我的任务
@Test
public void completeMyPersonalTask() {
// 任务ID
String taskId = "130003";
Map<String, Object> variables=new HashMap<String, Object>();
processEngine.getTaskService()// 与正在执行的任务管理相关的services
.complete(taskId,variables);
System.out.println("任务完成,任务ID:" + taskId);
}
}
执行// 完成我的任务
@Test
public void completeMyPersonalTask() {
之后数据库的数据如下