public void showImages(String taskId,HttpServletResponse response) throws IOException {
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
String processDefinitionId = task.getProcessDefinitionId();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
String processInstanceId = task.getProcessInstanceId();
List<HistoricActivityInstance> historyProcess = historyService // 历史相关Service
.createHistoricActivityInstanceQuery() // 创建历史活动实例查询
.processInstanceId(processInstanceId) // 执行流程实例id
.finished()
.list();
List<String> activityIds = new ArrayList<>();
List<String> flows = new ArrayList<>();
//获取流程图
for (HistoricActivityInstance hi : historyProcess) {
String activityType = hi.getActivityType();
if (activityType.equals("sequenceFlow") || activityType.equals("exclusiveGateway")) {
flows.add(hi.getActivityId());
} else if (activityType.equals("userTask") || activityType.equals("startEvent")) {
activityIds.add(hi.getActivityId());
}
}
activityIds.add(task.getTaskDefinitionKey());
ProcessEngineConfiguration engConf = ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration();
//定义流程画布生成器
ProcessDiagramGenerator processDiagramGenerator = engConf.getProcessDiagramGenerator();
InputStream in = processDiagramGenerator.generateDiagram(bpmnModel, "png", activityIds, flows, engConf.getActivityFontName(), engConf.getLabelFontName(), engConf.getAnnotationFontName(), engConf.getClassLoader(), 1.0, true);
OutputStream out = null;
byte[] buf = new byte[1024];
int legth = 0;
try {
out = response.getOutputStream();
while ((legth = in.read(buf)) != -1) {
out.write(buf, 0, legth);
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
flowable流程图高亮显示
最新推荐文章于 2024-07-13 13:37:16 发布