Browse Source

refactor(warehouse): 必填校验从模型下沉到各仓适配器

统一模型此前把运去哪的协议要求(packingType、两个预计日期、调拨出库必须给
shipTo)写进了构造期校验,接第二家仓时会被第一家的约束卡住:信仓既没有
packingType 字段、转运也只有发货日期并用仓库名代替地址,调用方却必须给这些
无意义的值才能构造命令。

改成按仓校验:

- WarehouseProduct:packingType 不再是构造期必填(-1 表示未给)
  运去哪的必填校验移到 YqnProductMapper
- TransferCommand:预计到仓日期与 shipTo 不再是构造期必填
  运去哪的必填校验移到 YqnTransferMapper
  保留跨仓共识的一致性校验(给了两个日期才比较先后)
- 信仓侧无需改动:它的必填项(deliveryMode / deliveryWay / palletRequired /
  预报头字段)本来就在适配器里校验

对运去哪调用方的影响:缺少这些字段仍然报错,只是从构造期的
IllegalArgumentException 变成调用时的 IllegalArgumentException(mapper 抛出),
错误信息里带仓方字段名,更明确。

顺带修探针里因模型放宽才暴露的问题:
- 写探针不再给 omsSku 硬编码 "1"、不再给转运编造 PROBE-SKU / PROBE-DEST / 假地址,
  缺 sku 或 destWarehouse 时直接跳过
- 转运探针不再传 estimateInboundDate / shipTo(信仓不收,也能验证模型已放宽)
- 基座里的 requireProperty 与凭据默认值恢复为「空值 + 必须由 -D 传入」

Co-Authored-By: Claude Code <noreply@anthropic.com>
feature/supplier-lingxing^2
lml 1 week ago
parent
commit
fa9bfd71ba
  1. 50
      warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/capability/WarehouseProduct.java
  2. 32
      warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/InboundCommand.java
  3. 20
      warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/TransferCommand.java
  4. 14
      warehouse-sdk-xincang/src/main/java/common/ecommerce/xincang/adapter/XincangForecastMapper.java
  5. 76
      warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/adapter/XincangModelRelaxTest.java
  6. 26
      warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/adapter/XincangProductTest.java
  7. 19
      warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/adapter/XincangTransferTest.java
  8. 23
      warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/probe/XincangWriteProbeTest.java
  9. 5
      warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnInboundMapper.java
  10. 33
      warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnProductMapper.java
  11. 22
      warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnTransferMapper.java
  12. 29
      warehouse-sdk-yqn/src/test/java/common/ecommerce/yqn/adapter/YqnProductTest.java

50
warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/capability/WarehouseProduct.java

@ -8,9 +8,12 @@ import java.util.Objects; @@ -8,9 +8,12 @@ import java.util.Objects;
/**
* 仓商品建档入参。
*
* <p>单位写进字段名(cm / g),避免适配器之间靠注释约定换算。
* 运去哪 API 115 的必填项(sku / 中英文名 / 包装方式 / 长宽高 / 重量 / SN)
* 在这里都是必填,缺了在构造期就失败,而不是等平台报错。</p>
* <p>单位写进字段名(cm / g),避免适配器之间靠注释约定换算。</p>
*
* <p>构造期只校验<b>所有仓都必须给</b>的字段:{@code omsSku}、{@code name}、
* 长宽高与重量为正。其余字段({@code nameEn} / {@code packingType} / 海关三项 /
* 品类等)的必填性与组合约束都由各适配器在拼报文时校验——
* 否则接第二家仓时会被第一家的约束卡住。</p>
*/
public final class WarehouseProduct {
@ -19,11 +22,21 @@ public final class WarehouseProduct { @@ -19,11 +22,21 @@ public final class WarehouseProduct {
private final String customItemNo;
private final String barcode;
private final String name;
/**
* 英文名。
*
* <p>运去哪必填(适配器会拒绝缺失);信仓接口只有中文名({@code chn_name}),
* 未给即不传。</p>
*/
private final String nameEn;
private final String description;
/** 产品类型:1 成品 / 2 配件 / 3 耗材;0 表示未指定(平台默认成品)。 */
private final int productType;
/** 发货包装:0 原包装发货 / 1 重新打包。 */
/**
* 发货包装:0 原包装发货 / 1 重新打包;<b>-1 表示未给</b>。
*
* <p>运去哪必填(适配器会拒绝缺失);信仓接口没有该字段,未给即不传。</p>
*/
private final int packingType;
private final double lengthCm;
private final double widthCm;
@ -75,12 +88,13 @@ public final class WarehouseProduct { @@ -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 { @@ -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 { @@ -343,7 +345,7 @@ public final class WarehouseProduct {
return this;
}
/** 0 原包装发货 / 1 重新打包;<b>必填</b>。 */
/** 0 原包装发货 / 1 重新打包;运去哪必填,信仓不用。 */
public Builder packingType(int v) {
this.packingType = v;
return this;

32
warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/InboundCommand.java

@ -8,8 +8,10 @@ import java.util.List; @@ -8,8 +8,10 @@ import java.util.List;
/**
* 入库计划创建命令。<b>写操作</b>,幂等键是 {@link #inboundRequestNo()}(仓方的来源单号)。
*
* <p>必填:单号、仓、库存类型、至少一条商品行。装箱、批次、附件都是可选的——
* 仓会在收货时按实际情况清点,但<b>给了就必须自洽</b>(一箱多 SKU 要用 sid 归并)。</p>
* <p>构造期只校验所有仓都必须给的:单号、库存类型取值。仓 / 商品行 / 日期等
* 各家要求不同(信仓「新增预报」只建单头、明细走「完善资料」),
* 必填性由各适配器在拼报文时校验;装箱、批次、附件的自洽性仍由模型保证
* (一箱多 SKU 要用 sid 归并)。</p>
*/
public final class InboundCommand {
@ -67,6 +69,14 @@ public final class InboundCommand { @@ -67,6 +69,14 @@ public final class InboundCommand {
/** 中文名称(信仓 {@code chn_name});null 表示不传。 */
private final String chnName;
/**
* 参考 SKU 种类数;null 表示不传。
*
* <p>信仓 {@code rfc_sku_count}(新增预报必填)。与 {@link #lines()} 行数无关:
* 报的是「预计有多少种 SKU」,建单时明细还没给。</p>
*/
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 { @@ -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<InboundLine>(b.lines));
this.cartons = Collections.unmodifiableList(new ArrayList<InboundCarton>(b.cartons));
this.batches = Collections.unmodifiableList(new ArrayList<InboundBatch>(b.batches));
@ -110,6 +119,7 @@ public final class InboundCommand { @@ -110,6 +119,7 @@ public final class InboundCommand {
this.oversize = b.oversize;
this.oversizeNote = b.oversizeNote;
this.chnName = b.chnName;
this.referenceSkuCount = b.referenceSkuCount;
}
public static Builder builder() {
@ -243,6 +253,11 @@ public final class InboundCommand { @@ -243,6 +253,11 @@ public final class InboundCommand {
return chnName;
}
/** 参考 SKU 种类数;null 表示不传(信仓 {@code rfc_sku_count})。 */
public Integer referenceSkuCount() {
return referenceSkuCount;
}
public static final class Builder {
private String inboundRequestNo;
@ -273,6 +288,7 @@ public final class InboundCommand { @@ -273,6 +288,7 @@ public final class InboundCommand {
private Boolean oversize;
private String oversizeNote;
private String chnName;
private Integer referenceSkuCount;
public Builder inboundRequestNo(String v) {
this.inboundRequestNo = v;
@ -432,6 +448,12 @@ public final class InboundCommand { @@ -432,6 +448,12 @@ public final class InboundCommand {
return this;
}
/** 参考 SKU 种类数(信仓 {@code rfc_sku_count},新增预报必填)。 */
public Builder referenceSkuCount(Integer v) {
this.referenceSkuCount = v;
return this;
}
public InboundCommand build() {
return new InboundCommand(this);
}

20
warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/TransferCommand.java

@ -8,6 +8,9 @@ import java.util.List; @@ -8,6 +8,9 @@ import java.util.List;
* 调拨单创建命令。<b>写操作</b>,幂等键是 {@link #transferRequestNo()}(仓方的 {@code sourceNo})。
*
* <p>运去哪对 {@code sourceNo} 有唯一约束,查询与取消都靠它,所以它同时是业务主键。</p>
*
* <p>构造期只校验跨仓共识的必填项;某一家仓特有的必填项(运去哪的日期与收货地址、
* 信仓的转运类型 / 方式 / 是否打托)由各适配器在拼报文时校验。</p>
*/
public final class TransferCommand {
@ -29,7 +32,7 @@ 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 { @@ -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 { @@ -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<Integer>(b.serviceTypes));

14
warehouse-sdk-xincang/src/main/java/common/ecommerce/xincang/adapter/XincangForecastMapper.java

@ -50,8 +50,15 @@ public final class XincangForecastMapper { @@ -50,8 +50,15 @@ public final class XincangForecastMapper {
req.rfcEtd = requireDate(cmd.predictionShipDate(), "predictionShipDate (rfc_etd)", ctx);
req.rfcEta = requireDate(cmd.estimateArriveDate(), "estimateArriveDate (rfc_eta)", ctx);
req.deliveryRequirements = require(cmd.deliveryRequirements(), "deliveryRequirements", ctx);
// 参考 SKU 种类数:没有明细时按行数给,有明细时也按行数(信仓只要求一个估计值)
req.rfcSkuCount = String.valueOf(cmd.lines().size());
if (cmd.referenceSkuCount() == null && cmd.lines().isEmpty()) {
throw validation(ctx,
"referenceSkuCount is required for xincang forecast (信仓 rfc_sku_count 必填)");
}
// 参考 SKU 种类数:优先用调用方显式给的值(信仓必填),
// 没有再退回明细行数——建单时明细通常还没有,不能只依赖行数
req.rfcSkuCount = cmd.referenceSkuCount() != null
? String.valueOf(cmd.referenceSkuCount())
: String.valueOf(cmd.lines().size());
req.chnName = blankToNull(cmd.chnName());
req.isOversize = cmd.oversize() == null ? null : (cmd.oversize() ? YES : NO);
req.oversizeVal = blankToNull(cmd.oversizeNote());
@ -72,6 +79,9 @@ public final class XincangForecastMapper { @@ -72,6 +79,9 @@ public final class XincangForecastMapper {
String forecastNo,
String productsJson,
WarehouseContext ctx) {
if (cmd.lines().isEmpty()) {
throw validation(ctx, "xincang improve_forecast requires at least one product line");
}
XincangDtos.ForecastImproveRequest req = new XincangDtos.ForecastImproveRequest();
req.forecastNo = require(forecastNo, "forecastNo", ctx);
req.destWarehouse = require(cmd.warehouseId(), "warehouseId (dest_warehouse)", ctx);

76
warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/adapter/XincangModelRelaxTest.java

@ -0,0 +1,76 @@ @@ -0,0 +1,76 @@
package common.ecommerce.xincang.adapter;
import common.ecommerce.shared.support.Money;
import common.ecommerce.warehouse.capability.WarehouseProduct;
import common.ecommerce.warehouse.model.InboundCommand;
import common.ecommerce.warehouse.model.InboundLine;
import org.junit.jupiter.api.Test;
import java.time.LocalDate;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* 统一模型里「某家仓必填、其他仓不需要」的字段不再在构造期拦截。
*
* <p>这些用例守护的是:信仓可以只给它认识的字段就构造出命令,
* 不会因为运去哪的必填项(nameEn / packingType / 海关三项 / 入库商品行)
* 被迫塞无意义的值。</p>
*/
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。
*
* <p>改前「海关三项必须整组给」在构造期强制,信仓调用方被迫填两个用不上的字段。</p>
*/
@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);
}
}

26
warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/adapter/XincangProductTest.java

@ -207,6 +207,32 @@ class XincangProductTest { @@ -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()

19
warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/adapter/XincangTransferTest.java

@ -192,6 +192,25 @@ class XincangTransferTest { @@ -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")

23
warehouse-sdk-xincang/src/test/java/common/ecommerce/xincang/probe/XincangWriteProbeTest.java

@ -170,6 +170,8 @@ class XincangWriteProbeTest { @@ -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 { @@ -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 { @@ -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 { @@ -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",

5
warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnInboundMapper.java

@ -34,6 +34,11 @@ public final class YqnInboundMapper { @@ -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();

33
warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnProductMapper.java

@ -29,6 +29,15 @@ public final class YqnProductMapper { @@ -29,6 +29,15 @@ public final class YqnProductMapper {
* 这里只做字段搬运与单位对齐(cm / g 与平台一致,不换算)。</p>
*/
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 { @@ -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 { @@ -78,8 +88,25 @@ public final class YqnProductMapper {
* {@link WarehouseProduct} 已在构造期挡掉「只给一半」的情况。</p>
*/
static List<YqnDtos.SaveProductRequest.Customs> toCustoms(Money declaredValue,
String hsCode, String countryCode) {
if (declaredValue == null || isBlank(hsCode) || isBlank(countryCode)) {
String hsCode, String countryCode,
String sku) {
// 「三项整组给」的校验从 WarehouseProduct 构造期移到这里:
// 信仓只用 declaredValue 当 amount,不要求另外两项,模型层不能强制。
int given = 0;
if (declaredValue != null) {
given++;
}
if (!isBlank(hsCode)) {
given++;
}
if (!isBlank(countryCode)) {
given++;
}
if (given != 0 && given != 3) {
throw new IllegalArgumentException(
"yqn product " + sku + " requires hsCode / countryOfOrigin / declaredValue together");
}
if (given == 0) {
return null;
}
YqnDtos.SaveProductRequest.Customs customs = new YqnDtos.SaveProductRequest.Customs();

22
warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnTransferMapper.java

@ -28,8 +28,28 @@ public final class YqnTransferMapper { @@ -28,8 +28,28 @@ public final class YqnTransferMapper {
private YqnTransferMapper() {
}
/** 统一命令 → 运去哪创建调拨单请求。 */
/**
* 统一命令 → 运去哪创建调拨单请求。
*
* <p>运去哪要求两个预计日期都给,且调拨出库必须带收货地址。这两条原本写在
* {@link TransferCommand} 的构造期,会把运去哪的约束强加给其它仓(信仓转运只有
* 发货日期、用仓库名代替地址),现在改到这里按运去哪的协议校验。</p>
*
* @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();

29
warehouse-sdk-yqn/src/test/java/common/ecommerce/yqn/adapter/YqnProductTest.java

@ -123,21 +123,38 @@ class YqnProductTest { @@ -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)

Loading…
Cancel
Save