1
0
Quellcode durchsuchen

Merge branch 'master' of zcb/kmall-pt-general into master

张创标 vor 4 Jahren
Ursprung
Commit
0c1ee69809

+ 2 - 2
kmall-admin/src/main/java/com/kmall/admin/controller/exportPDF/ExportPDFController.java

@@ -33,9 +33,9 @@ public class ExportPDFController {
 
     //打印pdf
     @RequestMapping("/printPdf")
-    public ModelAndView printPdf(String head ,String type,String sku,String storeId,String headUrl) throws Exception {
+    public ModelAndView printPdf(String head ,String type,String sku,String storeId,String headUrl,String prodBarcode) throws Exception {
 
-        PDFGoodsDto pdfGoodsDto = goodsService.queryForPDFData(sku,storeId);
+        PDFGoodsDto pdfGoodsDto = goodsService.queryForPDFData(sku,storeId,prodBarcode);
 
         if("1".equals(head)){
             Map<String, Object> model = new HashMap<>();

+ 2 - 2
kmall-admin/src/main/java/com/kmall/admin/dao/GoodsDao.java

@@ -4,7 +4,6 @@ import com.kmall.admin.dto.GoodsDetailsDto;
 import com.kmall.admin.dto.GoodsPanoramaDto;
 import com.kmall.admin.entity.GoodsEntity;
 import com.kmall.api.entity.exportpdf.PDFGoodsDto;
-import com.kmall.common.utils.print.ticket.item.Goods;
 import com.kmall.manager.dao.BaseDao;
 import org.apache.ibatis.annotations.Param;
 
@@ -45,7 +44,8 @@ public interface GoodsDao extends BaseDao<GoodsEntity> {
      * 查询pdf需要的数据
      * @param sku sku
      * @param storeId 门店id
+     * @param prodBarcode
      * @return
      */
-    PDFGoodsDto queryForPDFData(@Param("sku") String sku, @Param("storeId")String storeId);
+    PDFGoodsDto queryForPDFData(@Param("sku") String sku, @Param("storeId") String storeId, @Param("prodBarcode") String prodBarcode);
 }

+ 2 - 1
kmall-admin/src/main/java/com/kmall/admin/service/GoodsService.java

@@ -147,7 +147,8 @@ public interface GoodsService {
      * 查出pdf需要的需要
      * @param sku 商品sku
      * @param storeId
+     * @param prodBarcode
      * @return
      */
-    PDFGoodsDto queryForPDFData(String sku, String storeId);
+    PDFGoodsDto queryForPDFData(String sku, String storeId, String prodBarcode);
 }

+ 3 - 2
kmall-admin/src/main/java/com/kmall/admin/service/impl/GoodsServiceImpl.java

@@ -1047,11 +1047,12 @@ public class GoodsServiceImpl implements GoodsService {
      *
      * @param sku 商品sku
      * @param storeId
+     * @param prodBarcode
      * @return
      */
     @Override
-    public PDFGoodsDto queryForPDFData(String sku, String storeId) {
-        return goodsDao.queryForPDFData(sku,storeId);
+    public PDFGoodsDto queryForPDFData(String sku, String storeId, String prodBarcode) {
+        return goodsDao.queryForPDFData(sku,storeId,prodBarcode);
     }
 /*  @Override
     @Transactional

+ 4 - 0
kmall-admin/src/main/java/com/kmall/admin/utils/pdf/PdfUtil.java

@@ -34,6 +34,10 @@ public class PdfUtil {
               PDFWrite_12 pdfWrite12 = new PDFWrite_12();
               pdfWrite12.write(document,writer,pdfGoodsDto,fontUrl,uploadDir,headUrl);
               break;
+          case "18":
+              PDFWrite_18 pdfWrite18 = new PDFWrite_18();
+              pdfWrite18.write(document,writer,pdfGoodsDto,fontUrl,uploadDir,headUrl);
+              break;
           case "36":
               if ("1".equals(head)) {
                   PDFWrite_36 pdfWrite36 = new PDFWrite_36();

+ 5 - 5
kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_12.java

@@ -70,7 +70,7 @@ public class PDFWrite_12 {
         table = new PdfPTable(3);
 
         for (int i = 0; i < 3; i++) {
-            setTable(bfHei, table, 22, pdfGoodsDto.getProductName());
+            setTable(bfHei, table, 16, pdfGoodsDto.getProductName());
         }
 
         doc.add(table);
@@ -90,7 +90,7 @@ public class PDFWrite_12 {
         table = new PdfPTable(3);
 
         for (int i = 0; i < 3; i++) {
-            setTable(bfHei, table, 14, pdfGoodsDto.getEnglishName());
+            setTable(bfHei, table, 12, pdfGoodsDto.getEnglishName());
         }
         doc.add(table);
 
@@ -104,14 +104,14 @@ public class PDFWrite_12 {
 
 
             // --------------大价格-------------------------------
-            Font font = new Font(bfHei, 54);
+            Font font = new Font(bfHei, 44);
             Paragraph bigPrice = new Paragraph("¥"+pdfGoodsDto.getPrice().substring(0,pdfGoodsDto.getPrice().indexOf(".")), font);
             PdfPCell priceCell = new PdfPCell(bigPrice);
             setBasisStyle(priceCell, Element.ALIGN_RIGHT, Element.ALIGN_CENTER);
             pdfPTable4.addCell(priceCell);
 
             // --------------小价格-------------------------------
-            font = new Font(bfHei, 40);
+            font = new Font(bfHei, 30);
             Paragraph smallPrice = new Paragraph(pdfGoodsDto.getPrice().substring(pdfGoodsDto.getPrice().indexOf(".")), font);
             PdfPCell smallPriceCell = new PdfPCell(smallPrice);
             setBasisStyle(smallPriceCell, Element.ALIGN_LEFT, Element.ALIGN_CENTER);
@@ -137,7 +137,7 @@ public class PDFWrite_12 {
         table = new PdfPTable(3);
 
         for (int i = 0; i < 3; i++) {
-            setTable(bfHei, table, 16, "比建议零售价省¥"+pdfGoodsDto.getSavings());
+            setTable(bfHei, table, 12, "比建议零售价省¥"+pdfGoodsDto.getSavings());
         }
 
         doc.add(table);

+ 224 - 0
kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_18.java

@@ -0,0 +1,224 @@
+package com.kmall.admin.utils.pdf.type;
+
+import com.kmall.api.entity.exportpdf.PDFGoodsDto;
+import com.lowagie.text.*;
+import com.lowagie.text.pdf.*;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * @author zhangchuangbiao
+ * @version 1.0
+ * 2020-09-11 09:51
+ */
+public class PDFWrite_18 {
+
+
+    public void write(com.lowagie.text.Document doc, com.lowagie.text.pdf.PdfWriter writer, PDFGoodsDto pdfGoodsDto
+            , String fontUrl, String uploadDir, String headUrl) throws IOException, com.lowagie.text.DocumentException {
+
+        // 设置字体
+        com.lowagie.text.pdf.BaseFont bfHei = com.lowagie.text.pdf.BaseFont.createFont(fontUrl, com.lowagie.text.pdf.BaseFont.IDENTITY_H, com.lowagie.text.pdf.BaseFont.NOT_EMBEDDED);
+        com.lowagie.text.Font FontChinese11 = new com.lowagie.text.Font(bfHei, 11);
+
+        String path = uploadDir;
+        FileOutputStream out = new FileOutputStream(path);
+
+        doc.setMargins(0,0,0,0);
+
+        writer.setPdfVersion(com.lowagie.text.pdf.PdfWriter.PDF_VERSION_1_2);//版本(默认1.4)
+        doc.open();// 打开文档
+
+        // -----------------------标签头----------------------
+        getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto,headUrl);
+        getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto,headUrl);
+        getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto,headUrl);
+
+
+        doc.close();  //记得关闭document
+
+    }
+
+    private static void getPdfPTable(com.lowagie.text.Font fontChinese11, BaseFont bfHei, Document doc,
+                                     PDFGoodsDto pdfGoodsDto, String headUrl) throws IOException, com.lowagie.text.DocumentException {
+        PdfPTable table = new PdfPTable(3);
+        table = new PdfPTable(6);
+
+        for (int i = 0; i < 6; i++) {
+            Image img = Image.getInstance(headUrl);
+            img.setAlignment(Image.ALIGN_CENTER);  //设置图片居中
+
+            PdfPCell p = new PdfPCell(img,true);
+            p.setPaddingLeft(2);
+            p.setPaddingRight(2);
+            p.setPaddingTop(2);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+                canvas.moveTo(position.getLeft(), position.getTop());
+                canvas.lineTo(position.getRight(), position.getTop());
+            });
+
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+        doc.add(table);
+
+        // --------------产品名称-------------------------------
+        table = new PdfPTable(6);
+
+        for (int i = 0; i < 6; i++) {
+            setTable(bfHei, table, 16, pdfGoodsDto.getProductName());
+        }
+
+        doc.add(table);
+
+        Paragraph blankRow31 = new Paragraph(18f, " ", fontChinese11);
+        PdfPCell nextLine = new PdfPCell(blankRow31);
+        nextLine.setBorder(0);
+        nextLine.setCellEvent((cell,position,canvases)->{
+            PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+            cellRight(position, canvas);
+        });
+//        doc.add(nextLine);
+
+
+
+        // --------------产品英文名称-------------------------------
+        table = new PdfPTable(6);
+
+        for (int i = 0; i < 6; i++) {
+            setTable(bfHei, table, 10, pdfGoodsDto.getEnglishName());
+        }
+        doc.add(table);
+
+
+        table = new PdfPTable(6);
+
+        for (int i = 0; i < 6; i++) {
+            PdfPTable pdfPTable4 = new PdfPTable(2);
+            pdfPTable4.setWidths(new int[]{10,6});
+
+
+
+            // --------------大价格-------------------------------
+            Font font = new Font(bfHei, 28);
+            Paragraph bigPrice = new Paragraph("¥"+pdfGoodsDto.getPrice().substring(0,pdfGoodsDto.getPrice().indexOf(".")), font);
+            PdfPCell priceCell = new PdfPCell(bigPrice);
+            setBasisStyle(priceCell, Element.ALIGN_RIGHT, Element.ALIGN_CENTER);
+            pdfPTable4.addCell(priceCell);
+
+            // --------------小价格-------------------------------
+            font = new Font(bfHei, 20);
+            Paragraph smallPrice = new Paragraph(pdfGoodsDto.getPrice().substring(pdfGoodsDto.getPrice().indexOf(".")), font);
+            PdfPCell smallPriceCell = new PdfPCell(smallPrice);
+            setBasisStyle(smallPriceCell, Element.ALIGN_LEFT, Element.ALIGN_CENTER);
+            pdfPTable4.addCell(smallPriceCell);
+
+            PdfPCell p = new PdfPCell(pdfPTable4);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+            });
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+
+
+        doc.add(table);
+
+        // --------------空格--------------
+
+//        doc.add(nextLine);
+
+        // --------------底部1-------------------------------
+        table = new PdfPTable(6);
+
+        for (int i = 0; i < 6; i++) {
+            setTable(bfHei, table, 10, "比建议零售价省¥"+pdfGoodsDto.getSavings());
+        }
+
+        doc.add(table);
+
+
+        // --------------底部2-------------------------------
+        table = new PdfPTable(6);
+        for (int i = 0; i < 6; i++) {
+            setTable(bfHei, table, 8, "税率:"+pdfGoodsDto.getStartFax());
+        }
+        doc.add(table);
+
+        table = new PdfPTable(6);
+        for (int i = 0; i < 6; i++) {
+            // --------------底部左边PLU-------------------------------
+            PdfPTable pdfPTable7 = new PdfPTable(2);
+            Font font = new Font(bfHei, 7);
+            Paragraph PLU = new Paragraph(pdfGoodsDto.getPlu(), font);
+            PdfPCell pluCell = new PdfPCell(PLU);
+            setBasisStyle(pluCell, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE);
+            pluCell.setPaddingLeft(10);
+            // --------------底部右边条形码-------------------------------
+            Paragraph barCode = new Paragraph(pdfGoodsDto.getBarCode(), font);
+            PdfPCell barCodeCell = new PdfPCell(barCode);
+            setBasisStyle(barCodeCell, Element.ALIGN_RIGHT, Element.ALIGN_MIDDLE);
+            barCodeCell.setPaddingRight(10);
+            pdfPTable7.addCell(pluCell);
+            pdfPTable7.addCell(barCodeCell);
+            PdfPCell p = new PdfPCell(pdfPTable7);
+            p.setBorder(0);
+            p.setCellEvent((cell,position,canvases)->{
+                PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+                cellRight(position, canvas);
+            });
+            table.setWidthPercentage(100f);
+            table.addCell(p);
+        }
+        doc.add(table);
+
+//        doc.add(nextLine);
+
+    }
+
+    // 绘制右边边框虚线
+    private static void cellRight(Rectangle position, PdfContentByte canvas) {
+        canvas.saveState();
+        canvas.setLineWidth(0.5f);
+        canvas.setLineDash(new float[]{5.0f, 5.0f}, 0);
+        canvas.moveTo(position.getRight(), position.getTop());
+        canvas.lineTo(position.getRight(), position.getBottom());
+        canvas.stroke();
+    }
+
+    // 去除边框,设置水平垂直居中
+    private static void setBasisStyle(PdfPCell pluCell, int alignLeft, int alignMiddle) {
+        pluCell.setBorder(0);
+        pluCell.setHorizontalAlignment(alignLeft); // 水平居中
+        pluCell.setVerticalAlignment(alignMiddle); // 垂直居中
+    }
+
+    private static void setTable(BaseFont bfHei, PdfPTable table, int i2, String s) {
+        Font font = new Font(bfHei, i2); // 设置字体
+        PdfPTable pdfPTable3 = new PdfPTable(1);
+        Paragraph pararaph = new Paragraph(s, font); // 段落
+        PdfPCell nameCell = new PdfPCell(pararaph); // 单元Cell
+        setBasisStyle(nameCell, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
+        pdfPTable3.addCell(nameCell);
+
+        // 创建PCell来存储PTable,用来去除边框
+        PdfPCell p = new PdfPCell(pdfPTable3);
+        p.setBorder(0);
+        // 设置虚线边框
+        p.setCellEvent((cell, position, canvases) -> {
+            PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
+            cellRight(position, canvas);
+        });
+        // 填充满
+        table.setWidthPercentage(100f);
+        table.addCell(p);
+    }
+
+
+}

+ 1 - 1
kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_36.java

@@ -109,7 +109,7 @@ public class PDFWrite_36 {
 
 
             // --------------大价格-------------------------------
-            Font font = new Font(bfHei, 22);
+            Font font = new Font(bfHei, 20);
             Paragraph bigPrice = new Paragraph("¥"+pdfGoodsDto.getPrice().substring(0,pdfGoodsDto.getPrice().indexOf(".")), font);
             PdfPCell priceCell = new PdfPCell(bigPrice);
             setBasisStyle(priceCell, Element.ALIGN_RIGHT, Element.ALIGN_CENTER);

+ 3 - 0
kmall-admin/src/main/resources/mybatis/mapper/GoodsDao.xml

@@ -704,6 +704,9 @@
             <if test="sku != null and storeId != ''">
                and g.sku = #{sku}
             </if>
+            <if test="prodBarcode != null and prodBarcode != ''">
+                and g.prod_barcode = #{prodBarcode}
+            </if>
             <if test="storeId != null and storeId != ''">
                and rela.store_id = #{storeId}
             </if>