activiti6.0 查看流程图 审批后的流程进度显示红线

看到网上有很多实现此功能的代码,大概是找出历史记录,并按照时间排序,将历史记录里面的节点和连线全部展示。

如果是简单的流程,没有问题,如上图。

但是如果是下面的图,涉及到将流程回转的,那么历史表中会记录整个过程,这时候的再展示就不对了。

比如上图,如果一直循环在这里,那么整个线条是一致在循环的,这样的话,看到的将是一个闭环的红线,即便是简单的流程,如果有回退,那么看到的记录里面,仍然会有混乱。

问题解决思路:

找到当前待审批的任务,逐步前推,自然就不会有问题了。

废话少说,上代码:

/** 显示流程图
 * @param request
 */
@ResponseBody
@RequestMapping("/displayFlowCurrPic")
public void displayFlowCurrPicnew(HttpServletRequest request, HttpServletResponse response){
    BufferedImage img = new BufferedImage(300, 150, BufferedImage.TYPE_INT_RGB);
    String deploymentId=request.getParameter("deploymentId");
    try {
        ProcessDefinition  processDefinition=repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId)//使用部署对象ID查询
                .singleResult();
        List<Task> activeTasks=taskService.createTaskQuery().processDefinitionId(processDefinition.getId()).list();
        // 已执行的节点ID集合
        List<String> executedActivityIdList = new ArrayList<String>();
        List<String> highLines = new ArrayList<String>();
        List<String> highNodes = new ArrayList<String>();
        //log.info("获取已经执行的节点ID");

        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
        for(Task tk:activeTasks){
            executedActivityIdList.add(tk.getTaskDefinitionKey());
            highLines.addAll(getHighLines(bpmnModel,tk.getTaskDefinitionKey()));
            highNodes.addAll(getHighNodes(bpmnModel,tk.getTaskDefinitionKey()));
        }
        // 获取流程图图像字符流
        InputStream imageStream = new DefaultProcessDiagramGenerator().generateDiagram(bpmnModel, "png",
                highNodes, highLines, "宋体", "宋体", "宋体", null, 1.0);
        // 输出资源内容到相应对象
        byte[] b = new byte[1024];
        int len;
        while ((len = imageStream.read(b, 0, 1024)) != -1) {
            response.getOutputStream().write(b, 0, len);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
/**
 * 获取高亮的线
 * @param bpmnModel
 * @param key
 * @return
 */
private Set<String> getHighLines(BpmnModel bpmnModel,String key){
    FlowNode fl=(FlowNode) bpmnModel.getFlowElement(key);
    List<SequenceFlow> pvmTransitions = fl.getIncomingFlows();
    Set<String> highLines=new HashSet<>();
    for(SequenceFlow sf:pvmTransitions){
        highLines.add(sf.getId());
        if(StringUtils.isNotBlank(sf.getSourceRef())){
            highLines.addAll(getHighLines(bpmnModel,sf.getSourceRef()));
        }
    }
    return highLines;
}
/**
 * 获取高亮的线
 * @param bpmnModel
 * @param key
 * @return
 */
private Set<String> getHighNodes(BpmnModel bpmnModel,String key){
    FlowNode fl=(FlowNode) bpmnModel.getFlowElement(key);
    List<SequenceFlow> sequenceFlows = fl.getIncomingFlows();
    Set<String> highNodes=new HashSet<>();
    highNodes.add(key);
    for(SequenceFlow sf:sequenceFlows){
        if(StringUtils.isNotBlank(sf.getSourceRef())){
            highNodes.addAll(getHighNodes(bpmnModel,sf.getSourceRef()));
        }
    }
    return highNodes;
}

 

前端定义一个img标签,查询的时候:

$("#disFlowPic").attr("src","../api/displayFlowCurrPic?deploymentId="+deploymentId+"");
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值