/**
* 生成流程圖
*
* @param processId 任務(wù)ID
*/
@RequestMapping("/diagram/{processId}")
public void genProcessDiagram(HttpServletResponse response,
@PathVariable("processId") String processId) {
InputStream inputStream = flowTaskService.diagram(processId);
OutputStream os = null;
BufferedImage image = null;
try {
image = ImageIO.read(inputStream);
response.setContentType("image/png");
os = response.getOutputStream();
if (image != null) {
ImageIO.write(image, "png", os);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (os != null) {
os.flush();
os.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 獲取流程過程圖
*/
public InputStream diagram(String processId) {
String processDefinitionId;
// 獲取當前的流程實例
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
// 如果流程已經(jīng)結(jié)束,則得到結(jié)束節(jié)點
if (Objects.isNull(processInstance)) {
HistoricProcessInstance pi = historyService.createHistoricProcessInstanceQuery().processInstanceId(processId).singleResult();
processDefinitionId = pi.getProcessDefinitionId();
} else {// 如果流程沒有結(jié)束,則取當前活動節(jié)點
// 根據(jù)流程實例ID獲得當前處于活動狀態(tài)的ActivityId合集
ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
processDefinitionId = pi.getProcessDefinitionId();
}
// 獲得活動的節(jié)點
List<HistoricActivityInstance> highLightedFlowList = historyService.createHistoricActivityInstanceQuery()
.processInstanceId(processId).orderByHistoricActivityInstanceStartTime().asc().list();
List<String> highLightedFlows = new ArrayList<>();
List<String> highLightedNodes = new ArrayList<>();
//高亮線
for (HistoricActivityInstance tempActivity : highLightedFlowList) {
if ("sequenceFlow".equals(tempActivity.getActivityType())) {
//高亮線
highLightedFlows.add(tempActivity.getActivityId());
} else {
//高亮節(jié)點
highLightedNodes.add(tempActivity.getActivityId());
}
}
//獲取流程圖
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
ProcessEngineConfiguration configuration = processEngine.getProcessEngineConfiguration();
//獲取自定義圖片生成器
ProcessDiagramGenerator diagramGenerator = new CustomProcessDiagramGenerator();
return diagramGenerator.generateDiagram(bpmnModel, "png", highLightedNodes, highLightedFlows, configuration.getActivityFontName(),
configuration.getLabelFontName(), configuration.getAnnotationFontName(), configuration.getClassLoader(), 1.0, true);
}
文章來源地址http://www.zghlxwxcb.cn/news/detail-800917.html
文章來源:http://www.zghlxwxcb.cn/news/detail-800917.html
到了這里,關(guān)于Flowable 生成流程圖的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!