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

本文介绍了如何使用Java代码实现流程状态的变更,包括激活和挂起过程定义,通过`ReqManager`对象判断流程当前状态并进行相应操作。遇到流程已处于目标状态时,会给出提示。

1.演示

在这里插入图片描述
2.代码

 public Object changeState(ReqManager reqManager) {
   
   
        RetBean retbean = new RetBean();
        try {
   
   
            if (reqManager.getState().equals(FlowEngineConstant.ACTIVE)) 
在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); } } ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值