diff --git a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/capability/WarehouseProduct.java b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/capability/WarehouseProduct.java index 202eff1..30b34e9 100644 --- a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/capability/WarehouseProduct.java +++ b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/capability/WarehouseProduct.java @@ -8,9 +8,12 @@ import java.util.Objects; /** * 仓商品建档入参。 * - *
单位写进字段名(cm / g),避免适配器之间靠注释约定换算。 - * 运去哪 API 115 的必填项(sku / 中英文名 / 包装方式 / 长宽高 / 重量 / SN) - * 在这里都是必填,缺了在构造期就失败,而不是等平台报错。
+ *单位写进字段名(cm / g),避免适配器之间靠注释约定换算。
+ * + *构造期只校验所有仓都必须给的字段:{@code omsSku}、{@code name}、 + * 长宽高与重量为正。其余字段({@code nameEn} / {@code packingType} / 海关三项 / + * 品类等)的必填性与组合约束都由各适配器在拼报文时校验—— + * 否则接第二家仓时会被第一家的约束卡住。
*/ public final class WarehouseProduct { @@ -19,11 +22,21 @@ public final class WarehouseProduct { private final String customItemNo; private final String barcode; private final String name; + /** + * 英文名。 + * + *运去哪必填(适配器会拒绝缺失);信仓接口只有中文名({@code chn_name}), + * 未给即不传。
+ */ private final String nameEn; private final String description; /** 产品类型:1 成品 / 2 配件 / 3 耗材;0 表示未指定(平台默认成品)。 */ private final int productType; - /** 发货包装:0 原包装发货 / 1 重新打包。 */ + /** + * 发货包装:0 原包装发货 / 1 重新打包;-1 表示未给。 + * + *运去哪必填(适配器会拒绝缺失);信仓接口没有该字段,未给即不传。
+ */ private final int packingType; private final double lengthCm; private final double widthCm; @@ -75,12 +88,13 @@ public final class WarehouseProduct { this.customItemNo = b.customItemNo; this.barcode = b.barcode; this.name = require(b.name, "name"); - this.nameEn = require(b.nameEn, "nameEn"); + // nameEn 是运去哪的必填项;信仓只有 chn_name(取 name),没有英文名。 + // 必填性由 YqnProductMapper 校验,这里不做构造期强制。 + this.nameEn = b.nameEn; this.description = b.description; this.productType = b.productType; - if (b.packingType < 0) { - throw new IllegalArgumentException("packingType is required (0 原包装发货 / 1 重新打包)"); - } + // 不在构造期强制:这是运去哪的必填项,信仓不需要。必填性由各适配器按自己的 + // 协议校验,见 YqnProductMapper;未给时保持 -1 表示「不传」。 this.packingType = b.packingType; this.lengthCm = requirePositive(b.lengthCm, "lengthCm"); this.widthCm = requirePositive(b.widthCm, "widthCm"); @@ -103,21 +117,9 @@ public final class WarehouseProduct { this.productCategory = b.productCategory; this.imageUrl = b.imageUrl; - // 海关信息要么整组给、要么整组不给:国家编码 / HS Code / 申报价值缺一即失败 - int customsFields = 0; - if (hasText(hsCode)) { - customsFields++; - } - if (hasText(countryOfOrigin)) { - customsFields++; - } - if (declaredValue != null) { - customsFields++; - } - if (customsFields != 0 && customsFields != 3) { - throw new IllegalArgumentException( - "hsCode / countryOfOrigin / declaredValue must be set together for customs"); - } + // 海关信息「三项整组给」原本在这里校验。但信仓只用 declaredValue 当 amount(必填), + // 不需要 hsCode / countryOfOrigin;在模型层强制整组会把信仓卡死。 + // 整组校验移到需要海关信息的适配器(见 YqnProductMapper.toCustoms)。 } public static Builder builder() { @@ -343,7 +345,7 @@ public final class WarehouseProduct { return this; } - /** 0 原包装发货 / 1 重新打包;必填。 */ + /** 0 原包装发货 / 1 重新打包;运去哪必填,信仓不用。 */ public Builder packingType(int v) { this.packingType = v; return this; diff --git a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/InboundCommand.java b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/InboundCommand.java index c0cfc67..87545de 100644 --- a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/InboundCommand.java +++ b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/InboundCommand.java @@ -8,8 +8,10 @@ import java.util.List; /** * 入库计划创建命令。写操作,幂等键是 {@link #inboundRequestNo()}(仓方的来源单号)。 * - *必填:单号、仓、库存类型、至少一条商品行。装箱、批次、附件都是可选的—— - * 仓会在收货时按实际情况清点,但给了就必须自洽(一箱多 SKU 要用 sid 归并)。
+ *构造期只校验所有仓都必须给的:单号、库存类型取值。仓 / 商品行 / 日期等 + * 各家要求不同(信仓「新增预报」只建单头、明细走「完善资料」), + * 必填性由各适配器在拼报文时校验;装箱、批次、附件的自洽性仍由模型保证 + * (一箱多 SKU 要用 sid 归并)。
*/ public final class InboundCommand { @@ -67,6 +69,14 @@ public final class InboundCommand { /** 中文名称(信仓 {@code chn_name});null 表示不传。 */ private final String chnName; + /** + * 参考 SKU 种类数;null 表示不传。 + * + *信仓 {@code rfc_sku_count}(新增预报必填)。与 {@link #lines()} 行数无关: + * 报的是「预计有多少种 SKU」,建单时明细还没给。
+ */ + private final Integer referenceSkuCount; + private InboundCommand(Builder b) { if (b.inboundRequestNo == null || b.inboundRequestNo.trim().isEmpty()) { throw new IllegalArgumentException("inboundRequestNo must not be blank"); @@ -94,9 +104,8 @@ public final class InboundCommand { this.shipperPhone = b.shipperPhone; this.containerNo = b.containerNo; this.remark = b.remark; - if (b.lines.isEmpty()) { - throw new IllegalArgumentException("lines must not be empty"); - } + // lines 不在构造期强制:信仓的入库是「先建单头 → 再完善资料补明细」两步, + // 第一步本来就没有明细。需要明细的仓(运去哪、信仓的完善资料)由适配器校验。 this.lines = Collections.unmodifiableList(new ArrayList运去哪对 {@code sourceNo} 有唯一约束,查询与取消都靠它,所以它同时是业务主键。
+ * + *构造期只校验跨仓共识的必填项;某一家仓特有的必填项(运去哪的日期与收货地址、 + * 信仓的转运类型 / 方式 / 是否打托)由各适配器在拼报文时校验。
*/ public final class TransferCommand { @@ -29,7 +32,7 @@ public final class TransferCommand { private final String removeOrderId; /** 目的地地址 code(FBA 地址 code)。 */ private final String receiveStore; - /** 目的地地址;{@code TransferType.OUTBOUND} 时构造期必填。 */ + /** 目的地地址;调拨出库时部分仓必填(运去哪),必填性由适配器校验。 */ private final ShipTo shipTo; private final String remark; /** 增值服务:1 贴产品标 / 2 贴箱标 / 3 贴托盘标。 */ @@ -101,11 +104,10 @@ public final class TransferCommand { this.inventoryType = b.inventoryType; this.carrierType = b.carrierType; this.transportationType = b.transportationType; - if (b.estimateOutboundDate == null || b.estimateInboundDate == null) { - throw new IllegalArgumentException( - "estimateOutboundDate and estimateInboundDate are required"); - } - if (b.estimateInboundDate.isBefore(b.estimateOutboundDate)) { + // 日期必填是运去哪的要求,信仓转运只需要发货日期(pre_send_time)。 + // 必填性与先后顺序由各适配器校验;这里只保证「给了两个才比较先后」的自洽。 + if (b.estimateOutboundDate != null && b.estimateInboundDate != null + && b.estimateInboundDate.isBefore(b.estimateOutboundDate)) { throw new IllegalArgumentException( "estimateInboundDate must not be earlier than estimateOutboundDate"); } @@ -115,10 +117,8 @@ public final class TransferCommand { this.removeOrderId = b.removeOrderId; this.receiveStore = b.receiveStore; this.shipTo = b.shipTo; - // 调拨出库必须给收货地址;仓到仓由仓自己处理 - if (type == TransferType.OUTBOUND && shipTo == null) { - throw new IllegalArgumentException("shipTo is required when transfer type is OUTBOUND"); - } + // 收货地址在调拨出库时是否必填由各仓协议决定: + // 运去哪要求 shipTo;信仓用 other_warehouse(仓库名)代替,见对应适配器。 this.remark = b.remark; this.serviceTypes = java.util.Collections.unmodifiableList( new java.util.ArrayList这些用例守护的是:信仓可以只给它认识的字段就构造出命令, + * 不会因为运去哪的必填项(nameEn / packingType / 海关三项 / 入库商品行) + * 被迫塞无意义的值。
+ */ +class XincangModelRelaxTest { + + /** 商品:不给 nameEn / packingType / 海关三项也能构造(信仓都收不到这些字段)。 */ + @Test + void productBuildsWithoutYqnOnlyFields() { + WarehouseProduct product = WarehouseProduct.builder() + .omsSku("SKU-1") + .name("中文名") + .lengthCm(10).widthCm(10).heightCm(10).weightGrams(100) + .build(); + assertNotNull(product); + } + + /** + * 商品:信仓 amount 必填,但只需要 declaredValue,不需要 hsCode / countryOfOrigin。 + * + *改前「海关三项必须整组给」在构造期强制,信仓调用方被迫填两个用不上的字段。
+ */ + @Test + void productCustomsValueAloneIsAccepted() { + WarehouseProduct product = WarehouseProduct.builder() + .omsSku("SKU-2") + .name("中文名") + .lengthCm(10).widthCm(10).heightCm(10).weightGrams(100) + .declaredValue(Money.of("1.00", "USD")) + .build(); + assertNotNull(product); + } + + /** 入库:信仓「新增预报」只建单头,可以没有商品行(明细走「完善资料」)。 */ + @Test + void inboundHeaderOnlyIsEnoughForForecastCreate() { + InboundCommand head = InboundCommand.builder() + .inboundRequestNo("FC-1") + .warehouseId("NJ-2605") + .shipmentType("2") + .cabinetType("1") + .containerNo("CAB-1") + .predictionShipDate(LocalDate.now().plusDays(1)) + .estimateArriveDate(LocalDate.now().plusDays(30)) + .deliveryRequirements("1") + .referenceSkuCount(3) + .build(); + assertNotNull(head); + } + + /** 入库:完善资料阶段要明细,这时才加行,模型允许。 */ + @Test + void inboundWithLinesStillWorks() { + InboundCommand withLines = InboundCommand.builder() + .inboundRequestNo("FC-2") + .warehouseId("NJ-2605") + .line(InboundLine.builder().omsSku("SKU-1").quantity(1).build()) + .build(); + assertNotNull(withLines); + } +} diff --git a/warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/adapter/XincangProductTest.java b/warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/adapter/XincangProductTest.java index cfe3182..836425b 100644 --- a/warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/adapter/XincangProductTest.java +++ b/warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/adapter/XincangProductTest.java @@ -207,6 +207,32 @@ class XincangProductTest { } @Test + void productWithoutEnglishNameIsAccepted() { + // 信仓只有中文名(chn_name),没有 english name 字段; + // nameEn 是运去哪的必填项,不应在统一模型构造期强制 + routeProductList("[]"); + transport.route(XincangConstants.PATH_PRODUCT_ADD, req -> Responses.ok( + "{\"rst\":true,\"errno\":0,\"err\":\"\"}")); + WarehouseProduct noEnglishName = WarehouseProduct.builder() + .omsSku("APITEST008") + .name("测试商品") + .barcode("B-8") + .packingType(0) + .lengthCm(10).widthCm(10).heightCm(10).weightGrams(100) + .declaredValue(Money.of("1.00", "USD")) + .hsCode("9403600000") + .countryOfOrigin("US") + .build(); + + assertNotNull(adapter.createOrUpdate(ctx(), noEnglishName), + "缺 nameEn 时信仓应能正常建档"); + + String body = Objects.requireNonNull(transport.lastDataRequest()).body(); + assertTrue(body.contains("\"chn_name\":\"测试商品\""), body); + assertFalse(body.contains("nameEn"), "信仓不发送英文名"); + } + + @Test void missingDeclaredValueIsRejectedInsteadOfSendingZero() { routeProductList("[]"); WarehouseProduct noValue = WarehouseProduct.builder() diff --git a/warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/adapter/XincangTransferTest.java b/warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/adapter/XincangTransferTest.java index 9904c47..0240ae0 100644 --- a/warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/adapter/XincangTransferTest.java +++ b/warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/adapter/XincangTransferTest.java @@ -192,6 +192,25 @@ class XincangTransferTest { } @Test + void modelNoLongerRequiresInboundDateOrShipTo() { + // 信仓转运只用 pre_send_time,也不用收件地址;模型不再强制这两个字段 + TransferCommand minimal = TransferCommand.builder() + .transferRequestNo("TR-MIN") + .type(TransferType.OUTBOUND) + .fromWarehouseCode("CA-3790").toWarehouseCode("ONT8") + .estimateOutboundDate(LocalDate.parse("2026-11-20")) + .deliveryMode("FBA").deliveryWay("Amazon(亚马逊卡车自提)") + .palletRequired(false) + .line("SKU-1", 1) + .build(); + + transport.route(XincangConstants.PATH_TRANSFER_CREATE, req -> Responses.ok( + "{\"rst\":{\"order_no\":\"LTL-MIN\"},\"errno\":0,\"err\":\"\"}")); + + assertNotNull(adapter.create(ctx(), minimal)); + } + + @Test void nonOutboundTransferTypeIsRejected() { TransferCommand cmd = TransferCommand.builder() .transferRequestNo("TR-2") diff --git a/warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/probe/XincangWriteProbeTest.java b/warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/probe/XincangWriteProbeTest.java index 5efbc8a..cbd6226 100644 --- a/warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/probe/XincangWriteProbeTest.java +++ b/warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/probe/XincangWriteProbeTest.java @@ -170,6 +170,8 @@ class XincangWriteProbeTest { @Test void probeTransferRoundTrip() { XincangProbeSupport.requireCredentials(); + XincangProbeSupport.requireProperty("xincang.probe.sku"); + XincangProbeSupport.requireProperty("xincang.probe.destWarehouse"); System.out.println("\n================ xincang / fba.do_fba → fba_detail → fba.delete_fba ================"); XincangAdapter adapter = XincangProbeSupport.adapter(); String warehouseCode = XincangProbeSupport.warehouseCode(adapter); @@ -184,19 +186,16 @@ class XincangWriteProbeTest { .transferRequestNo(transferNo) .type(TransferType.OUTBOUND) .fromWarehouseCode(warehouseCode) - .toWarehouseCode(destWarehouse.isEmpty() ? "PROBE-DEST" : destWarehouse) + .toWarehouseCode(destWarehouse) .po(transferNo) - // 信仓 fba.do_fba 只用 pre_send_time,不用到仓日期;给同一天仅为满足模型约束 + // 信仓只用 pre_send_time;到仓日期与收件地址它都不收, + // 这里不传,顺便验证模型已不再强制这两个字段 .estimateOutboundDate(LocalDate.now().plusDays(1)) - .estimateInboundDate(LocalDate.now().plusDays(1)) - .shipTo(ShipTo.builder().name("Probe").countryCode("US").stateOrProvince("CA") - .city("Fontana").addressLine1("1 Probe St").postalCode("91752").build()) .deliveryMode(XincangProbeSupport.opt("xincang.probe.deliveryMode", "")) .deliveryWay(XincangProbeSupport.opt("xincang.probe.deliveryWay", "")) .orderType(XincangProbeSupport.opt("xincang.probe.orderType", "")) .palletRequired(Boolean.FALSE) - .line(XincangProbeSupport.SKU.isEmpty() ? "PROBE-SKU" : XincangProbeSupport.SKU, - XincangProbeSupport.qty()) + .line(XincangProbeSupport.SKU, XincangProbeSupport.qty()) .build(); TransferOrder created = XincangProbeSupport.step("do_fba fba_no=" + transferNo, @@ -224,6 +223,8 @@ class XincangWriteProbeTest { void probeTransferApprove() { XincangProbeSupport.requireCredentials(); XincangProbeSupport.requireProperty("xincang.probe.transferApprove"); + XincangProbeSupport.requireProperty("xincang.probe.sku"); + XincangProbeSupport.requireProperty("xincang.probe.destWarehouse"); System.out.println("\n================ xincang / fba.do_approve ================"); System.out.println(" [注意] 审核后的转运单无法删除,会留下数据。"); XincangAdapter adapter = XincangProbeSupport.adapter(); @@ -237,18 +238,14 @@ class XincangWriteProbeTest { .transferRequestNo(transferNo) .type(TransferType.OUTBOUND) .fromWarehouseCode(warehouseCode) - .toWarehouseCode(XincangProbeSupport.opt("xincang.probe.destWarehouse", "PROBE-DEST")) + .toWarehouseCode(XincangProbeSupport.opt("xincang.probe.destWarehouse", "")) .po(transferNo) .estimateOutboundDate(LocalDate.now().plusDays(1)) - .estimateInboundDate(LocalDate.now().plusDays(1)) - .shipTo(ShipTo.builder().name("Probe").countryCode("US").stateOrProvince("CA") - .city("Fontana").addressLine1("1 Probe St").postalCode("91752").build()) .deliveryMode(XincangProbeSupport.opt("xincang.probe.deliveryMode", "")) .deliveryWay(XincangProbeSupport.opt("xincang.probe.deliveryWay", "")) .orderType(XincangProbeSupport.opt("xincang.probe.orderType", "")) .palletRequired(Boolean.FALSE) - .line(XincangProbeSupport.SKU.isEmpty() ? "PROBE-SKU" : XincangProbeSupport.SKU, - XincangProbeSupport.qty()) + .line(XincangProbeSupport.SKU, XincangProbeSupport.qty()) .build(); TransferOrder created = XincangProbeSupport.step("do_fba", diff --git a/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnInboundMapper.java b/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnInboundMapper.java index 1640c5d..bc1d614 100644 --- a/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnInboundMapper.java +++ b/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnInboundMapper.java @@ -34,6 +34,11 @@ public final class YqnInboundMapper { /** 统一命令 → 运去哪创建入库计划请求。 */ public static YqnDtos.CreateInboundPlanRequest toRequest(InboundCommand cmd, String warehouseCode) { + // 运去哪要求至少一条商品行;信仓「新增预报」不需要(明细走完善资料), + // 所以这条校验从 InboundCommand 构造期移到这里 + if (cmd.lines().isEmpty()) { + throw new IllegalArgumentException("yqn inbound plan requires at least one product line"); + } requireContainerNo(cmd.containerNo()); YqnDtos.CreateInboundPlanRequest req = new YqnDtos.CreateInboundPlanRequest(); diff --git a/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnProductMapper.java b/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnProductMapper.java index 45a214e..44dec0a 100644 --- a/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnProductMapper.java +++ b/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnProductMapper.java @@ -29,6 +29,15 @@ public final class YqnProductMapper { * 这里只做字段搬运与单位对齐(cm / g 与平台一致,不换算)。 */ public static YqnDtos.SaveProductRequest toRequest(WarehouseProduct product) { + // 运去哪 API 115 把 packingType 列为必填;统一模型不再在构造期强制 + // (信仓没有该字段),所以在这里按运去哪的协议校验。 + if (product.packingType() < 0) { + throw new IllegalArgumentException( + "yqn product requires packingType (0 原包装发货 / 1 重新打包)"); + } + if (product.nameEn() == null || product.nameEn().trim().isEmpty()) { + throw new IllegalArgumentException("yqn product requires nameEn"); + } YqnDtos.SaveProductRequest req = new YqnDtos.SaveProductRequest(); req.sku = skuOf(product); req.customItemNo = product.customItemNo(); @@ -58,7 +67,8 @@ public final class YqnProductMapper { req.cost = cost.amount().doubleValue(); req.currency = cost.currencyCode(); } - req.customs = toCustoms(product.declaredValue(), product.hsCode(), product.countryOfOrigin()); + req.customs = toCustoms(product.declaredValue(), product.hsCode(), product.countryOfOrigin(), + product.omsSku()); return req; } @@ -78,8 +88,25 @@ public final class YqnProductMapper { * {@link WarehouseProduct} 已在构造期挡掉「只给一半」的情况。 */ static List运去哪要求两个预计日期都给,且调拨出库必须带收货地址。这两条原本写在 + * {@link TransferCommand} 的构造期,会把运去哪的约束强加给其它仓(信仓转运只有 + * 发货日期、用仓库名代替地址),现在改到这里按运去哪的协议校验。
+ * + * @throws IllegalArgumentException 缺日期,或调拨出库缺收货地址 + */ public static YqnDtos.CreateTransferPlanRequest toRequest(TransferCommand cmd) { + if (cmd.estimateOutboundDate() == null || cmd.estimateInboundDate() == null) { + throw new IllegalArgumentException( + "yqn transfer requires estimateOutboundDate and estimateInboundDate"); + } + if (cmd.estimateInboundDate().isBefore(cmd.estimateOutboundDate())) { + throw new IllegalArgumentException( + "estimateInboundDate must not be earlier than estimateOutboundDate"); + } + if (cmd.type() == common.ecommerce.warehouse.enums.TransferType.OUTBOUND + && cmd.shipTo() == null) { + throw new IllegalArgumentException("yqn transfer requires shipTo when type is OUTBOUND"); + } YqnDtos.CreateTransferPlanRequest req = new YqnDtos.CreateTransferPlanRequest(); req.type = YqnTransferType.codeOf(cmd.type()); req.orgWarehouseCode = cmd.fromWarehouseCode(); diff --git a/warehouse-sdk-yqn/src/test/java/common/ecommerce/yqn/adapter/YqnProductTest.java b/warehouse-sdk-yqn/src/test/java/common/ecommerce/yqn/adapter/YqnProductTest.java index 7707a9a..3bb6b81 100644 --- a/warehouse-sdk-yqn/src/test/java/common/ecommerce/yqn/adapter/YqnProductTest.java +++ b/warehouse-sdk-yqn/src/test/java/common/ecommerce/yqn/adapter/YqnProductTest.java @@ -123,21 +123,38 @@ class YqnProductTest { } @Test - void halfCustomsIsRejectedAtBuildTime() { - assertThrows(IllegalArgumentException.class, () -> WarehouseProduct.builder() + void halfCustomsIsRejectedByMapper() { + // 海关三项整组给原本在构造期校验,信仓只用 declaredValue 当 amount, + // 所以校验移到运去哪 mapper + WarehouseProduct halfCustoms = WarehouseProduct.builder() .omsSku("X").name("n").nameEn("n").packingType(0) .lengthCm(1).widthCm(1).heightCm(1).weightGrams(1).requireSn(0) .hsCode("123") - .build()); + .build(); + assertThrows(IllegalArgumentException.class, + () -> YqnProductMapper.toRequest(halfCustoms)); } @Test void requiredFieldsAreEnforced() { - assertThrows(IllegalArgumentException.class, () -> WarehouseProduct.builder() + // packingType 是运去哪的必填项,但统一模型里是可选(信仓没有该字段), + // 所以校验发生在 mapper,不是在构造期 + WarehouseProduct missingPackingType = WarehouseProduct.builder() .omsSku("X").name("n").nameEn("n") - // 缺 packingType .lengthCm(1).widthCm(1).heightCm(1).weightGrams(1).requireSn(0) - .build()); + .build(); + assertThrows(IllegalArgumentException.class, + () -> YqnProductMapper.toRequest(missingPackingType)); + + // nameEn 也是运去哪的必填项,同样在 mapper 校验 + WarehouseProduct missingNameEn = WarehouseProduct.builder() + .omsSku("X").name("n").packingType(0) + .lengthCm(1).widthCm(1).heightCm(1).weightGrams(1).requireSn(0) + .build(); + assertThrows(IllegalArgumentException.class, + () -> YqnProductMapper.toRequest(missingNameEn)); + + // 跨仓共识的必填项(长宽高 / 重量为正)仍在构造期校验 assertThrows(IllegalArgumentException.class, () -> WarehouseProduct.builder() .omsSku("X").name("n").nameEn("n").packingType(0) .lengthCm(0).widthCm(1).heightCm(1).weightGrams(1).requireSn(0)