From e13ab12bbd9ec0f01f6b68604e6e6debd8fca269 Mon Sep 17 00:00:00 2001 From: xs Date: Wed, 3 Jul 2024 15:55:08 +0800 Subject: [PATCH] =?UTF-8?q?2.5.5=20printer=EF=BC=9A=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=B1=80=E5=9F=9F=E7=BD=91=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hw/printer/RuoYiPrinterApplication.java | 2 +- .../printer/controller/PrinterController.java | 20 ++++++++--- .../hw/printer/service/IPrinterService.java | 20 +++++++++-- .../printer/service/PrinterServiceImpl.java | 34 ++++++++++++++++--- .../com/hw/printer/utils/HwPrintUtil.java | 3 +- 5 files changed, 63 insertions(+), 16 deletions(-) diff --git a/hw-modules/hw-printer/src/main/java/com/hw/printer/RuoYiPrinterApplication.java b/hw-modules/hw-printer/src/main/java/com/hw/printer/RuoYiPrinterApplication.java index 0e0da93..9f7e22d 100644 --- a/hw-modules/hw-printer/src/main/java/com/hw/printer/RuoYiPrinterApplication.java +++ b/hw-modules/hw-printer/src/main/java/com/hw/printer/RuoYiPrinterApplication.java @@ -17,7 +17,7 @@ public class RuoYiPrinterApplication public static void main(String[] args) { SpringApplication.run(RuoYiPrinterApplication.class, args); - System.out.println("(♥◠‿◠)ノ゙ 文件服务模块启动成功 ლ(´ڡ`ლ)゙ \n" + + System.out.println("(♥◠‿◠)ノ゙ 打印服务模块启动成功 ლ(´ڡ`ლ)゙ \n" + " .-------. ____ __ \n" + " | _ _ \\ \\ \\ / / \n" + " | ( ' ) | \\ _. / ' \n" + diff --git a/hw-modules/hw-printer/src/main/java/com/hw/printer/controller/PrinterController.java b/hw-modules/hw-printer/src/main/java/com/hw/printer/controller/PrinterController.java index 41f675f..2c7ad46 100644 --- a/hw-modules/hw-printer/src/main/java/com/hw/printer/controller/PrinterController.java +++ b/hw-modules/hw-printer/src/main/java/com/hw/printer/controller/PrinterController.java @@ -1,8 +1,10 @@ package com.hw.printer.controller; import com.hw.common.core.domain.R; +import com.hw.common.core.utils.ip.IpUtils; import com.hw.mes.api.domain.MesBaseBarcodeInfo; import com.hw.printer.api.domain.vo.PrintContentVo; +import com.hw.printer.api.domain.vo.PrinterVo; import com.hw.printer.service.IPrinterService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,13 +29,21 @@ public class PrinterController { /** * 批量打印物料条码接口 - * @param printContents + * @param printerVo * @return */ @PostMapping("/printBarcodes") - public R printBarcodes(@RequestBody List> printContents) { + public R printBarcodes(@RequestBody PrinterVo printerVo) { try { - printerService.printBarcodes(printContents); + String hostIp = IpUtils.getHostIp(); + String printType = printerVo.getPrintType(); + List> printContents = printerVo.getPrintContents(); + if(printType.equals(PrinterVo.PRINT_TYPE_RAW_LABEL)){ + printerService.printBarcodes(printContents,hostIp); + }else if(printType.equals(PrinterVo.PRINT_TYPE_PRODUCT_LABEL)){ + printerService.printProductBarcodes(printContents,hostIp); + } + return R.ok(); } catch (Exception e) { log.error("打印条码失败", e); @@ -41,7 +51,6 @@ public class PrinterController { } } - /** * 打印库位条码 * @param params @@ -50,7 +59,8 @@ public class PrinterController { @PostMapping("/printLocationLabel") public R printLocationLabel(@RequestBody HashMap params) { try { - printerService.printLocationLabel(params); + String hostIp = IpUtils.getHostIp(); + printerService.printLocationLabel(params,hostIp); return R.ok(); } catch (Exception e) { log.error("打印条码失败", e); diff --git a/hw-modules/hw-printer/src/main/java/com/hw/printer/service/IPrinterService.java b/hw-modules/hw-printer/src/main/java/com/hw/printer/service/IPrinterService.java index 1cc06ba..4a00eb3 100644 --- a/hw-modules/hw-printer/src/main/java/com/hw/printer/service/IPrinterService.java +++ b/hw-modules/hw-printer/src/main/java/com/hw/printer/service/IPrinterService.java @@ -15,18 +15,32 @@ import java.util.List; public interface IPrinterService { /** - * 打印条码接口 + * 打印原材料条码接口 + * * @param printContents + * @param ipAddress 客户端IP地址 * @return * @throws Exception */ - public void printBarcodes(List> printContents) throws Exception; + public void printBarcodes(List> printContents,String ipAddress) throws Exception; + /** + * 打印成品条码接口 + * + * @param printContents + * @param ipAddress 客户端IP地址 + * @return + * @throws Exception + */ + public void printProductBarcodes(List> printContents,String ipAddress) throws Exception; + /** * 打印库位条码接口 + * * @param params + * @param ipAddress 客户端IP地址 * @return */ - public void printLocationLabel(HashMap params) throws IOException; + public void printLocationLabel(HashMap params,String ipAddress) throws IOException; } diff --git a/hw-modules/hw-printer/src/main/java/com/hw/printer/service/PrinterServiceImpl.java b/hw-modules/hw-printer/src/main/java/com/hw/printer/service/PrinterServiceImpl.java index b99bfc1..3a173b3 100644 --- a/hw-modules/hw-printer/src/main/java/com/hw/printer/service/PrinterServiceImpl.java +++ b/hw-modules/hw-printer/src/main/java/com/hw/printer/service/PrinterServiceImpl.java @@ -65,14 +65,15 @@ public class PrinterServiceImpl implements IPrinterService { /** - * 打印条码接口 + * 打印原材料条码接口 * * @param printContents + * @param ipAddress 客户端IP地址 * @return * @throws Exception */ @Override - public void printBarcodes(List> printContents) throws Exception { + public void printBarcodes(List> printContents,String ipAddress) throws Exception { // HashMap params = new HashMap<>(); // params.put("localPrintPath", localPrintPath); // params.put("pdfTemplatePath", pdfTemplatePath); @@ -81,20 +82,43 @@ public class PrinterServiceImpl implements IPrinterService { // params.put("batchCode", barcodeInfo.getBatchCode()); // params.put("materialName", barcodeInfo.getMaterialName()); // params.put("date", DateUtils.getDate()); - HwPrintUtil.printBarcodes(localPrintPath, pdfTemplatePath, + HwPrintUtil.printBarcodes(ipAddress, pdfTemplatePath, generatePath, printContents); } + /** + * 打印成品条码接口 + * + * @param printContents + * @param ipAddress 客户端IP地址 + * @return + * @throws Exception + */ + @Override + public void printProductBarcodes(List> printContents,String ipAddress) throws Exception { +// HashMap params = new HashMap<>(); +// params.put("localPrintPath", localPrintPath); +// params.put("pdfTemplatePath", pdfTemplatePath); +// params.put("generatePath", generatePath); +// params.put("barcodeInfo", barcodeInfo.getBarcodeInfo()); +// params.put("batchCode", barcodeInfo.getBatchCode()); +// params.put("materialName", barcodeInfo.getMaterialName()); +// params.put("date", DateUtils.getDate()); + HwPrintUtil.printBarcodes(ipAddress, productLabelTemplatePath, + generateProductLabelPath, printContents); + } + /** * 打印库位条码接口 * * @param params + * @param ipAddress 客户端IP地址 * @return */ @Override - public void printLocationLabel(HashMap params) throws IOException { - HwPrintUtil.printLocationQRCode(localPrintPath, locationLabelTemplatePath, + public void printLocationLabel(HashMap params,String ipAddress) throws IOException { + HwPrintUtil.printLocationQRCode(ipAddress, locationLabelTemplatePath, generateLocationLabelPath, params); } diff --git a/hw-modules/hw-printer/src/main/java/com/hw/printer/utils/HwPrintUtil.java b/hw-modules/hw-printer/src/main/java/com/hw/printer/utils/HwPrintUtil.java index aaa940e..7207403 100644 --- a/hw-modules/hw-printer/src/main/java/com/hw/printer/utils/HwPrintUtil.java +++ b/hw-modules/hw-printer/src/main/java/com/hw/printer/utils/HwPrintUtil.java @@ -61,9 +61,7 @@ public class HwPrintUtil { // localPrintPath = "导出"; // localPrintPath = "ZD"; for (PrintService service : printServices) { - System.out.println(service.getName()); if (service.getName().contains(localPrintPath)) { - printService = service; break; } @@ -146,6 +144,7 @@ public class HwPrintUtil { PdfStamper stamper = new PdfStamper(reader, bos); // 动态地将变量的值填充到PDF表单相应字段 AcroFields form = stamper.getAcroFields(); + form.setFieldProperty("materialName", "multiline", true, null); for (PrintContentVo printContentVo : printContentVos) { if (printContentVo.getType() == PrintContentVo.TYPE_TEXT) { form.setField(printContentVo.getKey(), printContentVo.getValue());