From entry to actual combat -- flowable (workflow)

catalogue

preface

Related concepts

Flowable

flow chart

Process id

Task id

SpringBoot project integration Flowable

1,pom. Add dependency to XML file

Add flowable dependencies (there are many ways to find dependencies, which are found here with idea)

2. Configuration yml file

3. Draw flow chart

① Download compressed package

② Run war package

4. Must know API

common problem

What if github downloads slowly?

Does the xml generated by drawing a flowchart always report an error?

Is there a manual?

preface

Some time ago, Flowable was used in the project. Now I'll talk about the use of Flowable. Even friends without this foundation can easily read and practice.

Related concepts

Flowable

Flowable is a lightweight business process engine written in Java.

flow chart

The whole process is presented visually to make all kinds of situations clear at a glance. After construction, xml files can be generated and put into the project.

Process id

Create a unique ID of a process according to the proposed flow chart, and you can view the current process status through this ID.

Task id

After the process is created, the work to be approved will generate a task id on the corresponding approver. After the approver approves, the task id is invalid.

SpringBoot project integration Flowable

1,pom. Add dependency to XML file

Add flowable dependencies (there are many ways to find dependencies, which are found here with idea)

You can directly copy the following dependencies!

        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter</artifactId>
            <version>6.3.0</version>
        </dependency>

Connecting to mysql depends on my 8.0 Version 16, there is a vulnerability before this version!!!

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.16</version>
</dependency>

2. Configuration yml file

  flowable:
    # If asynchrony is turned off, the insertion of historical data is asynchronous. It will be in the same thing and cannot be rolled back
    # Development can be started, which will improve efficiency. It needs to be closed when going online
    async-executor-activate: false

3. Draw flow chart

① Download compressed package

(1) github website: Releases · flowable/flowable-engine · GitHub (click flowable-6.4.0.zip)

You can also directly click the following link to download https://github.com/flowable/flowable-engine/releases/download/flowable-6.4.0/flowable-6.4.0.zip

② Run war package

My Tomcat is 9.0 In version 38, unzip the compressed package downloaded in the previous step, run all war packages in tomcat, and access the {flowable modeler

After drawing the flow chart and verifying that there are no exceptions, you can save the generated xml file and put it in the resources/processes / directory of the project

4. Must know API

    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private HistoryService historyService;
    @Autowired
    private RepositoryService repositoryService;
    @Autowired
    private ProcessEngine processEngine;
/**
     * Create process
     *
     * @param key                 process id
     * @param userId              User ID
     * @param purchaseOrderNumber Purchase order No
     * @param remark              Purchase remarks
     * @return Process ID
     */
    @GetMapping("add")
    public String addExpense(String key, String userId, String purchaseOrderNumber, String remark) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("purchaseOrderNumber", purchaseOrderNumber);
        map.put("remark", remark);
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(key, map);
        return processInstance.getId();
    }
    /**
     * Gets the process task list of the specified user group
     *
     * @param group Users (groups)
     * @return    
     */
    @GetMapping("lists")
    public Object gettasksByGroup(String group) {
        List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup(group).list();
        return tasks.toString();
    }
     /**
     * Pass / reject task
     *
     * @param taskId   Task ID
     * @param approved 0 : Pass 1: Reject
     * @return ResultUtil It is the return object encapsulated by Zeng lingyao
     */
    @GetMapping("apply")
    public ResultUtil apply(String taskId, String approved) {
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        if (task == null) {
            return ResultVoUtil.error("The task does not exist!");
        }
        Map<String, Object> variables = new HashMap<>();
        Boolean apply = approved.equals("0") ? true : false;
        variables.put("approved", apply);
        taskService.complete(taskId, variables);
        return new ResultUtil("Operation succeeded");
    }
    /**
     * View historical process records
     *
     * @param processInstanceId Process ID
     * @return Historical information list
     */
    @GetMapping("historyList")
    public List<HistoricActivityInstance> getHistoryList(String processInstanceId) {
        return historyService.createHistoricActivityInstanceQuery()
                .processInstanceId(processInstanceId).finished().orderByHistoricActivityInstanceEndTime().asc().list();
    }

common problem

What if github downloads slowly?

A: private letter me, let you download nearly a hundred times faster!!!

Does the xml generated by drawing a flowchart always report an error?

It is recommended to click the check mark icon in the upper left corner before generating the xml file without exception

Is there a manual?

Flowable BPMN user manual (v 6.3.0)

The content is very good. For example, you want to find an api to create an instance

 

Keywords: Java Spring

Added by petrosa on Wed, 29 Dec 2021 01:33:26 +0200