flowable 工做流 路徑和節點 走過的節點描紅 高亮

在正常的flowable就是顯示當前節點,路徑須要咱們本身獲取,特別是來回的駁回會致使節點混亂,這裏主要就是如何正確的顯示流程圖網絡

效果:app

已經結束的流程ide

  正在執行的流程this

 代碼:一、生成圖片spa

// 源碼 www.1b23.compublic 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和高亮的節點id
        if (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;
    }

遞歸獲取高orm

//www.1b23.comprivate 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; 
} } }
相關文章
相關標籤/搜索