Browse Source

打印参数添加boxPackCount

dev
shenzhouyu 4 weeks ago
parent
commit
9fbdf11c66
  1. 69
      src/main/java/com/gaotao/modules/base/service/Impl/ReportLabelListServiceImpl.java
  2. 3
      src/main/resources/i18n/messages_en_US.properties
  3. 3
      src/main/resources/i18n/messages_zh_CN.properties

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

@ -713,7 +713,8 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe
customerId: "CUST123",// customerId是可选的,如果传了,系统会优先根据customerId解析标签编号 customerId: "CUST123",// customerId是可选的,如果传了,系统会优先根据customerId解析标签编号
addressNo: "ADDR001", // addressNo是可选的,传了会优先按customerId+addressNo精确匹配 addressNo: "ADDR001", // addressNo是可选的,传了会优先按customerId+addressNo精确匹配
"customFields": { "customFields": {
"QTY": ["100","200","300"],
"QTY": ["100","200","300"],// 有几个值就打印几张外箱标签
"boxPackCount": ["5","5","1"],// 与QTY一一对应:每个外箱对应的内包数,末箱不满则传实际包数;系统按此生成/替换外箱标签字段
"grossWeight": 15.6, "grossWeight": 15.6,
"netWeight": 14.9 "netWeight": 14.9
} }
@ -729,9 +730,13 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe
if (hasCustomerId) { if (hasCustomerId) {
// 传customerId时,按QTY数组逐项生成外箱任务 // 传customerId时,按QTY数组逐项生成外箱任务
List<String> outerQtyList = extractRequiredOuterQtyList(customFields); List<String> outerQtyList = extractRequiredOuterQtyList(customFields);
List<String> outerBoxPackCountList = extractOptionalBoxPackCountList(customFields, outerQtyList.size());
int outerBatchIndex = 1; 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); queryParams.put("customFields", outerCustomFields);
// 生成当前QTY对应的外箱标签(同一queryParams会复用IFS缓存) // 生成当前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<>(); Map<String, Object> labelData = i < labelDataList.size() ? labelDataList.get(i) : new HashMap<>();
Long taskId = enqueueSingleTask(outerPrinter.getIpAddress(), zplCode, outerRfidFlag, labelData, printRequest); Long taskId = enqueueSingleTask(outerPrinter.getIpAddress(), zplCode, outerRfidFlag, labelData, printRequest);
taskIds.add(taskId); 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++; 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<>(); Map<String, Object> outerCustomFields = new HashMap<>();
if (sourceCustomFields != null && !sourceCustomFields.isEmpty()) { if (sourceCustomFields != null && !sourceCustomFields.isEmpty()) {
outerCustomFields.putAll(sourceCustomFields); outerCustomFields.putAll(sourceCustomFields);
} }
boolean qtyUpdated = false; boolean qtyUpdated = false;
boolean boxPackCountUpdated = false;
for (String key : new ArrayList<>(outerCustomFields.keySet())) { 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); outerCustomFields.put(key, outerQty);
qtyUpdated = true; qtyUpdated = true;
} else if (StringUtils.equalsIgnoreCase(normalizedKey, "boxPackCount")
&& StringUtils.isNotBlank(outerBoxPackCount)) {
outerCustomFields.put(key, outerBoxPackCount);
boxPackCountUpdated = true;
} }
} }
if (!qtyUpdated) { if (!qtyUpdated) {
outerCustomFields.put("qty", outerQty); outerCustomFields.put("qty", outerQty);
} }
if (!boxPackCountUpdated && StringUtils.isNotBlank(outerBoxPackCount)) {
outerCustomFields.put("boxPackCount", outerBoxPackCount);
}
return outerCustomFields; return outerCustomFields;
} }
@ -1008,6 +1024,43 @@ public class ReportLabelListServiceImpl extends ServiceImpl<ReportLabelListMappe
return outerQtyList; 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;
}
/** /**
* 根据外箱标签解析对应内箱标签 * 根据外箱标签解析对应内箱标签
*/ */

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

@ -96,6 +96,9 @@ 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.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.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.qtyItemRequired=customFields.QTY item {0} cannot be empty.
label.error.boxPackCountArrayRequired=customFields.boxPackCount must be a non-empty array, for example ["2","2","1"]
label.error.boxPackCountSizeMismatch=customFields.boxPackCount length ({0}) must match QTY length ({1})
label.error.boxPackCountItemRequired=customFields.boxPackCount item {0} cannot be empty.
label.error.previewFieldRequired=Enter {0} for real-data preview. label.error.previewFieldRequired=Enter {0} for real-data preview.
label.error.integerRequired={0} must be an integer. label.error.integerRequired={0} must be an integer.
label.preview.field.consignmentId=Shipment ID label.preview.field.consignmentId=Shipment ID

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

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

Loading…
Cancel
Save