activiti跟踪流程实例图片

1、根据流程实例ID查询

/**
     * 查询流程实例图片
     *
     * @param processInstanceId
     * @return
     */
    @RequiresPermissions("activitiManage:processInstance")
    @RequestMapping("/showProcessInstance")
    public ModelAndView showProcessInstance(String processInstanceId) {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("admin/workflow/processInstancePng");
        ProcessInstance processInstance =
                runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        String processDefinitionId = processInstance.getProcessDefinitionId();
        ProcessDefinition processDefinition =
                repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
        String deploymentId = processDefinition.getDeploymentId();
        String imageName = processDefinition.getDiagramResourceName();
        List<ActivityImpl> processMap = getProcessMap(processInstance,processDefinition);
        ActivityImpl activity = processMap.get(0);
        int x = activity.getX();
        int y = activity.getY();
        int width = activity.getWidth();
        int height = activity.getHeight();
        InputStream resourceAsStream = repositoryService.getResourceAsStream(deploymentId, imageName);
        String base64Img = Base64Util.GetImageStr(resourceAsStream);
        mav.addObject("x", x);
        mav.addObject("y", y);
        mav.addObject("width", width);
        mav.addObject("height", height);
        mav.addObject("img", "data:image/png;base64," + base64Img);
        return mav;
    }

2、获取活动任务

 /**
     * 获取活动任务
     * @return
     */
    public List<ActivityImpl> getProcessMap(ProcessInstance pi,ProcessDefinition processDefinition) {
        List<ActivityImpl> actImpls = new ArrayList<ActivityImpl>();
        ProcessDefinitionImpl pdImpl = (ProcessDefinitionImpl) processDefinition;
        String processDefinitionId = pdImpl.getId();// 流程标识
        ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDefinitionId);
        List<ActivityImpl> activitiList = def.getActivities();// 获得当前任务的所有节点
        List<String> ActiveActivityIds = runtimeService.getActiveActivityIds(pi.getId());
        for (String activeId : ActiveActivityIds) {
            for (ActivityImpl activityImpl : activitiList) {
                String id = activityImpl.getId();
                if (activityImpl.isScope()) {
                    if (activityImpl.getActivities().size() > 1) {
                        List<ActivityImpl> subAcList = activityImpl.getActivities();
                        for (ActivityImpl subActImpl : subAcList) {
                            String subid = subActImpl.getId();
                            if (activeId.equals(subid)) {// 获得执行到那个节点
                                actImpls.add(subActImpl);
                                break;
                            }
                        }
                    }
                }
                if (activeId.equals(id)) {// 获得执行到那个节点
                    actImpls.add(activityImpl);
                }
            }
        }
        return actImpls;
    }

3、用输入流编码

 /**
     * 用输入流编码
     * @param in
     * @return
     */
    public static String GetImageStr(InputStream in)
    {//将图片文件转化为字节数组字符串,并对其进行Base64编码处理
        byte[] data = null;
        //读取图片字节数组
        try
        {
            data = new byte[in.available()];
            in.read(data);
            in.close();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        //对字节数组Base64编码
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(data);//返回Base64编码过的字节数组字符串
    }

4、jsp页面

<img src="${img}"/>
<div style="position: absolute;border:3px solid red;top:${y-1}px;left:${x-1}px;width:${width-3}px;height:${height-3}px;">

 

你可能感兴趣的:(Activiti)