From aaa8067a83360d3d09c3c8fa29b8e0b7e2a8b9d5 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Wed, 14 Oct 2026 16:56:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E5=A4=96=E7=AE=B1=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=20customFields=EF=BC=9A=E6=95=B0=E7=BB=84=E6=8C=89QTY?= =?UTF-8?q?=E7=9A=84=E5=BD=93=E5=89=8D=E4=B8=8B=E6=A0=87=E5=8F=96=E5=80=BC?= =?UTF-8?q?=EF=BC=8C=E9=9D=9E=E6=95=B0=E7=BB=84=E5=AD=97=E6=AE=B5=E7=94=B1?= =?UTF-8?q?=E6=89=80=E6=9C=89=E5=A4=96=E7=AE=B1=E5=85=B1=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Impl/ReportLabelListServiceImpl.java | 78 ++++++------------- .../resources/i18n/messages_en_US.properties | 1 + .../resources/i18n/messages_zh_CN.properties | 1 + 3 files changed, 27 insertions(+), 53 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 e3ded310..b6074cb2 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 @@ -719,7 +719,7 @@ public class ReportLabelListServiceImpl extends ServiceImpl customFields = printRequest.getCustomFields(); // 2. 获取外箱标签打印机配置 UserLabelPrinterData outerPrinter = getRequiredLabelPrinter(printRequest.getUserId(), outerLabelSetting.getLabelType()); @@ -730,13 +730,12 @@ public class ReportLabelListServiceImpl extends ServiceImpl outerQtyList = extractRequiredOuterQtyList(customFields); - // boxPackCount与QTY等长,按下标取当前外箱的内包数,避免整段数组被印到每一张标签上 - List boxPackCountList = extractRequiredBoxPackCountList(customFields, outerQtyList.size()); + // 所有数组字段必须与QTY等长,在入队前统一校验,避免部分标签已打印后才发现数据错位 + validateOuterCustomFieldArrays(customFields, outerQtyList.size()); int outerBatchIndex = 1; for (String outerQty : outerQtyList) { - String boxPackCount = boxPackCountList.get(outerBatchIndex - 1); Map outerCustomFields = buildOuterCustomFields( - customFields, outerQty, boxPackCount, outerBatchIndex, outerQtyList.size()); + customFields, outerQty, outerBatchIndex, outerQtyList.size()); queryParams.put("customFields", outerCustomFields); // 生成当前QTY对应的外箱标签(同一queryParams会复用IFS缓存) @@ -752,8 +751,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={}, boxPackCount={}, taskId={}", - outerBatchIndex, outerQtyList.size(), i + 1, totalLabels, outerQty, boxPackCount, taskId); + log.info("外箱标签任务已加入队列,batch={} / {}, index={} / {}, qty={}, taskId={}", + outerBatchIndex, outerQtyList.size(), i + 1, totalLabels, outerQty, taskId); } outerBatchIndex++; } @@ -963,36 +962,31 @@ public class ReportLabelListServiceImpl extends ServiceImpl buildOuterCustomFields(Map sourceCustomFields, String outerQty, - String boxPackCount, int serialNumber, int outerBoxes) { + 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())) { - 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 (sourceCustomFields != null) { + for (Map.Entry entry : sourceCustomFields.entrySet()) { + Object value = entry.getValue(); + if (value instanceof List values) { + value = values.get(serialNumber - 1); + } + if (StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(entry.getKey()), "qty")) { + value = outerQty; + qtyUpdated = true; + } + outerCustomFields.put(entry.getKey(), value); } } 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; } @@ -1027,37 +1021,15 @@ 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; + private void validateOuterCustomFieldArrays(Map customFields, int expectedSize) { 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)); + if (entry.getValue() instanceof List values && values.size() != expectedSize) { + throw new RuntimeException(labelSettingI18n.text( + "label.error.customFieldArraySizeMismatch", entry.getKey(), expectedSize, values.size())); } - 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 ef521fc4..62ebdd8e 100644 --- a/src/main/resources/i18n/messages_en_US.properties +++ b/src/main/resources/i18n/messages_en_US.properties @@ -96,6 +96,7 @@ 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.customFieldArraySizeMismatch=customFields.{0} array length must match QTY. QTY has {1} items, but this field has {2}. 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}. diff --git a/src/main/resources/i18n/messages_zh_CN.properties b/src/main/resources/i18n/messages_zh_CN.properties index c1fa5090..13f59ff8 100644 --- a/src/main/resources/i18n/messages_zh_CN.properties +++ b/src/main/resources/i18n/messages_zh_CN.properties @@ -96,6 +96,7 @@ 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.customFieldArraySizeMismatch=customFields.{0}数组数量必须与QTY一致,QTY共{1}项,当前字段共{2}项 label.error.boxPackCountRequired=外箱标签打印必须传入customFields.boxPackCount数组 label.error.boxPackCountArrayRequired=customFields.boxPackCount必须为非空数组,例如 ["5","5","1"] label.error.boxPackCountSizeMismatch=customFields.boxPackCount数量必须与QTY一致,QTY共{0}项,boxPackCount共{1}项