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 ed0989c..d65f0c0 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 @@ -722,35 +722,56 @@ public class ReportLabelListServiceImpl extends ServiceImpl customFields = printRequest.getCustomFields(); - List outerQtyList = extractRequiredOuterQtyList(customFields); - // 2. 获取外箱标签打印机配置 UserLabelPrinterData outerPrinter = getRequiredLabelPrinter(printRequest.getUserId(), outerLabelSetting.getLabelNo()); - // 3. 按QTY数组逐项生成外箱任务(复用同一个queryParams,确保IFS数据只查询一次) + // 3. 生成外箱打印任务 List taskIds = new ArrayList<>(); - int outerBatchIndex = 1; - for (String outerQty : outerQtyList) { - Map outerCustomFields = buildOuterCustomFields(customFields, outerQty); - queryParams.put("customFields", outerCustomFields); + boolean hasCustomerId = StringUtils.isNotBlank(printRequest.getCustomerId()); + if (hasCustomerId) { + // 传customerId时,按QTY数组逐项生成外箱任务 + List outerQtyList = extractRequiredOuterQtyList(customFields); + 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); + } - // 生成当前QTY对应的外箱标签(同一queryParams会复用IFS缓存) + 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++; + } + } else { + // 未传customerId时,沿用原逻辑,不强制校验customFields.QTY + if (customFields != null && !customFields.isEmpty()) { + queryParams.put("customFields", customFields); + } List zplCodeList = previewLabelWithRealData(outerLabelSetting.getLabelNo(), true, queryParams); List> labelDataList = getLabelDataForPrint(outerLabelSetting.getLabelNo(), queryParams); if (zplCodeList == null || zplCodeList.isEmpty()) { - throw new RuntimeException("外箱标签ZPL代码获取失败,qty=" + outerQty); + throw new RuntimeException("ZPL代码获取失败"); } - 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); + log.info("外箱标签任务已加入队列,index={} / {}, taskId={}", i + 1, totalLabels, taskId); } - outerBatchIndex++; } // 4. 外箱全部完成后仅补打一套内箱(若存在内箱配置)