Search in sources :

Example 1 with Execution

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();
        }
    }
}
Also used : Task(org.flowable.task.api.Task) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) BpmnModel(org.flowable.bpmn.model.BpmnModel) Execution(org.flowable.engine.runtime.Execution) ProcessEngineConfiguration(org.flowable.engine.ProcessEngineConfiguration) ProcessDiagramGenerator(org.flowable.image.ProcessDiagramGenerator) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 BpmnModel (org.flowable.bpmn.model.BpmnModel)1 ProcessEngineConfiguration (org.flowable.engine.ProcessEngineConfiguration)1 Execution (org.flowable.engine.runtime.Execution)1 ProcessInstance (org.flowable.engine.runtime.ProcessInstance)1 ProcessDiagramGenerator (org.flowable.image.ProcessDiagramGenerator)1 Task (org.flowable.task.api.Task)1