From 86cfbe8a67b90aaf60f7a331995483a59150b151 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Wed, 11 Nov 2026 14:19:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9E=E5=B8=A6=E6=89=93=E5=8D=B0=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E5=A4=96=E7=AE=B1=E7=9A=84=E5=85=A8=E9=83=A8=E5=AD=90?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=EF=BC=9A=E5=86=85=E7=AE=B1=E6=8C=89innerBox?= =?UTF-8?q?=EF=BC=8C=E5=A4=96=E7=AE=B1=E7=AD=89=E5=85=B6=E4=BB=96=E5=AD=90?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=A4=8D=E7=94=A8=E5=A4=96=E7=AE=B1customFie?= =?UTF-8?q?lds=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Impl/ReportLabelListServiceImpl.java | 145 ++++++++++-------- 1 file changed, 77 insertions(+), 68 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 f875ecfe..1b408bd3 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 @@ -783,7 +783,7 @@ public class ReportLabelListServiceImpl extends ServiceImpl baseQueryParams, UserLabelPrinterData outerPrinter, List taskIds) { - if (StringUtils.isBlank(printRequest.getCustomerId())) { - return; - } - List innerBoxList = printRequest.getInnerBox(); - if (innerBoxList == null || innerBoxList.isEmpty()) { - return; - } - - String innerLabelNo = resolveInnerLabelByCustomer(printRequest, outerLabelNo); - if (StringUtils.isBlank(innerLabelNo)) { - // 内箱配置为可选,未配置时仅打印外箱,不中断主流程 - log.info("外箱标签未维护内箱子标签映射,跳过内箱补打。outerLabelNo={}", outerLabelNo); - return; - } - - LabelSettingData innerLabelSetting = getRequiredLabelSetting(innerLabelNo, null); - UserLabelPrinterData innerPrinter = resolveInnerPrinter(printRequest.getUserId(), innerLabelSetting, outerPrinter); - - // 复用同一个queryParams,确保IFS缓存可跨外箱/内箱复用,避免重复调用getIfsDataFromApi - Map innerQueryParams = baseQueryParams; - int innerIndex = 1; - for (String innerQty : innerBoxList) { - if (StringUtils.isBlank(innerQty)) { + List childLabels = resolveChildLabelsByCustomer(printRequest, outerLabelNo, null); + for (CustomerLabelSettingData childLabel : childLabels) { + boolean isInnerLabel = "内箱标签".equals(StringUtils.trimToEmpty(childLabel.getLabelType())); + List quantities = isInnerLabel + ? printRequest.getInnerBox() : extractRequiredOuterQtyList(printRequest.getCustomFields()); + if (quantities == null || quantities.isEmpty()) { continue; } - Map innerCustomFields = buildInnerCustomFields(printRequest.getCustomFields(), innerQty.trim()); - innerQueryParams.put("customFields", innerCustomFields); - - // innerBox 的每个元素代表一份内箱标签,qty由当前元素覆盖 - List innerZplList = previewLabelWithRealData(innerLabelNo, true, innerQueryParams); - if (innerZplList == null || innerZplList.isEmpty()) { - throw new RuntimeException(labelSettingI18n.text("label.error.innerZplFailed", innerQty)); - } - List> innerLabelDataList = getLabelDataForPrint(innerLabelNo, innerQueryParams); - Map innerLabelData = innerLabelDataList != null && !innerLabelDataList.isEmpty() - ? new HashMap<>(innerLabelDataList.getFirst()) : new HashMap<>(); - if (innerZplList.size() > 1) { - log.warn("内箱标签生成了多条数据,本次按第一条打印。innerQty={}, count={}", innerQty, innerZplList.size()); + String childLabelNo = childLabel.getLabelNo(); + LabelSettingData childLabelSetting = getRequiredLabelSetting(childLabelNo, null); + UserLabelPrinterData childPrinter = resolveChildPrinter(printRequest.getUserId(), childLabelSetting, outerPrinter); + for (int batchIndex = 0; batchIndex < quantities.size(); batchIndex++) { + String qty = quantities.get(batchIndex); + if (StringUtils.isBlank(qty)) { + continue; + } + Map childCustomFields = isInnerLabel + ? buildInnerCustomFields(printRequest.getCustomFields(), qty.trim()) + : buildOuterCustomFields(printRequest.getCustomFields(), qty.trim(), batchIndex + 1, quantities.size()); + // 复用同一个queryParams,确保IFS缓存可跨主标签和子标签复用。 + baseQueryParams.put("customFields", childCustomFields); + List childZplList = previewLabelWithRealData(childLabelNo, true, baseQueryParams); + if (childZplList == null || childZplList.isEmpty()) { + throw new RuntimeException(labelSettingI18n.text( + isInnerLabel ? "label.error.innerZplFailed" : "label.error.outerZplFailed", qty)); + } + List> childLabelDataList = getLabelDataForPrint(childLabelNo, baseQueryParams); + // innerBox每项仍只打印一份;外箱子标签与主外箱一样打印全部数据行。 + int totalLabels = isInnerLabel ? 1 : childZplList.size(); + if (isInnerLabel && childZplList.size() > 1) { + log.warn("内箱标签生成了多条数据,本次按第一条打印。childLabelNo={}, innerQty={}, count={}", + childLabelNo, qty, childZplList.size()); + } + for (int i = 0; i < totalLabels; i++) { + Map labelData = childLabelDataList != null && i < childLabelDataList.size() + ? new HashMap<>(childLabelDataList.get(i)) : new HashMap<>(); + Long taskId = enqueueSingleTask(childPrinter.getIpAddress(), childZplList.get(i), + childLabelSetting.getRfidFlag(), labelData, printRequest); + taskIds.add(taskId); + log.info("子标签任务已加入队列,childLabelNo={}, labelType={}, batch={} / {}, index={} / {}, qty={}, taskId={}", + childLabelNo, childLabel.getLabelType(), batchIndex + 1, quantities.size(), i + 1, totalLabels, qty, taskId); + } } - Long taskId = enqueueSingleTask( - innerPrinter.getIpAddress(), - innerZplList.getFirst(), - innerLabelSetting.getRfidFlag(), - innerLabelData, - printRequest - ); - taskIds.add(taskId); - log.info("内箱标签任务已加入队列 {} / {}, qty={}, taskId={}", - innerIndex, innerBoxList.size(), innerQty, taskId); - innerIndex++; } } /** - * 解析内箱标签打印机:优先取内箱标签专属打印机,未配置则沿用外箱打印机 + * 解析子标签打印机:优先按子标签类型获取打印机,未配置则沿用主外箱打印机。 */ - private UserLabelPrinterData resolveInnerPrinter(String userId, LabelSettingData innerLabelSetting, UserLabelPrinterData outerPrinter) { - String innerLabelNo = innerLabelSetting == null ? "" : innerLabelSetting.getLabelNo(); - String innerLabelType = innerLabelSetting == null ? "" : innerLabelSetting.getLabelType(); + private UserLabelPrinterData resolveChildPrinter(String userId, LabelSettingData childLabelSetting, UserLabelPrinterData outerPrinter) { + String childLabelNo = childLabelSetting == null ? "" : childLabelSetting.getLabelNo(); + String childLabelType = childLabelSetting == null ? "" : childLabelSetting.getLabelType(); try { - return getRequiredLabelPrinter(userId, innerLabelType); + return getRequiredLabelPrinter(userId, childLabelType); } catch (Exception ex) { - log.warn("内箱标签未配置独立打印机,沿用外箱打印机。innerLabelNo={}, innerLabelType={}, reason={}", - innerLabelNo, innerLabelType, ex.getMessage()); + log.warn("子标签未配置独立打印机,沿用外箱打印机。childLabelNo={}, childLabelType={}, reason={}", + childLabelNo, childLabelType, ex.getMessage()); return outerPrinter; } } @@ -1051,24 +1044,34 @@ public class ReportLabelListServiceImpl extends ServiceImpl innerLabels = resolveChildLabelsByCustomer(printRequest, outerLabelNo, "内箱标签"); + return innerLabels.isEmpty() ? null : innerLabels.getFirst().getLabelNo(); + } + + /** + * 获取当前客户、工厂和父标签下的全部子标签;labelType为空时不限制类型,不按地址回退。 + */ + private List resolveChildLabelsByCustomer(PrintLabelRequest printRequest, + String outerLabelNo, String labelType) { String customerId = StringUtils.trimToNull(printRequest.getCustomerId()); if (StringUtils.isBlank(customerId) || StringUtils.isBlank(outerLabelNo)) { - return null; + return Collections.emptyList(); } try { CustomerLabelSettingData query = new CustomerLabelSettingData(); query.setSearchFlag("Y"); - query.setCustomerId(customerId.trim()); + query.setCustomerId(customerId); + query.setLabelType(labelType); List customerLabelList = baseService.getCustomerLabelSettingList(query); if (customerLabelList == null || customerLabelList.isEmpty()) { - return null; + return Collections.emptyList(); } + List childLabels = new ArrayList<>(); + Set addedLabelNos = new HashSet<>(); for (CustomerLabelSettingData item : customerLabelList) { if (item == null || StringUtils.isBlank(item.getLabelNo())) { continue; @@ -1077,20 +1080,26 @@ public class ReportLabelListServiceImpl extends ServiceImpl