I. Preface
In the last article, we introduced the knowledge of Activiti process definition management. In this article, we continue to learn about Activiti process instances and task management.
Two, text
Process Instance
The relationship between Process Instance and Process Definition in the previous article is somewhat similar to that between class and instance objects. Process Definition is the description of the whole process step and Process Instance is the largest execution route of process definition from start to end.
Execution object
Referring to Process Instance, there is another noun, Execution, which is the current route of execution according to the rules of Process Definition.
If there is only one execution route for Process Definition, then Execution and Process Instance are exactly the same. If there are multiple execution routes in Process Definition, Execution and Process Instance may or may not be the same. So it is concluded that there is and can only be one Process Instance in a process, while Execution can exist more than one.
Task
Task should be well understood, that is, the task information produced when the process is executed to a certain step or link.
In the last article, we introduced how to draw flow charts, how to deploy process definitions, and the relationship between process definitions and process instances. Now it's time to start process instances:
Code
Start process instance
Operation results:
Process instance ID:501
Process Definition ID:HelloWorld:2:404
Explain:
1) in data base Insert a record into the table of execution objects being executed by act_ru_execution
2) Insert a record in the history table of the act_hi_procinst procedure instance in the database
3) Insert a record in the history table of the act_hi_act active node in the database
4) The nodes in our diagram are task nodes, so a record is added to the history table of the act_ru_task process instance.
5) A record is also inserted into the act_hi_taskinst task history table of the database.
Examples of query history process
After the process instance is started, we can also query how many times a process instance has been executed altogether, because we just have a process in this case, so we can only find one process at present:
Operation results:
501 HelloWorld:2:404 Fri Jun 26 09:34:51 CST 2015 null
Query current personal tasks
After the process is started, because the node is a task node, a record of the task is inserted in the task table. Now we can query the task through the operator:
Operation results:
Task ID: 504
Task Name: Application submission
Task creation time: Fri Jun 2609:34:51 CST 2015
Manager of the task: Zhang San
Process instance ID:501
Execution object ID:501
Process Definition ID:HelloWorld:2:404
##################################################
Explain:
1) Task Service should be obtained from process Engine because it is a task query
2) Task Query Object Retrieved by TaskService
3) Adding query filtering conditions to query objects, using task Assignee to specify task handlers (i.e. agent tasks for querying specified users), and adding filtering conditions such as paging sorting.
4) Call the list method to execute the query and return the task list for the specified user
5) Task ID, name, transactor and creation time can be found in the act_ru_task table.
6) In this case, Process Instance is equivalent to Execution
7) When a Task node and Execution node are one-to-one, the relationship between them is represented by Execution_in the task object
8) Task ID corresponds to the "ID_" column in the database table act_ru_task
Finish the task
After querying the task, we will complete the task id 504:
Operation results:
Complete tasks: Task ID:504
Explain:
1) Complete the task, so Task Service is what you get from Process Engine.
2) When the code is executed and the query is executed as an employee, it will be found that there is no data at this time, because there is no data in the task being executed.
3) For a completed task, activiti will delete the task from the act_ru_task table, and the next task will be inserted.
4) The results can be found by inquiring as "department manager". Because the process is executed to the Department Manager to approve the node.
5) Re-execute the processing task code, and query as "department manager" after execution, with no result.
Repeat steps 3 and 4 until the process is completed.
Query History Task
Employee Zhang San's task has been completed. Now the task is to Department Manager Li Si. If we still query Zhang San's task now, we can't find it. Only by querying Li Si can we find it. However, we can query the historical task through process instance id. By querying the historical task, we can query both the tasks that have been handled and the tasks that are being performed. Come out:
Operation results:
504) Application submission 501 Fri Jun 2609:34:51 CST 2015 Fri Jun 2609:50 CST 2015 959867
################################
602) Approval [Department Manager] 501 Fri Jun 2609:50:51 CST 2015 null
################################
Does the query process end?
We can also query the current status of a process through the process instance id, whether it is still in the process of execution or whether the process execution is over:
Operation results:
The process is not over
Three, summary
In this article, we mainly study process instances, executing objects, tasks and their relationships. At the same time, we also introduce how to start and query process instances, judge whether the process instances are finished, view and handle tasks, and query historical tasks.
http://blog.csdn.net/zwk626542417/article/details/46646565