05.flowable 流程定义的挂起与激活

本文详细介绍如何使用Flowable流程引擎进行流程定义的挂起与激活操作,通过具体代码示例,帮助读者理解并掌握这一关键功能。

项目地址:https://gitee.com/lwj/flowable.git 分支flowable-base
视频讲解地址
https://space.bilibili.com/485524575/channel/detail?cid=94579

1、演示

在这里插入图片描述

2. 挂起与激活代码

public ReturnVo suspendOrActivateProcessDefinitionById(String processDefinitionId,int suspensionState) {
        ReturnVo returnVo = null;
        if (suspensionState == 1){
            repositoryService.suspendProcessDefinitionById(processDefinitionId, true, null);
            returnVo = new ReturnVo(ReturnCode.SUCCESS,"挂起成功");
        }else {
            repositoryService.activateProcessDefinitionById(processDefinitionId, true, null);
            returnVo = new ReturnVo(ReturnCode.SUCCESS,"激活成功");
        }
        return returnVo;
    }
本课程是《Flowable流程入门课程》的后续高级课程。在学习本课程前,应先学习入门课程,以掌握相关基础知识。高级课程着重讲解Flowable工作流的高级概念、复杂理论和实战应用。课程内容包括流程管理思想、技术标准、工作流的控制模式和资源模式;Flowable数据库表及变量;Spring、Spring Boot的集成;BPMN 2.0主要类图;Flowable高级服务如JAVA服务任务、脚本任务、Web Service任务、外部工作者任务、多实例任务、补偿处理程序、子流程和调用活动等;Flowable事件侦听器、执行侦听器和任务侦听器;Flowable历史和REST API;Flowable事务、并发性、身份管理及LDAP集成;Flowable高级主题如流程实例迁移、异步执行器的设计配置、用于高并发的UUID ID生成器、多租户、高级流程引擎配置、执行自定义SQL和实验性流程调试器等;Flowable Eclipse设计器特性及定制;Flowable 事件注册;Flowable相关标准和规范如ISO8601标准和cron等。本课程对Flowable官方文档进行了彻底梳理和融汇贯通,并结合实践,形象生动、系统全面、简单易懂地呈现给大家,让大家从开源软件文档冗长耗时、英文晦涩难懂、概念理解困难、知识点分散等困境中解脱出来,从而能快速地将Flowable具有的高级特性应用到项目的高级需求和复杂实践中去。课程特色:案例和代码驱动、基础概念经典实战相结合、知识环节融会贯通、关联知识平滑拓展、概念和原理展示形象生动。
在Spring Boot项目中使用Flowable部署并激活流程,通常需要以下几个关键步骤: ### 1. 引入依赖 在`pom.xml`中添加Flowable相关依赖: ```xml <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter</artifactId> <version>最新版本</version> </dependency> ``` ### 2. 配置数据库连接 在`application.properties`或`application.yml`中配置数据库连接信息,例如: ```properties spring.datasource.url=jdbc:mysql://localhost:3306/flowable_db?nullCatalogMeansCurrent=true spring.datasource.username=root spring.datasource.password=password spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver ``` ### 3. 部署流程定义 使用`RepositoryService`来部署流程定义。可以通过以下代码实现: ```java import org.flowable.engine.RepositoryService; import org.flowable.engine.repository.Deployment; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.io.InputStream; @Service public class FlowableDeploymentService { @Autowired private RepositoryService repositoryService; public Deployment deployProcessDefinition(String resourceName, InputStream inputStream) { return repositoryService.createDeployment() .addInputStream(resourceName, inputStream) .deploy(); } } ``` 在上述代码中,`RepositoryService`用于管理控制部署和流程定义的操作,提供了管理静态信息的功能[^2]。 ### 4. 启动流程实例 使用`RuntimeService`来启动流程实例,示例代码如下: ```java import org.flowable.engine.RuntimeService; import org.flowable.engine.runtime.ProcessInstance; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Map; @Service public class FlowableProcessInstanceService { @Autowired private RuntimeService runtimeService; public ProcessInstance startProcessInstanceByKey(String processDefinitionKey, Map<String, Object> variables) { return runtimeService.startProcessInstanceByKey(processDefinitionKey, variables); } } ``` 例如,以请假流程为例,开启流程实例的代码如下: ```java import org.flowable.engine.IdentityService; import org.flowable.engine.RuntimeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; import java.util.Map; @RestController public class FlowableController { @Autowired private IdentityService identityService; @Autowired private RuntimeService runtimeService; @PostMapping("/startLeave") public String startLeave(@RequestBody HandleTaskDto handleTaskDto) { identityService.setAuthenticatedUserId(handleTaskDto.getUserId()); Map<String, Object> variables = new HashMap<>(); variables.put("userId", handleTaskDto.getUserId()); variables.put("groupId", handleTaskDto.getGroupId()); runtimeService.startProcessInstanceByKey(handleTaskDto.getProcDefKey(), variables); return "流程启动成功"; } } class HandleTaskDto { private String userId; private String groupId; private String procDefKey; // Getters and Setters public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getGroupId() { return groupId; } public void setGroupId(String groupId) { this.groupId = groupId; } public String getProcDefKey() { return procDefKey; } public void setProcDefKey(String procDefKey) { this.procDefKey = procDefKey; } } ``` ### 5. 激活流程实例 通常情况下,启动流程实例后流程就会自动激活。如果流程挂起,可以使用`RuntimeService`来激活它: ```java import org.flowable.engine.RuntimeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class FlowableActivationService { @Autowired private RuntimeService runtimeService; public void activateProcessInstance(String processInstanceId) { runtimeService.activateProcessInstanceById(processInstanceId); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小学生05101

flowable

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

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

打赏作者

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

抵扣说明:

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

余额充值