用户任务(userTask,即用户操作的任务)

  • Assignee
  • 使用流程变量
    • ${username} or #{userName}
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//部署流程定义,启动流程实例
	@Test
	public void testTask() throws Exception {
		
		// 1 发布流程
		InputStream inputStreamBpmn = this.getClass().getResourceAsStream("taskProcess.bpmn");
		InputStream inputStreamPng = this.getClass().getResourceAsStream("taskProcess.png");
		processEngine.getRepositoryService()//
						.createDeployment()//
						.addInputStream("userTask.bpmn", inputStreamBpmn)//
						.addInputStream("userTask.png", inputStreamPng)//
						.deploy();
		
	// 2 启动流程
	//启动流程实例的同时,设置流程变量
		Map<String, Object> variables = new HashMap<String, Object>();
		variables.put("userID", "李白");
		ProcessInstance pi = processEngine.getRuntimeService()//
							.startProcessInstanceByKey("taskProcess",variables);
		System.out.println("pid:" + pi.getId());
	}
	
	//查询我的个人任务列表
	@Test
	public void findMyTaskList(){
		String userId = "李白";
		List<Task> list = processEngine.getTaskService()//
		                .createTaskQuery()//
		                .taskAssignee(userId)//指定个人任务查询
		                .list();
		for(Task task:list ){
			System.out.println("id="+task.getId());
			System.out.println("name="+task.getName());
			System.out.println("assinee="+task.getAssignee());
			System.out.println("createTime="+task.getCreateTime());
			System.out.println("executionId="+task.getExecutionId());
			
		}
	}
	
	//完成任务
	@Test
	public void completeTask(){
		String taskId = "3209";
		processEngine.getTaskService()//
					.complete(taskId);//
		System.out.println("完成任务");
	}

配置监听类

alt


import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;

public class TsskUserListener implements TaskListener {

	@Override
	public void notify(DelegateTask delegateTask) {
		 
		String assignee = delegateTask.getAssignee();
//		delegateTask.setVariable(variableName, value);
		System.out.println("办理人:"+assignee);
		//指定个人任务
		delegateTask.setAssignee("libai");
	}

}