From 1f9687b20db97f5df66ff7405fb386c72801feaa Mon Sep 17 00:00:00 2001 From: funny <834502597@qq.com> Date: Tue, 14 Apr 2026 11:31:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/NormalPGIControllerService.java | 2 +- .../common/pojo/dto/MaterialCodePrintDTO.java | 64 +++++++++++++ .../controller/MaterialCodeController.java | 43 +++++++++ .../controller/PackagingCodeController.java | 33 +++++++ .../template/label/material-pdf.html | 96 +++++++++++++++++++ .../template/label/packaging-pdf.html | 68 +++++++++++++ 6 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/dto/MaterialCodePrintDTO.java create mode 100644 nflg-wms-shipment/src/main/resources/template/label/material-pdf.html create mode 100644 nflg-wms-shipment/src/main/resources/template/label/packaging-pdf.html diff --git a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/service/NormalPGIControllerService.java b/nflg-wms-admin/src/main/java/com/nflg/wms/admin/service/NormalPGIControllerService.java index 87b502fc..e64adcf2 100644 --- a/nflg-wms-admin/src/main/java/com/nflg/wms/admin/service/NormalPGIControllerService.java +++ b/nflg-wms-admin/src/main/java/com/nflg/wms/admin/service/NormalPGIControllerService.java @@ -622,7 +622,7 @@ public class NormalPGIControllerService { // 这里需要同步一个信息,就是把箱码的状态也要改为收货状态, List parentIds = dto.getQrCodes().stream() .filter(qrCode -> qrCode.getPackagingType() == 0) - .map(WmsQrCodeMaster::getId) + .map(WmsQrCodeMaster::getParentBarcodeId) .distinct() .toList(); if (CollectionUtil.isNotEmpty(parentIds)) { diff --git a/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/dto/MaterialCodePrintDTO.java b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/dto/MaterialCodePrintDTO.java new file mode 100644 index 00000000..2aeb0f02 --- /dev/null +++ b/nflg-wms-common/src/main/java/com/nflg/wms/common/pojo/dto/MaterialCodePrintDTO.java @@ -0,0 +1,64 @@ +package com.nflg.wms.common.pojo.dto; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.math.BigDecimal; + +/** + * 物料码打印DTO + */ +@Data +@Accessors(chain = true) +public class MaterialCodePrintDTO { + + /** + * 二维码(Base64) + */ + private String qrCode; + + /** + * 唯一码 + */ + private String no; + + /** + * 物料编号 + */ + private String materialNo; + + /** + * 物料描述 + */ + private String materialDescribe; + + /** + * 数量 + */ + private BigDecimal num; + + /** + * 数量文本 + */ + private String numText; + + /** + * 单位 + */ + private String unit; + + /** + * 机台编号 + */ + private String deviceNo; + + /** + * 客户名称 + */ + private String customerName; + + /** + * 图片(Base64) + */ + private String lst; +} diff --git a/nflg-wms-shipment/src/main/java/com/nflg/wms/shipment/controller/MaterialCodeController.java b/nflg-wms-shipment/src/main/java/com/nflg/wms/shipment/controller/MaterialCodeController.java index 946a9425..db413d77 100644 --- a/nflg-wms-shipment/src/main/java/com/nflg/wms/shipment/controller/MaterialCodeController.java +++ b/nflg-wms-shipment/src/main/java/com/nflg/wms/shipment/controller/MaterialCodeController.java @@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.nflg.wms.common.pojo.ApiResult; import com.nflg.wms.common.pojo.PageData; +import com.nflg.wms.common.pojo.dto.MaterialCodePrintDTO; import com.nflg.wms.common.pojo.dto.MaterialPdfDTO; import com.nflg.wms.common.pojo.qo.*; import com.nflg.wms.common.pojo.vo.MaterialPdfVO; @@ -51,6 +52,7 @@ import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; import java.net.URLEncoder; +import java.net.URL; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -819,4 +821,45 @@ public class MaterialCodeController extends BaseController { InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); return ApiResult.success(fileUploadService.upload("tmp/sp/" + RandomUtil.randomString(10) + "/" + material.getNo() + "老鼠图.pdf", inputStream, MediaType.APPLICATION_PDF_VALUE)); } + + /** + * 导出标签图片PDF(打印预览) + * + * @param response HTTP响应 + * @param ids 清单明细id列表 + */ + @PostMapping("exportToPdf") + public void exportToPdf(HttpServletResponse response, @RequestBody @NotEmpty List ids) throws Exception { + List datas = materialCodeItemQrService.getListVOByItemIds(ids); + VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(datas)).throwMessage("没有需要导出的数据"); + + // 获取物料图片 + Map images = materialService.lambdaQuery() + .select(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage) + .in(WmsShipmentMaterial::getNo, datas.stream().map(ShipmentMaterialCodeQRVO::getMaterialNo).collect(Collectors.toSet())) + .list() + .stream() + .collect(Collectors.toMap(WmsShipmentMaterial::getNo, WmsShipmentMaterial::getImage)); + + // 构建打印数据 + Map variables = new HashMap<>(); + variables.put("list", datas.stream() + .map(data -> new MaterialCodePrintDTO() + .setNo(data.getNo()) + .setQrCode(QRCodeUtil.generateQRCodeBase64(data.getNo(), 200, 200)) + .setMaterialNo(data.getMaterialNo()) + .setMaterialDescribe(data.getMaterialDescribe()) + .setNum(data.getNum()) + .setNumText(data.getNumText()) + .setUnit(data.getUnit()) + .setDeviceNo(data.getDeviceNo()) + .setCustomerName(data.getCustomerName()) + .setLst(images.get(data.getMaterialNo())) + ).toList() + ); + + String html = ThymeleafUtil.generator("/template/label/", "material-pdf", ".html", variables); + URL baseUrl = new ClassPathResource("template/label/").getURL(); + PdfGeneratorUtil.generatePdf("物料码标签", html, baseUrl.toString(), response); + } } \ No newline at end of file diff --git a/nflg-wms-shipment/src/main/java/com/nflg/wms/shipment/controller/PackagingCodeController.java b/nflg-wms-shipment/src/main/java/com/nflg/wms/shipment/controller/PackagingCodeController.java index c099aa5f..a7c1c572 100644 --- a/nflg-wms-shipment/src/main/java/com/nflg/wms/shipment/controller/PackagingCodeController.java +++ b/nflg-wms-shipment/src/main/java/com/nflg/wms/shipment/controller/PackagingCodeController.java @@ -22,6 +22,7 @@ import com.nflg.wms.repository.service.*; import com.nflg.wms.shipment.service.BasdeSerialNumberControllerService; import com.nflg.wms.shipment.util.HtmlToImageUtil; import com.nflg.wms.shipment.util.KeyUtil; +import com.nflg.wms.shipment.util.PdfGeneratorUtil; import com.nflg.wms.shipment.util.QRCodeUtil; import com.nflg.wms.shipment.util.ThymeleafUtil; import com.nflg.wms.starter.BaseController; @@ -34,10 +35,12 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.core.io.ClassPathResource; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import java.io.ByteArrayOutputStream; +import java.net.URL; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -406,4 +409,34 @@ public class PackagingCodeController extends BaseController { headers.setContentLength(zipBytes.length); return new ResponseEntity<>(zipBytes, headers, HttpStatus.OK); } + + /** + * 导出标签图片PDF(打印预览) + */ + @PostMapping("exportToPdf") + public void exportToPdf(HttpServletResponse response, @RequestBody @NotEmpty List list) throws Exception { + List types = dictionaryItemService.getListByDictionaryCode("PackagingType"); + + // 构建打印数据 + Map variables = new HashMap<>(); + variables.put("list", list.stream() + .map(data -> { + String typeName = types.stream() + .filter(type -> type.getId().equals(data.getType())) + .map(DictionaryItem::getName) + .findFirst() + .orElse(""); + ShipmentPackagingCodeVO vo = new ShipmentPackagingCodeVO(); + vo.setNo(data.getNo()); + vo.setName(data.getName()); + vo.setTypeName(typeName); + vo.setQrCode(QRCodeUtil.generateQRCodeBase64(data.getNo(), 100, 100)); + return vo; + }).toList() + ); + + String html = ThymeleafUtil.generator("/template/label/", "packaging-pdf", ".html", variables); + URL baseUrl = new ClassPathResource("template/label/").getURL(); + PdfGeneratorUtil.generatePdf("包装码标签", html, baseUrl.toString(), response); + } } diff --git a/nflg-wms-shipment/src/main/resources/template/label/material-pdf.html b/nflg-wms-shipment/src/main/resources/template/label/material-pdf.html new file mode 100644 index 00000000..4f85a029 --- /dev/null +++ b/nflg-wms-shipment/src/main/resources/template/label/material-pdf.html @@ -0,0 +1,96 @@ + + + + + 物料码标签 + + + + +
+ + + + + + + + + + + + + + + + + +
+ +
0PC7B724KV6FM
+
+ 机台编号 + + 26LBZ4000L001 + + 客户名称 + + 北京市京联鑫路用材料有限公司 +
+ 物料编码 + + 3100006701 + + 数量 + + 10 +
+ +
+
+ + diff --git a/nflg-wms-shipment/src/main/resources/template/label/packaging-pdf.html b/nflg-wms-shipment/src/main/resources/template/label/packaging-pdf.html new file mode 100644 index 00000000..434ca57f --- /dev/null +++ b/nflg-wms-shipment/src/main/resources/template/label/packaging-pdf.html @@ -0,0 +1,68 @@ + + + + + 包装码标签 + + + + +
+ + + + + +
+ +
NFLG-QZ-002
+
+
包装名称: NFLG-QZ-002 测试包装名称
+
包装类型: 托盘
+
+
+ +