flowable 6.6.0连线及当前节点高亮

注意: flowable 6.6.0 之后的版本

流程流转过程中 可能会存在 驳回的情况, 所以 做了筛选, 只保留最新的线路图

   /**
     *  流程记录
     */
    private InputStream processRecordImage(String processInstanceId) throws IOException {
        HistoricProcessInstance hiProcInst =
                Optional.ofNullable(historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult())
                .orElseThrow(()->new IOException("流程实例没有找到"));
        List<String> highLightedActivities = taskService.createTaskQuery().processInstanceId(processInstanceId).list().stream()
                .map(task -> runtimeService.createExecutionQuery().executionId(task.getExecutionId()).singleResult().getActivityId()).collect(Collectors.toList());

        List<String> flowIds;
        if (highLightedActivities.size() > 0) {
            flowIds = runtimeService.createActivityInstanceQuery()
                    .orderByActivityInstanceStartTime().asc()
                    .orderByActivityInstanceEndTime().asc()
                    .processInstanceId(processInstanceId).list().stream()
                    .filter(hiActInst -> "sequenceFlow".equals(hiActInst.getActivityType()))
                    .map(ActivityInstance::getActivityId)
                    .collect(Collectors.toCollection(CopyOnWriteArrayList::new));
        } else {
            flowIds = historyService.createHistoricActivityInstanceQuery().orderByHistoricActivityInstanceStartTime().asc()
                    .orderByHistoricActivityInstanceEndTime().asc()
                    .processInstanceId(processInstanceId).list().stream()
                    .filter(hiActInst -> "sequenceFlow".equals(hiActInst.getActivityType()))
                    .map(HistoricActivityInstance::getActivityId)
                    .collect(Collectors.toCollection(CopyOnWriteArrayList::new));
        }

        List<String> highLightedFlows = new CopyOnWriteArrayList<>();

        flowIds.forEach(id -> {
            if (highLightedFlows.contains(id)) {
                int index = highLightedFlows.indexOf(id);
                highLightedFlows.removeIf(id1 -> highLightedFlows.indexOf(id1) > index);
            } else {
                highLightedFlows.add(id);
            }
        });

        return new DefaultProcessDiagramGenerator().generateDiagram(
                repositoryService.getBpmnModel(hiProcInst.getProcessDefinitionId()),
                "PNG",
                highLightedActivities,
                highLightedFlows,
                "宋体",
                "宋体",
                "宋体",
                null,
                1.0,
                true);
    }

flowable 6.6.0 之前的版本

    /**
     *  流程记录
     */
    private InputStream processRecordImage(String processInstanceId) {
        // 获取流程走向信息
        List<Map<String, String>> histActInsts = new ArrayList<>();
        // 连线信息
        List<Map<String, String>> flows = new ArrayList<>();
        // 高亮 流程节点
        List<String> activeActivityIds = new ArrayList<>();
        // 高亮连线ID
        List<String> highLightedFlows = new ArrayList<>();

        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();

        List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery()
                .orderByHistoricActivityInstanceStartTime().asc()
                .orderByHistoricActivityInstanceEndTime().asc()
                .processInstanceId(processInstanceId).list();

        //获取流程走向信息
        historicActivityInstances.forEach(hai -> {
            //如果存在 返回当前值 如果不存在 则返回Null
            Map<String, String> hihai = histActInsts.stream()
                    .filter(map -> map.get("id").equals(hai.getActivityId()))
                    .findFirst().orElse(null);
            if (hihai == null) {
                Map<String, String> hti = new HashMap<>();
                hti.put("id", hai.getActivityId());
                hti.put("name", hai.getActivityName());
                hti.put("type", hai.getActivityType());
                histActInsts.add(hti);
            } else {
                int index = histActInsts.indexOf(hihai);
                histActInsts.removeIf(map -> histActInsts.indexOf(map) > index);
            }
        });
//        所有节点都高亮
//        activeActivityIds = histActInsts.stream().map(map -> map.get("id")).collect(Collectors.toList());

        //当前节点高亮
        List<Task> taskList = taskService.createTaskQuery().processInstanceId(processInstanceId).list();
        for (Task obj : taskList) {
            ExecutionEntity executionEntity = (ExecutionEntity) runtimeService.createExecutionQuery()
                    .executionId(obj.getExecutionId()).singleResult();
            activeActivityIds.add(executionEntity.getActivityId());
        }

        for (int i = 0; i < histActInsts.size(); i++) {
            if (i == histActInsts.size()-1){
                break;
            }
            Map<String, String> flow = new HashMap<>();
            flow.put("source", histActInsts.get(i).get("id"));
            flow.put("target", histActInsts.get(i + 1).get("id"));
            flows.add(flow);
        }

        /* findFlowElementsOfTypeByProcInstId(processInstanceId, SequenceFlow.class).forEach(sequenceFlow -> {
            flows.forEach(flow -> {
                if (flow.get("source").equals(sequenceFlow.getSourceRef()) && flow.get("target").equals(sequenceFlow.getTargetRef())
                || flow.get("target").equals(sequenceFlow.getSourceRef()) && flow.get("source").equals(sequenceFlow.getTargetRef())){
                    highLightedFlows.add(sequenceFlow.getId());
                }
            });
        }); */

        BpmnModel bpmnModel = repositoryService.getBpmnModel(historicProcessInstance.getProcessDefinitionId());

        // 查询连接线信息-> update 2023-05-10
        Collection<FlowElement> flowElements = bpmnModel.getMainProcess().getFlowElements();
        List<SequenceFlow> elements = new ArrayList<>();
        for (FlowElement flowElement : flowElements) {
            if (flowElement instanceof SequenceFlow) {
                elements.add((SequenceFlow) flowElement);
            }
        }
        // 查询连接线信息结束 -> update 2023-05-10

        elements.forEach(sequenceFlow -> {
            flows.forEach(flow -> {
                if (flow.get("source").equals(sequenceFlow.getSourceRef()) && flow.get("target").equals(sequenceFlow.getTargetRef())
                        || flow.get("target").equals(sequenceFlow.getSourceRef()) && flow.get("source").equals(sequenceFlow.getTargetRef())) {
                    highLightedFlows.add(sequenceFlow.getId());
                }
            });
        });

        DefaultProcessDiagramGenerator defaultProcessDiagramGenerator = new DefaultProcessDiagramGenerator();
        //8. 转化成byte便于网络传输
        return defaultProcessDiagramGenerator.generateDiagram(bpmnModel, "PNG", activeActivityIds, highLightedFlows, "宋体", "宋体", "宋体", null, 1.0, true);
    }

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

li.siyuan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值