Browse Source

Merge remote-tracking branch 'origin/master'

master
常熟吴彦祖 4 weeks ago
parent
commit
321ca411b8
  1. 61
      src/main/java/com/gaotao/modules/base/service/Impl/ReportLabelListServiceImpl.java
  2. 4
      src/main/resources/i18n/messages_en_US.properties
  3. 4
      src/main/resources/i18n/messages_zh_CN.properties

61
src/main/java/com/gaotao/modules/base/service/Impl/ReportLabelListServiceImpl.java

@ -714,6 +714,7 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe
addressNo: "ADDR001", // addressNo是可选的,传了会优先按customerId+addressNo精确匹配
"customFields": {
"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);
// boxPackCount与QTY等长,按下标取当前外箱的内包数,避免整段数组被印到每一张标签上
List<String> boxPackCountList = extractRequiredBoxPackCountList(customFields, outerQtyList.size());
int outerBatchIndex = 1;
for (String outerQty : outerQtyList) {
Map<String, Object> outerCustomFields = buildOuterCustomFields(customFields, outerQty, outerBatchIndex, outerQtyList.size());
String boxPackCount = boxPackCountList.get(outerBatchIndex - 1);
Map<String, Object> outerCustomFields = buildOuterCustomFields(
customFields, outerQty, boxPackCount, outerBatchIndex, outerQtyList.size());
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, boxPackCount, taskId);
}
outerBatchIndex++;
}
@ -958,26 +963,36 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe
}
/**
* 构建外箱标签 customFields:保留原字段并覆盖 qty、当前箱序号和总箱数
* 构建外箱标签 customFields:保留原字段,并按当前外箱覆盖 qty、boxPackCount,同时写入箱序号和总箱数。
* 入参里的 QTY、boxPackCount 是等长数组,这里必须落成当前下标的单值,否则标签会印出整段数组。
*/
private Map<String, Object> buildOuterCustomFields(Map<String, Object> sourceCustomFields, String outerQty,
int serialNumber, int outerBoxes) {
String boxPackCount, 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())) {
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")) {
outerCustomFields.put(key, boxPackCount);
boxPackCountUpdated = true;
}
}
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;
}
@ -1011,6 +1026,40 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe
return outerQtyList;
}
/**
* 提取与QTY逐项对齐的boxPackCount。数量必须和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;
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));
}
boxPackCountList.add(packCount);
packIndex++;
}
return boxPackCountList;
}
/**
* 根据外箱标签解析对应内箱标签
*/

4
src/main/resources/i18n/messages_en_US.properties

@ -96,6 +96,10 @@ label.error.printerIpMissing=Printer IP is not configured: labelType={0}
label.error.qtyRequired=customFields.QTY array is required for outer-box label printing.
label.error.qtyArrayRequired=customFields.QTY must be a non-empty array, for example ["100","200","300"]
label.error.qtyItemRequired=customFields.QTY item {0} cannot be empty.
label.error.boxPackCountRequired=customFields.boxPackCount array is required for outer-box label printing.
label.error.boxPackCountArrayRequired=customFields.boxPackCount must be a non-empty array, for example ["5","5","1"]
label.error.boxPackCountSizeMismatch=customFields.boxPackCount length must match QTY. QTY has {0} items, boxPackCount has {1}.
label.error.boxPackCountItemRequired=customFields.boxPackCount item {0} cannot be empty.
label.error.previewFieldRequired=Enter {0} for real-data preview.
label.error.integerRequired={0} must be an integer.
label.preview.field.consignmentId=Shipment ID

4
src/main/resources/i18n/messages_zh_CN.properties

@ -96,6 +96,10 @@ label.error.printerIpMissing=打印机IP地址未配置:labelType={0}
label.error.qtyRequired=外箱标签打印必须传入customFields.QTY数组
label.error.qtyArrayRequired=customFields.QTY必须为非空数组,例如 ["100","200","300"]
label.error.qtyItemRequired=customFields.QTY第{0}项不能为空
label.error.boxPackCountRequired=外箱标签打印必须传入customFields.boxPackCount数组
label.error.boxPackCountArrayRequired=customFields.boxPackCount必须为非空数组,例如 ["5","5","1"]
label.error.boxPackCountSizeMismatch=customFields.boxPackCount数量必须与QTY一致,QTY共{0}项,boxPackCount共{1}项
label.error.boxPackCountItemRequired=customFields.boxPackCount第{0}项不能为空
label.error.previewFieldRequired=真实数据预览请填写{0}
label.error.integerRequired={0}必须为整数
label.preview.field.consignmentId=发货单ID

Loading…
Cancel
Save