Activiti流程圖查看

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   os   strong   io   

1、測試案例查看圖片

 public void viewImage() throws Exception {  // 建立倉庫服務對對象  RepositoryService repositoryService = processEngine.getRepositoryService();  // 從倉庫中找需要展示的檔案  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);   // 通過部署ID和檔案名稱得到檔案的輸入資料流   InputStream in =  repositoryService.getResourceAsStream(deploymentId, imageName);   FileUtils.copyInputStreamToFile(in, f);  }

 說明:

  1)     deploymentId為流程部署ID

  2)     resourceName為act_ge_bytearray表中NAME_列的值

  3)     使用repositoryService的getDeploymentResourceNames方法可以擷取指定部署下得所有檔案的名稱

  4)     使用repositoryService的getResourceAsStream方法傳入部署ID和檔案名稱可以擷取部署下指定名稱檔案的輸入資料流

  5)     最後的有關IO流的操作,使用FileUtils工具的copyInputStreamToFile方法完成流程流程到檔案的拷貝

 

2、web項目中在流程定義頁面查看圖片

    public String viewImage(){        InputStream  in = repositoryService.getResourceAsStream.getImageStream(deploymentId,imageName);//此處方法實際項目應該放在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);            }            // 關閉流            out.close();            in.close();        } catch (IOException e) {            e.printStackTrace();        }        return null;    }

 說明:

  1)     deploymentId為流程部署ID,imageName為圖片名稱

  2)     因為是從流程定義列表頁面查看圖片,id和imageName可以從流程定義(ProcessDefinition)中擷取(String getDeploymentId();和 String getDiagramResourceName();)

  3) web頁面標籤<a target="_blank" href="viewImage?deploymentId=1&imageName=imageName.png">查看流程圖</a> 

 

3、web項目查看當前流程圖

    public String viewCurrentImage(){        ProcessDefinition pd = service.getProcessDefinitionByTaskId(taskId);        // 1. 擷取流程部署ID        putContext("deploymentId", pd.getDeploymentId());        // 2. 擷取流程圖片的名稱        putContext("imageName", pd.getDiagramResourceName());                // 3.擷取當前活動的座標        Map<String,Object> currentActivityCoordinates =service.getCurrentActivityCoordinates(taskId);        putContext("acs", currentActivityCoordinates);        return "image";    }

  其中service.getProcessDefinitionByTaskId(taskId);的代碼實現:

public ProcessDefinition getProcessDefinitionByTaskId(String taskId) {        // 1. 得到task        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();        // 2. 通過task對象的pdid擷取流程定義對象        ProcessDefinition pd = repositoryService.getProcessDefinition(task.getProcessDefinitionId());        return pd;    }

  其中service.getCurrentActivityCoordinates(taskId);的代碼實現:

    public Map<String, Object> getCurrentActivityCoordinates(String taskId) {        Map<String, Object> coordinates = new HashMap<String, Object>();        // 1. 擷取到當前活動的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. 使用流程定義通過currentActivitiId得到使用中的物件        ActivityImpl activity =  pd.findActivity(currentActivitiId);        // 4. 擷取活動的座標        coordinates.put("x", activity.getX());        coordinates.put("y", activity.getY());        coordinates.put("width", activity.getWidth());        coordinates.put("height", activity.getHeight());        return coordinates;    }

  image頁面

  從個人工作清單頁面點擊<a target="_blank" href="/viewCurrentImage?taskId=1">查看當前流程圖</a>跳轉到下面頁面

<body><!-- 1.擷取到規則流程圖 這裡是用的strust2的標籤得到上面上面放入值棧的值--><img style="position: absolute;top: 0px;left: 0px;" src="viewImage?deploymentId=<s:property value=‘#deploymentId‘/>&imageName=<s:property value=‘#imageName‘/>"><!-- 2.根據當前活動的座標,動態繪製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>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.