流程定义查询
// 获取部署时的信息ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();RepositoryService repositoryService = processEngine.getRepositoryService();ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();//根据表 act_re_procdef 表中的key查询部署的流程定义List<ProcessDefinition> myEvection = processDefinitionQuery.processDefinitionKey("MyEvection").orderByProcessDefinitionVersion().desc().list();for (ProcessDefinition pro :myEvection) {System.out.println(pro.getId());System.out.println(pro.getName());System.out.println(pro.getKey());}
流程定义删除
@Testpublic void deleteProcess() {ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();//先获取已经部署的;ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();List<ProcessDefinition> myEvection = processDefinitionQuery.processDefinitionKey("MyEvection").orderByProcessDefinitionVersion().desc().list();for (ProcessDefinition pro :myEvection) {System.out.println(pro.getDeploymentId());//1}repositoryService.deleteDeployment("1");}
当流程没走完的时候,这种方式是不可以的,我们可以用级联删除的方式
repositoryService.deleteDeployment("1",true);
流程资源文件下载
/*** 流程资源文件下载*/@Testpublic void downloadProcessSource() {ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();//获得流程定义的服务ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();//获得流程定义实例ProcessDefinition myEvection = processDefinitionQuery.processDefinitionKey("MyEvection").singleResult();//获得流程部署idString deploymentId = myEvection.getDeploymentId();//获得流程部署资源名称String pngName = myEvection.getDiagramResourceName();//读取数据---获得一个流InputStream pngStream = repositoryService.getResourceAsStream(deploymentId, pngName);
// 获得bpmn资源信息String bpmnName = myEvection.getResourceName();InputStream bpmnStream = repositoryService.getResourceAsStream(deploymentId, bpmnName);//将流输出到本地File pngFile = new File("d:/evePng.png");File bpmnFile = new File("d:/eveBpmn.bpmn");try {FileOutputStream pngFileStream = new FileOutputStream(pngFile);FileOutputStream bpmnFileStream = new FileOutputStream(bpmnFile);IOUtils.copy(pngStream, pngFileStream);IOUtils.copy(bpmnStream, bpmnFileStream);bpmnFileStream.close();pngFileStream.close();pngStream.close();bpmnStream.close();} catch (IOException e) {e.printStackTrace();}}
历史记录查询
/*** 流程历史信息查看*/@Testpublic void SeeHistory() {ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();//获取历史服务serviceHistoryService historyService = processEngine.getHistoryService();//创建历史查询实例HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery();//查询条件List<HistoricActivityInstance> list = historicActivityInstanceQuery.processInstanceId("2501").orderByHistoricActivityInstanceStartTime().asc().list();for (HistoricActivityInstance his : list) {System.out.println(his.getActivityId());System.out.println(his.getActivityName());System.out.println(his.getAssignee());}}
demo部分差不多就这些,我们实际运用中要运用activiti表与实际业务表进行关联以满足复杂的业务需求;