Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Process variables of activiti

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

The so-called process variables are probably the data related to our business, such as I want to ask for leave, then I need to know who is asking for leave and who is who, that is, I want to know how the entity of activiti is related to the javaBean of our business.

Next, let's take a look at the database tables of the process variables. Of course, the tables we built are all process variables. Ha ha.

Act_ru_task (list of tasks in progress) and act_hi_taskinst (list of tasks in progress)

It mainly records the name of the task being executed, process instance ID, process definition DI, task key, and process variable information.

The information recorded by the historical task table is the same as that of the task table being executed, except that one is all the information and the information about the task that is being performed.

Act_hi_comment

Because it is mostly used for business operations, this table mainly records some different views on the same event for reference by other users. For example, when asking for leave, the project manager said, "if my staff and teachers work overtime, they have to give it to the family, and the director will give it directly." Right.

Act_ru_execute (instance table being executed) pay attention to business_key. This field is customized by us. My method is instance +. "+" Business ID ".

Act_ru_variable (process definition table information in progress)

Well, the tables provided by activiti have process variables, and now that we have these tables, let's take a look at how these tables are used when our business is implemented. Below I use two examples, one is that I am drawing the flow chart is to write a good process example, the other is to use javaBean to achieve.

Simple example

Deploy and start the process instance

[java] view plain copy

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine ()

/ * * deployment process definition from (inputStream) * /

@ Test

Public void deploymentProcessDefinition_input () {

InputStream inputStreamBpmn = this.getClass () .getResourceAsStream ("/ diagrams/porcessVariables.bpmn")

InputStream inputStreamPng = this.getClass () .getResourceAsStream ("/ diagrams/porcessVariables.png")

Deployment deployment = processEngine.getRepositoryService () / / Service for process definition and deployment related objects

.createDeplotation () / / create a deployment object

.name ("hellworld departmental Program")

.addInputStream ("porcessVariables.bpmn", inputStreamBpmn) / / use the resource name and input stream (always with the name of the resource file)

.addInputStream ("porcessVariables.png", inputStreamPng)

.deploy ()

System.out.println ("deployment" + deployment.getId ()); / / 1

System.out.println ("deployment" + deployment.getName ()); / / departmental procedures

}

@ Test

Public void startProcessInstance () {

/ / key of the process definition

String processInstenceKey = "processVariables"

ProcessInstance pi = processEngine.getRuntimeService () / / service related to the process instance and execution object being executed

.startProcessInstanceByKey (processInstenceKey); / / use the key defined by the process to start the id of the process instance helloworld.bpmn, and start it with key. The latest version is used by default.

System.out.println ("process instance id:" + pi.getId ()); / / process instance id

System.out.println ("process definition id:" + pi.getProcessDefinitionId ()); / / process definition ID helloworld:1:4

}

When we start up, there are no process variables, but then we need to set it. If we set it when we talk about the flow chart, for example, when we click on a task in bpmn, select Main config, and then write "Zhang San" in Assign, then if we want to start Zhang San's business process, we need the following code:

[java] view plain copy

@ Test

Public void setVariables () {

String taskId = "2004"

TaskService taskService = processEngine.getTaskService ()

TaskService.setVariableLocal (taskId, "days off", 3); / / bound to task ID

TaskService.setVariable (taskId, "date of leave", new Date ())

TaskService.setVariable (taskId, "reasons for asking for leave", "going home to see relatives")

System.out.println ("setup succeeded")

}

And the taskId of the above code is the currently executing task ID after the instance is started, and then we can see the name of Zhang San in the table such as act_ru_variable,act_ru_task, but this can be realized, but we will not use it in practice. Since it is object-oriented, we should do this.

[java] view plain copy

Public class Person implements Serializable {

/ * *

*

, /

Private static final long serialVersionUID = 1L

Private Integer id

Private String name

Public String getName () {

Return name

}

Public Integer getId () {

Return id

}

Public void setId (Integer id) {

This.id = id

}

Public void setName (String name) {

This.name = name

}

}

[java] view plain copy

@ Test

Public void setVariables () {

String taskId = "2004"

TaskService taskService = processEngine.getTaskService ()

/ * * use javaBean*/

Person p = new Person ()

P.setId (20)

P.setName ("menghaibintest")

TaskService.setVariable (taskId, "personnel Information", p)

System.out.println ("setup succeeded")

}

Take a look at the effect.

So let's get it.

[java] view plain copy

/ * *

* obtain process variables

, /

@ Test

Public void getVariables () {

TaskService taskService = processEngine.getTaskService ()

String taskId = "404"

Person p = (Person) taskService.getVariable (taskId, "personnel information")

System.out.println ("id:" + p.getId ())

System.out.println ("name" + p.getName ())

}

Of course, you may think this is still not friendly enough. I want to distinguish my business from the workflow table and associate it with only primary and foreign keys, so in the next blog, I will show you a method with the least coupling.

To sum up, since we want to set up process variables, we need to know where our process variables are located in the table in the database and how to set them in the workflow. Since it is object-oriented, we should no longer use a setting-by-setting approach.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report