|
|
|
@ -713,7 +713,8 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
customerId: "CUST123",// customerId是可选的,如果传了,系统会优先根据customerId解析标签编号 |
|
|
|
addressNo: "ADDR001", // addressNo是可选的,传了会优先按customerId+addressNo精确匹配 |
|
|
|
"customFields": { |
|
|
|
"QTY": ["100","200","300"], |
|
|
|
"QTY": ["100","200","300"],// 有几个值就打印几张外箱标签 |
|
|
|
"boxPackCount": ["5","5","1"],// 与QTY一一对应:每个外箱对应的内包数,末箱不满则传实际包数;系统按此生成/替换外箱标签字段 |
|
|
|
"grossWeight": 15.6, |
|
|
|
"netWeight": 14.9 |
|
|
|
} |
|
|
|
@ -729,9 +730,13 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
if (hasCustomerId) { |
|
|
|
// 传customerId时,按QTY数组逐项生成外箱任务 |
|
|
|
List<String> outerQtyList = extractRequiredOuterQtyList(customFields); |
|
|
|
List<String> outerBoxPackCountList = extractOptionalBoxPackCountList(customFields, outerQtyList.size()); |
|
|
|
int outerBatchIndex = 1; |
|
|
|
for (String outerQty : outerQtyList) { |
|
|
|
Map<String, Object> outerCustomFields = buildOuterCustomFields(customFields, outerQty); |
|
|
|
for (int qtyIndex = 0; qtyIndex < outerQtyList.size(); qtyIndex++) { |
|
|
|
String outerQty = outerQtyList.get(qtyIndex); |
|
|
|
String outerBoxPackCount = outerBoxPackCountList.isEmpty() |
|
|
|
? null : outerBoxPackCountList.get(qtyIndex); |
|
|
|
Map<String, Object> outerCustomFields = buildOuterCustomFields(customFields, outerQty, outerBoxPackCount); |
|
|
|
queryParams.put("customFields", outerCustomFields); |
|
|
|
|
|
|
|
// 生成当前QTY对应的外箱标签(同一queryParams会复用IFS缓存) |
|
|
|
@ -747,8 +752,8 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
Map<String, Object> 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("外箱标签任务已加入队列,batch={} / {}, index={} / {}, qty={}, boxPackCount={}, taskId={}", |
|
|
|
outerBatchIndex, outerQtyList.size(), i + 1, totalLabels, outerQty, outerBoxPackCount, taskId); |
|
|
|
} |
|
|
|
outerBatchIndex++; |
|
|
|
} |
|
|
|
@ -958,23 +963,34 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 构建外箱标签 customFields:保留原字段并覆盖 qty |
|
|
|
* 构建外箱标签 customFields:保留原字段并覆盖当前箱的 qty / boxPackCount |
|
|
|
*/ |
|
|
|
private Map<String, Object> buildOuterCustomFields(Map<String, Object> sourceCustomFields, String outerQty) { |
|
|
|
private Map<String, Object> buildOuterCustomFields(Map<String, Object> sourceCustomFields, |
|
|
|
String outerQty, |
|
|
|
String outerBoxPackCount) { |
|
|
|
Map<String, Object> outerCustomFields = new HashMap<>(); |
|
|
|
if (sourceCustomFields != null && !sourceCustomFields.isEmpty()) { |
|
|
|
outerCustomFields.putAll(sourceCustomFields); |
|
|
|
} |
|
|
|
boolean qtyUpdated = false; |
|
|
|
boolean boxPackCountUpdated = false; |
|
|
|
for (String key : new ArrayList<>(outerCustomFields.keySet())) { |
|
|
|
if (StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(key), "qty")) { |
|
|
|
String normalizedKey = StringUtils.trimToEmpty(key); |
|
|
|
if (StringUtils.equalsIgnoreCase(normalizedKey, "qty")) { |
|
|
|
outerCustomFields.put(key, outerQty); |
|
|
|
qtyUpdated = true; |
|
|
|
} else if (StringUtils.equalsIgnoreCase(normalizedKey, "boxPackCount") |
|
|
|
&& StringUtils.isNotBlank(outerBoxPackCount)) { |
|
|
|
outerCustomFields.put(key, outerBoxPackCount); |
|
|
|
boxPackCountUpdated = true; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!qtyUpdated) { |
|
|
|
outerCustomFields.put("qty", outerQty); |
|
|
|
} |
|
|
|
if (!boxPackCountUpdated && StringUtils.isNotBlank(outerBoxPackCount)) { |
|
|
|
outerCustomFields.put("boxPackCount", outerBoxPackCount); |
|
|
|
} |
|
|
|
return outerCustomFields; |
|
|
|
} |
|
|
|
|
|
|
|
@ -1008,6 +1024,43 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
return outerQtyList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 提取外箱内包数数组(可选;传入时必须与 QTY 一一对应) |
|
|
|
*/ |
|
|
|
private List<String> extractOptionalBoxPackCountList(Map<String, Object> customFields, int expectedSize) { |
|
|
|
if (customFields == null || customFields.isEmpty()) { |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
Object boxPackCountValue = null; |
|
|
|
for (Map.Entry<String, Object> entry : customFields.entrySet()) { |
|
|
|
if (StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(entry.getKey()), "boxPackCount")) { |
|
|
|
boxPackCountValue = entry.getValue(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (boxPackCountValue == null) { |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
if (!(boxPackCountValue instanceof List<?> boxPackCountList) || boxPackCountList.isEmpty()) { |
|
|
|
throw new RuntimeException(labelSettingI18n.text("label.error.boxPackCountArrayRequired")); |
|
|
|
} |
|
|
|
if (boxPackCountList.size() != expectedSize) { |
|
|
|
throw new RuntimeException(labelSettingI18n.text( |
|
|
|
"label.error.boxPackCountSizeMismatch", boxPackCountList.size(), expectedSize)); |
|
|
|
} |
|
|
|
List<String> result = new ArrayList<>(); |
|
|
|
int index = 1; |
|
|
|
for (Object packCountObj : boxPackCountList) { |
|
|
|
String packCount = packCountObj == null ? "" : packCountObj.toString().trim(); |
|
|
|
if (StringUtils.isBlank(packCount)) { |
|
|
|
throw new RuntimeException(labelSettingI18n.text("label.error.boxPackCountItemRequired", index)); |
|
|
|
} |
|
|
|
result.add(packCount); |
|
|
|
index++; |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据外箱标签解析对应内箱标签 |
|
|
|
*/ |
|
|
|
|