关于Ireport写章程

来源:互联网 发布:万能网络摄像机客户端 编辑:程序博客网 时间:2024/04/28 23:11

需要有多种身份放在不同页数的表格里获取图片
具体思路如下:
将数据库中决定的key传进来
在mmp添加映射(mmp知道对应字段的type是什么)
然后去数据库里的sql中查到图片路径(在服务器中的路径)->置换本地文件名->路径被set进reportMap里(以key做标识)
主要代码如下

/** 九连环 */    public  Map core(Map reportMap, String key, String imgDirectoryPath, List<PageData> datasource){        boolean flag = false;//同名文件是否覆盖(不覆盖=不保存)|default:false        Map<String, String> map  = new HashMap<>();        File imgFile = new File(imgDirectoryPath);        if (imgFile != null && imgFile.exists() && imgFile.isDirectory()) {// 进一步校验缺失图片 进行抓取            for (PageData p : datasource) {//数据源所有图片路径                String fileName = null;//回来再改这个                //the key!重要                if(p!=null){                    fileName = p.getString("UPLOAD_ADDRESS").substring(p.getString("UPLOAD_ADDRESS").lastIndexOf("/") + 1, p.getString("UPLOAD_ADDRESS").length());                    map.put(fileName, p.getString("UPLOAD_ADDRESS"));                }            }            //文件存在 进一步判断文件夹下级目录,不写通配(递归),只查一级子集 不总写就忘了            File[] files = imgFile.listFiles();            for(File f : files){                if(f.isFile()){                    String fname = f.getName();                    if(map.containsKey(fname)){//文件夹所有图片(文件)目录                        map.remove(fname);//从数据源中将已有同名名图片去除                        if(!reportMap.containsKey(key) || flag){                            reportMap.put(key, imgDirectoryPath+File.separator+fname);                        }                        continue;                    }                }            }            //pd_cond.put("idfan", imgFilePath);// pd_cond.put("idfan", "/uploadpics/"+MARKETPOID+".jpg");        } else {            //没有文件夹就意味着全没有,新建路径,同步全部数据源图片            boolean b = imgFile.mkdirs();//这步貌似可以省略,那边好像有了,先写着            if(b){                for (PageData p : datasource) {                    //System.out.println(p.getString("UPLOAD_ADDRESS"));// 这应该就是路径                    String fileName = null;//回来再改这个                    if(p!=null){                        fileName = p.getString("UPLOAD_ADDRESS").substring(p.getString("UPLOAD_ADDRESS").lastIndexOf("/") + 1, p.getString("UPLOAD_ADDRESS").length());                        map.put(fileName, p.getString("UPLOAD_ADDRESS"));                    }                }               }else{                logger.error("本地路径创建失败!");            }        }        //这的 bug依然存在,不能保存同名但不同MD5校验的图片(因为用的filename当key)        if(map!=null && !map.isEmpty()){            for (String s : map.keySet()) {                //System.out.println(s);// 这应该就是文件名                HttpURLConnectionPost.sendPost2(map.get(s), imgDirectoryPath);//get(s)这就是路径                reportMap.put(key, imgDirectoryPath+File.separator+s);                try {                    Thread.sleep(500);                } catch (InterruptedException e) {                    e.printStackTrace();                }            }        }        return reportMap;    }    enum TypeStone{        /*法人*/        FRID("FRID", null, "1", "frid"),         FRIDA("FRIDA", "1", "1", "frid"),         FRIDB("FRIDB", "0", "1", "frid"),        /*财务人员*/        CWID("CWID", null, "4", "cwid"),         CWIDA("CWIDA", "1", "4", "cwid"),         CWIDB("CWIDB", "0", "4", "cwid"),        /*联络员*/        LLYID("LLYID", null, "2", "cwid"),         LLYIDA("LLYIDA", "1", "2", "cwid"),         LLYIDB("LLYIDA", "0", "2", "cwid"),        /*自然人股东        ZZRGD("ZZRGD", null, "8", "zzrgd"),         ZZRGDA("ZZRGDA", "1", "8", "zzrgd"),         ZZRGDB("ZZRGDB", "0", "8", "zzrgd"),*/        /*委托代理人*/        WTDLR("WTDLR", null, "3", "wtdlr"),         WTDLRA("WTDLRA", "1", "3", "wtdlr"),         WTDLRB("WTDLRB", "0", "3", "wtdlr");        private TypeStone(String key, String type, String filetype, String clusterPath){            this.key = key;            this.type = type;            this.filetype = filetype;            this.clusterPath = clusterPath;        }        public static boolean containsKey(String key){            boolean b = false;            for(TypeStone t : TypeStone.values()){                if(toCompareStr(key, t.key)){                    b = true;                    break;                }            }            return b;        }        public static TypeStone getKey(String key){            for(TypeStone t : TypeStone.values()){                if(toCompareStr(key, t.key)){                    return t;                }            }            return null;        }        private String key;        private String type;        private String filetype;        private String clusterPath;        public String getKey() {            return key;        }        public void setKey(String key) {            this.key = key;        }        public String getType() {            return type;        }        public void setType(String type) {            this.type = type;        }        public String getFiletype() {            return filetype;        }        public void setFiletype(String filetype) {            this.filetype = filetype;        }        public String getClusterPath() {            return clusterPath;        }        public void setClusterPath(String clusterPath) {            this.clusterPath = clusterPath;        }    }    private static boolean isNotEmpty(String str){        if(str!=null && str.trim().length()>0){            return true;        }        return false;    }    private static boolean toCompareStr(String str1, String str2){        if(isNotEmpty(str1)&&isNotEmpty(str2)){            if(str1.equals(str2)){                return true;            }        }        return false;    }    /** 十八弯 */    public Map callCore (Map reportMap, String key, String globlePath, String marketpoid){        String imgDirectoryPath = globlePath+File.separator+marketpoid;        List<PageData> data = null;        PageData pdn = null;        //  TypeStone.        if(TypeStone.containsKey(key)){            TypeStone t = TypeStone.getKey(key);            if(isNotEmpty(t.filetype)){                pdn = new PageData();                pdn.put("MARKETPOID", marketpoid);// MARKETPOID                pdn.put("UPLOAD_FILETYPE", t.filetype);//pdn.put("UPLOAD_FILETYPE", mmp.get(key));                try {                    data = uploadinfoService.findByMarketIdCombineType(pdn);                } catch (Exception e) {                    System.out.println("here");                    logger.error(e);                }                if(data!=null && data.size()>0){                    if(isNotEmpty(t.type)){// 十大块五小块                        //五小块                        for(PageData p : data){                            if(!toCompareStr(String.valueOf(p.get("UPLOAD_TYPE")), t.type)){//!和t.type不一样的去掉                                p = null;                            }                        }                        imgDirectoryPath = globlePath + File.separator + marketpoid + File.separator + t.clusterPath + File.separator + t.type;                    }else{                        //十大块                        //nothing                        imgDirectoryPath = globlePath + File.separator + marketpoid + File.separator + t.clusterPath;                    }                    //二次判断                    if(data!=null && data.size()>0){                        reportMap = core(reportMap, key, imgDirectoryPath, data);                    }else{                        logger.info("方法【data.remove("+t.type+")】返回结果集为空");                    }                }else{                    logger.info("方法【uploadinfoService.findByMarketIdCombineType】返回结果集为空");                }            }else{                logger.info("fileType类型为空,无法查询!");            }        }else{            logger.info("key为空,,无法转换fileType类型进行查询!");        }        return reportMap;    }
原创粉丝点击