In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
In the workflow, the basic of all our workflows is the work engine (ProcessEngine), which inherits from the EngineService interface, including process deployment, and the database connection is realized by ProcessEngine. And ProcessEngineConfiguration: process engine configuration, you can set the database, etc., the default database is h3, persistence implementation uses Mybatis, here we use mysql.
So since both jbpm and activiti need ProcessEngine to drive, let's talk about the use of workflow engines.
Process deployment
When we draw a diagram of our business, and then deploy using the workflow engine, that is, put our flow chart information into the database, the diagram and code are as follows:
[java] view plain copy
/ * * deployment process definition * /
@ Test
Public void deploymentProcessDefinition () {
Deployment deployment = processEngine.getRepositoryService () / / Service for process definition and deployment related objects
.createDeplotation () / / create a deployment object
.name ("leaveBill departmental Program")
.addClasspathResource ("diagrams/LeaveBill.bpmn") / / load from ClassPath resources, only one file can be loaded at a time
.addClasspathResource ("diagrams/LeaveBill.png") / / load from ClassPath resources, only one file can be loaded at a time
.deploy ()
System.out.println ("deployment" + deployment.getId ()); / / 1
System.out.println ("deployment" + deployment.getName ()); / / departmental procedures
}
The print result is as follows:
Deployment1
Deploymenthellworld department program
Database (deployment related tables) parsing
If we look at the tables in the database, we can see that each deployment involves the three tables, act_re_deployment (process deployment table).
The table contains the name, ID, and deployment time of the process deployment
Act_re_procdef (process definition table)
The table contains the primary key key of the process definition, the version source file name and icon, and the process definition ID (key + version number + randomly generated numbers)
Act_ge_bytearray (resource file table)
Saved the location and storage of resources and deployment ID, version number ID and other information
Act_ge_property: primary key generation strategy table
Defines the policy information generated by the primary key
Execution process
As the name implies, when one of us starts to apply for leave, we have to implement an example of the process of asking for leave.
[java] view plain copy
/ * *
* execute a process instance
, /
@ Test
Public void startProcessInstance () {
String processInstanceKey = "LeaveBill"
ProcessInstance pi = processEngine.getRuntimeService ()
.startProcessInstanceByKey (processInstanceKey)
System.out.println ("process instance id:" + pi.getId ()); / / process instance id 101
System.out.println ("process definition id:" + pi.getProcessDefinitionId ()); / / process definition ID helloworld:1:4
}
So our process instance is started, so let's take a look at the table information we involved when starting the process instance.
Database analysis (case table) analysis
Act_ru_execution: table of execution objects that are being executed, focusing on process instances, objects, tasks
Contains information such as instance ID, process definition ID, and the name of the task to be executed (usertask1)
Act_ru_task: the list of tasks that are being executed. Where are the tasks executed for specific tasks?
Act_ru_identitylink process information variable act_hi_taskinst: historical task information that has been executed
Act_hi_taskinst: information on completed historical tasks
Act_hi_procinst: the history table of the process instance, which stores the information of the process instance after execution
Act_hi_actinst: stores all completed activities in history
Now that we have a general understanding of the table, then we will follow our established process to carry out our leave request. For example, if the first project manager is called Zhang San, then this process example has been started. First, we need Zhang San to perform the operation. So let's take a look at the details of Zhang San's task execution. The code is as follows:
[java] view plain copy
/ * *
* find the individual's current task to perform
, /
@ Test
Public void findMyTaskInfo () {
String assignee = "Zhang San"
List listTask = processEngine.getTaskService ()
.createTaskQuery ()
.taskAssignee (assignee)
.list ()
If (listTask = null & & listTask.size () > 0) {
For (Task task: listTask) {
System.out.println ("Task ID:" + task.getId ())
System.out.println ("Task name:" + task.getName ())
System.out.println (Task time: + task.getCreateTime ())
System.out.println ("Class members of the task:" + task.getAssignee ())
System.out.println ("instance of the task ID:" + task.getProcessDefinitionId ())
System.out.println ("ID of the execution object:" + task.getExecutionId ())
System.out.println ("Class members of the task:" + task.getAssignee ())
System.out.println ("process definition ID:" + task.getProcessInstanceId ())
}
}
}
The printed information is as follows: task ID:304, task name: [project manager] approval, task time: Sat Jan 23 14:54:35 CST 2016, task class person: Zhang San task instance ID:LeaveBill:2:204 execution object ID:301 task class person: Zhang San process definition ID:301
Mission accomplished
Then I will finish a process in which the task ID is 304, that is, the project manager agrees to ask for leave, the code is as follows:
[java] view plain copy
/ * * complete the task * /
@ Test
Public void completeMyPersoinTask () {
String taskId = "304"
ProcessEngine.getTaskService ()
.complete (taskId)
System.out.println ("complete the task, task ID:" + taskId)
}
Then when I continue to query the personal task, we can only find the director's task, because the project manager has completed the implementation, so the current task is invisible, but it exists in the historical information.
If we start the instance and query the current information, it will be queried in the table of act_ru_*. According to the task-related services, they are all taskService. Of course, Activiti also has many services, such as RepositoryService,RuntimeService, HistoryService and so on.
To sum up, first deploy, then start, after the individual login system, according to the individual name, look up the task ID, complete the personal task, until all are completed
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.