Activiti流程圖查看實(shí)例
本文實(shí)例展示了Activiti流程圖查看的實(shí)現(xiàn)方法,具體步驟如下所示:
1、測(cè)試用例查看圖片代碼如下:
public void viewImage() throws Exception { // 創(chuàng)建倉(cāng)庫(kù)服務(wù)對(duì)對(duì)象 RepositoryService repositoryService = processEngine.getRepositoryService(); // 從倉(cāng)庫(kù)中找需要展示的文件 String deploymentId = "701"; List<String> names = repositoryService.getDeploymentResourceNames(deploymentId); String imageName = null; for (String name : names) { if(name.indexOf(".png")>=0){ imageName = name; } } if(imageName!=null){ // System.out.println(imageName); File f = new File("e:/"+ imageName); // 通過(guò)部署ID和文件名稱得到文件的輸入流 InputStream in = repositoryService.getResourceAsStream(deploymentId, imageName); FileUtils.copyInputStreamToFile(in, f); }
說(shuō)明:
1) deploymentId為流程部署ID
2) resourceName為act_ge_bytearray表中NAME_列的值
3) 使用repositoryService的getDeploymentResourceNames方法可以獲取指定部署下得所有文件的名稱
4) 使用repositoryService的getResourceAsStream方法傳入部署ID和文件名稱可以獲取部署下指定名稱文件的輸入流
5) 最后的有關(guān)IO流的操作,使用FileUtils工具的copyInputStreamToFile方法完成流程流程到文件的拷貝
2、web項(xiàng)目中在流程定義頁(yè)面查看圖片:
public String viewImage(){ InputStream in = repositoryService.getResourceAsStream.getImageStream(deploymentId,imageName);//此處方法實(shí)際項(xiàng)目應(yīng)該放在service里面 HttpServletResponse resp = ServletActionContext.getResponse(); try { OutputStream out = resp.getOutputStream(); // 把圖片的輸入流程寫入resp的輸出流中 byte[] b = new byte[1024]; for (int len = -1; (len= in.read(b))!=-1; ) { out.write(b, 0, len); } // 關(guān)閉流 out.close(); in.close(); } catch (IOException e) { e.printStackTrace(); } return null; }
說(shuō)明:
1) deploymentId為流程部署ID,imageName為圖片名稱
2) 因?yàn)槭菑牧鞒潭x列表頁(yè)面查看圖片,id和imageName可以從流程定義(ProcessDefinition)中獲取(String getDeploymentId();和 String getDiagramResourceName();)
3) web頁(yè)面標(biāo)簽<a target="_blank" href="viewImage?deploymentId=1&imageName=imageName.png" rel="external nofollow" >查看流程圖</a>
3、web項(xiàng)目查看當(dāng)前流程圖
public String viewCurrentImage(){ ProcessDefinition pd = service.getProcessDefinitionByTaskId(taskId); // 1. 獲取流程部署ID putContext("deploymentId", pd.getDeploymentId()); // 2. 獲取流程圖片的名稱 putContext("imageName", pd.getDiagramResourceName()); // 3.獲取當(dāng)前活動(dòng)的坐標(biāo) Map<String,Object> currentActivityCoordinates =service.getCurrentActivityCoordinates(taskId); putContext("acs", currentActivityCoordinates); return "image"; }
其中service.getProcessDefinitionByTaskId(taskId);的代碼實(shí)現(xiàn):
public ProcessDefinition getProcessDefinitionByTaskId(String taskId) { // 1. 得到task Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); // 2. 通過(guò)task對(duì)象的pdid獲取流程定義對(duì)象 ProcessDefinition pd = repositoryService.getProcessDefinition(task.getProcessDefinitionId()); return pd; }
其中service.getCurrentActivityCoordinates(taskId);的代碼實(shí)現(xiàn):
public Map<String, Object> getCurrentActivityCoordinates(String taskId) { Map<String, Object> coordinates = new HashMap<String, Object>(); // 1. 獲取到當(dāng)前活動(dòng)的ID Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult(); String currentActivitiId = pi.getActivityId(); // 2. 獲取到流程定義 ProcessDefinitionEntity pd = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(task.getProcessDefinitionId()); // 3. 使用流程定義通過(guò)currentActivitiId得到活動(dòng)對(duì)象 ActivityImpl activity = pd.findActivity(currentActivitiId); // 4. 獲取活動(dòng)的坐標(biāo) coordinates.put("x", activity.getX()); coordinates.put("y", activity.getY()); coordinates.put("width", activity.getWidth()); coordinates.put("height", activity.getHeight()); return coordinates; }
image頁(yè)面部分:
從個(gè)人任務(wù)列表頁(yè)面點(diǎn)擊<a target="_blank" href="/viewCurrentImage?taskId=1" rel="external nofollow" >查看當(dāng)前流程圖</a>跳轉(zhuǎn)到下面頁(yè)面:
<body> <!-- 1.獲取到規(guī)則流程圖 這里是用的strust2的標(biāo)簽得到上面上面放入值棧的值--> <img style="position: absolute;top: 0px;left: 0px;" src="viewImage?deploymentId=<s:property value='#deploymentId'/>&imageName=<s:property value='#imageName'/>"> <!-- 2.根據(jù)當(dāng)前活動(dòng)的坐標(biāo),動(dòng)態(tài)繪制DIV --> <div style="position: absolute;border:1px solid red;top:<s:property value='#acs.y'/>px;left: <s:property value='#acs.x'/>px;width: <s:property value='#acs.width'/>px;height:<s:property value='#acs.height'/>px; "></div> </body>
- SpringBoot整合Activiti7的實(shí)現(xiàn)代碼
- SpringBoot2整合activiti6環(huán)境搭建過(guò)程解析
- 解決Springboot2.1.x配置Activiti7單獨(dú)數(shù)據(jù)源問(wèn)題
- spring boot activiti工作流的搭建與簡(jiǎn)單使用
- Android開(kāi)發(fā)之a(chǎn)ctiviti節(jié)點(diǎn)跳轉(zhuǎn)
- Android實(shí)現(xiàn)Activities之間進(jìn)行數(shù)據(jù)傳遞的方法
- activiti獲取流程圖實(shí)例
- activiti實(shí)現(xiàn)員工請(qǐng)假流程解析
相關(guān)文章
vue+springboot前后端分離工程跨域問(wèn)題解決方案解析
這篇文章主要介紹了vue+springboot前后端分離工程跨域問(wèn)題解決方案解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03Java中ConcurrentHashMap和Hashtable的區(qū)別
ConcurrentHashMap?和?Hashtable?都是用于在Java中實(shí)現(xiàn)線程安全的哈希表數(shù)據(jù)結(jié)構(gòu)的類,但它們有很多區(qū)別,本文就來(lái)詳細(xì)的介紹一下,感興趣的可以了解一下2023-10-10Java中l(wèi)ist根據(jù)id獲取對(duì)象的幾種方式
這篇文章主要給大家介紹了關(guān)于Java中l(wèi)ist根據(jù)id獲取對(duì)象的幾種方式,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用java具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07synchronized及JUC顯式locks?使用原理解析
這篇文章主要為大家介紹了synchronized及JUC顯式locks?使用原理解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12SpringBoot中@Insert、@Update實(shí)現(xiàn)批量新增更新的使用示例
本文主要介紹了SpringBoot中@Insert、@Update實(shí)現(xiàn)批量新增更新的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-10-10