From a042d3e3808061be7eac907654c64d04d7bce9da Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Wed, 14 Oct 2026 16:21:20 +0800 Subject: [PATCH] =?UTF-8?q?boxPackCount=E4=B8=8EQTY=E4=B8=80=E4=B8=80?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=EF=BC=8C=E5=BD=93=E5=89=8D=E5=A4=96=E7=AE=B1?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=8C=85=E6=95=B0=EF=BC=8C=E6=8C=89=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E4=B8=8B=E6=A0=87=E5=8D=B0=E5=88=B0=E8=AF=A5=E5=BC=A0?= =?UTF-8?q?=E5=A4=96=E7=AE=B1=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Impl/ReportLabelListServiceImpl.java | 61 +++++++++++++++++-- .../resources/i18n/messages_en_US.properties | 4 ++ .../resources/i18n/messages_zh_CN.properties | 4 ++ 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gaotao/modules/base/service/Impl/ReportLabelListServiceImpl.java b/src/main/java/com/gaotao/modules/base/service/Impl/ReportLabelListServiceImpl.java index 56e05c49..e3ded310 100644 --- a/src/main/java/com/gaotao/modules/base/service/Impl/ReportLabelListServiceImpl.java +++ b/src/main/java/com/gaotao/modules/base/service/Impl/ReportLabelListServiceImpl.java @@ -714,6 +714,7 @@ public class ReportLabelListServiceImpl extends ServiceImpl outerQtyList = extractRequiredOuterQtyList(customFields); + // boxPackCount与QTY等长,按下标取当前外箱的内包数,避免整段数组被印到每一张标签上 + List boxPackCountList = extractRequiredBoxPackCountList(customFields, outerQtyList.size()); int outerBatchIndex = 1; for (String outerQty : outerQtyList) { - Map outerCustomFields = buildOuterCustomFields(customFields, outerQty, outerBatchIndex, outerQtyList.size()); + String boxPackCount = boxPackCountList.get(outerBatchIndex - 1); + Map outerCustomFields = buildOuterCustomFields( + customFields, outerQty, boxPackCount, outerBatchIndex, outerQtyList.size()); queryParams.put("customFields", outerCustomFields); // 生成当前QTY对应的外箱标签(同一queryParams会复用IFS缓存) @@ -747,8 +752,8 @@ public class ReportLabelListServiceImpl extends ServiceImpl labelData = i < labelDataList.size() ? labelDataList.get(i) : new HashMap<>(); Long taskId = enqueueSingleTask(outerPrinter.getIpAddress(), zplCode, outerRfidFlag, labelData, printRequest); taskIds.add(taskId); - log.info("外箱标签任务已加入队列,batch={} / {}, index={} / {}, qty={}, taskId={}", - outerBatchIndex, outerQtyList.size(), i + 1, totalLabels, outerQty, taskId); + log.info("外箱标签任务已加入队列,batch={} / {}, index={} / {}, qty={}, boxPackCount={}, taskId={}", + outerBatchIndex, outerQtyList.size(), i + 1, totalLabels, outerQty, boxPackCount, taskId); } outerBatchIndex++; } @@ -958,26 +963,36 @@ public class ReportLabelListServiceImpl extends ServiceImpl buildOuterCustomFields(Map sourceCustomFields, String outerQty, - int serialNumber, int outerBoxes) { + String boxPackCount, int serialNumber, int outerBoxes) { Map outerCustomFields = new HashMap<>(); if (sourceCustomFields != null && !sourceCustomFields.isEmpty()) { outerCustomFields.putAll(sourceCustomFields); } boolean qtyUpdated = false; + boolean boxPackCountUpdated = false; for (String key : new ArrayList<>(outerCustomFields.keySet())) { - if (StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(key), "qty")) { + String normalizedKey = StringUtils.trimToEmpty(key); + if (StringUtils.equalsIgnoreCase(normalizedKey, "qty")) { outerCustomFields.put(key, outerQty); qtyUpdated = true; + } else if (StringUtils.equalsIgnoreCase(normalizedKey, "boxPackCount")) { + outerCustomFields.put(key, boxPackCount); + boxPackCountUpdated = true; } } if (!qtyUpdated) { outerCustomFields.put("qty", outerQty); } + if (!boxPackCountUpdated) { + outerCustomFields.put("boxPackCount", boxPackCount); + } outerCustomFields.put("serialNumber", serialNumber); outerCustomFields.put("outerBoxes", outerBoxes); + outerCustomFields.put("boxPackCount", boxPackCount); return outerCustomFields; } @@ -1011,6 +1026,40 @@ public class ReportLabelListServiceImpl extends ServiceImpl extractRequiredBoxPackCountList(Map customFields, int expectedSize) { + if (customFields == null || customFields.isEmpty()) { + throw new RuntimeException(labelSettingI18n.text("label.error.boxPackCountRequired")); + } + Object packValue = null; + for (Map.Entry entry : customFields.entrySet()) { + if (StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(entry.getKey()), "boxPackCount")) { + packValue = entry.getValue(); + break; + } + } + if (!(packValue instanceof List packList) || packList.isEmpty()) { + throw new RuntimeException(labelSettingI18n.text("label.error.boxPackCountArrayRequired")); + } + if (packList.size() != expectedSize) { + throw new RuntimeException(labelSettingI18n.text( + "label.error.boxPackCountSizeMismatch", expectedSize, packList.size())); + } + List boxPackCountList = new ArrayList<>(); + int packIndex = 1; + for (Object packObj : packList) { + String packCount = packObj == null ? "" : packObj.toString().trim(); + if (StringUtils.isBlank(packCount)) { + throw new RuntimeException(labelSettingI18n.text("label.error.boxPackCountItemRequired", packIndex)); + } + boxPackCountList.add(packCount); + packIndex++; + } + return boxPackCountList; + } + /** * 根据外箱标签解析对应内箱标签 */ diff --git a/src/main/resources/i18n/messages_en_US.properties b/src/main/resources/i18n/messages_en_US.properties index 368578a4..ef521fc4 100644 --- a/src/main/resources/i18n/messages_en_US.properties +++ b/src/main/resources/i18n/messages_en_US.properties @@ -96,6 +96,10 @@ label.error.printerIpMissing=Printer IP is not configured: labelType={0} label.error.qtyRequired=customFields.QTY array is required for outer-box label printing. label.error.qtyArrayRequired=customFields.QTY must be a non-empty array, for example ["100","200","300"] label.error.qtyItemRequired=customFields.QTY item {0} cannot be empty. +label.error.boxPackCountRequired=customFields.boxPackCount array is required for outer-box label printing. +label.error.boxPackCountArrayRequired=customFields.boxPackCount must be a non-empty array, for example ["5","5","1"] +label.error.boxPackCountSizeMismatch=customFields.boxPackCount length must match QTY. QTY has {0} items, boxPackCount has {1}. +label.error.boxPackCountItemRequired=customFields.boxPackCount item {0} cannot be empty. label.error.previewFieldRequired=Enter {0} for real-data preview. label.error.integerRequired={0} must be an integer. label.preview.field.consignmentId=Shipment ID diff --git a/src/main/resources/i18n/messages_zh_CN.properties b/src/main/resources/i18n/messages_zh_CN.properties index 2983f2cf..c1fa5090 100644 --- a/src/main/resources/i18n/messages_zh_CN.properties +++ b/src/main/resources/i18n/messages_zh_CN.properties @@ -96,6 +96,10 @@ label.error.printerIpMissing=打印机IP地址未配置:labelType={0} label.error.qtyRequired=外箱标签打印必须传入customFields.QTY数组 label.error.qtyArrayRequired=customFields.QTY必须为非空数组,例如 ["100","200","300"] label.error.qtyItemRequired=customFields.QTY第{0}项不能为空 +label.error.boxPackCountRequired=外箱标签打印必须传入customFields.boxPackCount数组 +label.error.boxPackCountArrayRequired=customFields.boxPackCount必须为非空数组,例如 ["5","5","1"] +label.error.boxPackCountSizeMismatch=customFields.boxPackCount数量必须与QTY一致,QTY共{0}项,boxPackCount共{1}项 +label.error.boxPackCountItemRequired=customFields.boxPackCount第{0}项不能为空 label.error.previewFieldRequired=真实数据预览请填写{0} label.error.integerRequired={0}必须为整数 label.preview.field.consignmentId=发货单ID