国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

Activiti流程圖查看實例

2019-11-26 15:27:46
字體:
來源:轉載
供稿:網友

本文實例展示了Activiti流程圖查看的實現方法,具體步驟如下所示:

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" rel="external nofollow" >查看流程圖</a>

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

public String viewCurrentImage(){ProcessDefinition pd = service.getProcessDefinitionByTaskId(taskId);// 1. 獲取流程部署IDputContext("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. 得到taskTask 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. 獲取到當前活動的IDTask 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" rel="external nofollow" >查看當前流程圖</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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 四川省| 榆林市| 梁平县| 盖州市| 合肥市| 紫金县| 武山县| 山东| 罗甸县| 治多县| 滕州市| 易门县| 通化县| 洛隆县| 平遥县| 泰兴市| 黄冈市| 尼木县| 河曲县| 乌拉特中旗| 栾城县| 于田县| 西乌| 广河县| 胶州市| 文安县| 元阳县| 集贤县| 新龙县| 吴江市| 威远县| 长宁区| 拉孜县| 斗六市| 光泽县| 邵阳县| 汤原县| 周口市| 辛集市| 龙门县| 盘山县|