This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.
1. What is workflow approval
According to my understanding, it is approval process management.
2. What is flowable
1. Official explanation
Here’s the official explanation:
The Flowable project provides a core set of open source business process engines that are compact and efficient. They provide workflow and business process management (BPM) platforms for developers, system administrators, and business users.
At its heart is a lightning-fast, proven dynamic BPMN process engine, accompanied by DMN decision tables and a CMMN case management engine, all written in Java. They are open source under the Apache 2.0 license and have a committed community.
All engines can run embedded in Java applications or as services in servers, clusters, and the cloud. They can run as standalone engines or services, or they can be integrated together to provide a rich suite for business process management. They integrate perfectly with Spring. With rich Java and REST apis, they are an ideal foundation for orchestrating human or robotic automation. They enable microservice choreography or soft wiring of the microservices themselves.
Here’s a summary:
- The purpose is to manage the business approval workflow.
- Use BPMN technology.
- Easily nested in the Spring architecture.
2. Distinguished family
Flowable also came from Activiti, where a bunch of guys went out with each other to start a business. But the wok is the same, just cooked in a different way. So in mind, Flowable is not that different from Activiti. It’s just more powerful.
3. What is BPMN
1. Explain the BPMN
Here’s the official explanation:
The standard Business Process Model and Notation (BPMN) will provide enterprises with the ability to understand their internal business processes in graphical notation and enable organizations to communicate these processes in a standard manner. In addition, graphical symbols will help to understand performance collaboration and business transactions between organizations. This ensures that the enterprise understands itself and its business participants, and enables the organization to quickly adapt to the new internal and B2B business environment.
Here’s a summary:
- BPMN has developed a standard set of business process modeling notations. The following figure is the symbol for modeling.
- BPMN defines a flowchart that is written using the above notation. The diagram below is drawn using BPMN rules.
To put it bluntly, the diagram as shown above is a BPMN flowchart.
2. Common symbols of BPMN
1. Start the node
Indicates where the process begins.
2. Task node
There are many tasks involved, as shown in the figure. One of the most common is user tasks. This option is required for all specified approvers.
3. Gateway components
Gateways correspond to judgment (and, or, or not). The three most commonly used gateways are mutually exclusive, parallel, and compatible gateways.
- Mutually exclusive gateway: it is equivalent to judgment. For example, if the input value is greater than 20, go to node A and less than 20 go to node B.
- Parallel gateway: Compatible gateways appear in pairs, indicating that all the people in the gateway agree to enter the next node.
3. Compatible gateway: the combination of mutually exclusive gateway and parallel gateway. If both A and B meet the mutually exclusive conditions, they both need to be transferred.
3. Here’s an example
The instructions are as follows:
- Enter the approval stage when the applicant for approval has been submitted
- Two project managers will approve and proceed to the next node after both of them agree.
- The manager approves, and anyone whose business is manage can approve. (Claim business is not described here)
- In this case, approval by the general manager/chairman is required if it is more than 20 days; if it is less than 20 days, approval by the general manager is required.
4.为什么选择flowable
In terms of technology choices, Flowable is newer and more functional than Activiti. Flowable is recommended to use new instead of old. But compared to Activiti, its online documentation is minimal. Getting started is harder.
Of course, you can develop your own approval flow system and design the fields of submitter and approver, which can be completed by SQL query. This is the most time-consuming and laborious approach, and is not functionally comparable to open source architecture. Open source Flowable/Activiti has developed its own system, which makes it more professional when talking to customers.
5. Common business processes
Standard approval flow systems have a set of standardized business processes. The following section describes how to operate the approval flow system.
1. Overall process
The business process is mainly divided into the following steps:Generally, the module names in the system are as follows.
Task management here can view the specific information of each approval node of a process. Non-essential business.
1. Edit process
This part is mainly about the production process.
1. Customize the form
The applicant should fill in the application items and application data when conducting the approval. If leave approval needs to fill in leave time and leave reason. So this form we want to customize.
2. Edit the process model
In other words, BPMN is used to draw a flow chart, in which the form of the approval process, the personnel of the next approval node and the flow conditions of entering the process are specified.
You can also import flowcharts. You can also specify the form the applicant needs to fill in when applying. (If the approver needs to add the approval form, it can also be configured here)
3. Deploy as a process definition
The process model does not take effect after being edited/imported. It can then be used and approved after the build process definition is published. Of course, the process definition module also has functions such as export activation.
2. Execute the approval
1. Feature list
When the process is designed, you can initiate and approve, and the user has the following capabilities.
2. Functional explanation
Rejected: The approval is reset and sent to a node for re-approval.
Transfer: A transfers to B for approval. After B’s approval, the node enters the next node.
Delegate: A transfers to B for approval. After B’s approval, A transfers to A, after A’s approval, the node enters the next node.
3. Query process instances and tasks
As you can see from the figure above, when the approval is initiated, the process instance is generated. The process instance and task management can view the approvals that have been initiated.
- Each set of approval information generates a process instance information.
- A process instance has multiple approval nodes (drawn in the flowchart), each of which is a piece of task management information.
Note the process definition and process instance concepts.
6. How to develop
Flowable is simple, but because there is less information on the market, and even less clarity, it is difficult for the technology to flow through the stack.
Flowable provides us with 47 tables and seven commonly used apis.
1. Tables provided
All database tables of Flowable begin with ACT_. The second part is a two-character identifier that describes the purpose of the table. The naming of service apis also roughly conforms to this rule.
-
- ACT_RE_*:’RE ‘stands for repository. Tables with this prefix contain “static” information, such as process definitions and process resources (images, rules, and so on).
-
- ACT_RU_*: ‘RU ‘for Runtime. These tables store runtime information, such as process instances, user tasks, variables, jobs, and so on. Flowable saves runtime data only while the process instance is running and deletes records when the process instance ends. This keeps the run-time tables small and fast.
-
- ACT_HI_*: ‘HI ‘stands for history. These tables store historical data, such as completed process instances, variables, tasks, and so on.
-
- ACT_GE_*: common data. Use it in multiple places.
-
- ACT_ID_*: represents organizational information, such as users, user groups, and so on. (Rarely used)
-
- FLW_*. No official description was found and all tables are empty.
1.ACT_GE_*
- ACT_GE_BYTEARRAY: Stores the BPMN XML of the process and the Image thumbnail of the process
- ACT_GE_PROPERTY: Basic information about Flowable. Such as the version information used by each module.
2.ACT_RE_*
- ACT_RE_DEPLOYMENT: Deployment object, stored process name
- ACT_RE_MODEL: Process-based model information
- ACT_RE_PROCDEF: process definition table
3.ACT_RU_*
- ACT_RU_ACTINST: Active table of the running instance
- ACT_RU_DEADLETTER_JOB: A JOB that cannot be executed for many times is recorded in this table
- ACT_RU_ENTITYLINK: not used yet. Update this table later.
- ACT_RU_EVENT_SUBSCR: run-time event
- ACT_RU_EXECUTION: A list of running instances
- ACT_RU_HISTORY_JOB; History table of running scheduled tasks
- ACT_RU_IDENTITYLINK: information about the current task executor
- ACT_RU_JOB: running asynchronous task
- ACT_RU_SUSPENDED_JOB: List of suspended tasks. If an asynchronous task is running, it is suspended. It will be recorded in the word list
- ACT_RU_TASK: running normal node task
- ACT_RU_TIMER_JOB: indicates the scheduled job table
- ACT_RU_VARIABLE: running process instance variable
4.ACT_ID_*
- ACT_ID_BYTEARRAY:
- ACT_ID_GROUP: indicates information about a user group
- ACT_ID_INFO: user details
- ACT_ID_MEMBERSHIP: Relationship between user groups and users
- ACT_ID_PRIV: permissions
- ACT_ID_PRIV_MAPPING: specifies the relationship between a user group and a permission
- ACT_ID_PROPERTY: extended list of user or user group attributes
- ACT_ID_TOKEN: logs related to login
- ACT_ID_USER: user
5.ACT_HI_*
- ACT_HI_ACTINST: process instance history
- ACT_HI_ATTACHMENT: history attachment of the instance, which is rarely used and will increase the loading of the database
- ACT_HI_COMMENT: historical remarks of the instance
- ACT_HI_DETAIL: details about the instance process
- ACT_HI_IDENTITYLINK: History generated in the instance node if the target person is specified
- ACT_HI_PROCINST: process instance history
- ACT_HI_TASKINST: Task history of the process instance
- ACT_HI_VARINST: Variable history of the process instance
6.FLW_*
- FLW_CHANNEL_DEFINITION: pool pipe definition table
- FLW_EVENT_DEFINITION: event definition
- FLW_EVENT_DEPLOYMENT: Event must be lost
- FLW_EVENT_RESOURCE: resource required by the event
- FLW_EV_DATABASECHANGELOG: Records of Liquibase execution
- FLW_EV_DATABASECHANGELOGLOCK: Liquibase performs the lock
- FLW_RU_BATCH: unknown yet
- FLW_RU_BATCH_PART: temporarily unknown
2. Provided apis
Flowable provides seven common apis that correspond to all the logic above, so you can complete the development of approval business by mastering these apis.
1.FormService
Management of form data.
FormService. GetStartFormKey () to obtain the form key formService. GetRenderedStartForm () query form json (no data)Copy the code
2.RepositoryService
Provides apis for editing and publishing approval processes. Mainly business apis for model management and process definition.
1.Provides the query process definition model with constraints of API repositoryService. CreateXXXQuery () such as: RepositoryService. CreateModelQuery (). The list () model query repositoryService. CreateProcessDefinitionQuery (). The list () query process definition RepositoryService. CreateXXXXQuery (.) XXXKey (XXX), query the key whether there is any)2.A big wave model and the general method of process definition model related repositoryService. GetModel () (model) repositoryService. SaveModel () (save the model) RepositoryService. DeleteModel () model (delete) repositoryService. CreateDeployment (). The deploy (); (deployment model) repositoryService. GetModelEditorSource () (get modelJSONData of UTF8 string) repositoryService. GetModelEditorSourceExtra () (get PNG format images)3.A process definition related repositoryService. GetProcessDefinition (ProcessDefinitionId); For the process definition information repositoryService. ActivateProcessDefinitionById () to activate the process definition repositoryService. SuspendProcessDefinitionById () Suspend the process definition repositoryService. DeleteDeployment () to delete the process definition repositoryService. GetProcessDiagram () to obtain a process definition flow images RepositoryService. GetResourceAsStream () to obtain a process definition XML stream repositoryService. GetBpmnModel (pde) getId ()) to obtain the BPMN objects (currently used the nodes in the flow chart)4.Authorization process definition related repositoryService. GetIdentityLinksForProcessDefinition () authorization process definition list RepositoryService. AddCandidateStarterGroup () new group process authorization repositoryService. AddCandidateStarterUser () new user authorization process RepositoryService. DeleteCandidateStarterGroup () to delete group process authorization repositoryService. DeleteCandidateStarterUser () to delete the user authorization processCopy the code
3.RuntimeService
Process the running process.
RuntimeService. CreateProcessInstanceBuilder (). The start () a process runtimeService. DeleteProcessInstance () to delete the running processes RuntimeService. SuspendProcessInstanceById () hangs a process definition runtimeService. ActivateProcessInstanceById activate process instance () runtimeService.getVariables(processInstanceId); Get the form to fill out the value of the runtimeService. GetActiveActivityIds (processInstanceId) access for flow chart of the nodes (the current to the flow chart of the node) runtimeService.createChangeActivityStateBuilder().moveExecutionsToSingleActivityId(executionIds, endId).changeState(); Termination of a processCopy the code
4.HistoryService
After the user initiates the approval, a process instance is generated. HistoryService is an API for processing process instances, but it includes both completed and unfinished process instances.
HistoryService. CreateHistoricProcessInstanceQuery (). The list () query process instances list (history process, including unfinished) HistoryService. CreateHistoricProcessInstanceQuery (). The list (). The foreach (). The getValue () can get the form in the history of the information historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); Eradicate id query process instances historyService. DeleteHistoricProcessInstance () to delete history process historyService. DeleteHistoricTaskInstance (taskid); To delete a task instance historyService. CreateHistoricActivityInstanceQuery (.) processInstanceId (processInstanceId). The list () process instance node list (The flow chart of the current node is used)Copy the code
If working with running process instances, use runtimeService.
5.TaskService
Approval processing of each node of a process instance.
Of examination and approval of node flow taskService. CreateTaskQuery (). The list () to-do tasks list taskService. CreateTaskQuery (). The taskId (taskId). SingleResult (); SaveTask (task); taskService.savetask (task); Modify task TaskService.setassignee () Set the approver TaskService.addcomment () Set the approval Remarks taskService.complete() completes the current approval taskService.getProcessInstanceComments(processInstanceId); Taskservice. delegateTask(taskId, delegater); Delegate task TaskService. claim(taskId, userId); Claim task taskService.unclaim(taskId); Unclaim taskService.complete(taskId, completeVariables); To complete the task task authorization taskService. AddGroupIdentityLink () new set of tasks authorization taskService. AddUserIdentityLink task authorization () the new staff TaskService. DeleteGroupIdentityLink () to delete group task authorization taskService. DeleteUserIdentityLink () to delete task authorizationCopy the code
6.ManagementService
Execute custom commands.
managementService.executeCommand(newClassA ()) executes an internal method of classACopy the code
You can use the following methods to get repositoryService in a custom method.
ProcessEngineConfiguration processEngineConfiguration =
CommandContextUtil.getProcessEngineConfiguration(commandContext);
RepositoryService repositoryService = processEngineConfiguration.getRepositoryService();
Copy the code
You can also get a collection of process definition methods.
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); ProcessDefinitionEntityManager processDefinitionEntityManager = processEngineConfiguration.getProcessDefinitionEntityManager(); Such as findById/findLatestProcessDefinitionByKey/findLatestProcessDefinitionByKeyAndTenantId, etc.Copy the code
7.IdentityService
For obtaining and saving identity information, here is mainly to obtain identity information.
identityService.createUserQuery().userId(userId).singleResult(); To get the detailed information of user of examination and approval identityService. CreateGroupQuery (). The groupId (groupId). SingleResult (); Obtain the specific information of the approval groupCopy the code