Flowable进阶学习(七)整合SpringBoot(自动部署、手动部署、启动流程、完成流程);多人会签与或签

一、整合SpringBoot

  1. 创建Maven项目
  2. 配置pom.xml文件
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.8</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.hx</groupId>
<artifactId>Flowable_SpringBoot2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Flowable_SpringBoot2</name>
<description>Demo project for Spring Boot</description>
<properties>
    <java.version>1.8</java.version>
</properties>
<dependencies>
    <dependency>
        <groupId>com.mysql</groupId>
        <artifactId>mysql-connector-j</artifactId>
        <version>8.0.32</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <version>1.5.9.RELEASE</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-spring-boot-starter</artifactId>
        <version>6.6.0</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>1.1.24</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.13.2</version>
        <scope>test</scope>
    </dependency>
</dependencies>
  1. 配置application.yml文件
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/flowable2?serverTimeZone=UTC&nullCatalogMeansCurrent=true
    username: root
    password: admin
    hikari:
      minimum-idle: 5
      idle-timeout: 600000
      maximum-pool-size: 10
      auto-commit: true
      pool-name: MyHikariCP
      max-lifetime: 1800000
      connection-timeout: 30000
      connection-test-query: SELECT 1
flowable:
# 关闭定时任务JOB
  async-executor-activate: false
# 将databaseSchemaUpdate设置为true。当flowable发现数据库不一致的时候,会自动将数据库表结构更新到最新版本。
  database-schema-update: true
server:
  port: 8888

自动部署

processes目录下的任何BPMN 2.0流程定义都会被自动部署。创建processes目录,并在其中创建示例流程定义(命名为one-task-process.bpmn20.xml)。
cases目录下的任何CMMN 1.1事例都会被自动部署。
forms目录下的任何Form定义都会被自动部署。

在SpringBoot项目中会自动部署存储在resource\processes目录下的流程定义。(但是只有在第一次启动的时候才会自动部署,而后续新增的部署文件不会部署。)
但是在我的实际测试过程中,发现在调用部署方法的时候,会重新部署processes目录下的流程定义。我们可以手动来条用deploy方法即可。

@Test
void test_deploy(){
    Deployment deploy = repositoryService.createDeployment()
            .name("ManualDeployment").deploy();
    System.out.println(deploy.getId());
}

在这里插入图片描述

手动部署

如果存在不希望被调用的流程定义,可以不放到processes目录下。

@Autowired
private RepositoryService repositoryService;
@Test
void deploy(){
    Deployment deployment = repositoryService.createDeployment()
            .addClasspathResource("processes/出差申请流程.bpmn20.xml")
            .name("出差申请流程2023").deploy();
    System.out.println("deployment.getId() = " + deployment.getId());
    System.out.println("deployment.getName() = " + deployment.getName());
}

启动流程

@Autowired
private RuntimeService runtimeService;
@Test
void startFlow() {
    Map<String, Object> params = new HashMap<>();
    params.put("assignee0", "whx");
    params.put("assignee1", "huathy");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("qjlc23", params);
}

处理\完成流程

@Autowired
private TaskService taskService;
@Test
void completeTask() {
    Task task = taskService.createTaskQuery()
            .processDefinitionKey("qjlc23")
            .taskCandidateOrAssigned("whx")
            .singleResult();
    if (task != null) {
        taskService.complete(task.getId());
        System.out.println(task.getAssignee()+"-完成任务-"+task.getId());
    }
}

二、多人会签

多人会签是指一个任务需要多个人来审批。多人或签是指的=一个任务需要多个人中的一个审批通过即可。

1. 绘制流程图

在这里插入图片描述
在这里插入图片描述

2. 编码

MultiInstCompleteTask.java

package com.example.flowdemo.listener;

import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;
import java.io.Serializable;

/**
 * @author Huathy
 * @date 2023-01-27 08:47
 * @description
 */
@Component("mulitiInstCompleteTask")
public class MultiInstCompleteTask implements Serializable {
    /**
     * 完成任务时需要触发的方法
     * @param execution
     * @return true/false 表示会签任务是否结束
     */
    public boolean completeTask(DelegateExecution execution){
        System.out.println("总会签数量:"+execution.getVariable("nrOfInstances"));
        System.out.println("当前完成会签数量:"+execution.getVariable("nrOfActiveInstances"));
        System.out.println("当前完成会签任务数量:"+execution.getVariable("nrOfCompletedInstances"));
        // 上面的这些nr*变量是由flowable提供的。而下面的flag是我们自定义的。
        Boolean flag = (Boolean) execution.getVariable("flag");
        System.out.println("当前意见:"+flag);
        return flag;
    }
}

MultiInstTaskListener.java

package com.example.flowdemo.listener;

import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;
import java.io.Serializable;

/**
 * @author Huathy
 * @date 2023-01-27 08:57
 * @description
 */
@Component("mulitiInstTaskListener")
public class MultiInstTaskListener implements Serializable {
    public void completeListener(DelegateExecution execution){
        System.out.println("任务ID execution.getId() = " + execution.getId());
        System.out.println("execution.getVariable(\"persons\") = " + execution.getVariable("persons"));
        System.out.println("execution.getVariable(\"person\") = " + execution.getVariable("person"));
    }
}

2. 启动流程

这里我们配置的是串行执行的,所以第一次启动流程只会创建一个任务。如果配置的是并行执行的,那么会在启动任务的时候创建所有的任务。
在这里插入图片描述

3. 完成任务

如果是串行执行的,那么在完成任务的时候,会创建下一个任务。
在这里插入图片描述在这里插入图片描述

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Flowable自动部署是指在Flowable框架中,将存放在指定位置的流程文件自动部署流程引擎中。默认情况下,Flowable自动部署放在`resources/processes`目录下的所有流程文件。流程文件的后缀可以是`bpmn20.xml`或者`bpmn`。可以通过在`application.properties`文件中配置相关属性来进行定制。其中,`flowable.check-process-definitions`属性用于控制在项目启动时是否检查文件目录中是否有流程文件并自动部署,默认值为`true`表示自动部署,`false`表示不检查不自动部署。`flowable.process-definition-location-prefix`属性用于指定流程文件的位置,默认为`classpath*:/processes/`,开发者也可以进行配置。`flowable.process-definition-location-suffixes`属性用于指定流程文件的后缀,默认为`**.bpmn20.xml,**.bpmn`,开发者也可以进行配置。\[1\] 另外,Flowable还支持动态部署,即在项目启动之后,动态上传一个流程的XML文件进行部署。可以通过调用Flowable提供的API来实现动态部署,例如使用`RepositoryService`的`createDeployment()`方法创建一个部署构建器,然后使用`addInputStream()`方法指定流程文件进行部署。除了`addInputStream`方法,还可以使用`addString`、`addBytes`、`addClasspathResource`等方法根据不同的使用场景选择合适的方法进行部署。需要注意的是,这些方法需要设置资源名,并且名称的后缀必须是`bpmn20.xml`或者`bpmn`,否则流程无法部署。\[3\] 总结起来,Flowable自动部署功能可以根据配置将指定位置的流程文件自动部署流程引擎中,同时也支持动态部署,即在项目运行时动态上传流程文件进行部署。 #### 引用[.reference_title] - *1* *3* [SpringBoot整合Flowable工作流之流程部署](https://blog.csdn.net/weixin_38192427/article/details/127512974)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Flowable进阶学习整合SpringBoot自动部署手动部署启动流程完成流程);多人会签与或](https://blog.csdn.net/qq_40366738/article/details/128767789)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Huathy-雨落江南,浮生若梦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值