1. Flow chart
2. Distribution of Personal Tasks 1 (Direct Assignment of Translators)
1. Configuration of Task Node in Flow Chart
2. Code
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); //Deploy process definitions and start process instances @Test public void testTask() throws Exception { // 1 Release process 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 Start-up process //Setting process variables while starting process instances ProcessInstance pi = processEngine.getRuntimeService()// .startProcessInstanceByKey("taskProcess"); System.out.println("pid:" + pi.getId()); } //Query my personal task list @Test public void findMyTaskList(){ String userId = "Zhang Sanfeng"; List<Task> list = processEngine.getTaskService()// .createTaskQuery()// .taskAssignee(userId)//Designated Personal Task Query .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()); } } //Complete tasks @Test public void completeTask(){ String taskId = "3209"; processEngine.getTaskService()// .complete(taskId);// System.out.println("Complete tasks"); }
Analysis:
- Zhang Sanfeng is a personal task manager
- However, the managers who assign tasks in this way are not flexible enough, because the managers of tasks in project development should not place XML files.
3. Personal Task Assignment Mode 2 (Using Process Variables)
1. Configuration of Task Node in Flow Chart
2. Code
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); //Deploy process definitions and start process instances @Test public void testTask() throws Exception { // 1 Release process 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 Start-up process //Setting process variables while starting process instances Map<String, Object> variables = new HashMap<String, Object>(); variables.put("userID", "Zhang Cuisan"); ProcessInstance pi = processEngine.getRuntimeService()// .startProcessInstanceByKey("taskProcess",variables); System.out.println("pid:" + pi.getId()); } //Query my personal task list @Test public void findMyTaskList(){ String userId = "Zhang Cuisan"; List<Task> list = processEngine.getTaskService()// .createTaskQuery()// .taskAssignee(userId)//Designated Personal Task Query .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()); } } //Complete tasks @Test public void completeTask(){ String taskId = "3209"; processEngine.getTaskService()// .complete(taskId);// System.out.println("Complete tasks"); }
Analysis:
- Zhang Cuishan is a personal task manager
- In development, you can specify the next task handler in the page, and set the next task handler through process variables.
4. Personal Task Assignment Mode 3 (Use Class)
1. Configuration of Task Node in Flow Chart
At this point, the flow chart's XML file is shown as follows:
2.TaskListenerImpl class, used to set up task handlers
public class TaskListenerImpl implements TaskListener { /**Assignment of Personal Tasks and Group Tasks*/ @Override public void notify(DelegateTask delegateTask) { String assignee = "Zhang Wuji"; //Assignment of Personal Tasks delegateTask.setAssignee(assignee); } }
3. Code
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); //Deploy process definitions and start process instances @Test public void testTask() throws Exception { // 1 Release process 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 Start-up process ProcessInstance pi = processEngine.getRuntimeService()// .startProcessInstanceByKey("taskProcess"); System.out.println("pid:" + pi.getId()); } //Query my personal task list @Test public void findMyTaskList(){ String userId = "Zhang Wuji"; List<Task> list = processEngine.getTaskService()// .createTaskQuery()// .taskAssignee(userId)//Designated Personal Task Query .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()); } } //Complete tasks @Test public void completeTask(){ String taskId = "3408"; processEngine.getTaskService()// .complete(taskId);// System.out.println("Complete tasks"); } //Personal tasks can be assigned from one person to another (claim tasks) @Test public void setAssigneeTask(){ //Task ID String taskId = "3408"; //Designated Claim Agent String userId = "Zhou Zhiruo"; processEngine.getTaskService()// .setAssignee(taskId, userId); }
Analysis:
-
delegateTask.setAssignee(assignee) is used in the class to assign a personal task to the administrator. At this time, Zhang Wuji is the administrator of the next task.
-
By processing Engine. getTaskService (). setAssignee (taskId, userId); assign personal tasks from one person to another, at this time Zhang Wuji is no longer the next task manager, but changed to Zhou Zhiruo.
-
In the process of development, the managers of each task can be stipulated. For example, the leader of Zhang San is Li Si, and the leader of Li Si is Wang Wu. If Zhang San submits a task, he can query that the leader of Zhang San is Li Si, and set up the manager of the next task by means of classes.
5. Summary
Personal tasks and three ways of assignment:
- Write assignee = "Zhang Sanfeng" directly in taskProcess.bpmn“
- Write assignee = "#{userID}" in taskProcess.bpmn, and the value of the variable is String. Use process variables to specify the dealer
- Using the TaskListener interface, to implement the interface in the class, define in the class:
delegateTask.setAssignee(assignee);// Designated Personal Task Manager
Use task ID and reassignment of transactors by transactors:
processEngine.getTaskService()//.setAssignee(taskId, userId);