flowable6&springboot2 工作流从入门到精通

相关文档

https://tkjohn.github.io/flowable-userguide/ 文档手册
https://github.com/flowable/flowable-engine/releases/tag/flowable-6.8.0 flowable-ui下载地址
image.png
https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.100/bin/apache-tomcat-8.5.100.zip tomcat下载
百度网盘提取-都给你准备好了哟 (:
链接:https://pan.baidu.com/s/1vlOT1J7B_kC595B2oPtG6w?pwd=ix4c
提取码:ix4c

项目初始化

pom.xml

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.18</version>
        <relativePath/>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- Flowable 工作流相关 -->
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter-process</artifactId>
            <version>6.8.0</version>
        </dependency>
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter-actuator</artifactId>
            <version>6.8.0</version>
        </dependency>
       <!-- MySQL 相关 -->
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

替换自己项目的parent和dependencies

application.yaml

spring:
  application:
    name: crazyFur-springboot-flowable
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/flowable?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
    username: root
    password: root
# 工作流 Flowable 配置
flowable:
  database-schema-update: true # 设置为 false,可通过 https://github.com/flowable/flowable-sql 初始化
  async-executor-activate: true
server:
  port: 8888

记得把数据库改成自己的数据库配置哟

主动启动类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CrazyfurSpringbootFlowableApplication {

    public static void main(String[] args) {
        SpringApplication.run(CrazyfurSpringbootFlowableApplication.class, args);
    }

}

启动项目,检查flowable相关的表是否已经生成,没有生成需要自行百度检查哟-看到有表了就表示🆗了

image.png

安装flowable-ui

解压flowable-6.8.0.zip
image.png
将flowable-ui.war放到tomcat的webapps目录下
image.png
启动tomcat
image.png
访问http://localhost:8080/flowable-ui/idm/#/login登录

flowable.common.app.idm-admin.user=admin 默认用户名admin
flowable.common.app.idm-admin.password=test 默认密码test

image.png
登录成功后的页面
image.png

helloworld

使用flowable-ui画流程图


image.png

image.png

image.png
image.png
helloworld/helloworld.bpmn20.xml 的文件内容

<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef" exporter="Flowable Open Source Modeler" exporterVersion="6.8.0">
<process id="helloword" name="第一个流程" isExecutable="true">
<documentation>这是一个请假流程</documentation>
<startEvent id="startEvent1" name="开始" flowable:formFieldValidation="true"/>
<userTask id="sid-5885E87F-B683-4262-B6BF-A414577BE8E9" name="hr审批" flowable:assignee="hr" flowable:formFieldValidation="true">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler">
<![CDATA[ false ]]>
</modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="sid-59A392ED-D43D-48AF-9520-39064641E1C2" sourceRef="startEvent1" targetRef="sid-5885E87F-B683-4262-B6BF-A414577BE8E9"/>
<endEvent id="sid-FE879718-BCB3-4067-9B4B-5FC44AA78F51" name="结束"/>
<sequenceFlow id="sid-64E09C57-97AD-4D23-AE2E-AE0B7C5E838A" sourceRef="sid-5885E87F-B683-4262-B6BF-A414577BE8E9" targetRef="sid-FE879718-BCB3-4067-9B4B-5FC44AA78F51"/>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_helloword">
<bpmndi:BPMNPlane bpmnElement="helloword" id="BPMNPlane_helloword">
<bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
<omgdc:Bounds height="30.0" width="30.0" x="100.0" y="163.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-5885E87F-B683-4262-B6BF-A414577BE8E9" id="BPMNShape_sid-5885E87F-B683-4262-B6BF-A414577BE8E9">
<omgdc:Bounds height="80.0" width="100.0" x="175.0" y="138.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-FE879718-BCB3-4067-9B4B-5FC44AA78F51" id="BPMNShape_sid-FE879718-BCB3-4067-9B4B-5FC44AA78F51">
<omgdc:Bounds height="28.0" width="28.0" x="320.0" y="164.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-59A392ED-D43D-48AF-9520-39064641E1C2" id="BPMNEdge_sid-59A392ED-D43D-48AF-9520-39064641E1C2" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
<omgdi:waypoint x="129.9499984899576" y="178.0"/>
<omgdi:waypoint x="174.9999999999917" y="178.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-64E09C57-97AD-4D23-AE2E-AE0B7C5E838A" id="BPMNEdge_sid-64E09C57-97AD-4D23-AE2E-AE0B7C5E838A" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0">
<omgdi:waypoint x="274.95000000000005" y="178.0"/>
<omgdi:waypoint x="320.0" y="178.0"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>

在项目中的情况
image.png

新建单元测试 com.crazyfur.bpm.test.HelloWorldTest

package com.crazyfur.bpm.test;

import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.List;

/**
 * description: ~~
 *
 * @author crazyfur
 * @version 1.0.0
 * @date 2024/05/28 12:25:11
 */
@SpringBootTest
public class HelloWorldTest {

    @Resource
    private RepositoryService repositoryService;

    @Resource
    private RuntimeService runtimeService;

    @Resource
    private TaskService taskService;


    /**
     * ① 部署流程
     */
    @Test
    public void deploy(){
        Deployment deploy = repositoryService.createDeployment()
                .addClasspathResource("helloworld/helloworld.bpmn20.xml")
                .name("请假-01")
                .deploy();
        System.out.println("deploy.getId() = " + deploy.getId());
    }

    /**
     * ② 启动流程
     */
    @Test
    public void startProcess(){
        // 根据流程id启动流程===》注意使用自己的流程id
        ProcessInstance instance = runtimeService.startProcessInstanceById("helloword:1:0a03cbb1-1caf-11ef-974d-4a5f08bacd87");
        System.out.println(instance.getId());
    }

    /**
     * ③ 审批流程任务
     */
    @Test
    public void assigneeTask(){
        // 根据审批人查找要审批的任务
        List<Task> list = taskService.createTaskQuery().taskAssignee("hr").list();
        list.forEach(task -> {
            System.out.println(task.getId());
            // 审批任务
            taskService.complete(task.getId());
        });
    }


}

image.png

运行

运行单元测试:① 部署流程

查看数据库:
image.png
运行单元测试:② 启动流程
查看数据库:
image.png
image.png
运行单元测试:③ 审批流程任务
查看数据库:hr的任务已经审批了
image.png
更多内容如下

  1. 任务分配

  2. 流程变量

  3. 用户任务、服务任务、邮件任务

  4. 网关服务

  5. 流程事件、信号、消息

  6. 子流程

  7. 流程设计器、表单设计器

  8. 会签、或签

  9. 转办 委派 抄送

  10. 任务回退、驳回

  11. 执行监听器、任务监听器

  12. 流程表达

    有需要更多文档联系作者:vx:crazyfur

  • 22
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值