之前基于flowable为公司开发了套轻量级的OA系统,最近有个需求,要求在正式发起审批前或者流程被驳回后重新发起前预测审批路径,参考了下flowable获取流程节点的顺序数据_10973441的技术博客_51CTO博客这篇文章,做了一些修改和补充。
准备工作
添加以下依赖
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<version>6.4.0</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-modeler-logic</artifactId>
<version>6.4.0</version>
</dependency>
代码片段
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.flowable.bpmn.model.*;
import org.flowable.engine.ManagementService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.ui.modeler.domain.Model;
import org.flowable.ui.modeler.serviceapi.ModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
@Slf4j
@Service
public class ProcessService {
@Autowired
RuntimeService runtimeService;
@Autowired
RepositoryService repositoryService;
@Autowired
ModelService modelService;
@Autowired
ManagementService managementService;
@Autowired
ProcessEngineConfigurationImpl processEngineConfiguration;
/**
* 1. 首先拿到BpmnModel,所有流程定义信息都可以通过BpmnModel获取;若流程尚未发起,则用modelId查询最新部署的流程定义数据;
* 若流程已经发起,可以通过流程实例的processDefinitionId查询流程定义的历史数据。
* @param variableMap 流程变量,用于计算条件分支
*/
public List<FlowElement> calApprovePath(String processInstanceId, String modelId, Map<String, Object> variableMap){
BpmnModel bpmnModel;
if(StringUtils.isNotBlank(processInstanceId)){