@PostMapping(value = "/flow/resource")
public FlowResultVO getFlowResource(@RequestBody HashMap<String, String> map) throws IOException {
String pId = map.get("pId");
String instId = map.get("instId");
List<String> highLightedActivities = new ArrayList<>();
List<String> highLightedFlows = new ArrayList<>();
BpmnModel bpmnModel = repositoryService.getBpmnModel(pId);
if (instId != null && instId != "") {
List<HistoricActivityInstance> historyProcess = historyService // 历史相关Service
.createHistoricActivityInstanceQuery() // 创建历史活动实例查询
.processInstanceId(instId) // 执行流程实例id
.finished()
.list();
for (HistoricActivityInstance hi : historyProcess) {
String activityType = hi.getActivityType();
if (activityType.equals("sequenceFlow") || activityType.equals("exclusiveGateway")) {
highLightedFlows.add(hi.getActivityId());
} else if (activityType.equals("userTask") || activityType.equals("startEvent")) {
highLightedActivities.add(hi.getActivityId());
}
}
}
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
ProcessEngineConfiguration engConf = processEngine.getProcessEngineConfiguration();
ProcessDiagramGenerator processDiagramGenerator = engConf.getProcessDiagramGenerator();
runtimeService.createProcessInstanceQuery().processInstanceId(pId).singleResult();
FlowResultVO flowResultVO = new FlowResultVO();
InputStream in = processDiagramGenerator.generateDiagram(bpmnModel, "PNG", highLightedActivities,
highLightedFlows,
"宋体", "宋体", "宋体", null, 1.0D, true);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
byte[] b = new byte[1024];
int len = -1;
while ((len = in.read(b, 0, 1024)) != -1) {
out.write(b, 0, len);
}
String resource = new BASE64Encoder().encode(out.toByteArray());
flowResultVO.setRetCode(MetaStatus.BIZ_SUCCESS);
flowResultVO.setRetMsg("获取流程资源成功");
flowResultVO.setResource(resource);
} catch (Exception e) {
flowResultVO.setRetCode(MetaStatus.BIZ_FAIL);
flowResultVO.setRetMsg("获取流程资源失败:" + e.getMessage());
log.error("获取流程资源失败:" + e.getMessage());
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
return flowResultVO;
}
获取flowable流程图资源
最新推荐文章于 2024-07-13 13:37:16 发布