Search in sources :

Example 1 with CustomProcessDiagramGenerator

use of com.ruoyi.flowable.flow.CustomProcessDiagramGenerator in project RuoYi-Flowable-Plus by KonBAI-Q.

the class WfTaskServiceImpl method diagram.

/**
 * 获取流程过程图
 *
 * @param processId
 * @return
 */
@Override
public InputStream diagram(String processId) {
    String processDefinitionId;
    // 获取当前的流程实例
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
    // 如果流程已经结束,则得到结束节点
    if (Objects.isNull(processInstance)) {
        HistoricProcessInstance pi = historyService.createHistoricProcessInstanceQuery().processInstanceId(processId).singleResult();
        processDefinitionId = pi.getProcessDefinitionId();
    } else {
        // 如果流程没有结束,则取当前活动节点
        // 根据流程实例ID获得当前处于活动状态的ActivityId合集
        ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        processDefinitionId = pi.getProcessDefinitionId();
    }
    // 获得活动的节点
    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 {
            // 高亮节点
            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);
}
Also used : ProcessEngineConfiguration(org.flowable.engine.ProcessEngineConfiguration) ProcessDiagramGenerator(org.flowable.image.ProcessDiagramGenerator) CustomProcessDiagramGenerator(com.ruoyi.flowable.flow.CustomProcessDiagramGenerator) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) CustomProcessDiagramGenerator(com.ruoyi.flowable.flow.CustomProcessDiagramGenerator) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) HistoricActivityInstance(org.flowable.engine.history.HistoricActivityInstance)

Aggregations

CustomProcessDiagramGenerator (com.ruoyi.flowable.flow.CustomProcessDiagramGenerator)1 ProcessEngineConfiguration (org.flowable.engine.ProcessEngineConfiguration)1 HistoricActivityInstance (org.flowable.engine.history.HistoricActivityInstance)1 HistoricProcessInstance (org.flowable.engine.history.HistoricProcessInstance)1 ProcessInstance (org.flowable.engine.runtime.ProcessInstance)1 ProcessDiagramGenerator (org.flowable.image.ProcessDiagramGenerator)1