Activiti6 self-road (eight) - View flowchart

Here Insert Picture Description

Previous chapters we have designed a flow chart and a flow chart of tasks to perform. For example, after Joe Smith to fill the leave application, if you want to know the process has to go, and how to deal with the progress achieved what how. Activiti function provides a flow chart view, you can see the progress of the process specified

//查看流程图
  	 @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<String> currentActs = Collections.EMPTY_LIST;
 	    if (processInstance != null)
 	        currentActs = runtimeService.getActiveActivityIds(processInstance.getId());

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

Process instance: 13
Here Insert Picture Description

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

You can see the process instance progress chart


If you think this article to help you, then click the Follow button troublesome picture on the right, thank you!

Technical progress in the exchange, dissemination of knowledge sharing in

Guess you like

Origin blog.csdn.net/qq_29914837/article/details/92391214