Chinaunix首页 | 论坛 | 博客
  • 博客访问: 614342
  • 博文数量: 298
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 3077
  • 用 户 组: 普通用户
  • 注册时间: 2019-06-17 10:57
文章分类

全部博文(298)

文章存档

2022年(96)

2021年(201)

2019年(1)

我的朋友

分类: Java

2021-08-10 12:46:10

 在正常的flowable就是显示当前节点,路径需要我们自己获取,特别是来回的驳回会导致节点混乱,这里主要就是如何正确的显示流程图

效果:

已经结束的流程

  正在执行的流程

 代码:1、生成图片

点击(此处)折叠或打开

  1. // 源码 1b23.com
  2. public byte[] createImage2(String processInstanceId) {
  3.         //1.获取当前的流程实例
  4.         ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
  5.         String processDefinitionId = null;
  6.         List<String> activeActivityIds = null;
  7.         //2.获取所有的历史轨迹对象
  8.         List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery()
  9.                 .processInstanceId(processInstanceId).list();
  10.         Map<String, HistoricActivityInstance> hisActivityMap = new HashMap<>();
  11.         list.forEach(historicActivityInstance -> {
  12.             if (!hisActivityMap.containsKey(historicActivityInstance.getActivityId())) {
  13.                 hisActivityMap.put(historicActivityInstance.getActivityId(), historicActivityInstance);
  14.             }
  15.         });
  16.         //3. 获取流程定义id和高亮的节点id
  17.         if (processInstance != null) {
  18.             //3.1. 正在运行的流程实例
  19.             processDefinitionId = processInstance.getProcessDefinitionId();
  20.             activeActivityIds = runtimeService.getActiveActivityIds(processInstanceId);
  21.         } else {
  22.             //3.2. 已经结束的流程实例
  23.             HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
  24.             processDefinitionId = historicProcessInstance.getProcessDefinitionId();
  25.             activeActivityIds = new ArrayList<>();
  26.             List<EndEvent> endEvents = bpmnModelService.findEndFlowElement(processDefinitionId);
  27.             List<String> finalActiveActivityIds = activeActivityIds;
  28.             endEvents.forEach(endEvent -> {
  29.                 if (hisActivityMap.containsKey(endEvent.getId())) {
  30.                     finalActiveActivityIds.add(endEvent.getId());
  31.                 }
  32.             });
  33.         }
  34.         //4. 获取流程定义的所有节点信息
  35.         List<FlowNode> flowNodes = bpmnModelService.findFlowNodes(processDefinitionId);
  36.         Map<String, FlowNode> activityMap = flowNodes.stream().collect(Collectors.toMap(FlowNode::getId, flowNode -> flowNode));
  37.         List<String> highLightedFlows = new ArrayList<>();
  38.         //5. 递归得到高亮线
  39.         activeActivityIds.forEach(activeActivityId -> this.getHighLightedFlows(activityMap, hisActivityMap, activeActivityId, highLightedFlows, activeActivityId));
  40.         //6. 获取bpmnModel对象
  41.         BpmnModel bpmnModel = bpmnModelService.getBpmnModelByProcessDefId(processDefinitionId);
  42.         //7. 生成图片流
  43.         InputStream inputStream = flowProcessDiagramGenerator.generateDiagram(bpmnModel, activeActivityIds, highLightedFlows);
  44.         //8. 转化成byte便于网络传输
  45.         byte[] datas = IoUtil.readInputStream(inputStream, "image inputStream name");
  46.         return datas;
  47.     }
递归获取高

点击(此处)折叠或打开

  1. //from fhadmin.cn
  2. private void getHighLightedFlows(Map<String, FlowNode> flowNodeMap,
  3.             Map<String, HistoricActivityInstance> hisActivityMap,
  4.             String activeActivityId,
  5.             List<String> highLightedFlows,
  6.             String oldActivityId) {
  7.         FlowNode flowNode = flowNodeMap.get(activeActivityId);
  8.         List<SequenceFlow> incomingFlows = flowNode.getIncomingFlows();
  9.         for (SequenceFlow sequenceFlow : incomingFlows) {
  10.             String sourceRefId = sequenceFlow.getSourceRef();
  11.             if (hisActivityMap.containsKey(sourceRefId) && !oldActivityId.equals(sourceRefId)) {
  12.                 highLightedFlows.add(sequenceFlow.getId());
  13.                 this.getHighLightedFlows(flowNodeMap, hisActivityMap, sourceRefId, highLightedFlows, oldActivityId);
  14.             } else {
  15.  
  16.           if (hisActivityMap.containsKey(sourceRefId)){
  17.               highLightedFlows.add(sequenceFlow.getId());
  18.           }
  19.           break;
  20. } } }


阅读(5626) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~