流程实例相关
首先部署流程定义
创建一个流程实例
查询待办任务
完成代办任务
package com.hyq;
import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.junit.Test;
import java.io.InputStream;
import java.util.List;
/**
* Created by Administrator on 2017/7/1.
* 流程实例
*/
public class ProcessInstanceTest {
private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
/**
* 部署流程定义-方式一
*/
@Test
public void deployProcess(){
System.out.print(processEngine);
RepositoryService repositoryService = processEngine.getRepositoryService();
String bpmn = "/diagram/purchasingflow01.bpmn";
String png = "/diagram/purchasingflow01.png";
InputStream bpmn_inputStream = this.getClass().getResourceAsStream(bpmn);
InputStream png_inputStream = this.getClass().getResourceAsStream(png);
Deployment deployment = repositoryService.createDeployment()
.addInputStream(bpmn, bpmn_inputStream)
.addInputStream(png, png_inputStream)
.name("我的流程部署2")
.deploy();
String id = deployment.getId();
String name = deployment.getName();
System.out.print("部署id:"+id);
System.out.print("部署name:"+name);
}
@Test
/**
* 启动一个流程实例
*/
public void startProceeInstance(){
RuntimeService runtimeService = processEngine.getRuntimeService();
String processDefinitionKey = "purchasingflow";
//根据流程定义的最高版本号来启动一个流程实例
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey);
System.out.println("流程实例的id:"+processInstance.getId());
System.out.println("流程定义的id:"+processInstance.getProcessDefinitionId());
}
@Test
/**
* 查询待办任务
*/
public void queryMyTask(){
TaskService taskService = processEngine.getTaskService();
String processDefinitionKey = "purchasingflow";
String assignee = "wangwu";
TaskQuery taskQuery = taskService.createTaskQuery();
taskQuery.taskAssignee(assignee).processDefinitionKey(processDefinitionKey);
List<Task> list = taskQuery.list();
for (Task task : list){
System.out.println("任务id:"+task.getId());
System.out.println("处理人:"+task.getAssignee());
System.out.println("任务名称:"+task.getName());
}
}
@Test
/**
* 办理任务
*/
public void dealTask(){
TaskService taskService = processEngine.getTaskService();
String taskId = "304";
taskService.complete(taskId);
System.out.println("完成任务:"+taskId);
}
}