Activiti7 獲取資源資訊及其查詢流程歷史資訊
阿新 • • 發佈:2020-09-01
獲取資源資訊
/** * 獲取資源資訊 * * @throws IOException */ @Test public void getProcessResources() throws IOException { // 1:流程定義ID String processDefinitionId = "holiday:1:7504"; // 2:獲取RepositoryService RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();// 3:建立查詢物件 ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery(); // 4:查詢流程定義 ProcessDefinition processDefinition = processDefinitionQuery.processDefinitionId(processDefinitionId).singleResult(); // 5:獲取資源名稱 String resourceName = processDefinition.getResourceName(); System.out.println("bpmn名稱:" + resourceName); // 6:獲取圖片名稱 String diagramResourceName = processDefinition.getDiagramResourceName(); System.out.println("png名稱:" + diagramResourceName); File bpmnFile = new File("E:\\dance\\activiti7\\src\\main\\resources\\cp\\holiday.bpmn"); File pngFile= new File("E:\\dance\\activiti7\\src\\main\\resources\\cp\\holiday.png"); // 7:根據部署ID和資源名稱獲取資源流 InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName); // 8:建立輸出流 FileOutputStream fileOutputStream = new FileOutputStream(bpmnFile); // 寫檔案 writeByte(resourceAsStream, fileOutputStream); // 獲取圖片 resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), diagramResourceName); fileOutputStream = new FileOutputStream(pngFile); // 寫檔案 writeByte(resourceAsStream, fileOutputStream); System.out.println("獲取資源成功!"); }
寫出流方法
private void writeByte(InputStream resourceAsStream, OutputStream fileOutputStream) throws IOException { int i = -1; byte[] content = new byte[1024]; while ((i = resourceAsStream.read(content)) != -1) { fileOutputStream.write(content, 0, i); } // 釋放資源 fileOutputStream.flush(); fileOutputStream.close(); resourceAsStream.close(); }
查詢流程歷史資訊
/** * 獲取歷史資訊 */ @Test public void testHistoric01() { // 獲取歷史資訊Service HistoryService historyService = defaultProcessEngine.getHistoryService(); // 啟動的流程例項的ID String processInstanceId = "10001"; // 根據流程例項ID查詢 歷史記錄 List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).orderByHistoricActivityInstanceStartTime().asc().list(); // 輸出資訊 list.forEach(historicActivityInstance -> { System.out.println("---------------------------------------------------"); System.out.println("當前啟用ID:" + historicActivityInstance.getActivityId()); System.out.println("當前啟用名稱:" + historicActivityInstance.getActivityName()); System.out.println("流程定義ID:" + historicActivityInstance.getProcessDefinitionId()); System.out.println("流程例項ID:" + historicActivityInstance.getProcessInstanceId()); System.out.println("---------------------------------------------------"); }); }
作者:彼岸舞
時間:2020\08\31
內容關於:Activiti工作流
本文來源於網路,只做技術分享,一概不負任何責任