ACTIVIT6流程图显示异常问题

问题描述

高兴满满的写着代码,写好了一个显示当前流程节点的流程图展示

service层

@Service
public class ProcessSerive {
    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private ProcessEngine processEngine;

    @Autowired
    private HistoryService historyService;

    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);
    }
}

controller层

//查看当前节点所在图
    @GetMapping("image/{processInstanceId}")
    public void image(HttpServletResponse response,
                      @PathVariable("processInstanceId") String processInstanceId) {
        try {
            InputStream is = processSerive.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);
        }
    }

迫不及待去页面大致看一下效果http://localhost:8443/image/45001

ACTIVIT6流程图显示异常问题_第1张图片
eror.png

晴天霹雳,what fuck?

不急,问一下大佬jessehua 解决了

activiti6 不支持png,service、controller 把 png 改成 JPEG,共3处

ACTIVIT6流程图显示异常问题_第2张图片
image.png

结语:学新东西遇到一个很小的问题,百度无果之后,很让人崩溃。但不要以为自己是第一个遇到问题的,问对的人,感恩。

你可能感兴趣的:(ACTIVIT6流程图显示异常问题)