代码参考 闲鹿群友@
自定义的ProcessController类里,判断流程是否已执行结束,执行结束 则查询历史流程
@RequestMapping(value = "/read-resource")
public void readResource(String pProcessInstanceId, HttpServletResponse response)
throws Exception {
// 设置页面不缓存
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
ProcessDefinitionQuery pdq = repositoryService.createProcessDefinitionQuery();
//运行中的流程
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(pProcessInstanceId).singleResult();
ProcessDefinition pd;
if(processInstance == null){
//历史流程/已结束的流程 比较复杂的流程图不建议显示执行流程,高亮线条流程等 看起来会比较乱
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(pProcessInstanceId).singleResult();
//已结束流程查询
pd = pdq.processDefinitionId(historicProcessInstance.getProcessDefinitionId()).singleResult();
}else{
//正在执行的流程查询
pd = pdq.processDefinitionId(processInstance.getProcessDefinitionId()).singleResult();
}
String resourceName = pd.getDiagramResourceName();
if(resourceName.endsWith(".png") && StringUtils.isEmpty(pProcessInstanceId) == false)
{
getActivitiProccessImage(pProcessInstanceId,response);
//ProcessDiagramGenerator.generateDiagram(pde, "png", getRuntimeService().getActiveActivityIds(processInstanceId));
}
else
{
// 通过接口读取
InputStream resourceAsStream = repositoryService.getResourceAsStream(pd.getDeploymentId(), resourceName);
// 输出资源内容到相应对象
byte[] b = new byte[1024];
int len = -1;
while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
response.getOutputStream().write(b, 0, len);
}
}
}