1、配置字体
package com.example.demo.config; import org.flowable.spring.SpringProcessEngineConfiguration; import org.flowable.spring.boot.EngineConfigurationConfigurer; import org.springframework.context.annotation.Configuration; @Configuration public class FlowableConfig implements EngineConfigurationConfigurer{ @Override public void configure(SpringProcessEngineConfiguration engineConfiguration) { engineConfiguration.setActivityFontName("宋体"); engineConfiguration.setLabelFontName("宋体"); engineConfiguration.setAnnotationFontName("宋体"); } }
2、流程图下载
@RequestMapping(value = "processDiagram")
public void genProcessDiagram(HttpServletResponse httpServletResponse, String processId) throws Exception {
ProcessInstance pi = commonFlowService.getCommonServicePOJO().getRuntimeService().createProcessInstanceQuery().processInstanceId(processId).singleResult();
//流程走完的不显示图
if (pi == null) {
return;
}
Task task = commonFlowService.getCommonServicePOJO().getTaskService().createTaskQuery().processInstanceId(pi.getId()).singleResult();
//使用流程实例ID,查询正在执行的执行对象表,返回流程实例对象
String InstanceId = task.getProcessInstanceId();
List executions = commonFlowService.getCommonServicePOJO().getRuntimeService()
.createExecutionQuery()
.processInstanceId(InstanceId)
.list();
//得到正在执行的Activity的Id
List activityIds = new ArrayList<>();
List flows = new ArrayList<>();
for (Execution exe : executions) {
List ids = commonFlowService.getCommonServicePOJO().getRuntimeService().getActiveActivityIds(exe.getId());
activityIds.addAll(ids);
}
//获取流程图
BpmnModel bpmnModel = commonFlowService.getCommonServicePOJO().getRepositoryService().getBpmnModel(pi.getProcessDefinitionId());
ProcessEngineConfiguration engconf = commonFlowService.getCommonServicePOJO().getProcessEngine().getProcessEngineConfiguration();
ProcessDiagramGenerator diagramGenerator = engconf.getProcessDiagramGenerator();
InputStream in = diagramGenerator.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 = httpServletResponse.getOutputStream();
while ((legth = in.read(buf)) != -1) {
out.write(buf, 0, legth);
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
3、需要的类
public class CommonFlowService implements FlowService{
private CommonServicePOJO commonServicePOJO;
public CommonServicePOJO getCommonServicePOJO() {
return commonServicePOJO;
}
public void setCommonServicePOJO(CommonServicePOJO commonServicePOJO) {
this.commonServicePOJO = commonServicePOJO;
}
}
package com.example.demo.util.flow;
import org.flowable.engine.*;
public class CommonServicePOJO {
private RuntimeService runtimeService;
private TaskService taskService;
private HistoryService historyService;
private ProcessEngine processEngine;
private RepositoryService repositoryService;
public RuntimeService getRuntimeService() {
return runtimeService;
}
public void setRuntimeService(RuntimeService runtimeService) {
this.runtimeService = runtimeService;
}
public TaskService getTaskService() {
return taskService;
}
public void setTaskService(TaskService taskService) {
this.taskService = taskService;
}
public HistoryService getHistoryService() {
return historyService;
}
public void setHistoryService(HistoryService historyService) {
this.historyService = historyService;
}
public ProcessEngine getProcessEngine() {
return processEngine;
}
public void setProcessEngine(ProcessEngine processEngine) {
this.processEngine = processEngine;
}
public RepositoryService getRepositoryService() {
return repositoryService;
}
public void setRepositoryService(RepositoryService repositoryService) {
this.repositoryService = repositoryService;
}
public CommonServicePOJO(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, ProcessEngine processEngine, RepositoryService repositoryService) {
this.runtimeService = runtimeService;
this.taskService = taskService;
this.historyService = historyService;
this.processEngine = processEngine;
this.repositoryService = repositoryService;
}
public CommonServicePOJO() {
}
}



