|
|
|
@ -783,7 +783,7 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 4. 外箱全部完成后仅补打一套内箱(若存在内箱配置) |
|
|
|
// 4. 主外箱全部入队后,连带打印全部子标签(内箱按innerBox,其他子标签按外箱QTY) |
|
|
|
enqueueInnerBoxTasksIfNeeded(printRequest, resolvedReportId, queryParams, outerPrinter, taskIds); |
|
|
|
|
|
|
|
// 5. 记录日志 |
|
|
|
@ -882,78 +882,71 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* customerId + innerBox 场景:打印外箱标签对应的内箱子标签 |
|
|
|
* 连带打印客户外箱的全部子标签:内箱按innerBox,外箱等其他子标签复用外箱customFields。 |
|
|
|
*/ |
|
|
|
private void enqueueInnerBoxTasksIfNeeded(PrintLabelRequest printRequest, |
|
|
|
String outerLabelNo, |
|
|
|
Map<String, Object> baseQueryParams, |
|
|
|
UserLabelPrinterData outerPrinter, |
|
|
|
List<Long> taskIds) { |
|
|
|
if (StringUtils.isBlank(printRequest.getCustomerId())) { |
|
|
|
return; |
|
|
|
} |
|
|
|
List<String> 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<String, Object> innerQueryParams = baseQueryParams; |
|
|
|
int innerIndex = 1; |
|
|
|
for (String innerQty : innerBoxList) { |
|
|
|
if (StringUtils.isBlank(innerQty)) { |
|
|
|
List<CustomerLabelSettingData> childLabels = resolveChildLabelsByCustomer(printRequest, outerLabelNo, null); |
|
|
|
for (CustomerLabelSettingData childLabel : childLabels) { |
|
|
|
boolean isInnerLabel = "内箱标签".equals(StringUtils.trimToEmpty(childLabel.getLabelType())); |
|
|
|
List<String> quantities = isInnerLabel |
|
|
|
? printRequest.getInnerBox() : extractRequiredOuterQtyList(printRequest.getCustomFields()); |
|
|
|
if (quantities == null || quantities.isEmpty()) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
Map<String, Object> innerCustomFields = buildInnerCustomFields(printRequest.getCustomFields(), innerQty.trim()); |
|
|
|
innerQueryParams.put("customFields", innerCustomFields); |
|
|
|
|
|
|
|
// innerBox 的每个元素代表一份内箱标签,qty由当前元素覆盖 |
|
|
|
List<String> innerZplList = previewLabelWithRealData(innerLabelNo, true, innerQueryParams); |
|
|
|
if (innerZplList == null || innerZplList.isEmpty()) { |
|
|
|
throw new RuntimeException(labelSettingI18n.text("label.error.innerZplFailed", innerQty)); |
|
|
|
} |
|
|
|
List<Map<String, Object>> innerLabelDataList = getLabelDataForPrint(innerLabelNo, innerQueryParams); |
|
|
|
Map<String, Object> 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<String, Object> childCustomFields = isInnerLabel |
|
|
|
? buildInnerCustomFields(printRequest.getCustomFields(), qty.trim()) |
|
|
|
: buildOuterCustomFields(printRequest.getCustomFields(), qty.trim(), batchIndex + 1, quantities.size()); |
|
|
|
// 复用同一个queryParams,确保IFS缓存可跨主标签和子标签复用。 |
|
|
|
baseQueryParams.put("customFields", childCustomFields); |
|
|
|
List<String> childZplList = previewLabelWithRealData(childLabelNo, true, baseQueryParams); |
|
|
|
if (childZplList == null || childZplList.isEmpty()) { |
|
|
|
throw new RuntimeException(labelSettingI18n.text( |
|
|
|
isInnerLabel ? "label.error.innerZplFailed" : "label.error.outerZplFailed", qty)); |
|
|
|
} |
|
|
|
List<Map<String, Object>> 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<String, Object> 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<ReportLabelListMappe |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查外箱下面有没有内箱。ParentReportID 等于外箱编号即表示挂了内箱,返回该行的 ReportID。 |
|
|
|
* 例如 ParentReportID=A068 时,A068 的内箱是 A067。不看标签类型,也不按地址回退。 |
|
|
|
* 没有这样的行就返回 null,调用方只打外箱。 |
|
|
|
* 仅解析当前客户、工厂和父标签下类型为“内箱标签”的子标签;未配置时返回null。 |
|
|
|
*/ |
|
|
|
private String resolveInnerLabelByCustomer(PrintLabelRequest printRequest, String outerLabelNo) { |
|
|
|
List<CustomerLabelSettingData> innerLabels = resolveChildLabelsByCustomer(printRequest, outerLabelNo, "内箱标签"); |
|
|
|
return innerLabels.isEmpty() ? null : innerLabels.getFirst().getLabelNo(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取当前客户、工厂和父标签下的全部子标签;labelType为空时不限制类型,不按地址回退。 |
|
|
|
*/ |
|
|
|
private List<CustomerLabelSettingData> 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<CustomerLabelSettingData> customerLabelList = baseService.getCustomerLabelSettingList(query); |
|
|
|
if (customerLabelList == null || customerLabelList.isEmpty()) { |
|
|
|
return null; |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
|
|
|
|
List<CustomerLabelSettingData> childLabels = new ArrayList<>(); |
|
|
|
Set<String> addedLabelNos = new HashSet<>(); |
|
|
|
for (CustomerLabelSettingData item : customerLabelList) { |
|
|
|
if (item == null || StringUtils.isBlank(item.getLabelNo())) { |
|
|
|
continue; |
|
|
|
@ -1077,20 +1080,26 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
&& !StringUtils.equalsIgnoreCase(printRequest.getSite(), item.getSite())) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 子标签且上级就是当前外箱,才是这张外箱的内箱 |
|
|
|
if (!"Y".equalsIgnoreCase(StringUtils.trimToEmpty(item.getSubLabelFlag()))) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (!StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(item.getParentLabelNo()), outerLabelNo)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
return item.getLabelNo(); |
|
|
|
if (StringUtils.isNotBlank(labelType) |
|
|
|
&& !StringUtils.equalsIgnoreCase(labelType, StringUtils.trimToEmpty(item.getLabelType()))) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 同一标签可能维护多条客户地址映射,连打时只生成一套任务。 |
|
|
|
if (addedLabelNos.add(item.getLabelNo().trim().toUpperCase(Locale.ROOT))) { |
|
|
|
childLabels.add(item); |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
return childLabels; |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("根据外箱标签解析内箱标签失败,customerId={}, outerLabelNo={}, error={}", |
|
|
|
customerId, outerLabelNo, e.getMessage()); |
|
|
|
return null; |
|
|
|
log.warn("根据外箱标签解析子标签失败,customerId={}, outerLabelNo={}, labelType={}, error={}", |
|
|
|
customerId, outerLabelNo, labelType, e.getMessage()); |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|