xwh 4 anni fa
parent
commit
434462ad05

+ 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<>();

+ 14 - 13
kmall-admin/src/main/java/com/kmall/admin/utils/pdf/type/PDFWrite_nohead_36.java

@@ -72,12 +72,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,15 +87,15 @@ public class PDFWrite_nohead_36 {
 
             PdfPCell priceCell = new PdfPCell(bigPrice);
             priceCell.setBorder(0);
-            priceCell.setHorizontalAlignment(Element.ALIGN_LEFT); // 水平居中
-            priceCell.setVerticalAlignment(Element.ALIGN_BOTTOM); // 垂直居中
-            priceCell.setPaddingRight(5f);
-            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);
@@ -111,7 +111,7 @@ public class PDFWrite_nohead_36 {
 
             PdfPCell p = new PdfPCell(pdfPTable8);
             p.setBorder(0);
-            table.setWidthPercentage(110f);
+            table.setWidthPercentage(112f);
             table.addCell(p);
         }
 
@@ -128,7 +128,7 @@ public class PDFWrite_nohead_36 {
             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);
@@ -146,7 +146,7 @@ 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);
@@ -154,7 +154,7 @@ public class PDFWrite_nohead_36 {
             pdfPTable7.addCell(imgCell);
             PdfPCell p = new PdfPCell(pdfPTable7);
             p.setBorder(0);
-            table.setWidthPercentage(110f);
+            table.setWidthPercentage(112f);
             table.addCell(p);
         }
         doc.add(table);
@@ -182,8 +182,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);
     }
 

+ 11 - 10
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,13 +66,13 @@ let vm = new Vue({
             }
 
         },
-		selectLabelHead: function () {
-
-
-
-
-			alert("selectLabelHead")
-		},
+		// selectLabelHead: function () {
+        //
+        //
+        //
+        //
+		// 	alert("selectLabelHead")
+		// },
 
 		exportPdf: function () {
             if (vm.q.storeId==''){
@@ -87,7 +87,8 @@ let vm = new Vue({
             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;
+                console.log(r)
+                alert(r)
             });
 		},
         barCodeEnter:function () {