问题描述
高兴满满的写着代码,写好了一个显示当前流程节点的流程图展示
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<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);
}
}
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);
}
}
eror.png迫不及待去页面大致看一下效果http://localhost:8443/image/45001
晴天霹雳,what fuck?
不急,问一下大佬jessehua 解决了
image.pngactiviti6 不支持png,service、controller 把 png 改成 JPEG,共3处
结语:学新东西遇到一个很小的问题,百度无果之后,很让人崩溃。但不要以为自己是第一个遇到问题的,问对的人,感恩。
网友评论