2026-08-13 17:13:58 +08:00
|
|
|
package com.baiyue.common.event;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
|
|
|
|
|
class FirstLegLoadingPlanCompletedV1Test {
|
|
|
|
|
private final ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void v1PayloadRoundTripsWithoutLosingLargeIds() throws Exception {
|
|
|
|
|
var item = new FirstLegLoadingPlanCompletedV1.Item("2088000000000000001", "SKU-1", "产品", "Product",
|
|
|
|
|
2, 20, 1, new BigDecimal("10.500"), new BigDecimal("9.500"), new BigDecimal("12.000"),
|
|
|
|
|
new BigDecimal("0.200"), "2088000000000000002", "ONT8", "ONT8", "FBA-1", "SHIP-1", "MARK");
|
|
|
|
|
var order = new FirstLegLoadingPlanCompletedV1.Order("2088000000000000003", "2088000000000000004",
|
|
|
|
|
"2088000000000000005", "FL-1", "2088000000000000006", "RK-1", "2088000000000000002",
|
|
|
|
|
"ONT8", "ONT8", 2, 20, 1, new BigDecimal("10.500"), new BigDecimal("9.500"),
|
2026-08-27 15:56:14 +08:00
|
|
|
new BigDecimal("0.200"), List.of(item), "9001", "客户甲", "FIRST_LEG", List.of());
|
2026-08-13 17:13:58 +08:00
|
|
|
var payload = new FirstLegLoadingPlanCompletedV1("2088000000000000007", "P-1", "2088000000000000008",
|
|
|
|
|
"CONT-1", "CAB-1", "2088000000000000009", "中转仓", List.of(order));
|
|
|
|
|
String json = mapper.writeValueAsString(payload);
|
|
|
|
|
assertThat(mapper.readValue(json, FirstLegLoadingPlanCompletedV1.class)).isEqualTo(payload);
|
|
|
|
|
assertThat(json).contains("2088000000000000003", "sourceInboundDetailId");
|
|
|
|
|
}
|
2026-08-19 09:28:40 +08:00
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void dropshipPayloadKeepsMultiplePalletsAndCartonMarks() throws Exception {
|
|
|
|
|
var sku1 = new FirstLegLoadingPlanCompletedV1.SkuPackageSnapshot(
|
|
|
|
|
"SKU-1", "产品1", 2, 20, List.of("BOX-001", "BOX-002"));
|
|
|
|
|
var sku2 = new FirstLegLoadingPlanCompletedV1.SkuPackageSnapshot(
|
|
|
|
|
"SKU-2", "产品2", 1, 5, List.of("BOX-003"));
|
|
|
|
|
var order = new FirstLegLoadingPlanCompletedV1.Order("100", "100", "200", "FL-200", "200",
|
|
|
|
|
"RK-100", "300", "ONT8", "ONT8", 3, 25, 2, BigDecimal.ONE,
|
2026-08-27 15:56:14 +08:00
|
|
|
BigDecimal.ONE, BigDecimal.ONE, List.of(), "9001", "客户甲", "ONE_CLICK_DROPSHIP",
|
2026-08-19 09:28:40 +08:00
|
|
|
List.of(new FirstLegLoadingPlanCompletedV1.PalletSnapshot("PLT-01", List.of(sku1)),
|
|
|
|
|
new FirstLegLoadingPlanCompletedV1.PalletSnapshot("PLT-02", List.of(sku2))));
|
|
|
|
|
var payload = new FirstLegLoadingPlanCompletedV1("1", "LP-1", "2", "CONT-1", null,
|
|
|
|
|
"3", "海外仓", List.of(order));
|
|
|
|
|
|
|
|
|
|
String json = mapper.writeValueAsString(payload);
|
|
|
|
|
FirstLegLoadingPlanCompletedV1 restored = mapper.readValue(json, FirstLegLoadingPlanCompletedV1.class);
|
|
|
|
|
|
|
|
|
|
assertThat(restored).isEqualTo(payload);
|
|
|
|
|
assertThat(json).contains("ONE_CLICK_DROPSHIP", "PLT-01", "BOX-003", "customerId");
|
|
|
|
|
}
|
2026-08-24 17:15:48 +08:00
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void legacyParserRetainsDestinationTypeWhenV2OrderCarriesIt() throws Exception {
|
|
|
|
|
String json = """
|
|
|
|
|
{"loadingPlanId":"1","planNo":"LP-1","containerBookingId":"2","containerNo":"CONT-1",
|
2026-08-27 16:42:27 +08:00
|
|
|
"warehouseId":"3","warehouseName":"海外仓","estimatedPortArrivalAt":"2026-09-30T12:00",
|
|
|
|
|
"actualPortArrivalAt":null,"estimatedWarehouseArrivalAt":"2026-10-03T09:00",
|
|
|
|
|
"orders":[{"sourceInboundId":"100","destinationWarehouseId":"3","packageCount":1,
|
|
|
|
|
"palletCount":2,"volumeWeightKg":12.500,"items":[],"customerId":"9001",
|
2026-08-27 15:56:14 +08:00
|
|
|
"customerName":"客户甲","destinationType":"OVERSEAS"}]}
|
2026-08-24 17:15:48 +08:00
|
|
|
""";
|
|
|
|
|
|
|
|
|
|
FirstLegLoadingPlanCompletedV1 restored = mapper.readValue(json, FirstLegLoadingPlanCompletedV1.class);
|
|
|
|
|
|
|
|
|
|
assertThat(restored.orders().get(0).destinationType()).isEqualTo("OVERSEAS");
|
2026-08-27 16:42:27 +08:00
|
|
|
assertThat(restored.estimatedPortArrivalAt()).isEqualTo("2026-09-30T12:00");
|
|
|
|
|
assertThat(restored.actualPortArrivalAt()).isNull();
|
|
|
|
|
assertThat(restored.estimatedWarehouseArrivalAt()).isEqualTo("2026-10-03T09:00");
|
|
|
|
|
assertThat(restored.orders().get(0).palletCount()).isEqualTo(2);
|
|
|
|
|
assertThat(restored.orders().get(0).volumeWeightKg()).isEqualByComparingTo("12.500");
|
2026-08-24 17:15:48 +08:00
|
|
|
}
|
2026-08-13 17:13:58 +08:00
|
|
|
}
|