这篇文章主要介绍“如何实现flowable工作流办理过的节点描高亮颜色”,在日常操作中,相信很多人在如何实现flowable工作流办理过的节点描高亮颜色问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何实现flowable工作流办理过的节点描高亮颜色”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
在正常的flowable就是显示当前节点,路径需要我们自己获取,特别是来回的驳回会导致节点混乱,这里主要就是如何正确的显示流程图
效果:
已经结束的流程
正在执行的流程
代码:1、生成图片
// 源码 www.fhadmin.orgpublic byte[] createImage2(String processInstanceId) {//1.获取当前的流程实例ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); String processDefinitionId = null;List<String> activeActivityIds = null;//2.获取所有的历史轨迹对象List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery() .processInstanceId(processInstanceId).list(); Map<String, HistoricActivityInstance> hisActivityMap = new HashMap<>();list.forEach(historicActivityInstance -> {if (!hisActivityMap.containsKey(historicActivityInstance.getActivityId())) { hisActivityMap.put(historicActivityInstance.getActivityId(), historicActivityInstance); } });//3. 获取流程定义id和高亮的节点idif (processInstance != null) {//3.1. 正在运行的流程实例processDefinitionId = processInstance.getProcessDefinitionId(); activeActivityIds = runtimeService.getActiveActivityIds(processInstanceId); } else {//3.2. 已经结束的流程实例HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); processDefinitionId = historicProcessInstance.getProcessDefinitionId(); activeActivityIds = new ArrayList<>();List<EndEvent> endEvents = bpmnModelService.findEndFlowElement(processDefinitionId);List<String> finalActiveActivityIds = activeActivityIds; endEvents.forEach(endEvent -> {if (hisActivityMap.containsKey(endEvent.getId())) { finalActiveActivityIds.add(endEvent.getId()); } }); }//4. 获取流程定义的所有节点信息List<FlowNode> flowNodes = bpmnModelService.findFlowNodes(processDefinitionId); Map<String, FlowNode> activityMap = flowNodes.stream().collect(Collectors.toMap(FlowNode::getId, flowNode -> flowNode));List<String> highLightedFlows = new ArrayList<>();//5. 递归得到高亮线activeActivityIds.forEach(activeActivityId -> this.getHighLightedFlows(activityMap, hisActivityMap, activeActivityId, highLightedFlows, activeActivityId));//6. 获取bpmnModel对象BpmnModel bpmnModel = bpmnModelService.getBpmnModelByProcessDefId(processDefinitionId);//7. 生成图片流InputStream inputStream = flowProcessDiagramGenerator.generateDiagram(bpmnModel, activeActivityIds, highLightedFlows);//8. 转化成byte便于网络传输byte[] datas = IoUtil.readInputStream(inputStream, "image inputStream name");return datas; }
递归获取高
//java项目 www.fhadmin.orgprivate void getHighLightedFlows(Map<String, FlowNode> flowNodeMap,Map<String, HistoricActivityInstance> hisActivityMap,String activeActivityId, List<String> highLightedFlows,String oldActivityId) { FlowNode flowNode = flowNodeMap.get(activeActivityId); List<SequenceFlow> incomingFlows = flowNode.getIncomingFlows();for (SequenceFlow sequenceFlow : incomingFlows) {String sourceRefId = sequenceFlow.getSourceRef();if (hisActivityMap.containsKey(sourceRefId) && !oldActivityId.equals(sourceRefId)) { highLightedFlows.add(sequenceFlow.getId());this.getHighLightedFlows(flowNodeMap, hisActivityMap, sourceRefId, highLightedFlows, oldActivityId); } else { if (hisActivityMap.containsKey(sourceRefId)){ highLightedFlows.add(sequenceFlow.getId()); } break; } } }
到此,关于“如何实现flowable工作流办理过的节点描高亮颜色”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。