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

How to understand the actual combat process of flowable workflow based on springboot

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "how to understand the actual combat process of flowable workflow based on springboot". In the daily operation, I believe that many people have doubts about how to understand the actual combat process of flowable workflow based on springboot. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "how to understand the actual combat process of flowable workflow based on springboot"! Next, please follow the editor to study!

Background

Use flowable-ui included in flowable to make flow chart.

Use the interface used by the springboot development process to complete the business function of the process

I. flowable-ui deployment and operation

Flowable-6.6.0 runs the official demo

1. Download flowable-6.6.0: https://github.com/flowable/flowable-engine/releases/download/flowable-6.6.0/flowable-6.6.0.zip from the official website

2. Throw the flowable-6.6.0\ wars\ flowable-ui.war in the compressed package into Tomcat and run

3. Open the http://localhost:8080/flowable-ui account: log in with admin/test

4. Enter the APP.MODELER creation process, and then export the process to the project for use, or configure

Apache-tomcat-9.0.37\ webapps\ flowable-ui\ WEB-INF\ classes\ flowable-default.properties

Connect to the local database

Note: java driver jar (mysql-connector-java-5.1.45.jar) needs to be copied to apache-tomcat-9.0.37\ webapps\ flowable-rest\ WEB-INF\ lib

In this way, the process back-end program created can directly use the

Second, draw the flow chart

According to the business needs, draw the flow chart in flowable-ui > APP.MODELER, such as the figure above. Explain some concepts first.

Events (event) are usually used to model what happens in the process lifecycle, with the start and end circles in the diagram.

A sequential flow (sequence flow) is a connector between two elements in a process. In the picture is the arrow line segment.

The gateway (gateway) is used to control the flow of execution. In the picture is [diamond (with X in the middle)]

User tasks (user task) are used to model tasks that need to be performed manually. The picture is [rectangle].

These are probably the elements of a simple workflow (there are many more that will not be extended here). Here is a description of how the workflow flows.

First, after the workflow is started, the [start] node automatically flows to the [student] node, waiting for the task to be executed. The assigned student user flows to the [teacher] node after the task is executed, and waits for the task to be executed again. After execution, the assigned teacher user flows to the [gateway], which checks each exit and flows to the qualified task. For example, if the teacher agrees to execute the task, it flows to the [principal] node and waits for the task to be executed. After execution, it is similar to the teacher, and after consent, it flows to the end node, and the whole process ends here.

Drawing details:

1. Retain the process model

2. Sequential flow can be restricted by setting flow conditions, such as the gateway exit above.

3. Executive users whose tasks need to be assigned can be assigned to candidate groups or directly to candidates

Finally, export the workflow file

File content

It's useless here, get rid of the third, the background project to build.

Background projects are based on jdk8 and use the springboot framework

Spring version

Org.springframework.boot spring-boot-starter-parent 2.3.0.RELEASE

The project depends on pom.xml

Org.flowable flowable-spring-boot-starter 6.6.0 mysql mysql-connector-java 5.1.45

Project configuration application.yml

Spring: datasource: url: jdbc:mysql://localhost:3306/flowable?useSSL=false&characterEncoding=UTF-8&serverTimezone=GMT%2B8 driver-class-name: com.mysql.jdbc.Driver username: root password: 123456 IV. Database

1. All database tables in Flowable start with ACT_. The second part is a two-character identifier that describes the purpose of the table. The naming of the service API also roughly conforms to this rule.

2. ACT_RE_: 'RE' stands for repository. Tables with this prefix contain "static" information, such as process definitions and process resources (pictures, rules, etc.).

3. ACT_RU_: 'RU' stands for runtime. These tables store runtime information, such as process instances (process instance), user tasks (user task), variables (variable), jobs (job), and so on. Flowable saves run-time data only when the process instance is running and deletes the record when the process instance ends. This ensures that the runtime table is small and fast.

4. ACT_HI_: 'HI' stands for history. These tables store historical data, such as completed process instances, variables, tasks, and so on.

5. ACT_GE_: general data. It is used in many places.

General purpose indicates that a detailed reference to Vargarissa

1) General data sheets (2)

Act_ge_bytearray: binary data tables, such as process definitions, process templates, byte flow files for flowcharts

Act_ge_property: attribute data sheet (not commonly used)

2) History tables (8, tables operated by HistoryService interface)

Act_hi_actinst: historical node table, which stores the information of each node running by the process instance (including non-task nodes such as start and end)

Act_hi_attachment: history attachment table, which stores the attachment information uploaded by history nodes (not commonly used)

Act_hi_comment: historical opinion form

Act_hi_detail: historical details table, storing some information about the operation of nodes (not commonly used)

Act_hi_identitylink: historical process personnel table, which stores information about candidates and managers of each node of the process. It is often used to query the completed tasks of a person or department.

Act_hi_procinst: historical process instance table, which stores historical data of process instances (including running process instances)

Act_hi_taskinst: historical process task table, storage historical task node

Act_hi_varinst: process history variable table, which stores the variable information of the process history node

3) user-related tables (4, tables operated by IdentityService interface)

Act_id_group: user group information table, corresponding to the candidate group information selected by the node

Act_id_info: user extension information table, storing user extension information

Act_id_membership: user and user group relationship table

Act_id_user: user information table, corresponding to the information of the manager or candidate selected by the node

4) process definition, process template related tables (3, tables operated by RepositoryService interface)

Act_re_deployment: subordinate information table, storing process definition, template deployment information

Act_re_procdef: the process definition information table stores the description information related to the process definition, but its real content is stored in the act_ge_ bytearray table in bytes

Act_re_model: the process template information table, which stores the description information related to the process template, but its real content is stored in the act_ge_ byte table in bytes.

5) process runtime tables (6, tables operated by RuntimeService interface)

Act_ru_task: runtime process task node table, which stores the task node information of the running process. It is important and is often used when querying people or departments'to-do tasks.

Act_ru_event_subscr: monitoring information table, not commonly used

Act_ru_execution: runtime process execution instance table, recording each branch information of the running process (when there is no sub-process, its data corresponds to the act_ru_ task table data one to one)

Act_ru_identitylink: runtime process personnel table, important, often used when querying people or department to-do tasks

Act_ru_job: runtime timed task data table, which stores timed task information of the process

Act_ru_variable: runtime process variable data table, which stores the variable information of each node of the running process

Process engine API and service

The engine API is the most common means of interacting with Flowable. The total entry point is ProcessEngine.

1. RepositoryService is probably the first service to use when using the Flowable engine. This service provides management and control deployment (deployments) and process definition (process)

Definitions). Manage static information. 2. RuntimeService is used to start a new process instance of a process definition.

3. IdentityService is very simple. It is used to manage (create, update, delete, query... ) groups and users.

4. FormService is an optional service. In other words, Flowable works well without it without sacrificing any functionality.

5. HistoryService exposes all historical data collected by the Flowable engine. To provide the ability to query historical data.

6. ManagementService usually does not need to be used when writing user applications in Flowable. It can read the information of database tables and raw data of tables, and also provides query and management operations for jobs (job).

7. DynamicBpmnService can be used to modify parts of a process definition without having to redeploy it. For example, you can modify the handler settings for a user task in the process definition, or modify the class name in a service task.

Next, use the previous leave flow chart and code it.

Code

Import lombok.extern.slf4j.Slf4j;import org.flowable.engine.HistoryService;import org.flowable.engine.RepositoryService;import org.flowable.engine.RuntimeService;import org.flowable.engine.history.HistoricProcessInstance;import org.flowable.engine.repository.Deployment;import org.flowable.engine.repository.ProcessDefinition;import org.flowable.engine.runtime.Execution;import org.flowable.engine.runtime.ProcessInstance;import org.flowable.idm.api.Group;import org.flowable.idm.api.User;import org.flowable.task.api.Task Import org.flowable.task.api.history.HistoricTaskInstance;import org.springframework.beans.factory.annotation.Autowired;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.zip.ZipInputStream;/** * TestFlowable * * @ Author * @ Date: 23:35 * @ Version 1.0 * / @ Slf4jpublic class TestFlowable {@ Autowired private RepositoryService repositoryService on 2021-10-17 @ Autowired private RuntimeService runtimeService; @ Autowired private HistoryService historyService; @ Autowired private org.flowable.engine.TaskService taskService; @ Autowired private org.flowable.engine.IdentityService identityService Public void createDeploymentZip () {/ * * @ Date: 23:38 * Step 1 on 2021-10-17: deploy xml (compressed to zip format, direct xml needs to be configured with relative path, trouble, not available) * / try {File zipTemp = new File ("f:/zhan_test.bpmn20.xml"); ZipInputStream zipInputStream = new ZipInputStream (new FileInputStream (zipTemp)) Deployment deployment = repositoryService .createdeployment () .addZipInputStream (zipInputStream) .deploy (); log.info ("deployment success: {}", deployment.getId ());} catch (FileNotFoundException e) {e.printStackTrace () } / * * @ Date: 23:40 * Step 2 on 2021-10-17: query the process definition of deployment * / List list = repositoryService.createProcessDefinitionQuery (). ProcessDefinitionKey ("leave_approval"). List (); List pages = repositoryService.createProcessDefinitionQuery (). ProcessDefinitionKey ("leave_approval"). ListPage (1,30) / * * @ Date: 23:40 * Step on 2021-10-17 * Step 3: start the process and create an instance * / String processDefinitionKey = "leave_approval"; / / the key defined by the process, corresponding to the flowchart of asking for leave String businessKey = "schoolleave"; / / Business code, use Map variablesDefinition = new HashMap () according to your own business / / process variable, you can customize the extension ProcessInstance processInstance = runtimeService.startProcessInstanceByKey (processDefinitionKey, businessKey, variablesDefinition); log.info ("start successfully: {}", processInstance.getId ()) / * * @ Date: 23:40 * Step 4 on 2021-10-17: query the list * list of all instances started by the specified process, or delete * / List executions = runtimeService.createExecutionQuery () .processDefinitionKey ("leave_approval") .list (); List executionPages = runtimeService.createExecutionQuery () .processDefinitionKey ("leave_approval") .listPage (1,30) / / runtimeService.deleteProcessInstance (processInstanceId, deleteReason); / / Delete the instance / * * @ Date: 23:40 on 2021-10-17 * Step 5: students query the tasks that can be operated and complete the task * / String candidateGroup = "stu_group" / / flowable:candidateGroups= "stu_group" List taskList in the candidate group xml file = taskService.createTaskQuery (). TaskCandidateGroup (candidateGroup). OrderByTaskCreateTime (). Desc (). List (); for (Task task: taskList) {/ / apply for task taskService.claim (task.getId (), "my"); / / complete taskService.complete (task.getId ()) } / * * @ Date: 23:40 * Step 6 on 2021-10-17: the teacher queries the available tasks and completes the task * / String candidateGroupTe = "te_group"; / / flowable:candidateGroups= "te_group" List taskListTe = taskService.createTaskQuery () in the candidate group xml file. TaskCandidateGroup (candidateGroupTe). OrderByTaskCreateTime (). Desc (). List () For (Task task: taskListTe) {/ / apply for task taskService.claim (task.getId (), "myte"); / / complete Map variables = new HashMap (); variables.put ("command", "agree") / / carries variables for determining the conditions of the gateway process. The condition here is to agree to taskService.complete (task.getId (), variables). } / * * @ Date: 0:17 on 2021-10-18 * Step 7: history query, because once the process is executed, the data of the activity will be emptied, and no data can be found in the API queried above. But provide historical query interface * / / historical process instance List historicProcessList = historyService.createHistoricProcessInstanceQuery () .processDefinitionKey ("leave_approval") .list () / / Historical task List historicTaskList = historyService.createHistoricTaskInstanceQuery () .processDefinitionKey ("leave_approval") .list (); / / instance history variable, task history variable / / historyService.createHistoricVariableInstanceQuery () .processInstanceId (processInstanceId); / / historyService.createHistoricVariableInstanceQuery () .taskId (taskId) / / * delimiter * * * / * Delimiter * * * / / API / / Mobile tasks that may be needed Artificially redirect task / / runtimeService.createChangeActivityStateBuilder () .processInstanceId (processInstanceId) / / .moveActivityIdTo (currentActivityTaskId, newActivityTaskId) .changeState () / / if grouping and users are configured in the database, List users = identityService.createUserQuery () .list () is also used. / / user id corresponds to the user List groups = identityService.createGroupQuery () .list () configured in xml. / / grouping query, grouping id corresponds to the grouping configured in xml, such as stu_group,te_group is the value of id in the table / / in addition, each query can spell conditions, built-in so many queries, including fuzzy queries, size comparison}. The study on "how to understand the actual combat process of flowable workflow based on springboot" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Development

Wechat

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

12
Report