From c648efdf2ada16d5af4267559cf0d139aff5db6a Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Thu, 30 Jul 2026 14:32:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=96=E7=AE=B1=E4=B9=9F=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E4=BC=A03=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Impl/ReportLabelListServiceImpl.java | 111 +++++++++++++----- 1 file changed, 84 insertions(+), 27 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 79764ef..ed0989c 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 @@ -715,45 +715,48 @@ public class ReportLabelListServiceImpl extends ServiceImpl customFields = printRequest.getCustomFields(); - if (customFields != null && !customFields.isEmpty()) { - queryParams.put("customFields", customFields); - } - // 可以根据需要添加更多参数 - // 2. 生成外箱标签:带真实数据的ZPL代码和对应数据 - List zplCodeList = previewLabelWithRealData(outerLabelSetting.getLabelNo(), true, queryParams); - // 同时获取原始数据用于保存WMS标签记录 - List> labelDataList = getLabelDataForPrint(outerLabelSetting.getLabelNo(), queryParams); - // 3. 验证ZPL代码 - if (zplCodeList == null || zplCodeList.isEmpty()) { - throw new RuntimeException("ZPL代码获取失败"); - } - log.info("生成了 {} 个外箱标签ZPL代码,准备打印", zplCodeList.size()); + List outerQtyList = extractRequiredOuterQtyList(customFields); - // 4. 获取外箱标签打印机配置 + // 2. 获取外箱标签打印机配置 UserLabelPrinterData outerPrinter = getRequiredLabelPrinter(printRequest.getUserId(), outerLabelSetting.getLabelNo()); - // 5. 将外箱打印任务加入队列(不直接打印) - int totalLabels = zplCodeList.size(); + // 3. 按QTY数组逐项生成外箱任务(复用同一个queryParams,确保IFS数据只查询一次) List taskIds = new ArrayList<>(); - for (int i = 0; i < totalLabels; i++) { - String zplCode = zplCodeList.get(i); - Map labelData = i < labelDataList.size() ? labelDataList.get(i) : new HashMap<>(); - Long taskId = enqueueSingleTask(outerPrinter.getIpAddress(), zplCode, outerRfidFlag, labelData, printRequest); - taskIds.add(taskId); - log.info("打印任务已加入队列 {} / {}, taskId={}", i + 1, totalLabels, taskId); + int outerBatchIndex = 1; + for (String outerQty : outerQtyList) { + Map outerCustomFields = buildOuterCustomFields(customFields, outerQty); + queryParams.put("customFields", outerCustomFields); + + // 生成当前QTY对应的外箱标签(同一queryParams会复用IFS缓存) + List zplCodeList = previewLabelWithRealData(outerLabelSetting.getLabelNo(), true, queryParams); + List> labelDataList = getLabelDataForPrint(outerLabelSetting.getLabelNo(), queryParams); + if (zplCodeList == null || zplCodeList.isEmpty()) { + throw new RuntimeException("外箱标签ZPL代码获取失败,qty=" + outerQty); + } + + int totalLabels = zplCodeList.size(); + for (int i = 0; i < totalLabels; i++) { + String zplCode = zplCodeList.get(i); + Map 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); + } + outerBatchIndex++; } - // 6. customerId + innerBox 场景:在外箱任务后自动补打对应内箱子标签 + // 4. 外箱全部完成后仅补打一套内箱(若存在内箱配置) enqueueInnerBoxTasksIfNeeded(printRequest, resolvedReportId, queryParams, outerPrinter, taskIds); - // 7. 记录日志 + // 5. 记录日志 log.info("✓ 所有打印任务已加入队列,共 {} 个任务,任务ID: {}", taskIds.size(), taskIds); } catch (Exception e) { System.err.println("RFID标签打印失败: " + e.getMessage()); @@ -850,13 +853,16 @@ public class ReportLabelListServiceImpl extends ServiceImpl innerQueryParams = new HashMap<>(baseQueryParams); + // 复用同一个queryParams,确保IFS缓存可跨外箱/内箱复用,避免重复调用getIfsDataFromApi + Map innerQueryParams = baseQueryParams; int innerIndex = 1; for (String innerQty : innerBoxList) { if (StringUtils.isBlank(innerQty)) { @@ -924,6 +930,57 @@ public class ReportLabelListServiceImpl extends ServiceImpl buildOuterCustomFields(Map sourceCustomFields, String outerQty) { + Map outerCustomFields = new HashMap<>(); + if (sourceCustomFields != null && !sourceCustomFields.isEmpty()) { + outerCustomFields.putAll(sourceCustomFields); + } + boolean qtyUpdated = false; + for (String key : new ArrayList<>(outerCustomFields.keySet())) { + if (StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(key), "qty")) { + outerCustomFields.put(key, outerQty); + qtyUpdated = true; + } + } + if (!qtyUpdated) { + outerCustomFields.put("qty", outerQty); + } + return outerCustomFields; + } + + /** + * 提取外箱QTY数组(仅支持数组,不兼容单值) + */ + private List extractRequiredOuterQtyList(Map customFields) { + if (customFields == null || customFields.isEmpty()) { + throw new RuntimeException("外箱标签打印必须传入customFields.QTY数组"); + } + Object qtyValue = null; + for (Map.Entry entry : customFields.entrySet()) { + if (StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(entry.getKey()), "qty")) { + qtyValue = entry.getValue(); + break; + } + } + if (!(qtyValue instanceof List qtyList) || qtyList.isEmpty()) { + throw new RuntimeException("customFields.QTY必须为非空数组,例如 [\"100\",\"200\",\"300\"]"); + } + List outerQtyList = new ArrayList<>(); + int qtyIndex = 1; + for (Object qtyObj : qtyList) { + String qty = qtyObj == null ? "" : qtyObj.toString().trim(); + if (StringUtils.isBlank(qty)) { + throw new RuntimeException("customFields.QTY第" + qtyIndex + "项不能为空"); + } + outerQtyList.add(qty); + qtyIndex++; + } + return outerQtyList; + } + /** * 根据外箱标签解析对应内箱标签 */