zoukankan      html  css  js  c++  java
  • flowable显示流程图,路径和节点

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

    效果:

    已经结束的流程

     正在执行的流程

     代码:1、生成图片

    public 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;
        }

    2、递归获取高private 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; 
    } } }

    如果有什么不懂的,可以随时问我,也可以加入我们qq群633168411,里面都是flowable爱好者,不搞虚的,只讲实的。

  • 相关阅读:
    组合数问题
    [Repost] 悬线法
    图论 List
    杂项 List
    动态规划 List
    Binary Search
    树状数组,Fenwick Tree
    HDU1086判断线段相交
    高效大数模板
    HDUOJ2298三分加二分
  • 原文地址:https://www.cnblogs.com/liuwenjun/p/11820108.html
Copyright © 2011-2022 走看看