菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
154
0

pdf备份

原创
05/13 14:22
阅读数 50579
 @RequestMapping(params = "exportXlsxdpdf")
        @ResponseBody 
          public void exportXlsxdpdf(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap,
                  OutputStream output) throws IOException, DocumentException {
            
              String id = request.getParameter("id"); //业务id

              int firstpage=8;//首页展示的条数
              int otherpage=13;//非首页展示的条数
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
            Date date=new Date(); 
              LdcOrderEntity ldcOrder = ldcOrderService.getEntity(LdcOrderEntity.class, id); 
            //找出所有的商品标记
              List<Map<String,Object>> mp=jdbcTemplate.queryForList("select * from ldc_order_box where box_orderid=? ",id);
               
              //计算出一共多少条
            int all=mp.size();
            //默认一页
            int pageNo=1;
            //如果条数大于首页的数量,计算出一共有多少页
            if(all>firstpage){ 
                  Double abc= (double)(all-firstpage)/otherpage;
                pageNo=(int) Math.ceil(abc)+1;
            } 
            //字体
            BaseFont unicode = BaseFont.createFont(request.getServletContext().getRealPath("/")+"webpage/com/jeecg/pdf/simsun.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            bf = unicode; 
            // A4纸
            Document document = new Document(PageSize.A4.rotate()); 
            PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
            document.open();
            //循环的时候取值,从第一条开始取
            //图片处理
            File file=new File(request.getServletContext().getRealPath("/")+"webpage/com/jeecg/pdf/pdfxd.png");
            if(file.exists()){
                Image image = Image.getInstance(request.getServletContext().getRealPath("/")+"webpage/com/jeecg/pdf/pdfxd.png"); 
                image.scaleAbsolute(100, 50);
                image.setAbsolutePosition(100, 430);
                document.add(image);
            }
            int a=0;
            //内容表格
            Font f = new Font(unicode,12,Font.BOLD);   
            Paragraph  paragraph = new Paragraph("南通斯密特森光电科技有限公司",f); 
            paragraph.setAlignment(Element.ALIGN_CENTER);
            paragraph.setSpacingBefore(0f); // 前间距
            paragraph.setSpacingAfter(0f); // 后间距
            document.add(paragraph);
            paragraph = new Paragraph("NANTONG SCHMIDT OPTO-ELECTRICAL TECHNOLOGY CO., LTD",f); 
            paragraph.setAlignment(Element.ALIGN_CENTER);
            paragraph.setSpacingBefore(0f); // 前间距
            paragraph.setSpacingAfter(0f); // 后间距
            document.add(paragraph);
            paragraph = new Paragraph("装  箱  单",f); 
            paragraph.setAlignment(Element.ALIGN_CENTER);
            paragraph.setSpacingBefore(0f); // 前间距
            paragraph.setSpacingAfter(0f); // 后间距
            document.add(paragraph);
            //table赋值
            PdfPTable table = new PdfPTable(8);
            table.setWidthPercentage(100); // 宽度100%填充
            table.setSpacingBefore(5f); // 前间距
            table.setSpacingAfter(0f); // 后间距 
            //定义该table一共有8列
            float[] columnWidths = { 1.8f, 2f, 1.8f, 1.8f, 1.8f, 1.8f, 1.8f, 1.8f};
            table.setWidths(columnWidths);
            List<PdfPRow> listRow_a = table.getRows(); 
            PdfPCell cells9_a[] = new PdfPCell[8];
            PdfPRow row9_a = new PdfPRow(cells9_a);
            cells9_a[0] = getCell("PACKING LIST" ,"1111","normal","10","14");  
            cells9_a[0].setColspan(3);
            cells9_a[5] = getCell("DATE:","1111","normal","10","24");   
            cells9_a[6] = getCell(formatter.format(date) ,"1111","normal","10","14");  
            listRow_a.add(row9_a); 
            document.add(table);  
            //table赋值
            table = new PdfPTable(8);
            table.setWidthPercentage(100); // 宽度100%填充
            table.setSpacingBefore(5f); // 前间距
            table.setSpacingAfter(0f); // 后间距 
            table.setWidths(columnWidths);
            List<PdfPRow> listRow_c = table.getRows(); 
            PdfPCell cells9_c[] = new PdfPCell[8];
            PdfPRow row9_c = new PdfPRow(cells9_c);
            cells9_c[0] = getCell("","1111","normal","10","14"); 
            cells9_c[1] = getCell("","1111","normal","10","14");
            cells9_c[1].setColspan(4);
            
            cells9_c[5] = getCell("INVOICE NO.:","1111","normal","10","14");
            cells9_c[6] = getCell(mp.get(0).get("fapiaono").toString(),"1111","normal","10","14"); 
            listRow_c.add(row9_c); 
            document.add(table); 
            //table赋值
            table = new PdfPTable(8);
            table.setWidthPercentage(100); // 宽度100%填充
            table.setSpacingBefore(5f); // 前间距
            table.setSpacingAfter(0f); // 后间距 
            table.setWidths(columnWidths);
            List<PdfPRow> listRow_d = table.getRows(); 
            PdfPCell cells9_d[] = new PdfPCell[8];
            PdfPRow row9_d = new PdfPRow(cells9_d);
            cells9_d[0] = getCell("","1111","normal","10","14"); 
            cells9_d[1] = getCell("","1111","normal","10","14");
            cells9_d[1].setColspan(4);
            cells9_d[5] = getCell("Salesno:","1111","normal","10","14"); 
            cells9_d[6] = getCell(mp.get(0).get("box_pono").toString(),"1111","normal","10","14"); 
            listRow_d.add(row9_d); 
            document.add(table); 
            //table赋值
            table = new PdfPTable(8);
            table.setWidthPercentage(100); // 宽度100%填充
            table.setSpacingBefore(5f); // 前间距
            table.setSpacingAfter(0f); // 后间距 
            table.setWidths(columnWidths);
            List<PdfPRow> listRow = table.getRows(); 
            PdfPCell cells9[] = new PdfPCell[8];
            PdfPRow row9 = new PdfPRow(cells9);
            cells9[0] = getCell("C/N","1011","normal","10","14"); 
            cells9[1] = getCell("CONTENT","1011","normal","10","14");
            cells9[1].setColspan(3);
            cells9[4] = getCell("MEASUREMENT","1011","normal","10","14");
            cells9[5] = getCell("QTY","1011","normal","10","14");
            cells9[6] = getCell("G.W.","1011","normal","10","14");
            cells9[7] = getCell("N.W","1011","normal","10","14"); 
            listRow.add(row9); 
            document.add(table);
            
            
            int zxs=0;//定义总数量
            double jineall=0;//定义总金额 
            
            for (int i = 0; i < pageNo; i++) {  
                int sunsl=0;//定义每页数量
                double jine=0;//定义每页金额
                //其他页面
                if(i!=0){ 
                    document.newPage();//创建一个新的页面 
                    for (int p = 0; p <otherpage; p++) {
                        if(a<mp.size()){//保证数组不越界
                            Map<String,Object> map = mp.get(a);
                        a++;  
                        table = new PdfPTable(8); 
                        table.setWidthPercentage(100); // 宽度100%填充
                        table.setSpacingBefore(5f); // 前间距
                        table.setSpacingAfter(0f); // 后间距
                        table.setWidths(columnWidths);
                        listRow = table.getRows();
                        
                        PdfPCell cells91[] = new PdfPCell[8];
                        PdfPRow row91 = new PdfPRow(cells91);
                        String box_no = "";
                        String box_pono = "";
                        String box_endescribe = ""; 
                        double box_Goods_Volume = 0.0;
                        int box_goods_number = 0;
                        double box_gross_weight = 0.0;
                        double box_goods_weight = 0.0;
                        int sumbox_no = 0;
                        String box_goodsdec = "";
                        if(map.get("box_no") !=null){
                             box_no = String.valueOf(map.get("box_no"));  
                             int sumh = Integer.parseInt(box_no.split("-")[1]);
                               int sumq = Integer.parseInt(box_no.split("-")[0]);
                               sumbox_no=sumh-sumq+1; 
                        }
                        if(map.get("box_pono") !=null) { 
                             box_pono = String.valueOf(map.get("box_pono")); 
                        }
                        if(map.get("box_endescribe") !=null) { 
                             box_endescribe = String.valueOf(map.get("box_endescribe")); 
                        }
                        if(map.get("box_Goods_Volume") !=null) { 
                             box_Goods_Volume = Double.parseDouble(String.valueOf(map.get("box_Goods_Volume"))); 
                        }
                        if(map.get("box_goods_number") !=null) { 
                             box_goods_number = Integer.parseInt(String.valueOf(map.get("box_goods_number")));
                        }
                        if(map.get("box_gross_weight") !=null) { 
                             box_gross_weight = Double.parseDouble(String.valueOf(map.get("box_gross_weight"))); 
                        }
                        if(map.get("box_goods_weight") !=null) { 
                             box_goods_weight = Double.parseDouble(String.valueOf(map.get("box_goods_weight"))); 
                        }
                        if(map.get("box_goodsdec") !=null) { 
                            box_goodsdec = String.valueOf(map.get("box_goodsdec")); 
                        }
                        
                        cells91[0] = getCell(box_no,"1111","normal","10","14"); 
                        cells91[1] = getCell(box_pono+" "+box_endescribe,"1111","normal","10","14");   

                        cells91[1].setColspan(3);
                        cells91[4] = getCell(String.valueOf(box_Goods_Volume),"1111","normal","10","14");   
                        cells91[5] = getCell(String.valueOf(box_goods_number),"1111","normal","10","14");   
                        cells91[6] = getCell(String.valueOf(box_gross_weight),"1111","normal","10","14");  
                        cells91[7] = getCell(String.valueOf(box_goods_weight),"1111","normal","10","14");  
                        listRow.add(row91);  
                        document.add(table); 
                         
                        table = new PdfPTable(8); 
                        table.setWidthPercentage(100); // 宽度100%填充
                        table.setSpacingBefore(5f); // 前间距
                        table.setSpacingAfter(0f); // 后间距
                        table.setWidths(columnWidths);
                        listRow = table.getRows();
                        
                        PdfPCell cells92[] = new PdfPCell[8];
                        PdfPRow row92 = new PdfPRow(cells92);
                        double sumbox_no1 = sumbox_no;
                        cells92[0] = getCell(sumbox_no+"","1111","normal","10","14");  
                        cells92[1] = getCell(box_goodsdec+"","1111","normal","10","14"); 
                        cells92[1].setColspan(3); 
                        cells92[4] = getCell(box_Goods_Volume*sumbox_no+"" ,"1111","normal","10","14");   
                        cells92[5] = getCell(box_Goods_Volume*box_goods_number+"","1111","normal","10","14");   
                        cells92[6] = getCell(box_Goods_Volume*box_gross_weight+"","1111","normal","10","14");   
                        cells92[7] = getCell(box_Goods_Volume*box_goods_weight+"","1111","normal","10","14");   
                        listRow.add(row92);  
                        document.add(table); 
                        zxs=zxs+sumbox_no;
                     }
                    }
                }else{
                    //首页 
                    for (int p = 0; p <firstpage; p++) {
                        if(a<mp.size()){
                            Map<String,Object> map = mp.get(a);
                            a++;  
                 
                            table = new PdfPTable(8); 
                            table.setWidthPercentage(100); // 宽度100%填充
                            table.setSpacingBefore(5f); // 前间距
                            table.setSpacingAfter(0f); // 后间距
                            table.setWidths(columnWidths);
                            listRow = table.getRows();
                            
                            PdfPCell cells91[] = new PdfPCell[8];
                            PdfPRow row91 = new PdfPRow(cells91);
                            String box_no = "";
                            String box_pono = "";
                            String box_endescribe = ""; 
                            double box_Goods_Volume = 0.0;
                            int box_goods_number = 0;
                            double box_gross_weight = 0.0;
                            double box_goods_weight = 0.0;
                            int sumbox_no = 0;
                            String box_goodsdec = "";
                            if(map.get("box_no") !=null){
                                 box_no = String.valueOf(map.get("box_no"));  
                                 int sumh = Integer.parseInt(box_no.split("-")[1]);
                                   int sumq = Integer.parseInt(box_no.split("-")[0]);
                                   sumbox_no=sumh-sumq+1; 
                            }
                            if(map.get("box_pono") !=null) { 
                                 box_pono = String.valueOf(map.get("box_pono")); 
                            }
                            if(map.get("box_endescribe") !=null) { 
                                 box_endescribe = String.valueOf(map.get("box_endescribe")); 
                            }
                            if(map.get("box_Goods_Volume") !=null) { 
                                 box_Goods_Volume = Double.parseDouble(String.valueOf(map.get("box_Goods_Volume"))); 
                            }
                            if(map.get("box_goods_number") !=null) { 
                                 box_goods_number = Integer.parseInt(String.valueOf(map.get("box_goods_number")));
                            }
                            if(map.get("box_gross_weight") !=null) { 
                                 box_gross_weight = Double.parseDouble(String.valueOf(map.get("box_gross_weight"))); 
                            }
                            if(map.get("box_goods_weight") !=null) { 
                                 box_goods_weight = Double.parseDouble(String.valueOf(map.get("box_goods_weight"))); 
                            }
                            if(map.get("box_goodsdec") !=null) { 
                                box_goodsdec = String.valueOf(map.get("box_goodsdec")); 
                            }
                            
                            cells91[0] = getCell(box_no,"1111","normal","10","14"); 
                            cells91[1] = getCell(box_pono+" "+box_endescribe,"1111","normal","10","14");   

                            cells91[1].setColspan(3);
                            cells91[4] = getCell(String.valueOf(box_Goods_Volume),"1111","normal","10","14");   
                            cells91[5] = getCell(String.valueOf(box_goods_number),"1111","normal","10","14");   
                            cells91[6] = getCell(String.valueOf(box_gross_weight),"1111","normal","10","14");  
                            cells91[7] = getCell(String.valueOf(box_goods_weight),"1111","normal","10","14");  
                            listRow.add(row91);  
                            document.add(table); 
                             
                            table = new PdfPTable(8); 
                            table.setWidthPercentage(100); // 宽度100%填充
                            table.setSpacingBefore(5f); // 前间距
                            table.setSpacingAfter(0f); // 后间距
                            table.setWidths(columnWidths);
                            listRow = table.getRows();
                            
                            PdfPCell cells92[] = new PdfPCell[8];
                            PdfPRow row92 = new PdfPRow(cells92);
                            double sumbox_no1 = sumbox_no;
                            cells92[0] = getCell(sumbox_no+"","1111","normal","10","14");  
                            cells92[1] = getCell(box_goodsdec+"","1111","normal","10","14"); 
                            cells92[1].setColspan(3); 
                            cells92[4] = getCell(box_Goods_Volume*sumbox_no+"" ,"1111","normal","10","14");   
                            cells92[5] = getCell(box_Goods_Volume*box_goods_number+"","1111","normal","10","14");   
                            cells92[6] = getCell(box_Goods_Volume*box_gross_weight+"","1111","normal","10","14");   
                            cells92[7] = getCell(box_Goods_Volume*box_goods_weight+"","1111","normal","10","14");   
                            listRow.add(row92);  
                            document.add(table); 
                            zxs=zxs+sumbox_no;
                       }
                    }
                }
                
                //最后一页的时候
                if((i+1)==pageNo){
                    String sql = " select " +
                                "        sum(box_goods_volume) box_goods_volume1, "+
                                    "           sum(box_goods_number) box_goods_number1, "+
                                    "           sum(box_gross_weight) box_gross_weight1, "+
                                    "        sum(box_goods_weight) box_goods_weight1  "+
                               "   from ldc_order a \n" +
                               "   left join ldc_order_box b on(a.id = b.box_orderid) " +
                               "  where 1=1  "  +
                               "    and  box_orderid = '"+id+"'" ;
                     Map<String, Object> map2 = jdbcTemplate.queryForMap(sql);
                     String box_goods_volume1 = "";
                     String box_goods_number1 = "";
                     String box_gross_weight1 = "";
                     String box_goods_weight1 = ""; 
                     if(map2.get("box_goods_volume1")!=null){
                         box_goods_volume1 = String.valueOf(map2.get("box_goods_volume1")); 
                     } 
                     if(map2.get("box_goods_volume1")!=null){
                         box_goods_number1 = String.valueOf(map2.get("box_goods_number1")); 
                     }
                     if(map2.get("box_goods_volume1")!=null){
                         box_gross_weight1 = String.valueOf(map2.get("box_gross_weight1")); 
                     }
                     if(map2.get("box_goods_volume1")!=null){
                         box_goods_weight1 = String.valueOf(map2.get("box_goods_weight1")); 
                     }
                          

                    table = new PdfPTable(8); 
                    table.setWidthPercentage(100); // 宽度100%填充
                    table.setSpacingBefore(5f); // 前间距
                    table.setSpacingAfter(0f); // 后间距
                    table.setWidths(columnWidths);
                    listRow = table.getRows();
                    
                    PdfPCell cells91_a[] = new PdfPCell[8];
                    PdfPRow row91_a = new PdfPRow(cells91_a);
                    cells91_a[0] = getCell("","0111","normal","10","20");  
                    cells91_a[1] = getCell("GRAND TOTAL:","0111","bold","12","20"); 
                    cells91_a[1].setColspan(2); 
                    cells91_a[3] = getCell(zxs+" Carton","0111","bold","12","20");  
                    cells91_a[4] = getCell(box_goods_volume1+" m3","0111","bold","12","20");  
                    cells91_a[5] = getCell(box_goods_number1+" PCS","0111","bold","12","20");  
                    cells91_a[6] = getCell(box_gross_weight1+" KGS","0111","bold","12","20"); 
                    cells91_a[7] = getCell(box_goods_weight1+" KGS","0111","bold","12","20");   
                    listRow.add(row91_a);  
                    document.add(table); 
                }
                
                paragraph = new Paragraph("PAGE "+(i+1)+" OF  "+pageNo,f); 
                paragraph.setAlignment(Element.ALIGN_CENTER); 
                paragraph.setSpacingBefore(0f); // 前间距
                paragraph.setSpacingAfter(0f); // 后间距
                document.add(paragraph);
            }
//            //图片处理
//             File file=new File(request.getServletContext().getRealPath("/")+"webpage/com/jeecg/pdf/hg.png");
//                if(file.exists()){
//                    Image image = Image.getInstance(request.getServletContext().getRealPath("/")+"webpage/com/jeecg/pdf/hg.png"); 
////                    image.scaleAbsolute(mmTopx(40), mmTopx(39));
//                    image.setAbsolutePosition(40, 520);
//                    document.add(image);
//                }
            // 关闭文档
            document.close();
            // 关闭书写器
            writer.flush();
            writer.close();
            
            response.setHeader("Expires", "0"); 
             response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
             response.setHeader("Pragma", "public"); 
             response.setContentType("application/pdf"); 
              
              //decMainService.exportOutPDF(request, response, id);
          }

 

发表评论

0/200
154 点赞
0 评论
收藏