From 9fbdf11c66f45b8c67ba42fe3af0fbfefe2244ec Mon Sep 17 00:00:00 2001 From: shenzhouyu Date: Wed, 14 Oct 2026 16:07:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0=E5=8F=82=E6=95=B0=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0boxPackCount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Impl/ReportLabelListServiceImpl.java | 69 ++++++++++++++++--- .../resources/i18n/messages_en_US.properties | 3 + .../resources/i18n/messages_zh_CN.properties | 3 + 3 files changed, 67 insertions(+), 8 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 2d44b0d1..e5e649be 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 @@ -713,7 +713,8 @@ public class ReportLabelListServiceImpl extends ServiceImpl outerQtyList = extractRequiredOuterQtyList(customFields); + List outerBoxPackCountList = extractOptionalBoxPackCountList(customFields, outerQtyList.size()); int outerBatchIndex = 1; - for (String outerQty : outerQtyList) { - Map outerCustomFields = buildOuterCustomFields(customFields, outerQty); + for (int qtyIndex = 0; qtyIndex < outerQtyList.size(); qtyIndex++) { + String outerQty = outerQtyList.get(qtyIndex); + String outerBoxPackCount = outerBoxPackCountList.isEmpty() + ? null : outerBoxPackCountList.get(qtyIndex); + Map outerCustomFields = buildOuterCustomFields(customFields, outerQty, outerBoxPackCount); 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, outerBoxPackCount, taskId); } outerBatchIndex++; } @@ -958,23 +963,34 @@ public class ReportLabelListServiceImpl extends ServiceImpl buildOuterCustomFields(Map sourceCustomFields, String outerQty) { + private Map buildOuterCustomFields(Map sourceCustomFields, + String outerQty, + String outerBoxPackCount) { 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") + && StringUtils.isNotBlank(outerBoxPackCount)) { + outerCustomFields.put(key, outerBoxPackCount); + boxPackCountUpdated = true; } } if (!qtyUpdated) { outerCustomFields.put("qty", outerQty); } + if (!boxPackCountUpdated && StringUtils.isNotBlank(outerBoxPackCount)) { + outerCustomFields.put("boxPackCount", outerBoxPackCount); + } return outerCustomFields; } @@ -1008,6 +1024,43 @@ public class ReportLabelListServiceImpl extends ServiceImpl extractOptionalBoxPackCountList(Map customFields, int expectedSize) { + if (customFields == null || customFields.isEmpty()) { + return Collections.emptyList(); + } + Object boxPackCountValue = null; + for (Map.Entry entry : customFields.entrySet()) { + if (StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(entry.getKey()), "boxPackCount")) { + boxPackCountValue = entry.getValue(); + break; + } + } + if (boxPackCountValue == null) { + return Collections.emptyList(); + } + if (!(boxPackCountValue instanceof List boxPackCountList) || boxPackCountList.isEmpty()) { + throw new RuntimeException(labelSettingI18n.text("label.error.boxPackCountArrayRequired")); + } + if (boxPackCountList.size() != expectedSize) { + throw new RuntimeException(labelSettingI18n.text( + "label.error.boxPackCountSizeMismatch", boxPackCountList.size(), expectedSize)); + } + List result = new ArrayList<>(); + int index = 1; + for (Object packCountObj : boxPackCountList) { + String packCount = packCountObj == null ? "" : packCountObj.toString().trim(); + if (StringUtils.isBlank(packCount)) { + throw new RuntimeException(labelSettingI18n.text("label.error.boxPackCountItemRequired", index)); + } + result.add(packCount); + index++; + } + return result; + } + /** * 根据外箱标签解析对应内箱标签 */ diff --git a/src/main/resources/i18n/messages_en_US.properties b/src/main/resources/i18n/messages_en_US.properties index 368578a4..51f1e2c2 100644 --- a/src/main/resources/i18n/messages_en_US.properties +++ b/src/main/resources/i18n/messages_en_US.properties @@ -96,6 +96,9 @@ 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.boxPackCountArrayRequired=customFields.boxPackCount must be a non-empty array, for example ["2","2","1"] +label.error.boxPackCountSizeMismatch=customFields.boxPackCount length ({0}) must match QTY length ({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..cded30a3 100644 --- a/src/main/resources/i18n/messages_zh_CN.properties +++ b/src/main/resources/i18n/messages_zh_CN.properties @@ -96,6 +96,9 @@ 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.boxPackCountArrayRequired=customFields.boxPackCount必须为非空数组,例如 ["2","2","1"] +label.error.boxPackCountSizeMismatch=customFields.boxPackCount长度({0})必须与QTY长度({1})一致 +label.error.boxPackCountItemRequired=customFields.boxPackCount第{0}项不能为空 label.error.previewFieldRequired=真实数据预览请填写{0} label.error.integerRequired={0}必须为整数 label.preview.field.consignmentId=发货单ID