Code Address:Gitee.com/zhangxin123…

BPM(Business Process Management) : Business process management

BPMN(Business Process Model and notation), a business process model and notation

1. Procedure

  • Deploy Activiti: Activiti is a bunch of JARS, so it needs to be deployed with business systems

  • Define a process: Define a business process.bPMN file using Activiti’s modeling tools

  • Deploy the process definition: Use the API provided by Activiti to store the process definition content, which can be viewed in the Activiti execution summary. Activiti stores business processes through a database.

  • Start processInstance: processInstance is also called processInstance, and starting a processInstance means starting a business process.

  • Users query tasks: Since all system processes are managed by Activiti, activiti can query the current step of the process. Activiti also manages what the current user needs to do without writing SQL queries.

  • Tasks for users: Once a user has found his or her own to-do list, he or she can perform a task. If the task needs to be completed by another user, Activiti can help push the workflow forward.

  • End of process: The process instance is completed when the business process is complete and there is no next task node.

2. Environment construction

Install the process definition plug-in actiBPM in Idea.

3. Create the process definition

  • Create the ***.bpmn file in the resource directory

  • Build a flowchart: Note the ID and name defined throughout the process, as well as the name and assignee of each node object

  • Copy ***. BPMN file, add suffix. XML, use idea Diagrams open, you can export the PNG file of the process definition

  • Deployment process

4. Test

See the code

5. Process definition and process instance

ProcessDefinition and ProcessInstance ProcessInstance are two very important concepts in activiti. Their relationship is similar to the concept of classes and objects in Java.

A process definition is a workflow defined in a BPMN file and is a set of work specifications. For example, the previous leave process

A process instance is a concrete business process. For example, if an employee initiates a leave, a process instance of the leave will be instantiated, and each of the different process instances will not affect each other.

In the table structure behind the scenes, there are many tables that contain fields for process definitions and process instances.

The process definition field is typically PROC_DEF_ID, and the process instance field is typically PROC_INST_ID.

Start the process instance and add the businessKey

When we went to see startProcessInstanceByKey this method, there are a lot of overloaded implementation method, can pass some different parameters.

  • String processDefinitionKey: The unique key of the process definition, which cannot be empty

  • String businessKey: The unique key associated with each process instance context

This is a very important convenience that Activiti provides to tie activiti’s workflow to the real business.

For example, when we need to approve a business order, the details of the order are not in activiti’s data, but we do need to look at them for approval.

  • Map<String,Object> variables: Process variables passed in the process instance

  • String tenantId: indicates the vstore ID, which supports the multi-tenant design

6. Process suspension and activation

Sometimes we need to pause a process and resume it after a while. For example, the reimbursement approval process is not accepted at the end of the month, the reception approval process is not accepted at the end of the year, and the after-sales reimbursement process is not accepted on non-working days. At this time, the process can be suspended, and the suspended process will not be continued.

There are two ways to operate when suspended

  • The entire process definition is suspended so that all process instances under the process definition are suspended and cannot be executed

  • Suspends the current instance, which is not allowed to operate

7. Process variables

Process variables also play an important role in Activiti. Our previous leave process did not use process variables, and each step was very fixed. However, when we need to realize some responsible business processes, such as approval by department manager within 3 days, and approval by general manager more than 3 days, we need process variables.

Scope of process variables

1. Global variables

  • This is the default scope of a process variable, and the scope is a complete process instance.

  • Variable names are not repeatable and duplicates are overwritten

2. Local variables

  • The Local variable is only scoped to the scope of a task or execution instance.

  • Variable names can be repeated without affecting each other

3. Use process variables

Once the process variables are defined, they can be used throughout the process definition. For example, you can use assignee on some task attributes, or {assignee} on some connections, or {evection. Num <3} on some connections.

These process variables can be used in Activiti using UEL expressions. UEL expressions can directly fetch the value of a variable, evaluate the expression of a Boolean result, and directly use properties of certain objects. For example, if the leave process created before needs to be approved by department manager within 3 days and approved by general manager more than 3 days, the following adjustments can be made:

     

Matters needing attention:

1) An error is reported if the process variable name does not exist in the UEL expression

2) If the value of the process variable in the UEL expression is NULL, the process does not execute as the UEL expression, but ends

3) If all UEL expressions do not meet the conditions, the process ends

4) If no condition is set on the line, the line with small flow sequence number will be followed

5) Setting the process variable will insert records in the current executed process variable table ACT_ru_variable and also in the history process variable table ACT_HI_VARinst

8. The gateway

  • ExclusiveGateway

An exclusive gateway to implement decisions in the process. When the process executes to this gateway, all branches determine whether the condition is true and execute the branch if true.

If the gateway has two branches that are true, the exclusive gateway selects the branch with the smaller ID to execute.

Note: process branch selection can also be realized on lines based on conditions. Different from gateway, if conditions on lines are not met, the process ends. An exclusive gateway will throw a system exception.

  • ParallelGateway

Parallel gateways allow the process to be split into multiple branches and to be brought together, and their functionality is based on incoming and outgoing sequential flows.

Fork: All outgoing sequential streams after parallel, creating a concurrent branch for each sequential stream

Join convergence: All branches that arrive at the parallel gateway wait to enter the branch until all branches that enter the sequential flow arrive and the process passes through the convergence gateway

The main difference from other gateways is that parallel gateways do not resolve conditions and ignore them even if they are defined in the sequential flow

  • Contains the gateway

An inclusion gateway can be considered a combination of an exclusive gateway and a parallel gateway

As with exclusive gateways, you can define conditions on outgoing sequential flows, and include gateways will resolve them. But the main difference is that the inclusion gateway can select more than one sequential stream, just like a parallel gateway

The functionality that includes gateways is based on incoming and outgoing sequential flows

Fork branches: All conditions for the outgoing sequence stream are resolved and the sequence stream that results in true continues in parallel, creating a branch for each sequence stream

Join convergence: all parallel branches arrive at the inclusion gateway and enter a waiting state until each branch that enters the sequential flow containing the process token arrives. This is the biggest difference with parallel gateways. In other words, the containing gateway will simply wait for the incoming sequential stream to be selected for execution, and then continue execution after convergence

  • The event gateway

The event gateway allows you to determine the direction of flow based on events. Each outgoing sequential flow of the gateway is connected to an intermediate capture event. When a process reaches an event-based gateway, the gateway enters a wait state: execution is paused. At the same time, a relative event subscription is created for each outgoing sequential stream.

The outgoing sequential flows of the event gateway are different from normal sequential flows in that they do not actually “execute”; instead, they let the process engine decide which events the process executing to the event gateway needs to subscribe to. Consider the following conditions:

1) The event gateway must have two or more outgoing sequential streams

2) After the event gateway, only the intermediateCarchEvent type can be used (Activiti does not support connecting to ReceiveTask based on the event gateway)

3) Intermediate capture events connected to the event gateway must have only one entry sequence stream

9. Group tasks

Set multiple candidates

Previously, the principal was flexibly specified by setting assignee. However, in daily work, there is still a common requirement that cannot be supported. For example, an order contract needs to be signed by a person in charge at the department manager level. However, there are multiple department managers in the company, and the business only needs to find any one of them to complete the approval. In this scenario, we cannot set the person in charge by setting process variables. This is where you need another tool that Activiti provides: Candidate Users.

At this point, you can set the task to multiple candidates, candiat-users, separated by commas.