Activiti6自学之路(八)——查看流程图

Activiti6自学之路(八)——查看流程图_第1张图片

前面章节我们已经设计了流程图和执行了流程图任务。比如张三填写了请假申请后,如果想要知道现在流程已经到哪里了,处理进度怎么样,哪怎么实现了。Activiti提供了查看流程图功能,可以看到指定流程进度

//查看流程图
  	 @RequestMapping(value = "/image", method = RequestMethod.GET)
     public void image(HttpServletResponse response,
      @RequestParam String processInstanceId) {
         try {
             InputStream is = getDiagram(processInstanceId);
             if (is == null)
                 return;

             response.setContentType("image/png");

             BufferedImage image = ImageIO.read(is);
             OutputStream out = response.getOutputStream();
             ImageIO.write(image, "png", out);

             is.close();
             out.close();
         } catch (Exception ex) {
             log.error("查看流程图失败", ex);
         }
     }
  	 
    
 	public InputStream getDiagram(String processInstanceId) {
 	    //获得流程实例
 	    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
 	            .processInstanceId(processInstanceId).singleResult();
 	    String processDefinitionId = StringUtils.EMPTY;
 	    if (processInstance == null) {
 	        //查询已经结束的流程实例
 	        HistoricProcessInstance processInstanceHistory =
 	                historyService.createHistoricProcessInstanceQuery()
 	                        .processInstanceId(processInstanceId).singleResult();
 	        if (processInstanceHistory == null)
 	            return null;
 	        else
 	            processDefinitionId = processInstanceHistory.getProcessDefinitionId();
 	    } else {
 	        processDefinitionId = processInstance.getProcessDefinitionId();
 	    }

 	    //使用宋体
 	    String fontName = "宋体";
 	    //获取BPMN模型对象
 	    BpmnModel model = repositoryService.getBpmnModel(processDefinitionId);
 	    //获取流程实例当前的节点,需要高亮显示
 	    List currentActs = Collections.EMPTY_LIST;
 	    if (processInstance != null)
 	        currentActs = runtimeService.getActiveActivityIds(processInstance.getId());

 	    return processEngine.getProcessEngineConfiguration()
 	            .getProcessDiagramGenerator()
 	            .generateDiagram(model, "png", currentActs, new ArrayList(),
 	                    fontName, fontName, fontName, null, 1.0);
 	}

流程实例:13
Activiti6自学之路(八)——查看流程图_第2张图片

http://127.0.0.1:8080/spring-activiti/leave/image?processInstanceId=13

即可看到流程实例进度图


如果你觉得本篇文章对你有所帮助的话,麻烦请点击头像右边的关注按钮,谢谢!

技术在交流中进步,知识在分享中传播

你可能感兴趣的:(Activiti,工作流)