ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
@Test
public void testTask() throws Exception {
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();
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("完成任务");
}
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();
System.out.println("办理人:"+assignee);
delegateTask.setAssignee("libai");
}
}