Jelajahi Sumber

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

肖文浩 4 tahun lalu
induk
melakukan
0971d45c79

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

@@ -3,14 +3,17 @@ package com.kmall.admin.controller.exportPDF;
 import com.kmall.admin.service.GoodsService;
 import com.kmall.admin.utils.pdf.ViewPDF;
 import com.kmall.api.entity.exportpdf.PDFGoodsDto;
+import org.apache.http.HttpResponse;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.servlet.ModelAndView;
 
-import javax.annotation.Resource;
-import java.util.*;
+import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
 
 /**
  * @author zhangchuangbiao
@@ -33,18 +36,25 @@ public class ExportPDFController {
 
     //打印pdf
     @RequestMapping("/printPdf")
-    public ModelAndView printPdf(String head ,String type,String sku,String storeId,String headUrl,String prodBarcode) throws Exception {
+    public ModelAndView printPdf(String head , String type, String sku, String storeId, String headUrl, String prodBarcode, HttpServletResponse response) throws Exception {
 
-        PDFGoodsDto pdfGoodsDto = goodsService.queryForPDFData(sku,storeId,prodBarcode);
+        PDFGoodsDto pdfGoodsDto = goodsService.queryForPDFData(sku, storeId, prodBarcode);
+        if (Objects.isNull(pdfGoodsDto)) {
+            response.setContentType("text/html;charset=utf-8");
+            response.getWriter().write("<script>alert('该条件有误,请重新输入');</script>");
+            response.getWriter().flush();
+            return null;
+        }
 
-        if("1".equals(head)){
+
+        if ("1".equals(head)) {
             Map<String, Object> model = new HashMap<>();
             model.put("dto", pdfGoodsDto);
-            model.put("type",type);
-            model.put("head",head);
-            model.put("fontUrl",fontUrl);
-            model.put("uploadDir",uploadDir);
-            model.put("headUrl",headUrl);
+            model.put("type", type);
+            model.put("head", head);
+            model.put("fontUrl", fontUrl);
+            model.put("uploadDir", uploadDir);
+            model.put("headUrl", headUrl);
             return new ModelAndView(new ViewPDF(), model);
         }else if ("0".equals(head)){
             Map<String, Object> model = new HashMap<>();

+ 23 - 18
kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_nohead_36.java

@@ -34,18 +34,20 @@ public class PDFWrite_nohead_36 {
 
         writer.setPdfVersion(PdfWriter.PDF_VERSION_1_2);//版本(默认1.4)
         doc.open();// 打开文档
-        doc.setMargins(0,0,0,0);
-
+        doc.setMargins(0,0,-20,0);
+        String dtoBarCode = pdfGoodsDto.getBarCode();
+        byte[] bytes = BarcodeUtil.generateBarCode128(dtoBarCode, 9.0d, 1.28d, false, true);
+        String uploadUrl = FileManager.upload(dtoBarCode + UUID.randomUUID().toString(), bytes, String.valueOf(bytes.length));
         // -----------------------标签头----------------------
         for (int i = 0; i < 9; i++) {
-            getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto);
+            getPdfPTable(FontChinese11, bfHei, doc,pdfGoodsDto,uploadUrl);
         }
 
         doc.close();  //记得关闭document
 
     }
 
-    private static void getPdfPTable(Font fontChinese11, BaseFont bfHei, Document doc, PDFGoodsDto pdfGoodsDto) throws IOException, DocumentException {
+    private static void getPdfPTable(Font fontChinese11, BaseFont bfHei, Document doc, PDFGoodsDto pdfGoodsDto,String uploadUrl) throws IOException, DocumentException {
         PdfPTable table = new PdfPTable(4);
 
         // --------------产品名称-------------------------------
@@ -72,12 +74,12 @@ public class PDFWrite_nohead_36 {
         table = new PdfPTable(4);
 
         for (int i = 0; i < 4; i++) {
-           PdfPTable pdfPTable4 = new PdfPTable(1);
-            Font font = new Font(bfHei, 20);
+//           PdfPTable pdfPTable4 = new PdfPTable(1);
+            Font font = new Font(bfHei, 18);
             Paragraph bigPrice = new Paragraph("¥"+pdfGoodsDto.getPrice().substring(0,pdfGoodsDto.getPrice().indexOf(".")), font);
             bigPrice.setAlignment(Element.ALIGN_BOTTOM);
             // --------------小价格-------------------------------
-            font = new Font(bfHei, 10);
+            font = new Font(bfHei, 9);
             Paragraph smallPrice = new Paragraph(pdfGoodsDto.getPrice().substring(pdfGoodsDto.getPrice().indexOf(".")), font);
             smallPrice.setAlignment(Element.ALIGN_BOTTOM);
             smallPrice.setIndentationLeft(50);
@@ -87,14 +89,15 @@ public class PDFWrite_nohead_36 {
 
             PdfPCell priceCell = new PdfPCell(bigPrice);
             priceCell.setBorder(0);
-            priceCell.setHorizontalAlignment(Element.ALIGN_LEFT); // 水平居中
-            priceCell.setVerticalAlignment(Element.ALIGN_BOTTOM); // 垂直居中
-            pdfPTable4.addCell(priceCell);
+            priceCell.setHorizontalAlignment(Element.ALIGN_RIGHT); // 右边
+            priceCell.setVerticalAlignment(Element.ALIGN_BOTTOM); // 下面
+            priceCell.setPaddingRight(15f);
+//            pdfPTable4.addCell(priceCell);
 
 
             // ----------------test-----------------------
             PdfPTable pdfPTable8 = new PdfPTable(2);
-            pdfPTable8.setWidths(new int[]{10,8});
+            pdfPTable8.setWidths(new int[]{10,11});
             font = new Font(bfHei, 6);
             // --------------左上的字-------------------------------
             Paragraph leftParagraph1 = new Paragraph("\n建议零售价省¥"+pdfGoodsDto.getSavings()+"\n\n", font);
@@ -110,7 +113,7 @@ public class PDFWrite_nohead_36 {
 
             PdfPCell p = new PdfPCell(pdfPTable8);
             p.setBorder(0);
-            table.setWidthPercentage(110f);
+            table.setWidthPercentage(112f);
             table.addCell(p);
         }
 
@@ -118,15 +121,15 @@ public class PDFWrite_nohead_36 {
         doc.add(table);
         String dtoBarCode = pdfGoodsDto.getBarCode();
         table = new PdfPTable(4);
-        byte[] bytes = BarcodeUtil.generateBarCode128(dtoBarCode, 9.0d, 1.28d, false, true);
-        String uploadUrl = FileManager.upload(dtoBarCode + UUID.randomUUID().toString(), bytes, String.valueOf(bytes.length));
+
         for (int i = 0; i < 4; i++) {
             // --------------底部黑色和条形码区域-------------------------------
             PdfPTable pdfPTable7 = new PdfPTable(2);
+            pdfPTable7.setWidths(new int[]{8,10});
             Font font = new Font(bfHei, 5.5f);
             font.setColor(Color.WHITE);
             Paragraph PLU = new Paragraph(pdfGoodsDto.getPlu(), font);
-            Paragraph blankParagraph = new Paragraph("                        ", font);
+            Paragraph blankParagraph = new Paragraph("                   ", font);
             Paragraph barCode = new Paragraph(dtoBarCode.substring(dtoBarCode.length()-4), font);
             blankParagraph.add(barCode);
             PLU.add(blankParagraph);
@@ -144,14 +147,15 @@ public class PDFWrite_nohead_36 {
             img.setAlignment(Image.ALIGN_CENTER);  //设置图片居中
             img.setBorder(Image.NO_BORDER);
             img.setBorderColor(Color.WHITE);
-            img.scaleAbsolute(72,10.5f);
+            img.scaleAbsolute(63,10.5f);
             PdfPCell imgCell = new PdfPCell(img,false);
             imgCell.setBorder(0);
+            imgCell.setPaddingLeft(3f);
             pdfPTable7.addCell(pluCell);
             pdfPTable7.addCell(imgCell);
             PdfPCell p = new PdfPCell(pdfPTable7);
             p.setBorder(0);
-            table.setWidthPercentage(110f);
+            table.setWidthPercentage(112f);
             table.addCell(p);
         }
         doc.add(table);
@@ -179,8 +183,9 @@ public class PDFWrite_nohead_36 {
         Font font = new Font(bfHei, i2); // 设置字体
         Paragraph paragraph = new Paragraph(s, font); // 段落
         PdfPCell nameCell = new PdfPCell(paragraph); // 单元Cell
+        nameCell.setPaddingRight(10f);
         setBasisStyle(nameCell, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE);
-        table.setWidthPercentage(110f);
+        table.setWidthPercentage(112f);
         table.addCell(nameCell);
     }
 

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

@@ -692,7 +692,7 @@
             g.name as productName,
             g.english_name as englishName,
             rela.retail_price as price,
-            (rela.market_price - rela.retail_price ) as savings,
+            IFNULL((rela.market_price - rela.retail_price ),0) as savings,
             g.goods_rate as startFax,
             g.goods_rate as endFax,
             g.plu as plu,
@@ -701,7 +701,7 @@
             mall_goods g
         left join mall_product_store_rela rela on g.id = rela.goods_id
         <where>
-            <if test="sku != null and storeId != ''">
+            <if test="sku != null and sku != ''">
                and g.sku = #{sku}
             </if>
             <if test="prodBarcode != null and prodBarcode != ''">

+ 20 - 19
kmall-admin/src/main/webapp/js/shop/goodsexportpdf.js

@@ -32,8 +32,8 @@ let vm = new Vue({
     },
     methods: {
         changeHead:function(){
-            console.log(vm.q)
-            console.log(vm.selectButtonDisabled)
+            // console.log(vm.q)
+            // console.log(vm.selectButtonDisabled)
             if (vm.q.isHead=='0'){
                 vm.pdfTypes=[ {id: '36',
                     name: '36规格'}
@@ -66,34 +66,35 @@ let vm = new Vue({
             }
 
         },
-		selectLabelHead: function () {
-
-
-
-
-			alert("selectLabelHead")
-		},
+		// selectLabelHead: function () {
+        //
+        //
+        //
+        //
+		// 	alert("selectLabelHead")
+		// },
 
 		exportPdf: function () {
-
-            window.open("../pdf/printPdf?type="+vm.q.pdfType+"&sku="+vm.q.sku+"&barCode="+vm.q.barCode+"&head="+vm.q.isHead+"&headUrl="+vm.q.headUrl+"&storeId="+vm.q.storeId);
-
-            $.get("../pdf/printPdf?type="+vm.q.pdfType+"&sku="+vm.q.sku+"&barCode="+vm.q.barCode+"&head="+vm.q.isHead+"&headUrl="+vm.q.headUrl+"&storeId="+vm.q.storeId, function (r) {
-                vm.mall2OrderingEarlyWarningReminds = r.mall2OrderingEarlyWarningReminds;
-            });
-        },
-        barCodeEnter:function() {
             if (vm.q.storeId==''){
                 alert("请先选择门店")
                 return;
             }
-            if (vm.q.sku==''){
-                alert("请先输入sku")
+            if (vm.q.sku=='' && vm.q.barCode==''){
+                alert("请先输入sku或者条形码")
                 return;
             }
 
+            window.open("../pdf/printPdf?type="+vm.q.pdfType+"&sku="+vm.q.sku+"&barCode="+vm.q.barCode+"&head="+vm.q.isHead+"&headUrl="+vm.q.headUrl+"&storeId="+vm.q.storeId);
+
+            $.get("../pdf/printPdf?type="+vm.q.pdfType+"&sku="+vm.q.sku+"&barCode="+vm.q.barCode+"&head="+vm.q.isHead+"&headUrl="+vm.q.headUrl+"&storeId="+vm.q.storeId, function (r) {
+                console.log(r)
+                alert(r)
+            });
+		},
+        barCodeEnter:function () {
             this.exportPdf();
         }
+
 	},
     mounted() {