|
|
|
@ -719,7 +719,7 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
"netWeight": 14.9 |
|
|
|
} |
|
|
|
}*/ |
|
|
|
// 则系统会替换customFields里的qty字段到ZPL代码里对应的位置 |
|
|
|
// customFields中的数组按QTY下标取值,非数组值由本次所有外箱标签共用 |
|
|
|
Map<String, Object> customFields = printRequest.getCustomFields(); |
|
|
|
// 2. 获取外箱标签打印机配置 |
|
|
|
UserLabelPrinterData outerPrinter = getRequiredLabelPrinter(printRequest.getUserId(), outerLabelSetting.getLabelType()); |
|
|
|
@ -730,13 +730,12 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
if (hasCustomerId) { |
|
|
|
// 传customerId时,按QTY数组逐项生成外箱任务 |
|
|
|
List<String> outerQtyList = extractRequiredOuterQtyList(customFields); |
|
|
|
// boxPackCount与QTY等长,按下标取当前外箱的内包数,避免整段数组被印到每一张标签上 |
|
|
|
List<String> boxPackCountList = extractRequiredBoxPackCountList(customFields, outerQtyList.size()); |
|
|
|
// 所有数组字段必须与QTY等长,在入队前统一校验,避免部分标签已打印后才发现数据错位 |
|
|
|
validateOuterCustomFieldArrays(customFields, outerQtyList.size()); |
|
|
|
int outerBatchIndex = 1; |
|
|
|
for (String outerQty : outerQtyList) { |
|
|
|
String boxPackCount = boxPackCountList.get(outerBatchIndex - 1); |
|
|
|
Map<String, Object> outerCustomFields = buildOuterCustomFields( |
|
|
|
customFields, outerQty, boxPackCount, outerBatchIndex, outerQtyList.size()); |
|
|
|
customFields, outerQty, outerBatchIndex, outerQtyList.size()); |
|
|
|
queryParams.put("customFields", outerCustomFields); |
|
|
|
|
|
|
|
// 生成当前QTY对应的外箱标签(同一queryParams会复用IFS缓存) |
|
|
|
@ -752,8 +751,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={}, boxPackCount={}, taskId={}", |
|
|
|
outerBatchIndex, outerQtyList.size(), i + 1, totalLabels, outerQty, boxPackCount, taskId); |
|
|
|
log.info("外箱标签任务已加入队列,batch={} / {}, index={} / {}, qty={}, taskId={}", |
|
|
|
outerBatchIndex, outerQtyList.size(), i + 1, totalLabels, outerQty, taskId); |
|
|
|
} |
|
|
|
outerBatchIndex++; |
|
|
|
} |
|
|
|
@ -963,36 +962,31 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 构建外箱标签 customFields:保留原字段,并按当前外箱覆盖 qty、boxPackCount,同时写入箱序号和总箱数。 |
|
|
|
* 入参里的 QTY、boxPackCount 是等长数组,这里必须落成当前下标的单值,否则标签会印出整段数组。 |
|
|
|
* 构建外箱标签 customFields:数组按QTY的当前下标取值,非数组字段由所有外箱共用。 |
|
|
|
* 调用前统一校验数组长度;保留字段原名和数据类型,并写入当前箱序号和总箱数。 |
|
|
|
*/ |
|
|
|
private Map<String, Object> buildOuterCustomFields(Map<String, Object> sourceCustomFields, String outerQty, |
|
|
|
String boxPackCount, int serialNumber, int outerBoxes) { |
|
|
|
int serialNumber, int outerBoxes) { |
|
|
|
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())) { |
|
|
|
String normalizedKey = StringUtils.trimToEmpty(key); |
|
|
|
if (StringUtils.equalsIgnoreCase(normalizedKey, "qty")) { |
|
|
|
outerCustomFields.put(key, outerQty); |
|
|
|
qtyUpdated = true; |
|
|
|
} else if (StringUtils.equalsIgnoreCase(normalizedKey, "boxPackCount")) { |
|
|
|
outerCustomFields.put(key, boxPackCount); |
|
|
|
boxPackCountUpdated = true; |
|
|
|
if (sourceCustomFields != null) { |
|
|
|
for (Map.Entry<String, Object> entry : sourceCustomFields.entrySet()) { |
|
|
|
Object value = entry.getValue(); |
|
|
|
if (value instanceof List<?> values) { |
|
|
|
value = values.get(serialNumber - 1); |
|
|
|
} |
|
|
|
if (StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(entry.getKey()), "qty")) { |
|
|
|
value = outerQty; |
|
|
|
qtyUpdated = true; |
|
|
|
} |
|
|
|
outerCustomFields.put(entry.getKey(), value); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!qtyUpdated) { |
|
|
|
outerCustomFields.put("qty", outerQty); |
|
|
|
} |
|
|
|
if (!boxPackCountUpdated) { |
|
|
|
outerCustomFields.put("boxPackCount", boxPackCount); |
|
|
|
} |
|
|
|
outerCustomFields.put("serialNumber", serialNumber); |
|
|
|
outerCustomFields.put("outerBoxes", outerBoxes); |
|
|
|
outerCustomFields.put("boxPackCount", boxPackCount); |
|
|
|
return outerCustomFields; |
|
|
|
} |
|
|
|
|
|
|
|
@ -1027,37 +1021,15 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 提取与QTY逐项对齐的boxPackCount。数量必须和QTY一致,当前外箱只取同一下标的值。 |
|
|
|
* 以QTY数量为准校验所有自定义数组字段,非数组字段无需逐箱配置。 |
|
|
|
*/ |
|
|
|
private List<String> extractRequiredBoxPackCountList(Map<String, Object> customFields, int expectedSize) { |
|
|
|
if (customFields == null || customFields.isEmpty()) { |
|
|
|
throw new RuntimeException(labelSettingI18n.text("label.error.boxPackCountRequired")); |
|
|
|
} |
|
|
|
Object packValue = null; |
|
|
|
private void validateOuterCustomFieldArrays(Map<String, Object> customFields, int expectedSize) { |
|
|
|
for (Map.Entry<String, Object> entry : customFields.entrySet()) { |
|
|
|
if (StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(entry.getKey()), "boxPackCount")) { |
|
|
|
packValue = entry.getValue(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!(packValue instanceof List<?> packList) || packList.isEmpty()) { |
|
|
|
throw new RuntimeException(labelSettingI18n.text("label.error.boxPackCountArrayRequired")); |
|
|
|
} |
|
|
|
if (packList.size() != expectedSize) { |
|
|
|
throw new RuntimeException(labelSettingI18n.text( |
|
|
|
"label.error.boxPackCountSizeMismatch", expectedSize, packList.size())); |
|
|
|
} |
|
|
|
List<String> boxPackCountList = new ArrayList<>(); |
|
|
|
int packIndex = 1; |
|
|
|
for (Object packObj : packList) { |
|
|
|
String packCount = packObj == null ? "" : packObj.toString().trim(); |
|
|
|
if (StringUtils.isBlank(packCount)) { |
|
|
|
throw new RuntimeException(labelSettingI18n.text("label.error.boxPackCountItemRequired", packIndex)); |
|
|
|
if (entry.getValue() instanceof List<?> values && values.size() != expectedSize) { |
|
|
|
throw new RuntimeException(labelSettingI18n.text( |
|
|
|
"label.error.customFieldArraySizeMismatch", entry.getKey(), expectedSize, values.size())); |
|
|
|
} |
|
|
|
boxPackCountList.add(packCount); |
|
|
|
packIndex++; |
|
|
|
} |
|
|
|
return boxPackCountList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|