package com.zcc.activiti05;
import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import javax.sound.midi.Soundbank;
import java.util.List;
/**
* 组任务测试
*/
public class GroupTest {
//部署流程
/*public static void main(String[] args) {
//创建流程引擎配置类
ProcessEngineConfiguration processEngineConfiguration=
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
//流程引擎对象
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
//创建RepositoryService
RepositoryService repositoryService = processEngine.getRepositoryService();
//部署对象
Deployment deployment = repositoryService.createDeployment().
addClasspathResource("diagram/my5.bpmn")
.name("请假流程").deploy();
System.out.println(deployment.getName());
System.out.println(deployment.getId());
}*/
//启动流程实例
/*public static void main(String[] args) {
//创建流程引擎配置类
ProcessEngineConfiguration processEngineConfiguration=
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
//流程引擎对象
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
//获取RuntimeService
RuntimeService runtimeService = processEngine.getRuntimeService();
//根据key启动流程实例
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess5");
System.out.println("流程部署id"+processInstance.getDeploymentId());
System.out.println("流程实例id"+processInstance.getId());//2501
System.out.println("活动id"+processInstance.getActivityId());
}*/
//完成个人任务
/* public static void main(String[] args) {
//创建流程引擎配置类
ProcessEngineConfiguration processEngineConfiguration=
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
//流程引擎对象
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
//获取taskService
TaskService taskService = processEngine.getTaskService();
//处理当前任务(要先查询当前用户下的任务id)
Task task = taskService.createTaskQuery().processDefinitionKey("myProcess5").taskAssignee("xiaozhang").singleResult();
if (task!=null){
taskService.complete(task.getId());
System.out.println(task.getId());//2505
System.out.println("当前用户完成了当前任务");
}
}*/
/* //查询候选用户组任务
public static void main(String[] args) {
//创建流程引擎配置类
ProcessEngineConfiguration processEngineConfiguration=
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
//流程引擎对象
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
//获取taskService
TaskService taskService = processEngine.getTaskService();
//设置查询条件
String key="myProcess5";
String candidateUser="zhangsan";
//查询
List<Task> list = taskService.createTaskQuery().processDefinitionKey(key).taskCandidateUser(candidateUser).list();
for (Task task : list) {
System.out.println("----------------------------");
System.out.println("流程实例id:" + task.getProcessInstanceId());
System.out.println("任务id:" + task.getId());
System.out.println("任务负责人:" + task.getAssignee());
System.out.println("任务名称:" + task.getName());
}
}*/
/*//测试zhangsan拾取组任务
//拾取任务的过程就是将候选用户设置为真正的任务处理人
public static void main(String[] args) {
//创建流程引擎配置类
ProcessEngineConfiguration processEngineConfiguration=
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
//流程引擎对象
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
//获取taskService
TaskService taskService = processEngine.getTaskService();
//设置查询条件
String key="myProcess5";
String candidateUser="zhangsan";
//查询
Task task = taskService.createTaskQuery().processDefinitionKey(key).taskCandidateUser(candidateUser).singleResult();
if (task!=null){
taskService.claim(task.getId(),candidateUser);
System.out.println("任务拾取完毕!");
}
}*/
//当前用户查询自己所有的任务
/*public static void main(String[] args) {
//创建流程引擎配置类
ProcessEngineConfiguration processEngineConfiguration =
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
//流程引擎对象
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
//获取taskService
TaskService taskService = processEngine.getTaskService();
//设置查询条件
String key = "myProcess5";
String assignee = "zhangsan";
//查询
List<Task> list = taskService.createTaskQuery().processDefinitionKey(key).taskAssignee(assignee)//设置任务处理人
.list();
for (Task task : list) {
System.out.println("----------------------------");
System.out.println("流程实例id:" + task.getProcessInstanceId());
System.out.println("任务id:" + task.getId());
System.out.println("任务负责人:" + task.getAssignee());
System.out.println("任务名称:" + task.getName());
}
}*/
//当前用户完成任务
/*public static void main(String[] args) {
//创建流程引擎配置类
ProcessEngineConfiguration processEngineConfiguration =
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
//流程引擎对象
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
//获取taskService
TaskService taskService = processEngine.getTaskService();
//设置查询条件
String key = "myProcess5";
String assignee = "zhangsan";
//查询
Task task = taskService.createTaskQuery().processDefinitionKey(key).taskAssignee(assignee)//设置任务处理人
.singleResult();
if (task!=null){
taskService.complete(task.getId());
System.out.println("任务执行完毕");
}
}*/
//归还任务
/*public static void main(String[] args) {
//创建流程引擎配置类
ProcessEngineConfiguration processEngineConfiguration =
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
//流程引擎对象
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
//获取taskService
TaskService taskService = processEngine.getTaskService();
//设置查询条件
String key = "myProcess5";
String assignee = "zhangsan";
//查询
Task task = taskService.createTaskQuery().processDefinitionKey(key).taskAssignee(assignee)//设置任务处理人
.singleResult();
if (task!=null){
taskService.setAssignee(task.getId(),null);//把任务归还 把任务执行人设置为null
System.out.println("任务执行完毕");
}
}*/
//任务的指定(这个任务指定给候选人来处理)
public static void main(String[] args) {
//创建流程引擎配置类
ProcessEngineConfiguration processEngineConfiguration =
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
//流程引擎对象
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
//获取taskService
TaskService taskService = processEngine.getTaskService();
//设置查询条件
String key = "myProcess5";
//当前任务处理人
String assignee = "zhangsan";
//任务候选人
String candidateUser="lisi";
//查询
Task task = taskService.createTaskQuery().processDefinitionKey(key).taskAssignee(assignee)//设置任务处理人
.singleResult();
if (task!=null){
taskService.setAssignee(task.getId(),candidateUser);//张三把当前任务指定给lisi处理
System.out.println("任务执行完毕");
}
}
}