<?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="sequenceFlow" name="sequenceFlow" 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="140.0" y="60.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="220.0" y="50.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="510.0" y="60.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="545.0" y="190.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="175.0" y="77.0"></omgdi:waypoint>
<omgdi:waypoint x="220.0" y="77.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="325.0" y="77.0"></omgdi:waypoint>
<omgdi:waypoint x="510.0" y="87.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="370.0" y="79.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="562.0" y="115.0"></omgdi:waypoint>
<omgdi:waypoint x="562.0" y="190.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="272.0" y="105.0"></omgdi:waypoint>
<omgdi:waypoint x="562.0" y="190.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="347.0" y="154.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
package com.ljw.a_sequenceFlow;
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 SequenceFlowTest {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
// 部署流程定义(classpath)
@Test
public void deploymentProcessDefinition_inputStream() {
InputStream bpmn = this.getClass().getResourceAsStream("sequenceFlow.bpmn");
InputStream png = this.getClass().getResourceAsStream("sequenceFlow.png");
Deployment deployment = processEngine.getRepositoryService()// 与流程定义和部署对象相关的sevices
.createDeployment()// 创建一个部署对象
.name("连线")// 添加部署名称
.addInputStream("sequenceFlow.bpmn", bpmn)
.addInputStream("sequenceFlow.png", png)
.deploy();
System.out.println("部署ID:" + deployment.getId());
System.out.println("部署名称:" + deployment.getName());
}
// 启动流程实例
@Test
public void deploymentProcessInstance() {
String key = "sequenceFlow";
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 = "85003";
//完成任务的同时,设置流程变量,使用流程变量用来指定完成任务后,下一个连线,对应sequenceFlow.bpmn文件中${message=='不重要'}
Map<String, Object> variables=new HashMap<String, Object>();
// variables.put("message", "不重要");
variables.put("message", "重要");
processEngine.getTaskService()// 与正在执行的任务管理相关的services
.complete(taskId,variables);
System.out.println("任务完成,任务ID:" + taskId);
}
}