This commit is contained in:
2026-10-20 14:22:53 +08:00
parent 19745e46c1
commit bf2508b6d6
24 changed files with 1222 additions and 88 deletions
@@ -64,6 +64,7 @@ public class DispatchBolPdfService {
return new DispatchBolPdfDtos.Request(DispatchBolPdfDtos.TEMPLATE, request.pageSpec(), fileName, List.copyOf(documents));
}
/** 核对页面容量并规范化打印字段,预约号缺失时保持空白。 */
private DispatchBolPdfDtos.Document normalizeDocument(DispatchBolPdfDtos.Document value, int index) {
int maxRows = value != null && value.pageNumber() == 1 ? MAX_FIRST_PAGE_ROWS : MAX_CONTINUATION_PAGE_ROWS;
if (value == null || value.cargoRows() == null || value.cargoRows().isEmpty() || value.cargoRows().size() > maxRows) {
@@ -77,15 +78,22 @@ public class DispatchBolPdfService {
text(row.warehouseNo()), text(row.fbaShipmentId()), text(row.poReferenceNo()), row.packageCount()));
}
return new DispatchBolPdfDtos.Document(text(value.shipFromName()), text(value.shipFromAddress()), text(value.carrierName()),
text(value.isaNumber()), text(value.appointmentTime()), text(value.trailerNumber()), text(value.sealNumber()),
optionalText(value.isaNumber()), text(value.appointmentTime()), text(value.trailerNumber()), text(value.sealNumber()),
text(value.fbaWarehouseCode()), text(value.shipToName()), text(value.shipToAddress()), text(value.dispatchNo()),
text(value.fbaShipmentIds()), text(value.poReferenceNos()), value.totalPackages(), value.pageNumber(), value.pageCount(), List.copyOf(rows));
}
/** 普通缺失字段沿用占位符,预约号通过可空文本单独处理。 */
private String text(String value) {
String normalized = optionalText(value);
return normalized.isBlank() ? "—" : normalized;
}
/** 保留空白语义,同时复用长度、规范化和控制字符校验。 */
private String optionalText(String value) {
String normalized = line(value);
if (normalized.codePointCount(0, normalized.length()) > 300 || normalized.codePoints().anyMatch(c -> Character.isISOControl(c))) invalid("document text is invalid");
return normalized.isBlank() ? "—" : normalized;
return normalized;
}
private String line(String value) { return value == null ? "" : Normalizer.normalize(value, Normalizer.Form.NFC).strip(); }
private void invalid(String message) { throw new BizException(ResultCode.VALIDATION_FAILED, message); }