1.流程定义查询和删除
查询
public static void main(String[] args) {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
List<ProcessDefinition> holiday = processDefinitionQuery.processDefinitionKey("holiday")
.orderByProcessDefinitionVersion()
.desc().list();
for (ProcessDefinition processDefinition:holiday){
System.out.println("流程定义ID:" + processDefinition.getId());
System.out.println("流程定义名称:" + processDefinition.getName());
System.out.println("流程定义KEY:" + processDefinition.getKey());
System.out.println("流程定义版本号:" + processDefinition.getVersion());
System.out.println("流程部署ID:" + processDefinition.getDeploymentId());
}
}
删除
public static void main(String[] args) {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
repositoryService.deleteDeployment("1");
}
删除影响的表和部署影响的表一样
正在执行的流程没结束时,删除定义信息会失败,报错是外键关联,无法删除。如果要强行删除,可使用repositoryService.deleteDeployment(“1”,true);
true代表级联删除,会先删除为完成的节点,最后删除流程定义信息
2.下载bpmn文件
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.apache.commons.io.IOUtils;
import java.io.*;
public class QueryBpmnFile {
public static void main(String[] args) {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
processDefinitionQuery.processDefinitionKey("holiday");
ProcessDefinition processDefinition = processDefinitionQuery.singleResult();
String deploymentId = processDefinition.getDeploymentId();
InputStream bpmnIs = repositoryService.getResourceAsStream(deploymentId,processDefinition.getResourceName());
try {
OutputStream bpmnOs = new FileOutputStream("C:\\Users\\10759\\Desktop\\bpmn\\" + processDefinition.getResourceName());
IOUtils.copy(bpmnIs,bpmnOs);
bpmnIs.close();
bpmnOs.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
3.历史信息查询
public static void main(String[] args) {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
HistoryService historyService = processEngine.getHistoryService();
HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery();
historicActivityInstanceQuery.processInstanceId("2501");//设置流程实例id
List<HistoricActivityInstance> list = historicActivityInstanceQuery
.orderByHistoricActivityInstanceStartTime().asc().list();
for (HistoricActivityInstance instance : list){
System.out.println(instance.getActivityId());
System.out.println(instance.getActivityName());
System.out.println(instance.getProcessDefinitionId());
System.out.println(instance.getProcessInstanceId());
}
}