use of org.flowable.engine.runtime.Execution in project Resource by lovelifeming.
the class ApproveProcessController method createProcessDiagram.
@ApiOperation("获取流程图")
@GetMapping("getProcessDiagram")
public void createProcessDiagram(HttpServletResponse response, @RequestParam @ApiParam("流程Id") String processId) throws IOException {
if (StringUtils.isBlank(processId))
response.getWriter().write("processId 不能为空");
ProcessInstance pi = service.getProcessByProcessId(processId);
// 流程走完的不显示图
if (pi == null) {
response.getWriter().write("任务已完成");
return;
}
Task task = service.getOneTaskByProcessId(pi.getId());
// 使用流程实例ID,查询正在执行的执行对象表,返回流程实例对象
String InstanceId = task.getProcessInstanceId();
List<Execution> executions = service.getExecutions(InstanceId);
// 得到正在执行的Activity的Id
List<String> activityIds = new ArrayList<>();
List<String> flows = new ArrayList<>();
for (Execution exe : executions) {
List<String> ids = service.getActiveActivityIds(exe.getId());
activityIds.addAll(ids);
}
// 获取流程图
BpmnModel bpmnModel = service.getBpmnModel(pi.getProcessDefinitionId());
ProcessEngineConfiguration engconf = service.getProcessEngineConfiguration();
ProcessDiagramGenerator diagramGenerator = engconf.getProcessDiagramGenerator();
InputStream in = diagramGenerator.generateDiagram(bpmnModel, "png", activityIds, flows, engconf.getActivityFontName(), engconf.getLabelFontName(), engconf.getAnnotationFontName(), engconf.getClassLoader(), 1.0);
// 自定义画图类
// InputStream in = new MyProcessDiagramGenerator().generateDiagram(bpmnModel, "png", activityIds, flows);
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();
}
}
}
Aggregations