Browse Source
订单详情(POST /v1/saleOrder/findOne)仓方一直给了这些字段,模型没接、 mapper 没读。按「仓方有、我们没有就加,并标注来源字段」补齐: 新增通用模型: - WarehouseAttachment:单据附件(name / type / url / packageNo)。acc type 保留仓方原值,不做跨仓归一(装箱单与发货计划归一会混) - SerialNumber:序列号(snCode / lineNo / providerProductId / deliverOrderItemId),售后追溯与召回靠它 OutboundOrder 新增(均标注运去哪来源字段): - attachments ← enclosure[] —— 之前 PackageResult.labelRef 恒为 null 的根因就是这里没映射 - serialNumbers ← orderSnInfo[].snList[] - signatureRequired ← isSignature(null 表示仓方未给,不是「否」) - insured ← isInsure - thirdPartyAccount ← thirdPartyAccount OutboundLine 新增: - totalAmount ← skuAmount(行总金额,与请求侧的单价×数量对称) - insuredAmount ← insureAmount - platformOrderItemIds ← ordList[].skuOrdList[](按 SKU 关联) - batchNos ← batchInfo(计划与出库批次按 key=value 去重) PackageResult 新增: - cost ← shipmentPackages[].cost 仓储层 WarehouseReturn.Attachment 与新的 WarehouseAttachment 结构重复, 下一轮合并。 新增 YqnOrderDetailExtrasTest(8 个)。全量 477 个测试通过。 Co-Authored-By: Claude <noreply@anthropic.com>feature/supplier-lingxing
7 changed files with 636 additions and 4 deletions
@ -0,0 +1,89 @@ |
|||||||
|
package common.ecommerce.warehouse.model; |
||||||
|
|
||||||
|
/** |
||||||
|
* 仓方采集的序列号(SN)。 |
||||||
|
* |
||||||
|
* <p>出库 / 入库时仓会按 SKU 扫序列号。售后追溯(这台设备是哪个订单发的、 |
||||||
|
* 召回范围、质保定责)全靠它,不能丢。</p> |
||||||
|
*/ |
||||||
|
public final class SerialNumber { |
||||||
|
|
||||||
|
private final String providerSku; |
||||||
|
/** 序列号本体。 */ |
||||||
|
private final String snCode; |
||||||
|
/** 对应的行号;仓方未给时为 null。 */ |
||||||
|
private final String lineNo; |
||||||
|
/** 仓方产品 id;未给时为 null。 */ |
||||||
|
private final String providerProductId; |
||||||
|
/** 仓侧明细行 id;可用于与单据行对齐。 */ |
||||||
|
private final Long deliverOrderItemId; |
||||||
|
|
||||||
|
private SerialNumber(Builder b) { |
||||||
|
this.providerSku = b.providerSku; |
||||||
|
this.snCode = b.snCode; |
||||||
|
this.lineNo = b.lineNo; |
||||||
|
this.providerProductId = b.providerProductId; |
||||||
|
this.deliverOrderItemId = b.deliverOrderItemId; |
||||||
|
} |
||||||
|
|
||||||
|
public static Builder builder() { |
||||||
|
return new Builder(); |
||||||
|
} |
||||||
|
|
||||||
|
public String providerSku() { |
||||||
|
return providerSku; |
||||||
|
} |
||||||
|
|
||||||
|
public String snCode() { |
||||||
|
return snCode; |
||||||
|
} |
||||||
|
|
||||||
|
public String lineNo() { |
||||||
|
return lineNo; |
||||||
|
} |
||||||
|
|
||||||
|
public String providerProductId() { |
||||||
|
return providerProductId; |
||||||
|
} |
||||||
|
|
||||||
|
public Long deliverOrderItemId() { |
||||||
|
return deliverOrderItemId; |
||||||
|
} |
||||||
|
|
||||||
|
public static final class Builder { |
||||||
|
private String providerSku; |
||||||
|
private String snCode; |
||||||
|
private String lineNo; |
||||||
|
private String providerProductId; |
||||||
|
private Long deliverOrderItemId; |
||||||
|
|
||||||
|
public Builder providerSku(String v) { |
||||||
|
this.providerSku = v; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public Builder snCode(String v) { |
||||||
|
this.snCode = v; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public Builder lineNo(String v) { |
||||||
|
this.lineNo = v; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public Builder providerProductId(String v) { |
||||||
|
this.providerProductId = v; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public Builder deliverOrderItemId(Long v) { |
||||||
|
this.deliverOrderItemId = v; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public SerialNumber build() { |
||||||
|
return new SerialNumber(this); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,91 @@ |
|||||||
|
package common.ecommerce.warehouse.model; |
||||||
|
|
||||||
|
/** |
||||||
|
* 单据附件(面单 / 装箱单 / BOL / 图片等)。 |
||||||
|
* |
||||||
|
* <p>各仓对附件的分类口径不同,{@link #type()} 保留仓方原值,SDK 不做跨仓归一—— |
||||||
|
* 归一会把「装箱单」和「发货计划」这类相近但不同的类型混掉。</p> |
||||||
|
* |
||||||
|
* <p>SDK 不落文件、不访问对象存储:{@link #url()} 原样给出,下载由宿主负责。</p> |
||||||
|
*/ |
||||||
|
public final class WarehouseAttachment { |
||||||
|
|
||||||
|
private final String name; |
||||||
|
/** 仓方附件类型原值,如 {@code ShippingLabel} / {@code BOL}。 */ |
||||||
|
private final String type; |
||||||
|
private final String url; |
||||||
|
/** 关联包裹号;不区分包裹的仓为 null。 */ |
||||||
|
private final String packageNo; |
||||||
|
private final String remark; |
||||||
|
|
||||||
|
private WarehouseAttachment(Builder b) { |
||||||
|
this.name = b.name; |
||||||
|
this.type = b.type; |
||||||
|
this.url = b.url; |
||||||
|
this.packageNo = b.packageNo; |
||||||
|
this.remark = b.remark; |
||||||
|
} |
||||||
|
|
||||||
|
public static Builder builder() { |
||||||
|
return new Builder(); |
||||||
|
} |
||||||
|
|
||||||
|
public String name() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
/** 仓方附件类型原值。 */ |
||||||
|
public String type() { |
||||||
|
return type; |
||||||
|
} |
||||||
|
|
||||||
|
public String url() { |
||||||
|
return url; |
||||||
|
} |
||||||
|
|
||||||
|
/** 关联包裹号;不区分包裹的仓为 null。 */ |
||||||
|
public String packageNo() { |
||||||
|
return packageNo; |
||||||
|
} |
||||||
|
|
||||||
|
public String remark() { |
||||||
|
return remark; |
||||||
|
} |
||||||
|
|
||||||
|
public static final class Builder { |
||||||
|
private String name; |
||||||
|
private String type; |
||||||
|
private String url; |
||||||
|
private String packageNo; |
||||||
|
private String remark; |
||||||
|
|
||||||
|
public Builder name(String v) { |
||||||
|
this.name = v; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public Builder type(String v) { |
||||||
|
this.type = v; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public Builder url(String v) { |
||||||
|
this.url = v; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public Builder packageNo(String v) { |
||||||
|
this.packageNo = v; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public Builder remark(String v) { |
||||||
|
this.remark = v; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public WarehouseAttachment build() { |
||||||
|
return new WarehouseAttachment(this); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,163 @@ |
|||||||
|
package common.ecommerce.yqn.adapter; |
||||||
|
|
||||||
|
import common.ecommerce.http.JacksonJsonCodec; |
||||||
|
import common.ecommerce.shared.spi.ChannelSecret; |
||||||
|
import common.ecommerce.shared.testkit.RecordingTransport; |
||||||
|
import common.ecommerce.shared.testkit.Responses; |
||||||
|
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||||
|
import common.ecommerce.warehouse.model.OutboundLine; |
||||||
|
import common.ecommerce.warehouse.model.OutboundOrder; |
||||||
|
import common.ecommerce.warehouse.model.PackageResult; |
||||||
|
import common.ecommerce.warehouse.model.SerialNumber; |
||||||
|
import common.ecommerce.warehouse.model.WarehouseAttachment; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseConnection; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||||
|
import common.ecommerce.yqn.YqnConstants; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.time.Clock; |
||||||
|
import java.time.Instant; |
||||||
|
import java.time.ZoneOffset; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull; |
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue; |
||||||
|
|
||||||
|
/** |
||||||
|
* 订单详情(API 128)的扩展字段:附件 / SN / 行金额 / 平台行号 / 包裹成本。 |
||||||
|
* |
||||||
|
* <p>这些字段仓方一直有,只是之前模型没接、mapper 没读。</p> |
||||||
|
*/ |
||||||
|
class YqnOrderDetailExtrasTest { |
||||||
|
|
||||||
|
private static final Clock CLOCK = Clock.fixed(Instant.parse("2026-11-11T00:00:00Z"), ZoneOffset.UTC); |
||||||
|
|
||||||
|
private static WarehouseContext ctx() { |
||||||
|
return WarehouseContext.of("YQN-RF_NY_US", WarehouseProvider.YQN, "RF_NY_US", |
||||||
|
WarehouseConnection.of(YqnConstants.PR_BASE_URL, |
||||||
|
ChannelSecret.builder().appSecret("key-1").build()), |
||||||
|
"req-detail", CLOCK); |
||||||
|
} |
||||||
|
|
||||||
|
private static final String BODY = |
||||||
|
"{\"code\":200,\"message\":\"ok\",\"data\":{" |
||||||
|
+ "\"orderNo\":\"OB-1\",\"orderStatusEnum\":\"shipped\",\"currency\":\"USD\"," |
||||||
|
+ "\"isSignature\":1,\"isInsure\":0," |
||||||
|
+ "\"thirdPartyAccount\":\"TP-ACCT\"," |
||||||
|
+ "\"productItems\":[" |
||||||
|
+ "{\"sku\":\"DM00001\",\"quantity\":2,\"lineNo\":\"1\"," |
||||||
|
+ "\"skuAmount\":20.00,\"insureAmount\":5.00," |
||||||
|
+ "\"batchInfo\":{" |
||||||
|
+ "\"planBatchItems\":[{\"qty\":2,\"batchParam\":[" |
||||||
|
+ "{\"batchAttriKey\":\"LotCode\",\"batchAttriValue\":\"L001\"}]}]," |
||||||
|
+ "\"outboundBatchItems\":[{\"qty\":2,\"batchParam\":[" |
||||||
|
+ "{\"batchAttriKey\":\"LotCode\",\"batchAttriValue\":\"L001\"}]}]}}]," |
||||||
|
+ "\"ordList\":[{\"sku\":\"DM00001\"," |
||||||
|
+ "\"skuOrdList\":[\"ORD-1\",\"ORD-2\"]}]," |
||||||
|
+ "\"enclosure\":[" |
||||||
|
+ "{\"type\":\"ShippingLabel\",\"name\":\"面单\"," |
||||||
|
+ "\"url\":\"https://files/label.pdf\"}," |
||||||
|
+ "{\"type\":\"BOL\",\"name\":\"提单\",\"url\":\"https://files/bol.pdf\"}]," |
||||||
|
+ "\"orderSnInfo\":[{\"sku\":\"DM00001\",\"productId\":\"P1\",\"snList\":[" |
||||||
|
+ "{\"sku\":\"DM00001\",\"snCode\":\"SN0001\",\"lineNo\":\"1\"," |
||||||
|
+ "\"productId\":1,\"deliverOrderItemId\":1001}]}]," |
||||||
|
+ "\"shipmentPackages\":[{\"trackingNo\":\"TRK1\",\"carrier\":\"FEDEX\"," |
||||||
|
+ "\"cost\":8.5,\"packageFlag\":0}]}}"; |
||||||
|
|
||||||
|
private static OutboundOrder query() { |
||||||
|
RecordingTransport transport = RecordingTransport.create() |
||||||
|
.route(YqnConstants.PATH_ORDER_FIND_ONE, req -> Responses.ok(BODY)); |
||||||
|
return new YqnAdapter(transport, new JacksonJsonCodec()) |
||||||
|
.get(ctx(), common.ecommerce.warehouse.model.OutboundRef.ofRequestNo("OB-1")); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void mapsAttachments() { |
||||||
|
List<WarehouseAttachment> attachments = query().attachments(); |
||||||
|
|
||||||
|
assertEquals(2, attachments.size()); |
||||||
|
assertEquals("面单", attachments.get(0).name()); |
||||||
|
assertEquals("ShippingLabel", attachments.get(0).type()); |
||||||
|
assertEquals("https://files/label.pdf", attachments.get(0).url()); |
||||||
|
assertEquals("BOL", attachments.get(1).type()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void mapsSerialNumbers() { |
||||||
|
List<SerialNumber> sns = query().serialNumbers(); |
||||||
|
|
||||||
|
assertEquals(1, sns.size()); |
||||||
|
SerialNumber sn = sns.get(0); |
||||||
|
assertEquals("DM00001", sn.providerSku()); |
||||||
|
assertEquals("SN0001", sn.snCode()); |
||||||
|
assertEquals("1", sn.lineNo()); |
||||||
|
assertEquals("P1", sn.providerProductId()); |
||||||
|
assertEquals(Long.valueOf(1001L), sn.deliverOrderItemId()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void mapsLineAmounts() { |
||||||
|
OutboundLine line = query().lines().get(0); |
||||||
|
|
||||||
|
assertEquals(new BigDecimal("20.0"), line.totalAmount().amount()); |
||||||
|
assertEquals(new BigDecimal("5.0"), line.insuredAmount().amount()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void mapsPlatformOrderItemIds() { |
||||||
|
OutboundLine line = query().lines().get(0); |
||||||
|
|
||||||
|
assertEquals(2, line.platformOrderItemIds().size()); |
||||||
|
assertEquals("ORD-1", line.platformOrderItemIds().get(0)); |
||||||
|
assertEquals("ORD-2", line.platformOrderItemIds().get(1)); |
||||||
|
} |
||||||
|
|
||||||
|
/** 计划批次与出库批次同一个批次号只保留一条。 */ |
||||||
|
@Test |
||||||
|
void mapsBatchNosWithoutDuplicates() { |
||||||
|
OutboundLine line = query().lines().get(0); |
||||||
|
|
||||||
|
assertEquals(1, line.batchNos().size()); |
||||||
|
assertEquals("LotCode=L001", line.batchNos().get(0)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void mapsSignatureAndInsureFlags() { |
||||||
|
OutboundOrder order = query(); |
||||||
|
|
||||||
|
assertEquals(Boolean.TRUE, order.signatureRequired()); |
||||||
|
assertEquals(Boolean.FALSE, order.insured()); |
||||||
|
assertEquals("TP-ACCT", order.thirdPartyAccount()); |
||||||
|
} |
||||||
|
|
||||||
|
/** 缺省时是 null,不是 false——不能把「仓方没给」当成「不需要签收」。 */ |
||||||
|
@Test |
||||||
|
void missingFlagsStayNull() { |
||||||
|
String minimal = "{\"code\":200,\"data\":{\"orderNo\":\"OB-2\"," |
||||||
|
+ "\"orderStatusEnum\":\"shipped\",\"currency\":\"USD\"}}"; |
||||||
|
RecordingTransport transport = RecordingTransport.create() |
||||||
|
.route(YqnConstants.PATH_ORDER_FIND_ONE, req -> Responses.ok(minimal)); |
||||||
|
|
||||||
|
OutboundOrder order = new YqnAdapter(transport, new JacksonJsonCodec()) |
||||||
|
.get(ctx(), common.ecommerce.warehouse.model.OutboundRef.ofRequestNo("OB-2")); |
||||||
|
|
||||||
|
assertNull(order.signatureRequired()); |
||||||
|
assertNull(order.insured()); |
||||||
|
assertTrue(order.attachments().isEmpty()); |
||||||
|
assertTrue(order.serialNumbers().isEmpty()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void mapsPackageCost() { |
||||||
|
List<PackageResult> packages; |
||||||
|
RecordingTransport transport = RecordingTransport.create() |
||||||
|
.route(YqnConstants.PATH_ORDER_FIND_ONE, req -> Responses.ok(BODY)); |
||||||
|
packages = new YqnAdapter(transport, new JacksonJsonCodec()) |
||||||
|
.packages(ctx(), common.ecommerce.warehouse.model.OutboundRef.ofRequestNo("OB-1")); |
||||||
|
|
||||||
|
assertEquals(1, packages.size()); |
||||||
|
assertEquals(new BigDecimal("8.5"), packages.get(0).cost().amount()); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue