This commit is contained in:
2026-09-11 11:51:26 +08:00
parent d60689ce02
commit d2cff49b9e
45 changed files with 569 additions and 66 deletions
@@ -22,5 +22,6 @@ public interface DomesticWarehouseDirectoryClient {
record Warehouse(Long id, Long tenantId, String warehouseCode, String warehouseName,
String warehouseType, String countryCode, String status) { }
record Address(String stateProvince) { }
record Address(String addressType, String countryCode, String stateProvince, String city,
String district, String postalCode, String addressLine1, String addressLine2) { }
}
@@ -2,6 +2,7 @@ package com.baiyue.lastleg.dispatch.service;
import com.baiyue.common.core.api.ResultCode;
import com.baiyue.common.core.exception.BizException;
import com.baiyue.lastleg.client.DomesticWarehouseDirectoryClient;
import com.baiyue.lastleg.client.PrintPdfClient;
import com.baiyue.lastleg.dispatch.dto.DispatchResponse;
import feign.FeignException;
@@ -13,6 +14,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@@ -27,6 +29,7 @@ public class DispatchBolPrintService {
@Resource private DispatchService dispatches;
@Resource private PrintPdfClient print;
@Resource private DomesticWarehouseDirectoryClient warehouses;
@Value("${baiyue.security.internal-service-token:}") private String internalToken;
public GeneratedPdf generate(String dispatchNo, String requestId) {
@@ -52,6 +55,7 @@ public class DispatchBolPrintService {
}
private List<PrintPdfClient.Document> documents(DispatchResponse detail) {
String shipFromAddress = warehouseAddress(detail.overseasWarehouseId());
Map<String, List<DispatchResponse.BolLine>> groups = new LinkedHashMap<>();
for (DispatchResponse.BolLine line : detail.bolLines()) groups.computeIfAbsent(text(line.fbaWarehouseCode()), ignored -> new ArrayList<>()).add(line);
List<PrintPdfClient.Document> documents = new ArrayList<>();
@@ -67,7 +71,7 @@ public class DispatchBolPrintService {
List<PrintPdfClient.CargoRow> rows = lines.subList(offset, end).stream()
.map(line -> new PrintPdfClient.CargoRow(text(line.containerNo()), text(line.palletNo()), text(line.fbaWarehouseCode()),
text(line.warehouseNo()), text(line.fbaShipmentId()), text(line.poReferenceNo()), line.packageCount())).toList();
documents.add(new PrintPdfClient.Document(text(detail.overseasWarehouseName()), "—", text(detail.carrierName()),
documents.add(new PrintPdfClient.Document(text(detail.overseasWarehouseName()), shipFromAddress, text(detail.carrierName()),
text(detail.fbaAppointmentNo()), dateTime(detail.estimatedArrivalAt()), text(detail.vehiclePlate()), "—",
group.getKey(), destination, "—", text(detail.dispatchNo()), unique(lines, true), unique(lines, false),
total, page + 1, pages, rows));
@@ -77,6 +81,41 @@ public class DispatchBolPrintService {
return List.copyOf(documents);
}
private String warehouseAddress(String warehouseId) {
long id;
try {
id = Long.parseLong(warehouseId == null ? "" : warehouseId.strip());
} catch (NumberFormatException exception) {
throw new BizException(ResultCode.VALIDATION_FAILED, "排车单未关联有效的海外仓");
}
try {
var response = warehouses.activeWarehouse(id, internalToken);
if (response == null || !response.successful() || response.data() == null) {
throw new BizException(ResultCode.SERVICE_UNAVAILABLE, "仓库主数据暂不可用,无法生成BOL");
}
List<DomesticWarehouseDirectoryClient.Address> addresses = response.data().addresses();
if (addresses == null || addresses.isEmpty()) return "—";
DomesticWarehouseDirectoryClient.Address address = addresses.stream().filter(Objects::nonNull)
.filter(value -> "OPERATING".equals(value.addressType())).findFirst()
.orElseGet(() -> addresses.stream().filter(Objects::nonNull).findFirst().orElse(null));
if (address == null) return "—";
List<String> parts = new ArrayList<>();
add(parts, address.addressLine1());
add(parts, address.addressLine2());
add(parts, address.city());
add(parts, address.stateProvince());
add(parts, address.postalCode());
add(parts, address.countryCode());
return parts.isEmpty() ? "—" : String.join(", ", parts);
} catch (FeignException exception) {
throw new BizException(ResultCode.SERVICE_UNAVAILABLE, "仓库主数据暂不可用,无法生成BOL");
}
}
private void add(List<String> parts, String value) {
if (value != null && !value.isBlank()) parts.add(value.strip());
}
static int pageCount(int rowCount) {
if (rowCount <= FIRST_PAGE_ROWS) return 1;
return 1 + (rowCount - FIRST_PAGE_ROWS + CONTINUATION_PAGE_ROWS - 1) / CONTINUATION_PAGE_ROWS;