记录

   
    /**
     * 另存为
     */
    public void save_txt() throws Exception{
        OutputStream toClient = null ;
        StringBuffer sb = new StringBuffer() ;
        try{
            response.reset();
            response.addHeader("content-type","application/x-msdownload");
            //a.txt是打开文件下载框,需要下载到本地的默认的文件类型和名字
            String filename = URLEncoder.encode("生育支付汇总-财务","utf-8") ;
            response.addHeader("Content-Disposition", "attachment;filename="+filename+".txt");
            response.setContentType("application/stream");
            response.setCharacterEncoding("UTF-8" ) ;
            response.setContentType("charset=UTF-8") ;
            
            //返回给前台的流
            toClient = new BufferedOutputStream(response.getOutputStream());
            String sql = "select * from V_PAY2CORP where aae002 = '"+param1+"'" ;
            List<Map<String, Object>>  list = CommonQueryUtil.result2MapList(sql) ;
            if(list == null || list.size() == 0){
                throw new Exception("您查询的数据不存在");
            }
            for(Map<String,Object> map : list){
                String pay2corptxt = map.get("PAY2CORPTXT").toString() ;
                sb.append(pay2corptxt).append("\r\n") ;
            }
            
        }catch(Exception e){
            System.out.println(e.getMessage());
            sb.append(e.getMessage()) ;
        }
        
        //通过流,返回给前台页面
        toClient.write(sb.toString().getBytes("UTF-8"));
        toClient.flush();
        toClient.close();
        
    }
    /**
     * 生育回盘
     * @throws Exception
     */
    public void save_txt_offer() throws Exception{
        OutputStream toClient = null ;
        StringBuffer sb = new StringBuffer() ;
        List<File> filelist = new ArrayList<File>();//文件txt集合
        String path = null ;
        String zip_path = null ;
        try{
            response.reset();
            response.addHeader("content-type","application/x-msdownload");
            //a.txt是打开文件下载框,需要下载到本地的默认的文件类型和名字
            String filename_zip = URLEncoder.encode("生育报盘银行信息.zip","utf-8") ;
            response.addHeader("Content-Disposition", "attachment;filename="+filename_zip);
            response.setContentType("application/stream");
            response.setCharacterEncoding("UTF-8" ) ;
            response.setContentType("charset=UTF-8") ;
            
            //1.查询数据
            String sql = " select aae002,zae004,id,aae002 || zae004 || '(' || ZAE005 || '人' || zae010 || '元' || ').txt' filename from zz01 where " + param1 ;
            List<Map<String, Object>>  list = CommonQueryUtil.result2MapList(sql) ;
            if(list == null || list.size() == 0){
                throw new Exception("您查询的数据zz01不存在");
            }
            
            path = request.getSession().getServletContext().getRealPath("/");
            File dir = new File(path + "/files");
            if(!dir.exists()){
                dir.mkdir() ;
            }
            
            zip_path = path + "/files/生育报盘银行信息.zip" ;
            File file = null ;
            BufferedWriter writer = null ;
            
            for(Map<String, Object> map : list){
                String filename = map.get("FILENAME").toString() ;
                String id = map.get("ID").toString() ;
                file = new File(path + "/files/" + filename) ;
                writer = new BufferedWriter( new FileWriter( file )) ;
                //查询人员明细数据
                sql = "select '"+map.get("AAE002")+"'  || '|' || a.aab001 || '|' || a.aac001 || '|' || a.aac003 || '|' || a.aac002 || '|' || t.aae010 || '|' || t.ZAE016 || '|' || '01' text_content from  ZZ02 T , AC01 A where A.AAC001=T.AAC001 and T.ZAE014 = '"+id+"'" ;
                List<Map<String, Object>>  list_list = CommonQueryUtil.result2MapList(sql) ;
                if(list_list == null || list_list.size() == 0){
//                    throw new Exception("zz02银行明细数据不存在,银行:" + map.get("ZAE004") + ",结算期:" + map.get("AAE002"));
                    writer.write("zz02银行明细数据不存在,银行:" + map.get("ZAE004") + ",结算期:" + map.get("AAE002") + "\r\n") ;
                }else{
                    for(Map<String,Object> map_list : list_list){
                        String text_content = map_list.get("TEXT_CONTENT").toString() ;
                        writer.write(text_content + "\r\n") ;
                    }
                }
                
                writer.flush() ;
                writer.close() ;
                filelist.add(new File(path + "/files/" + filename)) ;
            }
            
            System.out.println("---------------1");
            //打包
            zipFiles(filelist, new File(zip_path)) ;
            System.out.println("---------------2");
            
            //删除txt文件
            deleteFile(filelist) ;
            System.out.println("---------------3");
            
            File f = new File(zip_path);
            FileInputStream in = new FileInputStream(f) ;
            //返回给前台的流
            toClient = new BufferedOutputStream(response.getOutputStream());
            byte b[] = new byte[in.available()];
            in.read(b) ;
            System.out.println("==="+b.length);
            toClient.write(b) ;
            toClient.flush();
            toClient.close();
            
        }catch(Exception e){
            System.out.println(e.getMessage());
            sb.append(e.getMessage()) ;
        }
        
    }
    /**
     * 慢病系统外导入
     * 异常信息
     * @throws Exception
     */
    public void getErrorMessage() throws Exception{
        OutputStream toClient = null ;
        StringBuffer sb = new StringBuffer() ;
        try{
            response.reset();
            response.addHeader("content-type","application/x-msdownload");
            //a.txt是打开文件下载框,需要下载到本地的默认的文件类型和名字
            String filename= URLEncoder.encode("系统外慢病导入异常","utf-8") ;
            response.addHeader("Content-Disposition", "attachment;filename="+filename + "-"+ param2);
            response.setContentType("application/stream");
            response.setCharacterEncoding("UTF-8" ) ;
            response.setContentType("charset=UTF-8") ;
            
            //查询文件
            //删除txt文件
//            deleteFile(filelist) ;
            
            File f = new File(param1);
            FileInputStream in = new FileInputStream(f) ;
            //返回给前台的流
            toClient = new BufferedOutputStream(response.getOutputStream());
            byte b[] = new byte[in.available()];
            in.read(b) ;
            toClient.write(b) ;
            toClient.flush();
            toClient.close();
            
        }catch(Exception e){
            System.out.println(e.getMessage());
            sb.append(e.getMessage()) ;
        }
        
    }
    /**
     * 异常信息
     * @throws Exception
     */
    public void getErrorMessage_comm() throws Exception{
        OutputStream toClient = null ;
        StringBuffer sb = new StringBuffer() ;
        try{
            response.reset();
            response.addHeader("content-type","application/x-msdownload");
            //a.txt是打开文件下载框,需要下载到本地的默认的文件类型和名字
            param2 = URLEncoder.encode(param2,"utf-8") ;
            response.addHeader("Content-Disposition", "attachment;filename="+ param2);
            response.setContentType("application/stream");
            response.setCharacterEncoding("UTF-8" ) ;
            response.setContentType("charset=UTF-8") ;
            
            //查询文件
            //删除txt文件
//            deleteFile(filelist) ;
            
            File f = new File(param1);
            FileInputStream in = new FileInputStream(f) ;
            //返回给前台的流
            toClient = new BufferedOutputStream(response.getOutputStream());
            byte b[] = new byte[in.available()];
            in.read(b) ;
            toClient.write(b) ;
            toClient.flush();
            toClient.close();
            
        }catch(Exception e){
            System.out.println(e.getMessage());
            sb.append(e.getMessage()) ;
        }
        
    }
    
    public void zipFiles(List<File> srcfile, File zipfile) throws Exception{
        byte[] buf = new byte[1024];
        // Create the ZIP file
        ZipOutputStream  out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipfile)));
        // Compress the files
        for (int i = 0; i < srcfile.size(); i++) {
            File file = srcfile.get(i);
            FileInputStream in = new FileInputStream(file);
            // Add ZIP entry to output stream.
            out.putNextEntry(new ZipEntry(file.getName()));
            // Transfer bytes from the file to the ZIP file
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            // Complete the entry
            out.setEncoding("GB2312");
            out.closeEntry();
            in.close();
        }
        // Complete the ZIP file
        out.close();
    }
    
    public void deleteFile(List<File> list) throws Exception {
         for(File f : list){
             if(f.exists() && f.isFile()){
                 f.delete() ;
             }
         }
     }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值