43 changed files with 3979 additions and 2 deletions
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
package common.ecommerce.capability; |
||||
|
||||
import common.ecommerce.model.inbound.InboundReceipt; |
||||
import common.ecommerce.model.inbound.InboundReceiptQuery; |
||||
import common.ecommerce.model.support.Page; |
||||
import common.ecommerce.sdk.ChannelContext; |
||||
|
||||
/** |
||||
* FBA 到货接收明细能力。 |
||||
* |
||||
* <p>只读。返回库存分类账里的签收数据,同一货件商品可能有多行。</p> |
||||
*/ |
||||
public interface InboundReceiptCapable { |
||||
|
||||
/** 分页拉取 FBA 到货接收明细。 */ |
||||
Page<InboundReceipt> pull(ChannelContext ctx, InboundReceiptQuery query); |
||||
} |
||||
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
package common.ecommerce.capability; |
||||
|
||||
import common.ecommerce.model.inbound.InboundShipment; |
||||
import common.ecommerce.model.inbound.InboundShipmentQuery; |
||||
import common.ecommerce.model.support.Page; |
||||
import common.ecommerce.sdk.ChannelContext; |
||||
|
||||
/** |
||||
* 平台仓入库货件能力(FBT / WFS / AWD)。 |
||||
* |
||||
* <p>只读。查询条件里的时间字段、状态、货件号由各适配器按自己的协议映射, |
||||
* 不支持的维度显式抛异常。</p> |
||||
*/ |
||||
public interface InboundShipmentCapable { |
||||
|
||||
/** 分页拉取入库货件。 */ |
||||
Page<InboundShipment> pull(ChannelContext ctx, InboundShipmentQuery query); |
||||
} |
||||
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
package common.ecommerce.capability; |
||||
|
||||
import common.ecommerce.audit.CallObserver; |
||||
import common.ecommerce.error.ChannelException; |
||||
import common.ecommerce.model.Capability; |
||||
import common.ecommerce.model.account.ChannelAccount; |
||||
import common.ecommerce.model.inbound.InboundReceipt; |
||||
import common.ecommerce.model.inbound.InboundReceiptQuery; |
||||
import common.ecommerce.model.inbound.InboundShipment; |
||||
import common.ecommerce.model.inbound.InboundShipmentQuery; |
||||
import common.ecommerce.model.support.Page; |
||||
import common.ecommerce.sdk.CallSupport; |
||||
import common.ecommerce.sdk.ChannelContext; |
||||
|
||||
/** |
||||
* 门面持有的入库视图:平台仓入库货件(FBT / WFS / AWD)与 FBA 到货接收明细。 |
||||
* |
||||
* <p>两者都是<b>只读</b>查询,不改变平台数据。每次调用前做能力检查, |
||||
* 缺失时显式抛 {@code UnsupportedCapabilityException},不静默返回空页。</p> |
||||
* |
||||
* <p>查询条件里的店铺、时间字段、状态由适配器按自己的协议映射; |
||||
* 平台不支持的维度会抛 {@code ValidationException},而不是被悄悄忽略。</p> |
||||
*/ |
||||
public final class Inbounds { |
||||
|
||||
private final PlatformAdapter adapter; |
||||
private final ChannelAccount account; |
||||
private final ChannelContext ctx; |
||||
private final CallObserver observer; |
||||
|
||||
public Inbounds(PlatformAdapter adapter, ChannelAccount account, ChannelContext ctx) { |
||||
this(adapter, account, ctx, CallObserver.NOOP); |
||||
} |
||||
|
||||
public Inbounds(PlatformAdapter adapter, ChannelAccount account, ChannelContext ctx, |
||||
CallObserver observer) { |
||||
this.adapter = adapter; |
||||
this.account = account; |
||||
this.ctx = ctx; |
||||
this.observer = observer == null ? CallObserver.NOOP : observer; |
||||
} |
||||
|
||||
/** |
||||
* 换一个链路 ID 的副本,供缓存的视图对象在每次调用时刷新。 |
||||
* |
||||
* @see ChannelContext#withRequestId(String) |
||||
*/ |
||||
public Inbounds withRequestId(String requestId) { |
||||
return new Inbounds(adapter, account, ctx.withRequestId(requestId), observer); |
||||
} |
||||
|
||||
/** 分页拉取平台仓入库货件。 */ |
||||
public Page<InboundShipment> shipments(final InboundShipmentQuery query) { |
||||
return CallSupport.observe(observer, ctx, "inbounds.shipments", |
||||
CallSupport.params( |
||||
"timeType", query.timeType(), |
||||
"after", query.after(), |
||||
"before", query.before(), |
||||
"storeCount", query.storeIds().size(), |
||||
"statusCount", query.statuses().size(), |
||||
"hasShipmentNo", query.shipmentNo() != null, |
||||
"hasInboundOrderNo", query.inboundOrderNo() != null, |
||||
"pageSize", query.pageSize(), |
||||
"cursor", query.cursor()), |
||||
page -> page.size(), |
||||
() -> { |
||||
require(Capability.INBOUND_SHIPMENT, InboundShipmentCapable.class); |
||||
return ((InboundShipmentCapable) adapter).pull(ctx, query); |
||||
}); |
||||
} |
||||
|
||||
/** 分页拉取 FBA 到货接收明细。 */ |
||||
public Page<InboundReceipt> receipts(final InboundReceiptQuery query) { |
||||
return CallSupport.observe(observer, ctx, "inbounds.receipts", |
||||
CallSupport.params( |
||||
"eventDate", query.eventDate(), |
||||
"shipmentCount", query.shipmentIds().size(), |
||||
"pageSize", query.pageSize(), |
||||
"cursor", query.cursor()), |
||||
page -> page.size(), |
||||
() -> { |
||||
require(Capability.INBOUND_RECEIPT, InboundReceiptCapable.class); |
||||
return ((InboundReceiptCapable) adapter).pull(ctx, query); |
||||
}); |
||||
} |
||||
|
||||
private void require(Capability capability, Class<?> type) { |
||||
if (!adapter.supports(account, capability) || !type.isInstance(adapter)) { |
||||
throw new ChannelException.UnsupportedCapabilityException(capability); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,212 @@
@@ -0,0 +1,212 @@
|
||||
package common.ecommerce.model.inbound; |
||||
|
||||
import common.ecommerce.model.ChannelProvider; |
||||
import common.ecommerce.model.support.PlatformTime; |
||||
|
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* FBA 到货接收明细(一条签收记录)。 |
||||
* |
||||
* <p>同一货件同一商品可能有多行签收明细(按签收日期 / 索引拆分), |
||||
* 主键用 {@code shipmentId + fnsku + uniqueIndex + uniqueMd5} 组合, |
||||
* 不要只按货件号聚合。</p> |
||||
* |
||||
* <p>{@code quantity} 可能是负数(亚马逊库存分类账的调整行),原样保留, |
||||
* 不做绝对值处理。</p> |
||||
*/ |
||||
public final class InboundReceipt { |
||||
|
||||
private final String omsStoreId; |
||||
private final ChannelProvider sourceProvider; |
||||
private final String sourceAccountId; |
||||
private final Integer sid; |
||||
private final String shipmentId; |
||||
private final String fnsku; |
||||
private final String sku; |
||||
private final String productName; |
||||
private final int quantity; |
||||
private final String fulfillmentCenterId; |
||||
private final PlatformTime receivedAt; |
||||
private final String receivedDateReport; |
||||
private final Integer uniqueIndex; |
||||
private final String uniqueMd5; |
||||
|
||||
private InboundReceipt(Builder b) { |
||||
this.omsStoreId = Objects.requireNonNull(b.omsStoreId, "omsStoreId"); |
||||
this.sourceProvider = Objects.requireNonNull(b.sourceProvider, "sourceProvider"); |
||||
this.sourceAccountId = b.sourceAccountId; |
||||
this.sid = b.sid; |
||||
this.shipmentId = b.shipmentId; |
||||
this.fnsku = b.fnsku; |
||||
this.sku = b.sku; |
||||
this.productName = b.productName; |
||||
this.quantity = b.quantity; |
||||
this.fulfillmentCenterId = b.fulfillmentCenterId; |
||||
this.receivedAt = b.receivedAt; |
||||
this.receivedDateReport = b.receivedDateReport; |
||||
this.uniqueIndex = b.uniqueIndex; |
||||
this.uniqueMd5 = b.uniqueMd5; |
||||
} |
||||
|
||||
public static Builder builder() { |
||||
return new Builder(); |
||||
} |
||||
|
||||
public String omsStoreId() { |
||||
return omsStoreId; |
||||
} |
||||
|
||||
public ChannelProvider sourceProvider() { |
||||
return sourceProvider; |
||||
} |
||||
|
||||
public String sourceAccountId() { |
||||
return sourceAccountId; |
||||
} |
||||
|
||||
/** 领星店铺 id。 */ |
||||
public Integer sid() { |
||||
return sid; |
||||
} |
||||
|
||||
/** FBA 货件单号。 */ |
||||
public String shipmentId() { |
||||
return shipmentId; |
||||
} |
||||
|
||||
public String fnsku() { |
||||
return fnsku; |
||||
} |
||||
|
||||
/** MSKU。 */ |
||||
public String sku() { |
||||
return sku; |
||||
} |
||||
|
||||
/** Listing 标题。 */ |
||||
public String productName() { |
||||
return productName; |
||||
} |
||||
|
||||
/** 签收数量;可能为负。 */ |
||||
public int quantity() { |
||||
return quantity; |
||||
} |
||||
|
||||
/** FBA 物流中心编码。 */ |
||||
public String fulfillmentCenterId() { |
||||
return fulfillmentCenterId; |
||||
} |
||||
|
||||
/** 签收时间;优先用带时区的 {@code received_date} 解析。 */ |
||||
public PlatformTime receivedAt() { |
||||
return receivedAt; |
||||
} |
||||
|
||||
/** 处理过的接收日期({@code yyyy-MM-dd}),保留平台原文。 */ |
||||
public String receivedDateReport() { |
||||
return receivedDateReport; |
||||
} |
||||
|
||||
/** 单内签收日期索引,与 {@link #uniqueMd5()} 组成唯一索引。 */ |
||||
public Integer uniqueIndex() { |
||||
return uniqueIndex; |
||||
} |
||||
|
||||
public String uniqueMd5() { |
||||
return uniqueMd5; |
||||
} |
||||
|
||||
public static final class Builder { |
||||
|
||||
private String omsStoreId; |
||||
private ChannelProvider sourceProvider; |
||||
private String sourceAccountId; |
||||
private Integer sid; |
||||
private String shipmentId; |
||||
private String fnsku; |
||||
private String sku; |
||||
private String productName; |
||||
private int quantity; |
||||
private String fulfillmentCenterId; |
||||
private PlatformTime receivedAt; |
||||
private String receivedDateReport; |
||||
private Integer uniqueIndex; |
||||
private String uniqueMd5; |
||||
|
||||
public Builder omsStoreId(String omsStoreId) { |
||||
this.omsStoreId = omsStoreId; |
||||
return this; |
||||
} |
||||
|
||||
public Builder sourceProvider(ChannelProvider sourceProvider) { |
||||
this.sourceProvider = sourceProvider; |
||||
return this; |
||||
} |
||||
|
||||
public Builder sourceAccountId(String sourceAccountId) { |
||||
this.sourceAccountId = sourceAccountId; |
||||
return this; |
||||
} |
||||
|
||||
public Builder sid(Integer sid) { |
||||
this.sid = sid; |
||||
return this; |
||||
} |
||||
|
||||
public Builder shipmentId(String shipmentId) { |
||||
this.shipmentId = shipmentId; |
||||
return this; |
||||
} |
||||
|
||||
public Builder fnsku(String fnsku) { |
||||
this.fnsku = fnsku; |
||||
return this; |
||||
} |
||||
|
||||
public Builder sku(String sku) { |
||||
this.sku = sku; |
||||
return this; |
||||
} |
||||
|
||||
public Builder productName(String productName) { |
||||
this.productName = productName; |
||||
return this; |
||||
} |
||||
|
||||
public Builder quantity(int quantity) { |
||||
this.quantity = quantity; |
||||
return this; |
||||
} |
||||
|
||||
public Builder fulfillmentCenterId(String fulfillmentCenterId) { |
||||
this.fulfillmentCenterId = fulfillmentCenterId; |
||||
return this; |
||||
} |
||||
|
||||
public Builder receivedAt(PlatformTime receivedAt) { |
||||
this.receivedAt = receivedAt; |
||||
return this; |
||||
} |
||||
|
||||
public Builder receivedDateReport(String receivedDateReport) { |
||||
this.receivedDateReport = receivedDateReport; |
||||
return this; |
||||
} |
||||
|
||||
public Builder uniqueIndex(Integer uniqueIndex) { |
||||
this.uniqueIndex = uniqueIndex; |
||||
return this; |
||||
} |
||||
|
||||
public Builder uniqueMd5(String uniqueMd5) { |
||||
this.uniqueMd5 = uniqueMd5; |
||||
return this; |
||||
} |
||||
|
||||
public InboundReceipt build() { |
||||
return new InboundReceipt(this); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,116 @@
@@ -0,0 +1,116 @@
|
||||
package common.ecommerce.model.inbound; |
||||
|
||||
import java.time.LocalDate; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* FBA 到货接收明细查询条件。 |
||||
* |
||||
* <p>领星要求 {@code event_date}(签收日期)与 {@code fba_shipment_id}(货件号) |
||||
* 至少传一个;构造时直接校验,避免把空条件发到平台后拿到该店铺全部数据。</p> |
||||
*/ |
||||
public final class InboundReceiptQuery { |
||||
|
||||
private final String sid; |
||||
private final LocalDate eventDate; |
||||
private final List<String> shipmentIds; |
||||
private final int pageSize; |
||||
private final String cursor; |
||||
|
||||
private InboundReceiptQuery(Builder b) { |
||||
if (b.eventDate == null && b.shipmentIds.isEmpty()) { |
||||
throw new IllegalArgumentException("eventDate or shipmentIds is required"); |
||||
} |
||||
this.sid = b.sid; |
||||
this.eventDate = b.eventDate; |
||||
this.shipmentIds = Collections.unmodifiableList(new ArrayList<String>(b.shipmentIds)); |
||||
this.pageSize = b.pageSize; |
||||
this.cursor = b.cursor; |
||||
} |
||||
|
||||
public static Builder builder() { |
||||
return new Builder(); |
||||
} |
||||
|
||||
/** 领星店铺 id;为空时适配器使用当前账户的 {@code externalStoreId}。 */ |
||||
public String sid() { |
||||
return sid; |
||||
} |
||||
|
||||
/** 签收日期;与货件号至少传一个。 */ |
||||
public LocalDate eventDate() { |
||||
return eventDate; |
||||
} |
||||
|
||||
/** FBA 货件号列表;与签收日期至少传一个。 */ |
||||
public List<String> shipmentIds() { |
||||
return shipmentIds; |
||||
} |
||||
|
||||
public int pageSize() { |
||||
return pageSize; |
||||
} |
||||
|
||||
/** 字符串化的 offset;首次查询为 null。 */ |
||||
public String cursor() { |
||||
return cursor; |
||||
} |
||||
|
||||
public Builder toBuilder() { |
||||
return builder() |
||||
.sid(sid) |
||||
.eventDate(eventDate) |
||||
.shipmentIds(shipmentIds) |
||||
.pageSize(pageSize) |
||||
.cursor(cursor); |
||||
} |
||||
|
||||
public static final class Builder { |
||||
|
||||
private String sid; |
||||
private LocalDate eventDate; |
||||
private List<String> shipmentIds = Collections.emptyList(); |
||||
private int pageSize = 1000; |
||||
private String cursor; |
||||
|
||||
public Builder sid(String sid) { |
||||
this.sid = sid; |
||||
return this; |
||||
} |
||||
|
||||
public Builder eventDate(LocalDate eventDate) { |
||||
this.eventDate = eventDate; |
||||
return this; |
||||
} |
||||
|
||||
public Builder shipmentIds(List<String> shipmentIds) { |
||||
this.shipmentIds = shipmentIds == null ? Collections.<String>emptyList() : shipmentIds; |
||||
return this; |
||||
} |
||||
|
||||
public Builder shipmentIds(String... shipmentIds) { |
||||
List<String> values = new ArrayList<String>(); |
||||
if (shipmentIds != null) { |
||||
Collections.addAll(values, shipmentIds); |
||||
} |
||||
this.shipmentIds = values; |
||||
return this; |
||||
} |
||||
|
||||
public Builder pageSize(int pageSize) { |
||||
this.pageSize = pageSize; |
||||
return this; |
||||
} |
||||
|
||||
public Builder cursor(String cursor) { |
||||
this.cursor = cursor; |
||||
return this; |
||||
} |
||||
|
||||
public InboundReceiptQuery build() { |
||||
return new InboundReceiptQuery(this); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,424 @@
@@ -0,0 +1,424 @@
|
||||
package common.ecommerce.model.inbound; |
||||
|
||||
import common.ecommerce.model.ChannelProvider; |
||||
import common.ecommerce.model.support.PlatformTime; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* 平台仓入库货件(FBT / WFS / AWD)。 |
||||
* |
||||
* <p>三类平台的字段差异较大,模型只保留公共语义: |
||||
* 货件号、入库单号、店铺、仓库、状态、承运与时间、商品行、关联发货单。 |
||||
* 平台专有字段(如 AWD 的 referenceId)放在对应字段或留着不建模, |
||||
* 不在统一模型里塞一堆只有一家平台有值的属性。</p> |
||||
* |
||||
* <p>{@code status} 保留平台原始值(FBT 是数字状态,WFS / AWD 是字符串状态), |
||||
* {@code statusName} 是平台给的展示名。宿主不要按数值比较,按原始值透传即可。</p> |
||||
*/ |
||||
public final class InboundShipment { |
||||
|
||||
private final String omsStoreId; |
||||
private final ChannelProvider sourceProvider; |
||||
private final String sourceAccountId; |
||||
private final String shipmentId; |
||||
private final String shipmentNo; |
||||
private final String inboundOrderNo; |
||||
private final String stockOrderNo; |
||||
private final String warehouseReferenceId; |
||||
private final String storeId; |
||||
private final String storeName; |
||||
private final List<String> storeIds; |
||||
private final List<String> storeNames; |
||||
private final String warehouseName; |
||||
private final String countryName; |
||||
private final String status; |
||||
private final String statusName; |
||||
private final String localStatus; |
||||
private final String shipStatus; |
||||
private final String carrierCode; |
||||
private final String trackingNo; |
||||
private final String destinationAddress; |
||||
private final String returnAddress; |
||||
private final String creator; |
||||
private final String remark; |
||||
private final PlatformTime createdAt; |
||||
private final PlatformTime updatedAt; |
||||
private final PlatformTime shippedAt; |
||||
private final PlatformTime estimatedArrivalAt; |
||||
private final PlatformTime actualArrivalAt; |
||||
private final List<InboundShipmentLine> lines; |
||||
private final List<InboundShippingRef> shippingRefs; |
||||
|
||||
private InboundShipment(Builder b) { |
||||
this.omsStoreId = Objects.requireNonNull(b.omsStoreId, "omsStoreId"); |
||||
this.sourceProvider = Objects.requireNonNull(b.sourceProvider, "sourceProvider"); |
||||
this.sourceAccountId = b.sourceAccountId; |
||||
this.shipmentId = b.shipmentId; |
||||
this.shipmentNo = b.shipmentNo; |
||||
this.inboundOrderNo = b.inboundOrderNo; |
||||
this.stockOrderNo = b.stockOrderNo; |
||||
this.warehouseReferenceId = b.warehouseReferenceId; |
||||
this.storeId = b.storeId; |
||||
this.storeName = b.storeName; |
||||
this.storeIds = Collections.unmodifiableList(new ArrayList<String>(b.storeIds)); |
||||
this.storeNames = Collections.unmodifiableList(new ArrayList<String>(b.storeNames)); |
||||
this.warehouseName = b.warehouseName; |
||||
this.countryName = b.countryName; |
||||
this.status = b.status; |
||||
this.statusName = b.statusName; |
||||
this.localStatus = b.localStatus; |
||||
this.shipStatus = b.shipStatus; |
||||
this.carrierCode = b.carrierCode; |
||||
this.trackingNo = b.trackingNo; |
||||
this.destinationAddress = b.destinationAddress; |
||||
this.returnAddress = b.returnAddress; |
||||
this.creator = b.creator; |
||||
this.remark = b.remark; |
||||
this.createdAt = b.createdAt; |
||||
this.updatedAt = b.updatedAt; |
||||
this.shippedAt = b.shippedAt; |
||||
this.estimatedArrivalAt = b.estimatedArrivalAt; |
||||
this.actualArrivalAt = b.actualArrivalAt; |
||||
this.lines = Collections.unmodifiableList(new ArrayList<InboundShipmentLine>(b.lines)); |
||||
this.shippingRefs = Collections.unmodifiableList(new ArrayList<InboundShippingRef>(b.shippingRefs)); |
||||
} |
||||
|
||||
public static Builder builder() { |
||||
return new Builder(); |
||||
} |
||||
|
||||
public String omsStoreId() { |
||||
return omsStoreId; |
||||
} |
||||
|
||||
public ChannelProvider sourceProvider() { |
||||
return sourceProvider; |
||||
} |
||||
|
||||
public String sourceAccountId() { |
||||
return sourceAccountId; |
||||
} |
||||
|
||||
/** 平台/领星内部货件 id。 */ |
||||
public String shipmentId() { |
||||
return shipmentId; |
||||
} |
||||
|
||||
/** 货件单号;平台的业务主键。 */ |
||||
public String shipmentNo() { |
||||
return shipmentNo; |
||||
} |
||||
|
||||
/** 入库单 / 入库任务号。 */ |
||||
public String inboundOrderNo() { |
||||
return inboundOrderNo; |
||||
} |
||||
|
||||
/** 备货单号(AWD)。 */ |
||||
public String stockOrderNo() { |
||||
return stockOrderNo; |
||||
} |
||||
|
||||
/** AWD 的 referenceId。 */ |
||||
public String warehouseReferenceId() { |
||||
return warehouseReferenceId; |
||||
} |
||||
|
||||
/** 单店铺场景的店铺 id;跨店铺货件以 {@link #storeIds()} 为准。 */ |
||||
public String storeId() { |
||||
return storeId; |
||||
} |
||||
|
||||
public String storeName() { |
||||
return storeName; |
||||
} |
||||
|
||||
/** 跨店铺货件的店铺 id 列表。 */ |
||||
public List<String> storeIds() { |
||||
return storeIds; |
||||
} |
||||
|
||||
public List<String> storeNames() { |
||||
return storeNames; |
||||
} |
||||
|
||||
public String warehouseName() { |
||||
return warehouseName; |
||||
} |
||||
|
||||
public String countryName() { |
||||
return countryName; |
||||
} |
||||
|
||||
/** 平台原始状态值。 */ |
||||
public String status() { |
||||
return status; |
||||
} |
||||
|
||||
public String statusName() { |
||||
return statusName; |
||||
} |
||||
|
||||
/** 货件本地状态(如 WFS 的「已申报」、FBT 的 orderStatusName)。 */ |
||||
public String localStatus() { |
||||
return localStatus; |
||||
} |
||||
|
||||
/** 发货状态(FBT 的 shipStatus)。 */ |
||||
public String shipStatus() { |
||||
return shipStatus; |
||||
} |
||||
|
||||
public String carrierCode() { |
||||
return carrierCode; |
||||
} |
||||
|
||||
public String trackingNo() { |
||||
return trackingNo; |
||||
} |
||||
|
||||
/** 配送地址,保留平台拼接后的原文。 */ |
||||
public String destinationAddress() { |
||||
return destinationAddress; |
||||
} |
||||
|
||||
/** 退货地址,保留平台拼接后的原文。 */ |
||||
public String returnAddress() { |
||||
return returnAddress; |
||||
} |
||||
|
||||
public String creator() { |
||||
return creator; |
||||
} |
||||
|
||||
public String remark() { |
||||
return remark; |
||||
} |
||||
|
||||
public PlatformTime createdAt() { |
||||
return createdAt; |
||||
} |
||||
|
||||
public PlatformTime updatedAt() { |
||||
return updatedAt; |
||||
} |
||||
|
||||
public PlatformTime shippedAt() { |
||||
return shippedAt; |
||||
} |
||||
|
||||
public PlatformTime estimatedArrivalAt() { |
||||
return estimatedArrivalAt; |
||||
} |
||||
|
||||
public PlatformTime actualArrivalAt() { |
||||
return actualArrivalAt; |
||||
} |
||||
|
||||
public List<InboundShipmentLine> lines() { |
||||
return lines; |
||||
} |
||||
|
||||
public List<InboundShippingRef> shippingRefs() { |
||||
return shippingRefs; |
||||
} |
||||
|
||||
public static final class Builder { |
||||
|
||||
private String omsStoreId; |
||||
private ChannelProvider sourceProvider; |
||||
private String sourceAccountId; |
||||
private String shipmentId; |
||||
private String shipmentNo; |
||||
private String inboundOrderNo; |
||||
private String stockOrderNo; |
||||
private String warehouseReferenceId; |
||||
private String storeId; |
||||
private String storeName; |
||||
private List<String> storeIds = Collections.emptyList(); |
||||
private List<String> storeNames = Collections.emptyList(); |
||||
private String warehouseName; |
||||
private String countryName; |
||||
private String status; |
||||
private String statusName; |
||||
private String localStatus; |
||||
private String shipStatus; |
||||
private String carrierCode; |
||||
private String trackingNo; |
||||
private String destinationAddress; |
||||
private String returnAddress; |
||||
private String creator; |
||||
private String remark; |
||||
private PlatformTime createdAt; |
||||
private PlatformTime updatedAt; |
||||
private PlatformTime shippedAt; |
||||
private PlatformTime estimatedArrivalAt; |
||||
private PlatformTime actualArrivalAt; |
||||
private List<InboundShipmentLine> lines = Collections.emptyList(); |
||||
private List<InboundShippingRef> shippingRefs = Collections.emptyList(); |
||||
|
||||
public Builder omsStoreId(String omsStoreId) { |
||||
this.omsStoreId = omsStoreId; |
||||
return this; |
||||
} |
||||
|
||||
public Builder sourceProvider(ChannelProvider sourceProvider) { |
||||
this.sourceProvider = sourceProvider; |
||||
return this; |
||||
} |
||||
|
||||
public Builder sourceAccountId(String sourceAccountId) { |
||||
this.sourceAccountId = sourceAccountId; |
||||
return this; |
||||
} |
||||
|
||||
public Builder shipmentId(String shipmentId) { |
||||
this.shipmentId = shipmentId; |
||||
return this; |
||||
} |
||||
|
||||
public Builder shipmentNo(String shipmentNo) { |
||||
this.shipmentNo = shipmentNo; |
||||
return this; |
||||
} |
||||
|
||||
public Builder inboundOrderNo(String inboundOrderNo) { |
||||
this.inboundOrderNo = inboundOrderNo; |
||||
return this; |
||||
} |
||||
|
||||
public Builder stockOrderNo(String stockOrderNo) { |
||||
this.stockOrderNo = stockOrderNo; |
||||
return this; |
||||
} |
||||
|
||||
public Builder warehouseReferenceId(String warehouseReferenceId) { |
||||
this.warehouseReferenceId = warehouseReferenceId; |
||||
return this; |
||||
} |
||||
|
||||
public Builder storeId(String storeId) { |
||||
this.storeId = storeId; |
||||
return this; |
||||
} |
||||
|
||||
public Builder storeName(String storeName) { |
||||
this.storeName = storeName; |
||||
return this; |
||||
} |
||||
|
||||
public Builder storeIds(List<String> storeIds) { |
||||
this.storeIds = storeIds == null ? Collections.<String>emptyList() : storeIds; |
||||
return this; |
||||
} |
||||
|
||||
public Builder storeNames(List<String> storeNames) { |
||||
this.storeNames = storeNames == null ? Collections.<String>emptyList() : storeNames; |
||||
return this; |
||||
} |
||||
|
||||
public Builder warehouseName(String warehouseName) { |
||||
this.warehouseName = warehouseName; |
||||
return this; |
||||
} |
||||
|
||||
public Builder countryName(String countryName) { |
||||
this.countryName = countryName; |
||||
return this; |
||||
} |
||||
|
||||
public Builder status(String status) { |
||||
this.status = status; |
||||
return this; |
||||
} |
||||
|
||||
public Builder statusName(String statusName) { |
||||
this.statusName = statusName; |
||||
return this; |
||||
} |
||||
|
||||
public Builder localStatus(String localStatus) { |
||||
this.localStatus = localStatus; |
||||
return this; |
||||
} |
||||
|
||||
public Builder shipStatus(String shipStatus) { |
||||
this.shipStatus = shipStatus; |
||||
return this; |
||||
} |
||||
|
||||
public Builder carrierCode(String carrierCode) { |
||||
this.carrierCode = carrierCode; |
||||
return this; |
||||
} |
||||
|
||||
public Builder trackingNo(String trackingNo) { |
||||
this.trackingNo = trackingNo; |
||||
return this; |
||||
} |
||||
|
||||
public Builder destinationAddress(String destinationAddress) { |
||||
this.destinationAddress = destinationAddress; |
||||
return this; |
||||
} |
||||
|
||||
public Builder returnAddress(String returnAddress) { |
||||
this.returnAddress = returnAddress; |
||||
return this; |
||||
} |
||||
|
||||
public Builder creator(String creator) { |
||||
this.creator = creator; |
||||
return this; |
||||
} |
||||
|
||||
public Builder remark(String remark) { |
||||
this.remark = remark; |
||||
return this; |
||||
} |
||||
|
||||
public Builder createdAt(PlatformTime createdAt) { |
||||
this.createdAt = createdAt; |
||||
return this; |
||||
} |
||||
|
||||
public Builder updatedAt(PlatformTime updatedAt) { |
||||
this.updatedAt = updatedAt; |
||||
return this; |
||||
} |
||||
|
||||
public Builder shippedAt(PlatformTime shippedAt) { |
||||
this.shippedAt = shippedAt; |
||||
return this; |
||||
} |
||||
|
||||
public Builder estimatedArrivalAt(PlatformTime estimatedArrivalAt) { |
||||
this.estimatedArrivalAt = estimatedArrivalAt; |
||||
return this; |
||||
} |
||||
|
||||
public Builder actualArrivalAt(PlatformTime actualArrivalAt) { |
||||
this.actualArrivalAt = actualArrivalAt; |
||||
return this; |
||||
} |
||||
|
||||
public Builder lines(List<InboundShipmentLine> lines) { |
||||
this.lines = lines == null ? Collections.<InboundShipmentLine>emptyList() : lines; |
||||
return this; |
||||
} |
||||
|
||||
public Builder shippingRefs(List<InboundShippingRef> shippingRefs) { |
||||
this.shippingRefs = shippingRefs == null |
||||
? Collections.<InboundShippingRef>emptyList() : shippingRefs; |
||||
return this; |
||||
} |
||||
|
||||
public InboundShipment build() { |
||||
return new InboundShipment(this); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,368 @@
@@ -0,0 +1,368 @@
|
||||
package common.ecommerce.model.inbound; |
||||
|
||||
/** |
||||
* 入库货件商品行。 |
||||
* |
||||
* <p>数量字段统一用 {@code int},平台没给值时按 0 处理; |
||||
* 「申发差异 / 申收差异」这类平台字段不重复建模,由调用方用 |
||||
* {@link #declaredQuantity()}、{@link #shippedQuantity()}、{@link #receivedQuantity()} |
||||
* 自行计算。</p> |
||||
* |
||||
* <p>尺寸与重量保留平台原始数值与单位,不做单位换算。</p> |
||||
*/ |
||||
public final class InboundShipmentLine { |
||||
|
||||
private final String lineId; |
||||
private final String productId; |
||||
private final String sku; |
||||
private final String msku; |
||||
private final String fnsku; |
||||
private final String asin; |
||||
private final String parentAsin; |
||||
private final String productName; |
||||
private final String gtin; |
||||
private final String imageUrl; |
||||
private final int declaredQuantity; |
||||
private final int shippedQuantity; |
||||
private final int receivedQuantity; |
||||
private final int normalQuantity; |
||||
private final int defectiveQuantity; |
||||
private final int boxQuantity; |
||||
private final Integer quantityInBox; |
||||
private final String prepCategory; |
||||
private final String prepOwner; |
||||
private final String labelOwner; |
||||
private final Double length; |
||||
private final Double width; |
||||
private final Double height; |
||||
private final String lengthUnit; |
||||
private final Double weight; |
||||
private final String weightUnit; |
||||
private final String expiration; |
||||
|
||||
private InboundShipmentLine(Builder b) { |
||||
this.lineId = b.lineId; |
||||
this.productId = b.productId; |
||||
this.sku = b.sku; |
||||
this.msku = b.msku; |
||||
this.fnsku = b.fnsku; |
||||
this.asin = b.asin; |
||||
this.parentAsin = b.parentAsin; |
||||
this.productName = b.productName; |
||||
this.gtin = b.gtin; |
||||
this.imageUrl = b.imageUrl; |
||||
this.declaredQuantity = b.declaredQuantity; |
||||
this.shippedQuantity = b.shippedQuantity; |
||||
this.receivedQuantity = b.receivedQuantity; |
||||
this.normalQuantity = b.normalQuantity; |
||||
this.defectiveQuantity = b.defectiveQuantity; |
||||
this.boxQuantity = b.boxQuantity; |
||||
this.quantityInBox = b.quantityInBox; |
||||
this.prepCategory = b.prepCategory; |
||||
this.prepOwner = b.prepOwner; |
||||
this.labelOwner = b.labelOwner; |
||||
this.length = b.length; |
||||
this.width = b.width; |
||||
this.height = b.height; |
||||
this.lengthUnit = b.lengthUnit; |
||||
this.weight = b.weight; |
||||
this.weightUnit = b.weightUnit; |
||||
this.expiration = b.expiration; |
||||
} |
||||
|
||||
public static Builder builder() { |
||||
return new Builder(); |
||||
} |
||||
|
||||
public String lineId() { |
||||
return lineId; |
||||
} |
||||
|
||||
public String productId() { |
||||
return productId; |
||||
} |
||||
|
||||
public String sku() { |
||||
return sku; |
||||
} |
||||
|
||||
/** 平台 MSKU。 */ |
||||
public String msku() { |
||||
return msku; |
||||
} |
||||
|
||||
public String fnsku() { |
||||
return fnsku; |
||||
} |
||||
|
||||
public String asin() { |
||||
return asin; |
||||
} |
||||
|
||||
public String parentAsin() { |
||||
return parentAsin; |
||||
} |
||||
|
||||
public String productName() { |
||||
return productName; |
||||
} |
||||
|
||||
public String gtin() { |
||||
return gtin; |
||||
} |
||||
|
||||
public String imageUrl() { |
||||
return imageUrl; |
||||
} |
||||
|
||||
/** 申报数量。 */ |
||||
public int declaredQuantity() { |
||||
return declaredQuantity; |
||||
} |
||||
|
||||
/** 发货数量。 */ |
||||
public int shippedQuantity() { |
||||
return shippedQuantity; |
||||
} |
||||
|
||||
/** 签收数量。 */ |
||||
public int receivedQuantity() { |
||||
return receivedQuantity; |
||||
} |
||||
|
||||
/** 合格数量(FBT)。 */ |
||||
public int normalQuantity() { |
||||
return normalQuantity; |
||||
} |
||||
|
||||
/** 次品数量(FBT)。 */ |
||||
public int defectiveQuantity() { |
||||
return defectiveQuantity; |
||||
} |
||||
|
||||
/** 箱数(AWD)。 */ |
||||
public int boxQuantity() { |
||||
return boxQuantity; |
||||
} |
||||
|
||||
/** 单箱数量(AWD);未提供时为 null。 */ |
||||
public Integer quantityInBox() { |
||||
return quantityInBox; |
||||
} |
||||
|
||||
/** 预处理类别(AWD)。 */ |
||||
public String prepCategory() { |
||||
return prepCategory; |
||||
} |
||||
|
||||
/** 预处理提供方(AWD):AMAZON / SELF。 */ |
||||
public String prepOwner() { |
||||
return prepOwner; |
||||
} |
||||
|
||||
/** 标签类型(AWD):AMAZON / SELF。 */ |
||||
public String labelOwner() { |
||||
return labelOwner; |
||||
} |
||||
|
||||
public Double length() { |
||||
return length; |
||||
} |
||||
|
||||
public Double width() { |
||||
return width; |
||||
} |
||||
|
||||
public Double height() { |
||||
return height; |
||||
} |
||||
|
||||
/** 长度单位:INCHES / CENTIMETERS。 */ |
||||
public String lengthUnit() { |
||||
return lengthUnit; |
||||
} |
||||
|
||||
public Double weight() { |
||||
return weight; |
||||
} |
||||
|
||||
/** 重量单位:POUNDS / KILOGRAMS。 */ |
||||
public String weightUnit() { |
||||
return weightUnit; |
||||
} |
||||
|
||||
/** 有效期,保留平台原始字符串。 */ |
||||
public String expiration() { |
||||
return expiration; |
||||
} |
||||
|
||||
public static final class Builder { |
||||
|
||||
private String lineId; |
||||
private String productId; |
||||
private String sku; |
||||
private String msku; |
||||
private String fnsku; |
||||
private String asin; |
||||
private String parentAsin; |
||||
private String productName; |
||||
private String gtin; |
||||
private String imageUrl; |
||||
private int declaredQuantity; |
||||
private int shippedQuantity; |
||||
private int receivedQuantity; |
||||
private int normalQuantity; |
||||
private int defectiveQuantity; |
||||
private int boxQuantity; |
||||
private Integer quantityInBox; |
||||
private String prepCategory; |
||||
private String prepOwner; |
||||
private String labelOwner; |
||||
private Double length; |
||||
private Double width; |
||||
private Double height; |
||||
private String lengthUnit; |
||||
private Double weight; |
||||
private String weightUnit; |
||||
private String expiration; |
||||
|
||||
public Builder lineId(String lineId) { |
||||
this.lineId = lineId; |
||||
return this; |
||||
} |
||||
|
||||
public Builder productId(String productId) { |
||||
this.productId = productId; |
||||
return this; |
||||
} |
||||
|
||||
public Builder sku(String sku) { |
||||
this.sku = sku; |
||||
return this; |
||||
} |
||||
|
||||
public Builder msku(String msku) { |
||||
this.msku = msku; |
||||
return this; |
||||
} |
||||
|
||||
public Builder fnsku(String fnsku) { |
||||
this.fnsku = fnsku; |
||||
return this; |
||||
} |
||||
|
||||
public Builder asin(String asin) { |
||||
this.asin = asin; |
||||
return this; |
||||
} |
||||
|
||||
public Builder parentAsin(String parentAsin) { |
||||
this.parentAsin = parentAsin; |
||||
return this; |
||||
} |
||||
|
||||
public Builder productName(String productName) { |
||||
this.productName = productName; |
||||
return this; |
||||
} |
||||
|
||||
public Builder gtin(String gtin) { |
||||
this.gtin = gtin; |
||||
return this; |
||||
} |
||||
|
||||
public Builder imageUrl(String imageUrl) { |
||||
this.imageUrl = imageUrl; |
||||
return this; |
||||
} |
||||
|
||||
public Builder declaredQuantity(int declaredQuantity) { |
||||
this.declaredQuantity = declaredQuantity; |
||||
return this; |
||||
} |
||||
|
||||
public Builder shippedQuantity(int shippedQuantity) { |
||||
this.shippedQuantity = shippedQuantity; |
||||
return this; |
||||
} |
||||
|
||||
public Builder receivedQuantity(int receivedQuantity) { |
||||
this.receivedQuantity = receivedQuantity; |
||||
return this; |
||||
} |
||||
|
||||
public Builder normalQuantity(int normalQuantity) { |
||||
this.normalQuantity = normalQuantity; |
||||
return this; |
||||
} |
||||
|
||||
public Builder defectiveQuantity(int defectiveQuantity) { |
||||
this.defectiveQuantity = defectiveQuantity; |
||||
return this; |
||||
} |
||||
|
||||
public Builder boxQuantity(int boxQuantity) { |
||||
this.boxQuantity = boxQuantity; |
||||
return this; |
||||
} |
||||
|
||||
public Builder quantityInBox(Integer quantityInBox) { |
||||
this.quantityInBox = quantityInBox; |
||||
return this; |
||||
} |
||||
|
||||
public Builder prepCategory(String prepCategory) { |
||||
this.prepCategory = prepCategory; |
||||
return this; |
||||
} |
||||
|
||||
public Builder prepOwner(String prepOwner) { |
||||
this.prepOwner = prepOwner; |
||||
return this; |
||||
} |
||||
|
||||
public Builder labelOwner(String labelOwner) { |
||||
this.labelOwner = labelOwner; |
||||
return this; |
||||
} |
||||
|
||||
public Builder length(Double length) { |
||||
this.length = length; |
||||
return this; |
||||
} |
||||
|
||||
public Builder width(Double width) { |
||||
this.width = width; |
||||
return this; |
||||
} |
||||
|
||||
public Builder height(Double height) { |
||||
this.height = height; |
||||
return this; |
||||
} |
||||
|
||||
public Builder lengthUnit(String lengthUnit) { |
||||
this.lengthUnit = lengthUnit; |
||||
return this; |
||||
} |
||||
|
||||
public Builder weight(Double weight) { |
||||
this.weight = weight; |
||||
return this; |
||||
} |
||||
|
||||
public Builder weightUnit(String weightUnit) { |
||||
this.weightUnit = weightUnit; |
||||
return this; |
||||
} |
||||
|
||||
public Builder expiration(String expiration) { |
||||
this.expiration = expiration; |
||||
return this; |
||||
} |
||||
|
||||
public InboundShipmentLine build() { |
||||
return new InboundShipmentLine(this); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,192 @@
@@ -0,0 +1,192 @@
|
||||
package common.ecommerce.model.inbound; |
||||
|
||||
import java.time.Instant; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 入库货件查询条件(单次查询,不推进水位线)。 |
||||
* |
||||
* <p>覆盖 FBT / WFS / AWD 三类平台仓货件的公共维度:店铺、时间窗、货件单号、 |
||||
* 入库单号、状态、分页。各平台不支持的字段由适配器显式拒绝,不做静默忽略。</p> |
||||
* |
||||
* <p>时间窗语义为左闭右开 {@code [after, before)};平台只接受日期时, |
||||
* 适配器会按北京时间取日期部分。</p> |
||||
*/ |
||||
public final class InboundShipmentQuery { |
||||
|
||||
private final InboundShipmentTimeType timeType; |
||||
private final Instant after; |
||||
private final Instant before; |
||||
private final List<String> storeIds; |
||||
private final List<String> statuses; |
||||
private final String shipmentNo; |
||||
private final String inboundOrderNo; |
||||
private final int pageSize; |
||||
private final String cursor; |
||||
|
||||
private InboundShipmentQuery(Builder b) { |
||||
if (b.after != null && b.before != null && !b.after.isBefore(b.before)) { |
||||
throw new IllegalArgumentException("after must be before before"); |
||||
} |
||||
this.timeType = b.timeType; |
||||
this.after = b.after; |
||||
this.before = b.before; |
||||
this.storeIds = Collections.unmodifiableList(new ArrayList<String>(b.storeIds)); |
||||
this.statuses = Collections.unmodifiableList(new ArrayList<String>(b.statuses)); |
||||
this.shipmentNo = b.shipmentNo; |
||||
this.inboundOrderNo = b.inboundOrderNo; |
||||
this.pageSize = b.pageSize; |
||||
this.cursor = b.cursor; |
||||
} |
||||
|
||||
public static Builder builder() { |
||||
return new Builder(); |
||||
} |
||||
|
||||
/** 时间字段,默认 {@link InboundShipmentTimeType#CREATED}。 */ |
||||
public InboundShipmentTimeType timeType() { |
||||
return timeType; |
||||
} |
||||
|
||||
/** 时间窗起点;为 null 时不传。 */ |
||||
public Instant after() { |
||||
return after; |
||||
} |
||||
|
||||
/** 时间窗终点;为 null 时不传。 */ |
||||
public Instant before() { |
||||
return before; |
||||
} |
||||
|
||||
/** |
||||
* 店铺 id 过滤;为空时适配器使用当前账户的 {@code externalStoreId}。 |
||||
* |
||||
* <p>不做「不传就返回全部店铺」的降级,避免跨店铺泄露数据。</p> |
||||
*/ |
||||
public List<String> storeIds() { |
||||
return storeIds; |
||||
} |
||||
|
||||
/** 货件状态原始值;各平台取值不同,适配器按自己的协议解释。 */ |
||||
public List<String> statuses() { |
||||
return statuses; |
||||
} |
||||
|
||||
/** 货件单号(FBT cargoCode / AWD shipmentId)。 */ |
||||
public String shipmentNo() { |
||||
return shipmentNo; |
||||
} |
||||
|
||||
/** 入库单号(WFS inbound_order_id)。 */ |
||||
public String inboundOrderNo() { |
||||
return inboundOrderNo; |
||||
} |
||||
|
||||
public int pageSize() { |
||||
return pageSize; |
||||
} |
||||
|
||||
/** |
||||
* 分页游标:上一页 {@code Page.nextCursor()} 的返回值。 |
||||
* |
||||
* <p>FBT / WFS 存字符串化的 offset,AWD 存页码;具体含义由各平台实现说明。</p> |
||||
*/ |
||||
public String cursor() { |
||||
return cursor; |
||||
} |
||||
|
||||
public Builder toBuilder() { |
||||
return builder() |
||||
.timeType(timeType) |
||||
.after(after) |
||||
.before(before) |
||||
.storeIds(storeIds) |
||||
.statuses(statuses) |
||||
.shipmentNo(shipmentNo) |
||||
.inboundOrderNo(inboundOrderNo) |
||||
.pageSize(pageSize) |
||||
.cursor(cursor); |
||||
} |
||||
|
||||
public static final class Builder { |
||||
|
||||
private InboundShipmentTimeType timeType = InboundShipmentTimeType.CREATED; |
||||
private Instant after; |
||||
private Instant before; |
||||
private List<String> storeIds = Collections.emptyList(); |
||||
private List<String> statuses = Collections.emptyList(); |
||||
private String shipmentNo; |
||||
private String inboundOrderNo; |
||||
private int pageSize = 50; |
||||
private String cursor; |
||||
|
||||
public Builder timeType(InboundShipmentTimeType timeType) { |
||||
this.timeType = timeType == null ? InboundShipmentTimeType.CREATED : timeType; |
||||
return this; |
||||
} |
||||
|
||||
public Builder after(Instant after) { |
||||
this.after = after; |
||||
return this; |
||||
} |
||||
|
||||
public Builder before(Instant before) { |
||||
this.before = before; |
||||
return this; |
||||
} |
||||
|
||||
public Builder storeIds(List<String> storeIds) { |
||||
this.storeIds = storeIds == null ? Collections.<String>emptyList() : storeIds; |
||||
return this; |
||||
} |
||||
|
||||
public Builder storeIds(String... storeIds) { |
||||
List<String> values = new ArrayList<String>(); |
||||
if (storeIds != null) { |
||||
Collections.addAll(values, storeIds); |
||||
} |
||||
this.storeIds = values; |
||||
return this; |
||||
} |
||||
|
||||
public Builder statuses(List<String> statuses) { |
||||
this.statuses = statuses == null ? Collections.<String>emptyList() : statuses; |
||||
return this; |
||||
} |
||||
|
||||
public Builder statuses(String... statuses) { |
||||
List<String> values = new ArrayList<String>(); |
||||
if (statuses != null) { |
||||
Collections.addAll(values, statuses); |
||||
} |
||||
this.statuses = values; |
||||
return this; |
||||
} |
||||
|
||||
public Builder shipmentNo(String shipmentNo) { |
||||
this.shipmentNo = shipmentNo; |
||||
return this; |
||||
} |
||||
|
||||
public Builder inboundOrderNo(String inboundOrderNo) { |
||||
this.inboundOrderNo = inboundOrderNo; |
||||
return this; |
||||
} |
||||
|
||||
public Builder pageSize(int pageSize) { |
||||
this.pageSize = pageSize; |
||||
return this; |
||||
} |
||||
|
||||
public Builder cursor(String cursor) { |
||||
this.cursor = cursor; |
||||
return this; |
||||
} |
||||
|
||||
public InboundShipmentQuery build() { |
||||
return new InboundShipmentQuery(this); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
package common.ecommerce.model.inbound; |
||||
|
||||
/** |
||||
* 入库货件查询使用的时间字段。 |
||||
* |
||||
* <p>不同平台的可用字段不同,适配器只映射自己支持的取值; |
||||
* 不支持的取值显式抛 {@code ValidationException},不静默降级成别的时间字段。</p> |
||||
*/ |
||||
public enum InboundShipmentTimeType { |
||||
|
||||
/** 创建时间。 */ |
||||
CREATED, |
||||
|
||||
/** 平台更新时间。 */ |
||||
UPDATED, |
||||
|
||||
/** 完成时间(如 FBT 货件的完成时间)。 */ |
||||
COMPLETED |
||||
} |
||||
@ -0,0 +1,103 @@
@@ -0,0 +1,103 @@
|
||||
package common.ecommerce.model.inbound; |
||||
|
||||
import common.ecommerce.model.support.PlatformTime; |
||||
|
||||
/** |
||||
* 入库货件关联的发货单摘要。 |
||||
* |
||||
* <p>FBT 的 {@code shippingInfo} 会给出数量与状态;WFS 只给发货单号, |
||||
* 此时数量为 0、状态为 null。</p> |
||||
*/ |
||||
public final class InboundShippingRef { |
||||
|
||||
private final String shippingListCode; |
||||
private final int quantity; |
||||
private final Integer status; |
||||
private final String statusName; |
||||
private final PlatformTime shippedAt; |
||||
private final PlatformTime arrivedAt; |
||||
|
||||
private InboundShippingRef(Builder b) { |
||||
this.shippingListCode = b.shippingListCode; |
||||
this.quantity = b.quantity; |
||||
this.status = b.status; |
||||
this.statusName = b.statusName; |
||||
this.shippedAt = b.shippedAt; |
||||
this.arrivedAt = b.arrivedAt; |
||||
} |
||||
|
||||
public static Builder builder() { |
||||
return new Builder(); |
||||
} |
||||
|
||||
/** 发货单号。 */ |
||||
public String shippingListCode() { |
||||
return shippingListCode; |
||||
} |
||||
|
||||
public int quantity() { |
||||
return quantity; |
||||
} |
||||
|
||||
public Integer status() { |
||||
return status; |
||||
} |
||||
|
||||
public String statusName() { |
||||
return statusName; |
||||
} |
||||
|
||||
/** 实际发货时间。 */ |
||||
public PlatformTime shippedAt() { |
||||
return shippedAt; |
||||
} |
||||
|
||||
/** 到货时间。 */ |
||||
public PlatformTime arrivedAt() { |
||||
return arrivedAt; |
||||
} |
||||
|
||||
public static final class Builder { |
||||
|
||||
private String shippingListCode; |
||||
private int quantity; |
||||
private Integer status; |
||||
private String statusName; |
||||
private PlatformTime shippedAt; |
||||
private PlatformTime arrivedAt; |
||||
|
||||
public Builder shippingListCode(String shippingListCode) { |
||||
this.shippingListCode = shippingListCode; |
||||
return this; |
||||
} |
||||
|
||||
public Builder quantity(int quantity) { |
||||
this.quantity = quantity; |
||||
return this; |
||||
} |
||||
|
||||
public Builder status(Integer status) { |
||||
this.status = status; |
||||
return this; |
||||
} |
||||
|
||||
public Builder statusName(String statusName) { |
||||
this.statusName = statusName; |
||||
return this; |
||||
} |
||||
|
||||
public Builder shippedAt(PlatformTime shippedAt) { |
||||
this.shippedAt = shippedAt; |
||||
return this; |
||||
} |
||||
|
||||
public Builder arrivedAt(PlatformTime arrivedAt) { |
||||
this.arrivedAt = arrivedAt; |
||||
return this; |
||||
} |
||||
|
||||
public InboundShippingRef build() { |
||||
return new InboundShippingRef(this); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
package common.ecommerce.lingxing.platform; |
||||
|
||||
import common.ecommerce.model.inbound.InboundReceipt; |
||||
import common.ecommerce.model.inbound.InboundReceiptQuery; |
||||
import common.ecommerce.model.support.Page; |
||||
|
||||
/** |
||||
* 子平台的 FBA 到货接收明细能力。 |
||||
*/ |
||||
public interface LingxingInboundReceiptSource { |
||||
|
||||
/** 分页拉取 FBA 到货接收明细。 */ |
||||
Page<InboundReceipt> receipts(LingxingCall call, InboundReceiptQuery query); |
||||
} |
||||
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
package common.ecommerce.lingxing.platform; |
||||
|
||||
import common.ecommerce.model.inbound.InboundShipment; |
||||
import common.ecommerce.model.inbound.InboundShipmentQuery; |
||||
import common.ecommerce.model.support.Page; |
||||
|
||||
/** |
||||
* 子平台的平台仓入库货件能力(FBT / WFS / AWD)。 |
||||
* |
||||
* <p>三类平台的协议差异较大,各自实现一个 Source,由子平台按账户平台装配。</p> |
||||
*/ |
||||
public interface LingxingInboundShipmentSource { |
||||
|
||||
/** 分页拉取入库货件。 */ |
||||
Page<InboundShipment> shipments(LingxingCall call, InboundShipmentQuery query); |
||||
} |
||||
@ -0,0 +1,197 @@
@@ -0,0 +1,197 @@
|
||||
package common.ecommerce.lingxing.platform.inbound; |
||||
|
||||
import common.ecommerce.http.HttpRequest; |
||||
import common.ecommerce.http.HttpResponse; |
||||
import common.ecommerce.lingxing.LingxingApi; |
||||
import common.ecommerce.lingxing.http.LingxingEnvelope; |
||||
import common.ecommerce.lingxing.platform.LingxingCall; |
||||
import common.ecommerce.lingxing.platform.LingxingInboundShipmentSource; |
||||
import common.ecommerce.lingxing.platform.inbound.dto.AwdAddressDto; |
||||
import common.ecommerce.lingxing.platform.inbound.dto.AwdGoodsItemDto; |
||||
import common.ecommerce.lingxing.platform.inbound.dto.AwdShipmentDto; |
||||
import common.ecommerce.model.ChannelProvider; |
||||
import common.ecommerce.model.inbound.InboundShipment; |
||||
import common.ecommerce.model.inbound.InboundShipmentLine; |
||||
import common.ecommerce.model.inbound.InboundShipmentQuery; |
||||
import common.ecommerce.model.inbound.InboundShipmentTimeType; |
||||
import common.ecommerce.model.support.Page; |
||||
import common.ecommerce.model.support.PlatformTime; |
||||
|
||||
import java.time.Instant; |
||||
import java.time.ZoneId; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 领星 · AWD 入库货件列表 |
||||
* ({@code POST /amzStaServer/openapi/awd/inbound-shipment/page})。 |
||||
* |
||||
* <p>分页是 {@code page}/{@code length}(页码从 1 开始),游标存字符串化的页码。 |
||||
* 时间窗按 ISO instant 传;{@code dateType} 1 创建 / 2 更新,完成时间不支持。</p> |
||||
* |
||||
* <p>该接口的货件号过滤字段是 {@code shipmentId};没有入库单号过滤。</p> |
||||
*/ |
||||
public final class AwdCargoSource implements LingxingInboundShipmentSource { |
||||
|
||||
private static final int DEFAULT_PAGE_SIZE = 100; |
||||
private static final int MAX_PAGE_SIZE = 200; |
||||
|
||||
private static final int DATE_TYPE_CREATED = 1; |
||||
private static final int DATE_TYPE_UPDATED = 2; |
||||
|
||||
private static final String OP = "inbounds.shipments"; |
||||
|
||||
@Override |
||||
public Page<InboundShipment> shipments(LingxingCall call, InboundShipmentQuery query) { |
||||
if (query.inboundOrderNo() != null) { |
||||
throw InboundSupport.validation(call, OP, |
||||
"AWD inbound shipment does not support inboundOrderNo filter"); |
||||
} |
||||
|
||||
int length = query.pageSize() <= 0 ? DEFAULT_PAGE_SIZE |
||||
: Math.min(query.pageSize(), MAX_PAGE_SIZE); |
||||
int page = query.cursor() == null ? 1 : Integer.parseInt(query.cursor()); |
||||
|
||||
Map<String, Object> body = new LinkedHashMap<String, Object>(); |
||||
body.put("page", page); |
||||
body.put("length", length); |
||||
body.put("dateType", dateType(call, query.timeType())); |
||||
body.put("sidList", InboundSupport.resolveLongStoreIds(call, query, OP)); |
||||
if (query.after() != null) { |
||||
body.put("startDateTime", query.after().toString()); |
||||
} |
||||
if (query.before() != null) { |
||||
body.put("endDateTime", query.before().toString()); |
||||
} |
||||
if (query.shipmentNo() != null) { |
||||
body.put("shipmentId", query.shipmentNo()); |
||||
} |
||||
if (!query.statuses().isEmpty()) { |
||||
body.put("statusList", new ArrayList<String>(query.statuses())); |
||||
} |
||||
|
||||
HttpRequest req = call.signed(LingxingApi.INBOUND_SHIPMENT_AWD, body, OP); |
||||
HttpResponse resp = call.execute(req); |
||||
LingxingEnvelope envelope = call.envelope(resp, OP); |
||||
|
||||
List<AwdShipmentDto> dtos = call.json().listAt(envelope.body(), "data.records", AwdShipmentDto.class); |
||||
List<InboundShipment> out = new ArrayList<InboundShipment>(dtos.size()); |
||||
ZoneId zone = InboundSupport.marketplaceZone(call); |
||||
for (AwdShipmentDto dto : dtos) { |
||||
try { |
||||
out.add(toShipment(dto, call, zone)); |
||||
} catch (RuntimeException e) { |
||||
throw InboundSupport.mappingFailure(e, envelope, call, OP); |
||||
} |
||||
} |
||||
|
||||
boolean hasMore = dtos.size() >= length |
||||
&& (envelope.total() < 0 || (long) page * length < envelope.total()); |
||||
return Page.of(out, hasMore ? String.valueOf(page + 1) : null); |
||||
} |
||||
|
||||
private static int dateType(LingxingCall call, InboundShipmentTimeType timeType) { |
||||
InboundShipmentTimeType effective = |
||||
timeType == null ? InboundShipmentTimeType.CREATED : timeType; |
||||
if (effective == InboundShipmentTimeType.CREATED) { |
||||
return DATE_TYPE_CREATED; |
||||
} |
||||
if (effective == InboundShipmentTimeType.UPDATED) { |
||||
return DATE_TYPE_UPDATED; |
||||
} |
||||
throw InboundSupport.validation(call, OP, |
||||
"AWD inbound shipment does not support timeType=" + effective); |
||||
} |
||||
|
||||
private static InboundShipment toShipment(AwdShipmentDto dto, LingxingCall call, ZoneId zone) { |
||||
String storeId = dto.getSid() == null ? null : String.valueOf(dto.getSid()); |
||||
String orderId = InboundSupport.trimToNull(dto.getOrderId()); |
||||
return InboundShipment.builder() |
||||
.omsStoreId(call.ctx().omsStoreId()) |
||||
.sourceProvider(ChannelProvider.LINGXING) |
||||
.sourceAccountId(storeId) |
||||
.shipmentId(orderId) |
||||
.shipmentNo(orderId) |
||||
.stockOrderNo(InboundSupport.trimToNull(dto.getStockOrderId())) |
||||
.warehouseReferenceId(InboundSupport.trimToNull(dto.getWarehouseReferenceId())) |
||||
.storeId(storeId) |
||||
.storeIds(storeId == null |
||||
? Collections.<String>emptyList() : Collections.singletonList(storeId)) |
||||
.status(InboundSupport.trimToNull(dto.getStatus())) |
||||
.carrierCode(InboundSupport.trimToNull(dto.getCarrierCode())) |
||||
.trackingNo(InboundSupport.trimToNull(dto.getTrackingId())) |
||||
.destinationAddress(deliveredAddress(dto.getDeliveredAddress())) |
||||
.returnAddress(shippingAddress(dto.getShippingAddress())) |
||||
.creator(InboundSupport.trimToNull(dto.getCreateByName())) |
||||
.remark(InboundSupport.trimToNull(dto.getRemark())) |
||||
.createdAt(platformTime(dto.getGmtCreate(), zone)) |
||||
.updatedAt(platformTime(dto.getGmtModified(), zone)) |
||||
.shippedAt(platformTime(dto.getShipBy(), zone)) |
||||
.lines(toLines(dto.getGoodsItems())) |
||||
.build(); |
||||
} |
||||
|
||||
private static List<InboundShipmentLine> toLines(List<AwdGoodsItemDto> items) { |
||||
if (items == null || items.isEmpty()) { |
||||
return Collections.emptyList(); |
||||
} |
||||
List<InboundShipmentLine> lines = new ArrayList<InboundShipmentLine>(items.size()); |
||||
for (AwdGoodsItemDto item : items) { |
||||
String name = InboundSupport.trimToNull(item.getProductName()); |
||||
if (name == null) { |
||||
name = InboundSupport.trimToNull(item.getTitle()); |
||||
} |
||||
lines.add(InboundShipmentLine.builder() |
||||
.productId(InboundSupport.trimToNull(item.getAsin())) |
||||
.sku(InboundSupport.trimToNull(item.getSku())) |
||||
.msku(InboundSupport.trimToNull(item.getMsku())) |
||||
.fnsku(InboundSupport.trimToNull(item.getFnsku())) |
||||
.asin(InboundSupport.trimToNull(item.getAsin())) |
||||
.parentAsin(InboundSupport.trimToNull(item.getParentAsin())) |
||||
.productName(name) |
||||
.imageUrl(InboundSupport.trimToNull(item.getUrl())) |
||||
.receivedQuantity(InboundSupport.intOrZero(item.getReceivedQuantity())) |
||||
.boxQuantity(InboundSupport.intOrZero(item.getBoxQuantity())) |
||||
.quantityInBox(InboundSupport.integerOrNull(item.getQuantityInBox())) |
||||
.prepCategory(InboundSupport.trimToNull(item.getPrepCategory())) |
||||
.prepOwner(InboundSupport.trimToNull(item.getPrepOwner())) |
||||
.labelOwner(InboundSupport.trimToNull(item.getLabelOwner())) |
||||
.length(item.getLength()) |
||||
.width(item.getWidth()) |
||||
.height(item.getHeight()) |
||||
.lengthUnit(InboundSupport.trimToNull(item.getLengthUnit())) |
||||
.weight(item.getWeight()) |
||||
.weightUnit(InboundSupport.trimToNull(item.getWeightUnit())) |
||||
.expiration(InboundSupport.trimToNull(item.getExpiration())) |
||||
.build()); |
||||
} |
||||
return lines; |
||||
} |
||||
|
||||
private static String deliveredAddress(AwdAddressDto address) { |
||||
if (address == null) { |
||||
return null; |
||||
} |
||||
return InboundSupport.joinAddress(address.getDestinationAddressLine1(), |
||||
address.getDestinationAddressLine2(), address.getDestinationCity(), |
||||
address.getDestinationStateOrRegion(), address.getDestinationPostalCode(), |
||||
address.getDestinationCountryCode()); |
||||
} |
||||
|
||||
private static String shippingAddress(AwdAddressDto address) { |
||||
if (address == null) { |
||||
return null; |
||||
} |
||||
return InboundSupport.joinAddress(address.getShipperName(), address.getAddressLine1(), |
||||
address.getAddressLine2(), address.getCity(), address.getStateOrProvinceCode(), |
||||
address.getPostalCode(), address.getCountryCode()); |
||||
} |
||||
|
||||
private static PlatformTime platformTime(String value, ZoneId zone) { |
||||
Instant instant = InboundSupport.parseIso(value); |
||||
return instant == null ? null : PlatformTime.of(instant, zone); |
||||
} |
||||
} |
||||
@ -0,0 +1,120 @@
@@ -0,0 +1,120 @@
|
||||
package common.ecommerce.lingxing.platform.inbound; |
||||
|
||||
import common.ecommerce.http.HttpRequest; |
||||
import common.ecommerce.http.HttpResponse; |
||||
import common.ecommerce.lingxing.LingxingApi; |
||||
import common.ecommerce.lingxing.http.LingxingEnvelope; |
||||
import common.ecommerce.lingxing.platform.LingxingCall; |
||||
import common.ecommerce.lingxing.platform.LingxingInboundReceiptSource; |
||||
import common.ecommerce.lingxing.platform.inbound.dto.FbaReceivedInventoryDto; |
||||
import common.ecommerce.model.ChannelProvider; |
||||
import common.ecommerce.model.inbound.InboundReceipt; |
||||
import common.ecommerce.model.inbound.InboundReceiptQuery; |
||||
import common.ecommerce.model.support.Page; |
||||
import common.ecommerce.model.support.PlatformTime; |
||||
|
||||
import java.time.Instant; |
||||
import java.time.ZoneId; |
||||
import java.util.ArrayList; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 领星 · FBA 到货接收明细 |
||||
* ({@code POST /erp/sc/data/fba_report/receivedInventory})。 |
||||
* |
||||
* <p>分页是 {@code offset}/{@code length}(默认 1000),游标存字符串化的 offset。 |
||||
* 响应 {@code data} 是数组,{@code total} 在顶层。</p> |
||||
* |
||||
* <p>签收时间优先用带时区的 {@code received_date},其次 {@code received_date_locale}, |
||||
* 最后退回秒级时间戳;三者都没有时保留 null。</p> |
||||
*/ |
||||
public final class FbaReceivedInventorySource implements LingxingInboundReceiptSource { |
||||
|
||||
private static final int DEFAULT_PAGE_SIZE = 1000; |
||||
private static final int MAX_PAGE_SIZE = 1000; |
||||
|
||||
private static final String OP = "inbounds.receipts"; |
||||
|
||||
@Override |
||||
public Page<InboundReceipt> receipts(LingxingCall call, InboundReceiptQuery query) { |
||||
int length = query.pageSize() <= 0 ? DEFAULT_PAGE_SIZE |
||||
: Math.min(query.pageSize(), MAX_PAGE_SIZE); |
||||
int offset = query.cursor() == null ? 0 : Integer.parseInt(query.cursor()); |
||||
|
||||
Map<String, Object> body = new LinkedHashMap<String, Object>(); |
||||
body.put("sid", resolveSid(call, query)); |
||||
body.put("offset", offset); |
||||
body.put("length", length); |
||||
if (query.eventDate() != null) { |
||||
body.put("event_date", query.eventDate().toString()); |
||||
} |
||||
InboundSupport.putIfNotEmpty(body, "fba_shipment_id", query.shipmentIds()); |
||||
|
||||
HttpRequest req = call.signed(LingxingApi.INBOUND_RECEIPT_FBA, body, OP); |
||||
HttpResponse resp = call.execute(req); |
||||
LingxingEnvelope envelope = call.envelope(resp, OP); |
||||
|
||||
List<FbaReceivedInventoryDto> dtos = |
||||
call.json().listAt(envelope.body(), "data", FbaReceivedInventoryDto.class); |
||||
List<InboundReceipt> out = new ArrayList<InboundReceipt>(dtos.size()); |
||||
ZoneId zone = InboundSupport.marketplaceZone(call); |
||||
for (FbaReceivedInventoryDto dto : dtos) { |
||||
try { |
||||
out.add(toReceipt(dto, call, zone)); |
||||
} catch (RuntimeException e) { |
||||
throw InboundSupport.mappingFailure(e, envelope, call, OP); |
||||
} |
||||
} |
||||
|
||||
int nextOffset = offset + dtos.size(); |
||||
boolean hasMore = dtos.size() >= length |
||||
&& (envelope.total() < 0 || nextOffset < envelope.total()); |
||||
return Page.of(out, hasMore ? String.valueOf(nextOffset) : null); |
||||
} |
||||
|
||||
/** sid 必填;账户店铺不是数字时显式失败,不跨店铺查询。 */ |
||||
private static Integer resolveSid(LingxingCall call, InboundReceiptQuery query) { |
||||
String raw = query.sid(); |
||||
if (raw == null || raw.trim().isEmpty()) { |
||||
raw = call.ctx().account().externalStoreId(); |
||||
} |
||||
Integer sid = InboundSupport.parseInt(raw); |
||||
if (sid == null) { |
||||
throw InboundSupport.validation(call, OP, |
||||
"sid must be a numeric lingxing store id: " + raw); |
||||
} |
||||
return sid; |
||||
} |
||||
|
||||
private static InboundReceipt toReceipt(FbaReceivedInventoryDto dto, LingxingCall call, ZoneId zone) { |
||||
return InboundReceipt.builder() |
||||
.omsStoreId(call.ctx().omsStoreId()) |
||||
.sourceProvider(ChannelProvider.LINGXING) |
||||
.sourceAccountId(dto.getSid() == null ? null : String.valueOf(dto.getSid())) |
||||
.sid(dto.getSid()) |
||||
.shipmentId(InboundSupport.trimToNull(dto.getFbaShipmentId())) |
||||
.fnsku(InboundSupport.trimToNull(dto.getFnsku())) |
||||
.sku(InboundSupport.trimToNull(dto.getSku())) |
||||
.productName(InboundSupport.trimToNull(dto.getProductName())) |
||||
.quantity(InboundSupport.intOrZero(dto.getQuantity())) |
||||
.fulfillmentCenterId(InboundSupport.trimToNull(dto.getFulfillmentCenterId())) |
||||
.receivedAt(receivedAt(dto, zone)) |
||||
.receivedDateReport(InboundSupport.trimToNull(dto.getReceivedDateReport())) |
||||
.uniqueIndex(dto.getUniqueIndex()) |
||||
.uniqueMd5(InboundSupport.trimToNull(dto.getUniqueMd5())) |
||||
.build(); |
||||
} |
||||
|
||||
private static PlatformTime receivedAt(FbaReceivedInventoryDto dto, ZoneId zone) { |
||||
Instant instant = InboundSupport.parseIso(dto.getReceivedDate()); |
||||
if (instant == null) { |
||||
instant = InboundSupport.parseIso(dto.getReceivedDateLocale()); |
||||
} |
||||
if (instant == null && dto.getReceivedDateTimestamp() != null) { |
||||
instant = Instant.ofEpochSecond(dto.getReceivedDateTimestamp()); |
||||
} |
||||
return instant == null ? null : PlatformTime.of(instant, zone); |
||||
} |
||||
} |
||||
@ -0,0 +1,203 @@
@@ -0,0 +1,203 @@
|
||||
package common.ecommerce.lingxing.platform.inbound; |
||||
|
||||
import common.ecommerce.http.HttpRequest; |
||||
import common.ecommerce.http.HttpResponse; |
||||
import common.ecommerce.lingxing.LingxingApi; |
||||
import common.ecommerce.lingxing.http.LingxingEnvelope; |
||||
import common.ecommerce.lingxing.platform.LingxingCall; |
||||
import common.ecommerce.lingxing.platform.LingxingInboundShipmentSource; |
||||
import common.ecommerce.lingxing.platform.inbound.dto.FbtCargoDto; |
||||
import common.ecommerce.lingxing.platform.inbound.dto.FbtCargoGoodDto; |
||||
import common.ecommerce.lingxing.platform.inbound.dto.FbtShippingInfoDto; |
||||
import common.ecommerce.model.ChannelProvider; |
||||
import common.ecommerce.model.inbound.InboundShipment; |
||||
import common.ecommerce.model.inbound.InboundShipmentLine; |
||||
import common.ecommerce.model.inbound.InboundShipmentQuery; |
||||
import common.ecommerce.model.inbound.InboundShipmentTimeType; |
||||
import common.ecommerce.model.inbound.InboundShippingRef; |
||||
import common.ecommerce.model.support.Page; |
||||
import common.ecommerce.model.support.PlatformTime; |
||||
|
||||
import java.time.Instant; |
||||
import java.time.LocalDateTime; |
||||
import java.time.ZoneId; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 领星 · FBT 货件列表 |
||||
* ({@code POST /basicOpen/fbtShipment/cargo/list})。 |
||||
* |
||||
* <p>分页是 {@code offset}/{@code length}(上限 200),游标存字符串化的 offset。 |
||||
* 时间窗按北京时间取日期;{@code timeType} 只支持创建时间与完成时间, |
||||
* 更新时间显式拒绝。</p> |
||||
* |
||||
* <p>货件号过滤走 {@code queryType=3} + {@code queryValue}; |
||||
* 该接口没有入库单号过滤,传了直接拒绝。</p> |
||||
*/ |
||||
public final class FbtCargoSource implements LingxingInboundShipmentSource { |
||||
|
||||
private static final int DEFAULT_PAGE_SIZE = 20; |
||||
private static final int MAX_PAGE_SIZE = 200; |
||||
|
||||
/** queryType: 3 = 货件单号。 */ |
||||
private static final int QUERY_TYPE_CARGO_CODE = 3; |
||||
|
||||
private static final String OP = "inbounds.shipments"; |
||||
|
||||
@Override |
||||
public Page<InboundShipment> shipments(LingxingCall call, InboundShipmentQuery query) { |
||||
if (query.inboundOrderNo() != null) { |
||||
throw InboundSupport.validation(call, OP, |
||||
"FBT cargo list does not support inboundOrderNo filter"); |
||||
} |
||||
|
||||
int length = query.pageSize() <= 0 ? DEFAULT_PAGE_SIZE |
||||
: Math.min(query.pageSize(), MAX_PAGE_SIZE); |
||||
int offset = query.cursor() == null ? 0 : Integer.parseInt(query.cursor()); |
||||
|
||||
Map<String, Object> body = new LinkedHashMap<String, Object>(); |
||||
body.put("offset", offset); |
||||
body.put("length", length); |
||||
body.put("storeIdList", InboundSupport.resolveLongStoreIds(call, query, OP)); |
||||
body.put("timeType", timeTypeCode(call, query.timeType())); |
||||
if (query.after() != null) { |
||||
body.put("startTime", InboundSupport.DATE.format( |
||||
LocalDateTime.ofInstant(query.after(), PlatformTime.BEIJING_ZONE))); |
||||
} |
||||
if (query.before() != null) { |
||||
body.put("endTime", InboundSupport.DATE.format( |
||||
LocalDateTime.ofInstant(query.before(), PlatformTime.BEIJING_ZONE))); |
||||
} |
||||
if (query.shipmentNo() != null) { |
||||
body.put("queryType", QUERY_TYPE_CARGO_CODE); |
||||
body.put("queryValue", Collections.singletonList(query.shipmentNo())); |
||||
} |
||||
if (!query.statuses().isEmpty()) { |
||||
body.put("cargoStatusList", InboundSupport.parseStatusCodes(call, query.statuses(), OP)); |
||||
} |
||||
|
||||
HttpRequest req = call.signed(LingxingApi.INBOUND_SHIPMENT_FBT, body, OP); |
||||
HttpResponse resp = call.execute(req); |
||||
LingxingEnvelope envelope = call.envelope(resp, OP); |
||||
|
||||
List<FbtCargoDto> dtos = call.json().listAt(envelope.body(), "data.list", FbtCargoDto.class); |
||||
List<InboundShipment> out = new ArrayList<InboundShipment>(dtos.size()); |
||||
ZoneId zone = InboundSupport.marketplaceZone(call); |
||||
for (FbtCargoDto dto : dtos) { |
||||
try { |
||||
out.add(toShipment(dto, call, zone)); |
||||
} catch (RuntimeException e) { |
||||
throw InboundSupport.mappingFailure(e, envelope, call, OP); |
||||
} |
||||
} |
||||
|
||||
int nextOffset = offset + dtos.size(); |
||||
boolean hasMore = dtos.size() >= length |
||||
&& (envelope.total() < 0 || nextOffset < envelope.total()); |
||||
return Page.of(out, hasMore ? String.valueOf(nextOffset) : null); |
||||
} |
||||
|
||||
/** 0 创建时间 / 1 完成时间;更新时间该接口不支持。 */ |
||||
private static int timeTypeCode(LingxingCall call, InboundShipmentTimeType timeType) { |
||||
InboundShipmentTimeType effective = |
||||
timeType == null ? InboundShipmentTimeType.CREATED : timeType; |
||||
if (effective == InboundShipmentTimeType.CREATED) { |
||||
return 0; |
||||
} |
||||
if (effective == InboundShipmentTimeType.COMPLETED) { |
||||
return 1; |
||||
} |
||||
throw InboundSupport.validation(call, OP, |
||||
"FBT cargo list does not support timeType=" + effective); |
||||
} |
||||
|
||||
private static InboundShipment toShipment(FbtCargoDto dto, LingxingCall call, ZoneId zone) { |
||||
List<String> storeIds = new ArrayList<String>(); |
||||
for (Long id : safe(dto.getStoreIds())) { |
||||
if (id != null) { |
||||
storeIds.add(String.valueOf(id)); |
||||
} |
||||
} |
||||
String storeId = dto.getStoreId() == null ? null : String.valueOf(dto.getStoreId()); |
||||
if (storeId == null && storeIds.size() == 1) { |
||||
storeId = storeIds.get(0); |
||||
} |
||||
|
||||
return InboundShipment.builder() |
||||
.omsStoreId(call.ctx().omsStoreId()) |
||||
.sourceProvider(ChannelProvider.LINGXING) |
||||
.sourceAccountId(storeId) |
||||
.shipmentId(dto.getId() == null ? null : String.valueOf(dto.getId())) |
||||
.shipmentNo(InboundSupport.trimToNull(dto.getCargoCode())) |
||||
.storeId(storeId) |
||||
.storeName(InboundSupport.trimToNull(dto.getStoreName())) |
||||
.storeIds(storeIds) |
||||
.storeNames(safe(dto.getStoreNames())) |
||||
.warehouseName(InboundSupport.trimToNull(dto.getShippingWarehouse())) |
||||
.status(dto.getOrderStatus() == null ? null : String.valueOf(dto.getOrderStatus())) |
||||
.statusName(InboundSupport.trimToNull(dto.getOrderStatusName())) |
||||
.localStatus(InboundSupport.trimToNull(dto.getOrderStatusName())) |
||||
.shipStatus(InboundSupport.trimToNull(dto.getShipStatus())) |
||||
.createdAt(platformTime(dto.getCreateTime(), zone)) |
||||
.shippedAt(platformTime(dto.getDeliveryTime(), zone)) |
||||
.estimatedArrivalAt(platformTime(dto.getExpectedDeliveryTime(), zone)) |
||||
.actualArrivalAt(platformTime(dto.getActualDeliveryTime(), zone)) |
||||
.lines(toLines(dto.getOrderGoodList())) |
||||
.shippingRefs(toShippingRefs(dto.getShippingInfo(), zone)) |
||||
.build(); |
||||
} |
||||
|
||||
private static List<InboundShipmentLine> toLines(List<FbtCargoGoodDto> goods) { |
||||
if (goods == null || goods.isEmpty()) { |
||||
return Collections.emptyList(); |
||||
} |
||||
List<InboundShipmentLine> lines = new ArrayList<InboundShipmentLine>(goods.size()); |
||||
for (FbtCargoGoodDto good : goods) { |
||||
lines.add(InboundShipmentLine.builder() |
||||
.lineId(good.getId() == null ? null : String.valueOf(good.getId())) |
||||
.productId(InboundSupport.trimToNull(good.getProductId())) |
||||
.sku(InboundSupport.trimToNull(good.getSku())) |
||||
.msku(InboundSupport.trimToNull(good.getMsku())) |
||||
.productName(InboundSupport.trimToNull(good.getProductName())) |
||||
.imageUrl(InboundSupport.trimToNull(good.getImageUrl())) |
||||
.declaredQuantity(InboundSupport.intOrZero(good.getDeclarationQuantity())) |
||||
.shippedQuantity(InboundSupport.intOrZero(good.getShipmentQuantity())) |
||||
.receivedQuantity(InboundSupport.intOrZero(good.getSignedQuantity())) |
||||
.normalQuantity(InboundSupport.intOrZero(good.getNormalQuantity())) |
||||
.defectiveQuantity(InboundSupport.intOrZero(good.getDefectiveQuantity())) |
||||
.build()); |
||||
} |
||||
return lines; |
||||
} |
||||
|
||||
private static List<InboundShippingRef> toShippingRefs(List<FbtShippingInfoDto> infos, ZoneId zone) { |
||||
if (infos == null || infos.isEmpty()) { |
||||
return Collections.emptyList(); |
||||
} |
||||
List<InboundShippingRef> refs = new ArrayList<InboundShippingRef>(infos.size()); |
||||
for (FbtShippingInfoDto info : infos) { |
||||
refs.add(InboundShippingRef.builder() |
||||
.shippingListCode(InboundSupport.trimToNull(info.getShippingListCode())) |
||||
.quantity(InboundSupport.intOrZero(info.getShippingNum())) |
||||
.status(info.getShippingStatus()) |
||||
.statusName(InboundSupport.trimToNull(info.getShippingStatusName())) |
||||
.shippedAt(platformTime(info.getActualDeliveryTime(), zone)) |
||||
.arrivedAt(platformTime(info.getArrivalTime(), zone)) |
||||
.build()); |
||||
} |
||||
return refs; |
||||
} |
||||
|
||||
private static PlatformTime platformTime(String value, ZoneId zone) { |
||||
Instant instant = InboundSupport.parseBeijingDateTime(value); |
||||
return instant == null ? null : PlatformTime.of(instant, zone); |
||||
} |
||||
|
||||
private static <T> List<T> safe(List<T> value) { |
||||
return value == null ? Collections.<T>emptyList() : value; |
||||
} |
||||
} |
||||
@ -0,0 +1,212 @@
@@ -0,0 +1,212 @@
|
||||
package common.ecommerce.lingxing.platform.inbound; |
||||
|
||||
import common.ecommerce.error.ChannelException; |
||||
import common.ecommerce.error.ValidationException; |
||||
import common.ecommerce.lingxing.http.LingxingEnvelope; |
||||
import common.ecommerce.lingxing.platform.LingxingCall; |
||||
import common.ecommerce.model.ChannelProvider; |
||||
import common.ecommerce.model.inbound.InboundShipmentQuery; |
||||
import common.ecommerce.model.support.PlatformTime; |
||||
|
||||
import java.time.Instant; |
||||
import java.time.LocalDate; |
||||
import java.time.LocalDateTime; |
||||
import java.time.OffsetDateTime; |
||||
import java.time.ZoneId; |
||||
import java.time.format.DateTimeFormatter; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 入库查询的公共小工具:时间解析、店铺 id 解析、参数校验与映射错误包装。 |
||||
* |
||||
* <p>四类平台的时间格式不同(FBT/WFS 是北京时间文本,AWD 是 ISO instant, |
||||
* FBA 是带偏移的 ISO 文本),集中在这里避免每个 Source 各写一套。</p> |
||||
*/ |
||||
final class InboundSupport { |
||||
|
||||
/** FBT / WFS 的日期格式。 */ |
||||
static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
||||
|
||||
/** FBT / WFS 的日期时间格式。 */ |
||||
static final DateTimeFormatter DATE_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
||||
|
||||
private InboundSupport() { |
||||
} |
||||
|
||||
/** 北京时间文本 {@code yyyy-MM-dd HH:mm:ss} → UTC instant。 */ |
||||
static Instant parseBeijingDateTime(String value) { |
||||
String text = trimToNull(value); |
||||
if (text == null) { |
||||
return null; |
||||
} |
||||
return LocalDateTime.parse(text, DATE_TIME).atZone(PlatformTime.BEIJING_ZONE).toInstant(); |
||||
} |
||||
|
||||
/** 北京时间日期 {@code yyyy-MM-dd} → 当天 00:00:00 的 UTC instant。 */ |
||||
static Instant parseBeijingDate(String value) { |
||||
String text = trimToNull(value); |
||||
if (text == null) { |
||||
return null; |
||||
} |
||||
return LocalDate.parse(text, DATE).atStartOfDay(PlatformTime.BEIJING_ZONE).toInstant(); |
||||
} |
||||
|
||||
/** |
||||
* ISO 时间文本 → UTC instant。 |
||||
* |
||||
* <p>兼容 {@code 2018-11-04T00:00:00+00:00}(带偏移)与 {@code ...Z}; |
||||
* 只有日期时按北京时间当天 0 点处理。</p> |
||||
*/ |
||||
static Instant parseIso(String value) { |
||||
String text = trimToNull(value); |
||||
if (text == null) { |
||||
return null; |
||||
} |
||||
if (text.length() == 10) { |
||||
return parseBeijingDate(text); |
||||
} |
||||
try { |
||||
return OffsetDateTime.parse(text).toInstant(); |
||||
} catch (RuntimeException ignored) { |
||||
// 落到下面的 Instant.parse
|
||||
} |
||||
return Instant.parse(text); |
||||
} |
||||
|
||||
/** 店铺 id 列表:调用方没传时用当前账户的店铺,避免跨店铺查询。 */ |
||||
static List<String> resolveStoreIds(LingxingCall call, InboundShipmentQuery query, String op) { |
||||
if (!query.storeIds().isEmpty()) { |
||||
return query.storeIds(); |
||||
} |
||||
String storeId = trimToNull(call.ctx().account().externalStoreId()); |
||||
if (storeId == null) { |
||||
throw validation(call, op, |
||||
"account externalStoreId is not a usable lingxing store id; set storeIds explicitly"); |
||||
} |
||||
return Collections.singletonList(storeId); |
||||
} |
||||
|
||||
/** 店铺 id 列表(数值型协议用);非数字显式失败。 */ |
||||
static List<Long> resolveLongStoreIds(LingxingCall call, InboundShipmentQuery query, String op) { |
||||
List<String> raw = resolveStoreIds(call, query, op); |
||||
List<Long> out = new ArrayList<Long>(raw.size()); |
||||
for (String value : raw) { |
||||
Long id = parseLong(value); |
||||
if (id == null) { |
||||
throw validation(call, op, "store id must be numeric: " + value); |
||||
} |
||||
out.add(id); |
||||
} |
||||
return out; |
||||
} |
||||
|
||||
/** 状态列表:数值型协议用;非数字显式失败。 */ |
||||
static List<Integer> parseStatusCodes(LingxingCall call, List<String> statuses, String op) { |
||||
List<Integer> out = new ArrayList<Integer>(statuses.size()); |
||||
for (String value : statuses) { |
||||
Integer code = parseInt(value); |
||||
if (code == null) { |
||||
throw validation(call, op, "status must be numeric: " + value); |
||||
} |
||||
out.add(code); |
||||
} |
||||
return out; |
||||
} |
||||
|
||||
static Long parseLong(String value) { |
||||
String text = trimToNull(value); |
||||
if (text == null) { |
||||
return null; |
||||
} |
||||
try { |
||||
return Long.valueOf(text); |
||||
} catch (NumberFormatException e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
static Integer parseInt(String value) { |
||||
String text = trimToNull(value); |
||||
if (text == null) { |
||||
return null; |
||||
} |
||||
try { |
||||
return Integer.valueOf(text); |
||||
} catch (NumberFormatException e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
static int intOrZero(Integer value) { |
||||
return value == null ? 0 : value; |
||||
} |
||||
|
||||
static int intOrZero(String value) { |
||||
Integer parsed = parseInt(value); |
||||
return parsed == null ? 0 : parsed; |
||||
} |
||||
|
||||
static Integer integerOrNull(String value) { |
||||
return parseInt(value); |
||||
} |
||||
|
||||
/** 地址拼接:跳过空段,用 {@code , } 连接。 */ |
||||
static String joinAddress(String... parts) { |
||||
StringBuilder sb = new StringBuilder(); |
||||
if (parts == null) { |
||||
return null; |
||||
} |
||||
for (String part : parts) { |
||||
String text = trimToNull(part); |
||||
if (text == null) { |
||||
continue; |
||||
} |
||||
if (sb.length() > 0) { |
||||
sb.append(", "); |
||||
} |
||||
sb.append(text); |
||||
} |
||||
return sb.length() == 0 ? null : sb.toString(); |
||||
} |
||||
|
||||
static void putIfNotEmpty(java.util.Map<String, Object> body, String key, List<?> values) { |
||||
if (values != null && !values.isEmpty()) { |
||||
body.put(key, values); |
||||
} |
||||
} |
||||
|
||||
static String trimToNull(String value) { |
||||
if (value == null) { |
||||
return null; |
||||
} |
||||
String trimmed = value.trim(); |
||||
return trimmed.isEmpty() ? null : trimmed; |
||||
} |
||||
|
||||
static ValidationException validation(LingxingCall call, String operation, String message) { |
||||
return new ValidationException(ChannelException.builder() |
||||
.message(message) |
||||
.operation(operation) |
||||
.provider(ChannelProvider.LINGXING.name()) |
||||
.omsStoreId(call.ctx().omsStoreId()) |
||||
.requestId(call.ctx().requestId()) |
||||
.retryable(false)); |
||||
} |
||||
|
||||
static ValidationException mappingFailure(RuntimeException e, LingxingEnvelope envelope, |
||||
LingxingCall call, String operation) { |
||||
return new ValidationException(ChannelException.builder() |
||||
.message("lingxing inbound mapping failed: " + e.getMessage()) |
||||
.operation(operation) |
||||
.provider(ChannelProvider.LINGXING.name()) |
||||
.omsStoreId(call.ctx().omsStoreId()) |
||||
.requestId(call.ctx().requestId()) |
||||
.rawResponse(envelope.body()), e); |
||||
} |
||||
|
||||
static ZoneId marketplaceZone(LingxingCall call) { |
||||
return ZoneId.of(call.ctx().account().marketplaceZone()); |
||||
} |
||||
} |
||||
@ -0,0 +1,190 @@
@@ -0,0 +1,190 @@
|
||||
package common.ecommerce.lingxing.platform.inbound; |
||||
|
||||
import common.ecommerce.http.HttpRequest; |
||||
import common.ecommerce.http.HttpResponse; |
||||
import common.ecommerce.lingxing.LingxingApi; |
||||
import common.ecommerce.lingxing.http.LingxingEnvelope; |
||||
import common.ecommerce.lingxing.platform.LingxingCall; |
||||
import common.ecommerce.lingxing.platform.LingxingInboundShipmentSource; |
||||
import common.ecommerce.lingxing.platform.inbound.dto.WfsCargoDto; |
||||
import common.ecommerce.lingxing.platform.inbound.dto.WfsCargoGoodDto; |
||||
import common.ecommerce.model.ChannelProvider; |
||||
import common.ecommerce.model.inbound.InboundShipment; |
||||
import common.ecommerce.model.inbound.InboundShipmentLine; |
||||
import common.ecommerce.model.inbound.InboundShipmentQuery; |
||||
import common.ecommerce.model.inbound.InboundShipmentTimeType; |
||||
import common.ecommerce.model.inbound.InboundShippingRef; |
||||
import common.ecommerce.model.support.Page; |
||||
import common.ecommerce.model.support.PlatformTime; |
||||
|
||||
import java.time.Instant; |
||||
import java.time.LocalDateTime; |
||||
import java.time.ZoneId; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 领星 · WFS 货件列表 |
||||
* ({@code POST /cepf/warehouse/api/openApi/queryWFSCargoPage})。 |
||||
* |
||||
* <p>分页是 {@code offset}/{@code length}(上限 200),游标存字符串化的 offset。 |
||||
* 创建时间用 {@code start_time}/{@code end_time}(日期,双闭区间); |
||||
* 更新时间用 {@code update_time_ge}/{@code update_time_le}(北京时间日期时间)。 |
||||
* 完成时间该接口不支持。</p> |
||||
* |
||||
* <p>该接口只有入库单号过滤,没有货件号过滤;传 {@code shipmentNo} 直接拒绝。</p> |
||||
*/ |
||||
public final class WfsCargoSource implements LingxingInboundShipmentSource { |
||||
|
||||
private static final int DEFAULT_PAGE_SIZE = 15; |
||||
private static final int MAX_PAGE_SIZE = 200; |
||||
|
||||
private static final String OP = "inbounds.shipments"; |
||||
|
||||
@Override |
||||
public Page<InboundShipment> shipments(LingxingCall call, InboundShipmentQuery query) { |
||||
if (query.shipmentNo() != null) { |
||||
throw InboundSupport.validation(call, OP, |
||||
"WFS cargo list does not support shipmentNo filter; use inboundOrderNo"); |
||||
} |
||||
|
||||
int length = query.pageSize() <= 0 ? DEFAULT_PAGE_SIZE |
||||
: Math.min(query.pageSize(), MAX_PAGE_SIZE); |
||||
int offset = query.cursor() == null ? 0 : Integer.parseInt(query.cursor()); |
||||
|
||||
Map<String, Object> body = new LinkedHashMap<String, Object>(); |
||||
body.put("offset", offset); |
||||
body.put("length", length); |
||||
body.put("store_id", InboundSupport.resolveStoreIds(call, query, OP)); |
||||
applyTimeWindow(body, call, query); |
||||
if (query.inboundOrderNo() != null) { |
||||
body.put("inbound_order_id", query.inboundOrderNo()); |
||||
} |
||||
if (!query.statuses().isEmpty()) { |
||||
body.put("cargo_status_list", InboundSupport.parseStatusCodes(call, query.statuses(), OP)); |
||||
} |
||||
|
||||
HttpRequest req = call.signed(LingxingApi.INBOUND_SHIPMENT_WFS, body, OP); |
||||
HttpResponse resp = call.execute(req); |
||||
LingxingEnvelope envelope = call.envelope(resp, OP); |
||||
|
||||
List<WfsCargoDto> dtos = call.json().listAt(envelope.body(), "data.records", WfsCargoDto.class); |
||||
List<InboundShipment> out = new ArrayList<InboundShipment>(dtos.size()); |
||||
ZoneId zone = InboundSupport.marketplaceZone(call); |
||||
for (WfsCargoDto dto : dtos) { |
||||
try { |
||||
out.add(toShipment(dto, call, zone)); |
||||
} catch (RuntimeException e) { |
||||
throw InboundSupport.mappingFailure(e, envelope, call, OP); |
||||
} |
||||
} |
||||
|
||||
int nextOffset = offset + dtos.size(); |
||||
boolean hasMore = dtos.size() >= length |
||||
&& (envelope.total() < 0 || nextOffset < envelope.total()); |
||||
return Page.of(out, hasMore ? String.valueOf(nextOffset) : null); |
||||
} |
||||
|
||||
private static void applyTimeWindow(Map<String, Object> body, LingxingCall call, |
||||
InboundShipmentQuery query) { |
||||
InboundShipmentTimeType timeType = |
||||
query.timeType() == null ? InboundShipmentTimeType.CREATED : query.timeType(); |
||||
if (timeType == InboundShipmentTimeType.CREATED) { |
||||
if (query.after() != null) { |
||||
body.put("start_time", InboundSupport.DATE.format( |
||||
LocalDateTime.ofInstant(query.after(), PlatformTime.BEIJING_ZONE))); |
||||
} |
||||
if (query.before() != null) { |
||||
body.put("end_time", InboundSupport.DATE.format( |
||||
LocalDateTime.ofInstant(query.before(), PlatformTime.BEIJING_ZONE))); |
||||
} |
||||
return; |
||||
} |
||||
if (timeType == InboundShipmentTimeType.UPDATED) { |
||||
if (query.after() != null) { |
||||
body.put("update_time_ge", InboundSupport.DATE_TIME.format( |
||||
LocalDateTime.ofInstant(query.after(), PlatformTime.BEIJING_ZONE))); |
||||
} |
||||
if (query.before() != null) { |
||||
body.put("update_time_le", InboundSupport.DATE_TIME.format( |
||||
LocalDateTime.ofInstant(query.before(), PlatformTime.BEIJING_ZONE))); |
||||
} |
||||
return; |
||||
} |
||||
throw InboundSupport.validation(call, OP, |
||||
"WFS cargo list does not support timeType=" + timeType); |
||||
} |
||||
|
||||
private static InboundShipment toShipment(WfsCargoDto dto, LingxingCall call, ZoneId zone) { |
||||
String storeId = InboundSupport.trimToNull(dto.getStoreId()); |
||||
return InboundShipment.builder() |
||||
.omsStoreId(call.ctx().omsStoreId()) |
||||
.sourceProvider(ChannelProvider.LINGXING) |
||||
.sourceAccountId(storeId) |
||||
.shipmentId(InboundSupport.trimToNull(dto.getId())) |
||||
.shipmentNo(InboundSupport.trimToNull(dto.getCargoCode())) |
||||
.inboundOrderNo(InboundSupport.trimToNull(dto.getInBoundOrderId())) |
||||
.storeId(storeId) |
||||
.storeName(InboundSupport.trimToNull(dto.getStoreName())) |
||||
.storeIds(storeId == null |
||||
? Collections.<String>emptyList() : Collections.singletonList(storeId)) |
||||
.storeNames(dto.getStoreName() == null |
||||
? Collections.<String>emptyList() |
||||
: Collections.singletonList(dto.getStoreName())) |
||||
.countryName(InboundSupport.trimToNull(dto.getCountryName())) |
||||
.status(InboundSupport.trimToNull(dto.getCargoStatus())) |
||||
.statusName(InboundSupport.trimToNull(dto.getStatusName())) |
||||
.localStatus(InboundSupport.trimToNull(dto.getCargoSyncStatus())) |
||||
.carrierCode(InboundSupport.trimToNull(dto.getLogisticsCode())) |
||||
.destinationAddress(InboundSupport.trimToNull(dto.getDistributionAddresses())) |
||||
.returnAddress(InboundSupport.trimToNull(dto.getReturnAddresses())) |
||||
.creator(InboundSupport.trimToNull(dto.getCreator())) |
||||
.createdAt(platformTime(dto.getCargoCreateDate(), zone)) |
||||
.updatedAt(platformTime(dto.getUpdateDate(), zone)) |
||||
.lines(toLines(dto.getCargoGoodList())) |
||||
.shippingRefs(toShippingRefs(dto.getShippingListCodes())) |
||||
.build(); |
||||
} |
||||
|
||||
private static List<InboundShipmentLine> toLines(List<WfsCargoGoodDto> goods) { |
||||
if (goods == null || goods.isEmpty()) { |
||||
return Collections.emptyList(); |
||||
} |
||||
List<InboundShipmentLine> lines = new ArrayList<InboundShipmentLine>(goods.size()); |
||||
for (WfsCargoGoodDto good : goods) { |
||||
lines.add(InboundShipmentLine.builder() |
||||
.sku(InboundSupport.trimToNull(good.getSku())) |
||||
.msku(InboundSupport.trimToNull(good.getMsku())) |
||||
.productName(InboundSupport.trimToNull(good.getProductName())) |
||||
.gtin(InboundSupport.trimToNull(good.getGtin())) |
||||
.declaredQuantity(InboundSupport.intOrZero(good.getDeclareNum())) |
||||
.shippedQuantity(InboundSupport.intOrZero(good.getShipmentsNum())) |
||||
.receivedQuantity(InboundSupport.intOrZero(good.getReceivedNum())) |
||||
.defectiveQuantity(InboundSupport.intOrZero(good.getDamagedQty())) |
||||
.build()); |
||||
} |
||||
return lines; |
||||
} |
||||
|
||||
/** WFS 只给发货单号,没有数量与状态。 */ |
||||
private static List<InboundShippingRef> toShippingRefs(List<String> codes) { |
||||
if (codes == null || codes.isEmpty()) { |
||||
return Collections.emptyList(); |
||||
} |
||||
List<InboundShippingRef> refs = new ArrayList<InboundShippingRef>(codes.size()); |
||||
for (String code : codes) { |
||||
refs.add(InboundShippingRef.builder() |
||||
.shippingListCode(InboundSupport.trimToNull(code)) |
||||
.build()); |
||||
} |
||||
return refs; |
||||
} |
||||
|
||||
private static PlatformTime platformTime(String value, ZoneId zone) { |
||||
Instant instant = InboundSupport.parseBeijingDateTime(value); |
||||
return instant == null ? null : PlatformTime.of(instant, zone); |
||||
} |
||||
} |
||||
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
package common.ecommerce.lingxing.platform.inbound.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
/** |
||||
* 领星 · AWD 地址。 |
||||
* |
||||
* <p>送达地址用 {@code destination*} 字段,发货地址用不带前缀的字段; |
||||
* 两类结构共用本 DTO,按实际有值的字段拼接。</p> |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public class AwdAddressDto { |
||||
|
||||
@JsonProperty("destinationAddressLine1") |
||||
private String destinationAddressLine1; |
||||
|
||||
@JsonProperty("destinationAddressLine2") |
||||
private String destinationAddressLine2; |
||||
|
||||
@JsonProperty("destinationCity") |
||||
private String destinationCity; |
||||
|
||||
@JsonProperty("destinationStateOrRegion") |
||||
private String destinationStateOrRegion; |
||||
|
||||
@JsonProperty("destinationPostalCode") |
||||
private String destinationPostalCode; |
||||
|
||||
@JsonProperty("destinationCountryCode") |
||||
private String destinationCountryCode; |
||||
|
||||
@JsonProperty("addressLine1") |
||||
private String addressLine1; |
||||
|
||||
@JsonProperty("addressLine2") |
||||
private String addressLine2; |
||||
|
||||
@JsonProperty("city") |
||||
private String city; |
||||
|
||||
@JsonProperty("stateOrProvinceCode") |
||||
private String stateOrProvinceCode; |
||||
|
||||
@JsonProperty("postalCode") |
||||
private String postalCode; |
||||
|
||||
@JsonProperty("countryCode") |
||||
private String countryCode; |
||||
|
||||
@JsonProperty("shipperName") |
||||
private String shipperName; |
||||
|
||||
@JsonProperty("phoneNumber") |
||||
private String phoneNumber; |
||||
|
||||
@JsonProperty("zone") |
||||
private String zone; |
||||
} |
||||
@ -0,0 +1,82 @@
@@ -0,0 +1,82 @@
|
||||
package common.ecommerce.lingxing.platform.inbound.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
/** |
||||
* 领星 · AWD 货件商品行。 |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public class AwdGoodsItemDto { |
||||
|
||||
@JsonProperty("asin") |
||||
private String asin; |
||||
|
||||
@JsonProperty("parentAsin") |
||||
private String parentAsin; |
||||
|
||||
@JsonProperty("fnsku") |
||||
private String fnsku; |
||||
|
||||
@JsonProperty("msku") |
||||
private String msku; |
||||
|
||||
@JsonProperty("sku") |
||||
private String sku; |
||||
|
||||
@JsonProperty("productName") |
||||
private String productName; |
||||
|
||||
@JsonProperty("title") |
||||
private String title; |
||||
|
||||
/** 图片 url。 */ |
||||
@JsonProperty("url") |
||||
private String url; |
||||
|
||||
/** 签收数量。 */ |
||||
@JsonProperty("receivedQuantity") |
||||
private Integer receivedQuantity; |
||||
|
||||
/** 箱数,平台给的是字符串。 */ |
||||
@JsonProperty("boxQuantity") |
||||
private String boxQuantity; |
||||
|
||||
/** 单箱数量,平台给的是字符串。 */ |
||||
@JsonProperty("quantityInBox") |
||||
private String quantityInBox; |
||||
|
||||
@JsonProperty("prepCategory") |
||||
private String prepCategory; |
||||
|
||||
@JsonProperty("prepOwner") |
||||
private String prepOwner; |
||||
|
||||
@JsonProperty("labelOwner") |
||||
private String labelOwner; |
||||
|
||||
@JsonProperty("length") |
||||
private Double length; |
||||
|
||||
@JsonProperty("width") |
||||
private Double width; |
||||
|
||||
@JsonProperty("height") |
||||
private Double height; |
||||
|
||||
@JsonProperty("lengthUnit") |
||||
private String lengthUnit; |
||||
|
||||
@JsonProperty("weight") |
||||
private Double weight; |
||||
|
||||
@JsonProperty("weightUnit") |
||||
private String weightUnit; |
||||
|
||||
@JsonProperty("expiration") |
||||
private String expiration; |
||||
} |
||||
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
package common.ecommerce.lingxing.platform.inbound.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 领星 · AWD 入库货件 |
||||
* ({@code /amzStaServer/openapi/awd/inbound-shipment/page} 的 {@code data.records[]})。 |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public class AwdShipmentDto { |
||||
|
||||
/** AWD 货件单号。 */ |
||||
@JsonProperty("orderId") |
||||
private String orderId; |
||||
|
||||
/** 备货单号。 */ |
||||
@JsonProperty("stockOrderId") |
||||
private String stockOrderId; |
||||
|
||||
/** referenceId。 */ |
||||
@JsonProperty("warehouseReferenceId") |
||||
private String warehouseReferenceId; |
||||
|
||||
/** 货件状态:CREATED / SHIPPED / IN_TRANSIT / RECEIVING / DELIVERED / CLOSED / CANCELLED。 */ |
||||
@JsonProperty("status") |
||||
private String status; |
||||
|
||||
@JsonProperty("gmtCreate") |
||||
private String gmtCreate; |
||||
|
||||
@JsonProperty("gmtModified") |
||||
private String gmtModified; |
||||
|
||||
/** 发货日期,平台给的是 {@code YYYY-MM-DD}。 */ |
||||
@JsonProperty("shipBy") |
||||
private String shipBy; |
||||
|
||||
@JsonProperty("trackingId") |
||||
private String trackingId; |
||||
|
||||
@JsonProperty("carrierCode") |
||||
private String carrierCode; |
||||
|
||||
@JsonProperty("sid") |
||||
private Long sid; |
||||
|
||||
@JsonProperty("remark") |
||||
private String remark; |
||||
|
||||
@JsonProperty("createByName") |
||||
private String createByName; |
||||
|
||||
/** 送达地址。 */ |
||||
@JsonProperty("awdDeliveredGoodsBO") |
||||
private AwdAddressDto deliveredAddress; |
||||
|
||||
/** 商品行。 */ |
||||
@JsonProperty("awdDeliveredGoodsItemBOS") |
||||
private List<AwdGoodsItemDto> goodsItems = new ArrayList<AwdGoodsItemDto>(); |
||||
|
||||
/** 发货地址。 */ |
||||
@JsonProperty("awdShippingAddressBO") |
||||
private AwdAddressDto shippingAddress; |
||||
} |
||||
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
package common.ecommerce.lingxing.platform.inbound.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
/** |
||||
* 领星 · FBA 到货接收明细 |
||||
* ({@code /erp/sc/data/fba_report/receivedInventory} 的 {@code data[]})。 |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public class FbaReceivedInventoryDto { |
||||
|
||||
@JsonProperty("sid") |
||||
private Integer sid; |
||||
|
||||
/** 签收时间,带时区偏移,如 {@code 2018-11-04T00:00:00+00:00}。 */ |
||||
@JsonProperty("received_date") |
||||
private String receivedDate; |
||||
|
||||
/** 本地时区签收时间。 */ |
||||
@JsonProperty("received_date_locale") |
||||
private String receivedDateLocale; |
||||
|
||||
/** 签收时间戳(秒)。 */ |
||||
@JsonProperty("received_date_timestamp") |
||||
private Long receivedDateTimestamp; |
||||
|
||||
@JsonProperty("fnsku") |
||||
private String fnsku; |
||||
|
||||
/** MSKU。 */ |
||||
@JsonProperty("sku") |
||||
private String sku; |
||||
|
||||
@JsonProperty("product_name") |
||||
private String productName; |
||||
|
||||
/** 签收数量;可能为负数。 */ |
||||
@JsonProperty("quantity") |
||||
private Integer quantity; |
||||
|
||||
@JsonProperty("fba_shipment_id") |
||||
private String fbaShipmentId; |
||||
|
||||
@JsonProperty("fulfillment_center_id") |
||||
private String fulfillmentCenterId; |
||||
|
||||
@JsonProperty("unique_index") |
||||
private Integer uniqueIndex; |
||||
|
||||
@JsonProperty("unique_md5") |
||||
private String uniqueMd5; |
||||
|
||||
/** 处理过的接收日期,{@code yyyy-MM-dd}。 */ |
||||
@JsonProperty("received_date_report") |
||||
private String receivedDateReport; |
||||
} |
||||
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
package common.ecommerce.lingxing.platform.inbound.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 领星 · FBT 货件({@code /basicOpen/fbtShipment/cargo/list} 的 {@code data.list[]})。 |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public class FbtCargoDto { |
||||
|
||||
/** 货件 ID。 */ |
||||
@JsonProperty("id") |
||||
private Long id; |
||||
|
||||
/** 货件单号。 */ |
||||
@JsonProperty("cargoCode") |
||||
private String cargoCode; |
||||
|
||||
/** 收货仓。 */ |
||||
@JsonProperty("shippingWarehouse") |
||||
private String shippingWarehouse; |
||||
|
||||
@JsonProperty("createTime") |
||||
private String createTime; |
||||
|
||||
@JsonProperty("deliveryTime") |
||||
private String deliveryTime; |
||||
|
||||
@JsonProperty("expectedDeliveryTime") |
||||
private String expectedDeliveryTime; |
||||
|
||||
@JsonProperty("actualDeliveryTime") |
||||
private String actualDeliveryTime; |
||||
|
||||
/** 订单状态原始值。 */ |
||||
@JsonProperty("orderStatus") |
||||
private Integer orderStatus; |
||||
|
||||
@JsonProperty("orderStatusName") |
||||
private String orderStatusName; |
||||
|
||||
/** 发货状态,平台给的是展示文案(如「已发货」)。 */ |
||||
@JsonProperty("shipStatus") |
||||
private String shipStatus; |
||||
|
||||
/** 单店铺 id;跨店铺货件以 {@code storeIds} 为准。 */ |
||||
@JsonProperty("storeId") |
||||
private Long storeId; |
||||
|
||||
@JsonProperty("storeName") |
||||
private String storeName; |
||||
|
||||
@JsonProperty("storeIds") |
||||
private List<Long> storeIds = new ArrayList<Long>(); |
||||
|
||||
@JsonProperty("storeNames") |
||||
private List<String> storeNames = new ArrayList<String>(); |
||||
|
||||
@JsonProperty("orderGoodList") |
||||
private List<FbtCargoGoodDto> orderGoodList = new ArrayList<FbtCargoGoodDto>(); |
||||
|
||||
@JsonProperty("shippingInfo") |
||||
private List<FbtShippingInfoDto> shippingInfo = new ArrayList<FbtShippingInfoDto>(); |
||||
} |
||||
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
package common.ecommerce.lingxing.platform.inbound.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
/** |
||||
* 领星 · FBT 货件商品行。 |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public class FbtCargoGoodDto { |
||||
|
||||
@JsonProperty("id") |
||||
private Long id; |
||||
|
||||
@JsonProperty("goodId") |
||||
private String goodId; |
||||
|
||||
@JsonProperty("productId") |
||||
private String productId; |
||||
|
||||
@JsonProperty("skuId") |
||||
private String skuId; |
||||
|
||||
@JsonProperty("sku") |
||||
private String sku; |
||||
|
||||
@JsonProperty("msku") |
||||
private String msku; |
||||
|
||||
@JsonProperty("productName") |
||||
private String productName; |
||||
|
||||
@JsonProperty("imageUrl") |
||||
private String imageUrl; |
||||
|
||||
/** 申报数量。 */ |
||||
@JsonProperty("declarationQuantity") |
||||
private Integer declarationQuantity; |
||||
|
||||
/** 发货数量。 */ |
||||
@JsonProperty("shipmentQuantity") |
||||
private Integer shipmentQuantity; |
||||
|
||||
/** 签收数量。 */ |
||||
@JsonProperty("signedQuantity") |
||||
private Integer signedQuantity; |
||||
|
||||
/** 合格数量。 */ |
||||
@JsonProperty("normalQuantity") |
||||
private Integer normalQuantity; |
||||
|
||||
/** 次品数量。 */ |
||||
@JsonProperty("defectiveQuantity") |
||||
private Integer defectiveQuantity; |
||||
} |
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
package common.ecommerce.lingxing.platform.inbound.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
/** |
||||
* 领星 · FBT 货件关联的发货单。 |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public class FbtShippingInfoDto { |
||||
|
||||
@JsonProperty("shippingListCode") |
||||
private String shippingListCode; |
||||
|
||||
/** 发货数量,平台给的是字符串。 */ |
||||
@JsonProperty("shippingNum") |
||||
private String shippingNum; |
||||
|
||||
@JsonProperty("shippingStatus") |
||||
private Integer shippingStatus; |
||||
|
||||
@JsonProperty("shippingStatusName") |
||||
private String shippingStatusName; |
||||
|
||||
@JsonProperty("actualDeliveryTime") |
||||
private String actualDeliveryTime; |
||||
|
||||
@JsonProperty("arrivalTime") |
||||
private String arrivalTime; |
||||
} |
||||
@ -0,0 +1,82 @@
@@ -0,0 +1,82 @@
|
||||
package common.ecommerce.lingxing.platform.inbound.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 领星 · WFS 货件({@code /cepf/warehouse/api/openApi/queryWFSCargoPage} |
||||
* 的 {@code data.records[]})。 |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public class WfsCargoDto { |
||||
|
||||
/** WFS 货件 id。 */ |
||||
@JsonProperty("id") |
||||
private String id; |
||||
|
||||
/** 货件单号。 */ |
||||
@JsonProperty("cargo_code") |
||||
private String cargoCode; |
||||
|
||||
/** 入库单号。 */ |
||||
@JsonProperty("in_bound_order_id") |
||||
private String inBoundOrderId; |
||||
|
||||
@JsonProperty("store_id") |
||||
private String storeId; |
||||
|
||||
@JsonProperty("store_name") |
||||
private String storeName; |
||||
|
||||
@JsonProperty("country_name") |
||||
private String countryName; |
||||
|
||||
@JsonProperty("creator") |
||||
private String creator; |
||||
|
||||
/** 平台物流方式编码。 */ |
||||
@JsonProperty("logistics_code") |
||||
private String logisticsCode; |
||||
|
||||
@JsonProperty("cargo_create_date") |
||||
private String cargoCreateDate; |
||||
|
||||
@JsonProperty("update_date") |
||||
private String updateDate; |
||||
|
||||
/** 平台状态(字符串,如 PENDING_SHIPMENT_DETAILS)。 */ |
||||
@JsonProperty("cargo_status") |
||||
private String cargoStatus; |
||||
|
||||
/** 货件同步状态文案(如「已申报」)。 */ |
||||
@JsonProperty("cargo_sync_status") |
||||
private String cargoSyncStatus; |
||||
|
||||
/** 本地状态码:0~4。 */ |
||||
@JsonProperty("status") |
||||
private Integer status; |
||||
|
||||
@JsonProperty("status_name") |
||||
private String statusName; |
||||
|
||||
/** 配送地址,平台已拼接成一段文本。 */ |
||||
@JsonProperty("distribution_addresses") |
||||
private String distributionAddresses; |
||||
|
||||
/** 退货地址,平台已拼接成一段文本。 */ |
||||
@JsonProperty("return_addresses") |
||||
private String returnAddresses; |
||||
|
||||
@JsonProperty("shipping_list_codes") |
||||
private List<String> shippingListCodes = new ArrayList<String>(); |
||||
|
||||
@JsonProperty("cargo_good_list") |
||||
private List<WfsCargoGoodDto> cargoGoodList = new ArrayList<WfsCargoGoodDto>(); |
||||
} |
||||
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
package common.ecommerce.lingxing.platform.inbound.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
/** |
||||
* 领星 · WFS 货件商品行。 |
||||
* |
||||
* <p>数量字段平台给的都是字符串,映射时按整数解析;无法解析按 0 处理。</p> |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public class WfsCargoGoodDto { |
||||
|
||||
@JsonProperty("msku") |
||||
private String msku; |
||||
|
||||
@JsonProperty("sku") |
||||
private String sku; |
||||
|
||||
@JsonProperty("product_name") |
||||
private String productName; |
||||
|
||||
@JsonProperty("gtin") |
||||
private String gtin; |
||||
|
||||
@JsonProperty("declare_num") |
||||
private String declareNum; |
||||
|
||||
@JsonProperty("shipments_num") |
||||
private String shipmentsNum; |
||||
|
||||
@JsonProperty("received_num") |
||||
private String receivedNum; |
||||
|
||||
/** 平台字段名就是 {@code dameged_qty}(拼写错误),按原样接收。 */ |
||||
@JsonProperty("dameged_qty") |
||||
private String damagedQty; |
||||
} |
||||
@ -0,0 +1,128 @@
@@ -0,0 +1,128 @@
|
||||
package common.ecommerce.lingxing.adapter; |
||||
|
||||
import common.ecommerce.error.ChannelException; |
||||
import common.ecommerce.http.JacksonJsonCodec; |
||||
import common.ecommerce.lingxing.LingxingApi; |
||||
import common.ecommerce.lingxing.support.LingxingTestSupport; |
||||
import common.ecommerce.model.Capability; |
||||
import common.ecommerce.model.Platform; |
||||
import common.ecommerce.model.account.ChannelAccount; |
||||
import common.ecommerce.model.inbound.InboundReceipt; |
||||
import common.ecommerce.model.inbound.InboundReceiptQuery; |
||||
import common.ecommerce.model.inbound.InboundShipment; |
||||
import common.ecommerce.model.inbound.InboundShipmentQuery; |
||||
import common.ecommerce.model.support.Page; |
||||
import common.ecommerce.sdk.ChannelConnection; |
||||
import common.ecommerce.sdk.ChannelSdk; |
||||
import common.ecommerce.spi.ChannelSecret; |
||||
import common.ecommerce.testkit.InMemoryAccounts; |
||||
import common.ecommerce.testkit.InMemoryLockProvider; |
||||
import common.ecommerce.testkit.InMemoryTokenStore; |
||||
import common.ecommerce.testkit.JsonFixture; |
||||
import common.ecommerce.testkit.RecordingTransport; |
||||
import common.ecommerce.testkit.Responses; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.time.Instant; |
||||
import java.time.LocalDate; |
||||
|
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.ENDPOINT; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.account; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.assertUrlStartsWith; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.lastUrl; |
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
import static org.junit.jupiter.api.Assertions.assertFalse; |
||||
import static org.junit.jupiter.api.Assertions.assertThrows; |
||||
import static org.junit.jupiter.api.Assertions.assertTrue; |
||||
|
||||
/** 领星入库能力:按子平台收窄 + 门面路由。 */ |
||||
class LingxingInboundCapabilityTest { |
||||
|
||||
private static ChannelConnection connection() { |
||||
return ChannelConnection.of(ENDPOINT, ChannelSecret.builder() |
||||
.appKey(LingxingTestSupport.APP_KEY) |
||||
.appSecret(LingxingTestSupport.APP_SECRET) |
||||
.build()); |
||||
} |
||||
|
||||
private static LingxingAdapter adapter(RecordingTransport transport) { |
||||
return new LingxingAdapter(transport, new JacksonJsonCodec(), |
||||
new InMemoryTokenStore(), new InMemoryLockProvider(), LingxingTestSupport.CLOCK); |
||||
} |
||||
|
||||
private static ChannelSdk sdk(RecordingTransport transport, ChannelAccount account) { |
||||
return ChannelSdk.builder() |
||||
.accountRepository(new InMemoryAccounts().put(account)) |
||||
.clock(LingxingTestSupport.CLOCK) |
||||
.register(adapter(transport)) |
||||
.build(); |
||||
} |
||||
|
||||
@Test |
||||
void capabilitiesFollowSubPlatformWiring() { |
||||
LingxingAdapter adapter = adapter(RecordingTransport.create()); |
||||
|
||||
ChannelAccount amazon = account(Platform.AMAZON_SC, 10001, "123456789"); |
||||
assertTrue(adapter.supports(amazon, Capability.INBOUND_SHIPMENT)); |
||||
assertTrue(adapter.supports(amazon, Capability.INBOUND_RECEIPT)); |
||||
|
||||
ChannelAccount tiktok = account(Platform.TIKTOK, 10011, "134225003201380864"); |
||||
assertTrue(adapter.supports(tiktok, Capability.INBOUND_SHIPMENT)); |
||||
assertFalse(adapter.supports(tiktok, Capability.INBOUND_RECEIPT)); |
||||
|
||||
ChannelAccount walmart = account(Platform.WALMART_SC, 10008, "110000000020008001"); |
||||
assertTrue(adapter.supports(walmart, Capability.INBOUND_SHIPMENT)); |
||||
assertFalse(adapter.supports(walmart, Capability.INBOUND_RECEIPT)); |
||||
|
||||
ChannelAccount ebay = account(Platform.EBAY, 10003, "1"); |
||||
assertFalse(adapter.supports(ebay, Capability.INBOUND_SHIPMENT)); |
||||
assertFalse(adapter.supports(ebay, Capability.INBOUND_RECEIPT)); |
||||
} |
||||
|
||||
@Test |
||||
void facadeRoutesAmazonScShipmentsToAwd() { |
||||
RecordingTransport transport = RecordingTransport.create() |
||||
.route(LingxingApi.INBOUND_SHIPMENT_AWD.path(), r -> Responses.ok( |
||||
JsonFixture.load("fixtures/lingxing/inbound/awdShipment/success.json"))); |
||||
ChannelAccount amazon = account(Platform.AMAZON_SC, 10001, "123456789"); |
||||
|
||||
Page<InboundShipment> page = sdk(transport, amazon).inbounds(amazon.key(), connection()) |
||||
.shipments(InboundShipmentQuery.builder() |
||||
.storeIds("123456789") |
||||
.after(Instant.parse("2026-04-01T00:00:00Z")) |
||||
.before(Instant.parse("2026-04-02T00:00:00Z")) |
||||
.build()); |
||||
|
||||
assertEquals(1, page.size()); |
||||
assertEquals("AWD20230715001", page.items().get(0).shipmentNo()); |
||||
assertUrlStartsWith(lastUrl(transport), ENDPOINT + LingxingApi.INBOUND_SHIPMENT_AWD.path()); |
||||
} |
||||
|
||||
@Test |
||||
void facadeRoutesAmazonScReceiptsToFba() { |
||||
RecordingTransport transport = RecordingTransport.create() |
||||
.route(LingxingApi.INBOUND_RECEIPT_FBA.path(), r -> Responses.ok( |
||||
JsonFixture.load( |
||||
"fixtures/lingxing/inbound/fbaReceivedInventory/success.json"))); |
||||
ChannelAccount amazon = account(Platform.AMAZON_SC, 10001, "101"); |
||||
|
||||
Page<InboundReceipt> page = sdk(transport, amazon).inbounds(amazon.key(), connection()) |
||||
.receipts(InboundReceiptQuery.builder() |
||||
.eventDate(LocalDate.parse("2026-04-01")) |
||||
.build()); |
||||
|
||||
assertEquals(1, page.size()); |
||||
assertEquals("FBA1Y4ZJFZ", page.items().get(0).shipmentId()); |
||||
assertUrlStartsWith(lastUrl(transport), ENDPOINT + LingxingApi.INBOUND_RECEIPT_FBA.path()); |
||||
} |
||||
|
||||
@Test |
||||
void ebayRejectsInboundShipmentsExplicitly() { |
||||
RecordingTransport transport = RecordingTransport.create(); |
||||
ChannelAccount ebay = account(Platform.EBAY, 10003, "1"); |
||||
|
||||
assertThrows(ChannelException.UnsupportedCapabilityException.class, |
||||
() -> sdk(transport, ebay).inbounds(ebay.key(), connection()) |
||||
.shipments(InboundShipmentQuery.builder().storeIds("1").build())); |
||||
} |
||||
} |
||||
@ -0,0 +1,118 @@
@@ -0,0 +1,118 @@
|
||||
package common.ecommerce.lingxing.platform.inbound; |
||||
|
||||
import common.ecommerce.error.ValidationException; |
||||
import common.ecommerce.lingxing.LingxingApi; |
||||
import common.ecommerce.model.Platform; |
||||
import common.ecommerce.model.inbound.InboundShipment; |
||||
import common.ecommerce.model.inbound.InboundShipmentQuery; |
||||
import common.ecommerce.model.inbound.InboundShipmentTimeType; |
||||
import common.ecommerce.model.support.Page; |
||||
import common.ecommerce.testkit.JsonFixture; |
||||
import common.ecommerce.testkit.RecordingTransport; |
||||
import common.ecommerce.testkit.Responses; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.time.Instant; |
||||
|
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.ENDPOINT; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.account; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.assertBodyContains; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.assertUrlStartsWith; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.call; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.lastBody; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.lastUrl; |
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
import static org.junit.jupiter.api.Assertions.assertNotNull; |
||||
import static org.junit.jupiter.api.Assertions.assertNull; |
||||
import static org.junit.jupiter.api.Assertions.assertThrows; |
||||
|
||||
/** 领星 AWD 入库货件列表:请求构造 + 响应映射 + 不支持的维度。 */ |
||||
class AwdCargoSourceTest { |
||||
|
||||
private final RecordingTransport transport = RecordingTransport.create() |
||||
.route(LingxingApi.INBOUND_SHIPMENT_AWD.path(), |
||||
r -> Responses.ok(JsonFixture.load("fixtures/lingxing/inbound/awdShipment/success.json"))); |
||||
|
||||
private static InboundShipmentQuery.Builder baseQuery() { |
||||
return InboundShipmentQuery.builder() |
||||
.storeIds("123456789") |
||||
.after(Instant.parse("2026-04-01T00:00:00Z")) |
||||
.before(Instant.parse("2026-04-02T00:00:00Z")); |
||||
} |
||||
|
||||
@Test |
||||
void requestCarriesPageAndIsoTimeWindow() { |
||||
new AwdCargoSource().shipments( |
||||
call(transport, account(Platform.AMAZON_SC, 10001, "123456789")), |
||||
baseQuery() |
||||
.timeType(InboundShipmentTimeType.UPDATED) |
||||
.shipmentNo("AWD20230715001") |
||||
.statuses("SHIPPED", "IN_TRANSIT") |
||||
.pageSize(50) |
||||
.cursor("2") |
||||
.build()); |
||||
|
||||
assertUrlStartsWith(lastUrl(transport), ENDPOINT + LingxingApi.INBOUND_SHIPMENT_AWD.path()); |
||||
String body = lastBody(transport); |
||||
assertBodyContains(body, "\"page\":2"); |
||||
assertBodyContains(body, "\"length\":50"); |
||||
assertBodyContains(body, "\"dateType\":2"); |
||||
assertBodyContains(body, "\"sidList\":[123456789]"); |
||||
assertBodyContains(body, "\"startDateTime\":\"2026-04-01T00:00:00Z\""); |
||||
assertBodyContains(body, "\"endDateTime\":\"2026-04-02T00:00:00Z\""); |
||||
assertBodyContains(body, "\"shipmentId\":\"AWD20230715001\""); |
||||
assertBodyContains(body, "\"statusList\":[\"SHIPPED\",\"IN_TRANSIT\"]"); |
||||
} |
||||
|
||||
@Test |
||||
void mapsShipmentWithAddressesAndLines() { |
||||
Page<InboundShipment> page = new AwdCargoSource().shipments( |
||||
call(transport, account(Platform.AMAZON_SC, 10001, "123456789")), |
||||
baseQuery().build()); |
||||
|
||||
assertEquals(1, page.size()); |
||||
assertNull(page.nextCursor()); |
||||
|
||||
InboundShipment shipment = page.items().get(0); |
||||
assertEquals("AWD20230715001", shipment.shipmentNo()); |
||||
assertEquals("STOCK001", shipment.stockOrderNo()); |
||||
assertEquals("PHX5", shipment.warehouseReferenceId()); |
||||
assertEquals("SHIPPED", shipment.status()); |
||||
assertEquals("UPS", shipment.carrierCode()); |
||||
assertEquals("1Z1234567890123456", shipment.trackingNo()); |
||||
assertEquals("123456789", shipment.storeId()); |
||||
assertEquals("易碎品", shipment.remark()); |
||||
assertEquals("456 Distribution Ave, Building 3, Phoenix, AZ, 85001, US", |
||||
shipment.destinationAddress()); |
||||
assertEquals("Example Shipper, 123 Main St, Suite 100, Seattle, WA, 98101, US", |
||||
shipment.returnAddress()); |
||||
assertNotNull(shipment.createdAt()); |
||||
assertNotNull(shipment.updatedAt()); |
||||
assertNotNull(shipment.shippedAt()); |
||||
|
||||
assertEquals(1, shipment.lines().size()); |
||||
assertEquals("B0ABCD1234", shipment.lines().get(0).asin()); |
||||
assertEquals("B0PARENT12", shipment.lines().get(0).parentAsin()); |
||||
assertEquals("X000123ABC", shipment.lines().get(0).fnsku()); |
||||
assertEquals(18, shipment.lines().get(0).receivedQuantity()); |
||||
assertEquals(5, shipment.lines().get(0).boxQuantity()); |
||||
assertEquals(Integer.valueOf(20), shipment.lines().get(0).quantityInBox()); |
||||
assertEquals("AMAZON", shipment.lines().get(0).labelOwner()); |
||||
assertEquals(Double.valueOf(15.75), shipment.lines().get(0).length()); |
||||
assertEquals("INCHES", shipment.lines().get(0).lengthUnit()); |
||||
} |
||||
|
||||
@Test |
||||
void completedTimeTypeIsRejected() { |
||||
assertThrows(ValidationException.class, () -> new AwdCargoSource().shipments( |
||||
call(transport, account(Platform.AMAZON_SC, 10001, "123456789")), |
||||
baseQuery().timeType(InboundShipmentTimeType.COMPLETED).build())); |
||||
} |
||||
|
||||
@Test |
||||
void inboundOrderNoIsRejected() { |
||||
assertThrows(ValidationException.class, () -> new AwdCargoSource().shipments( |
||||
call(transport, account(Platform.AMAZON_SC, 10001, "123456789")), |
||||
baseQuery().inboundOrderNo("IN-1").build())); |
||||
} |
||||
} |
||||
@ -0,0 +1,108 @@
@@ -0,0 +1,108 @@
|
||||
package common.ecommerce.lingxing.platform.inbound; |
||||
|
||||
import common.ecommerce.error.ValidationException; |
||||
import common.ecommerce.lingxing.LingxingApi; |
||||
import common.ecommerce.model.Platform; |
||||
import common.ecommerce.model.inbound.InboundReceipt; |
||||
import common.ecommerce.model.inbound.InboundReceiptQuery; |
||||
import common.ecommerce.model.support.Page; |
||||
import common.ecommerce.testkit.JsonFixture; |
||||
import common.ecommerce.testkit.RecordingTransport; |
||||
import common.ecommerce.testkit.Responses; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.time.Instant; |
||||
import java.time.LocalDate; |
||||
|
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.ENDPOINT; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.account; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.assertBodyContains; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.assertBodyNotContains; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.assertUrlStartsWith; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.call; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.lastBody; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.lastUrl; |
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
import static org.junit.jupiter.api.Assertions.assertNotNull; |
||||
import static org.junit.jupiter.api.Assertions.assertNull; |
||||
import static org.junit.jupiter.api.Assertions.assertThrows; |
||||
|
||||
/** 领星 FBA 到货接收明细:请求构造 + 响应映射 + 必填校验。 */ |
||||
class FbaReceivedInventorySourceTest { |
||||
|
||||
private final RecordingTransport transport = RecordingTransport.create() |
||||
.route(LingxingApi.INBOUND_RECEIPT_FBA.path(), |
||||
r -> Responses.ok(JsonFixture.load( |
||||
"fixtures/lingxing/inbound/fbaReceivedInventory/success.json"))); |
||||
|
||||
@Test |
||||
void requestCarriesEventDateAndShipmentIds() { |
||||
new FbaReceivedInventorySource().receipts( |
||||
call(transport, account(Platform.AMAZON_SC, 10001, "101")), |
||||
InboundReceiptQuery.builder() |
||||
.eventDate(LocalDate.parse("2026-04-01")) |
||||
.shipmentIds("FBA1Y4ZJFZ") |
||||
.pageSize(500) |
||||
.build()); |
||||
|
||||
assertUrlStartsWith(lastUrl(transport), ENDPOINT + LingxingApi.INBOUND_RECEIPT_FBA.path()); |
||||
String body = lastBody(transport); |
||||
assertBodyContains(body, "\"sid\":101"); |
||||
assertBodyContains(body, "\"offset\":0"); |
||||
assertBodyContains(body, "\"length\":500"); |
||||
assertBodyContains(body, "\"event_date\":\"2026-04-01\""); |
||||
assertBodyContains(body, "\"fba_shipment_id\":[\"FBA1Y4ZJFZ\"]"); |
||||
} |
||||
|
||||
@Test |
||||
void shipmentIdOnlyQueryOmitsEventDate() { |
||||
new FbaReceivedInventorySource().receipts( |
||||
call(transport, account(Platform.AMAZON_SC, 10001, "101")), |
||||
InboundReceiptQuery.builder() |
||||
.shipmentIds("FBA1Y4ZJFZ") |
||||
.build()); |
||||
|
||||
String body = lastBody(transport); |
||||
assertBodyNotContains(body, "event_date"); |
||||
assertBodyContains(body, "\"fba_shipment_id\":[\"FBA1Y4ZJFZ\"]"); |
||||
} |
||||
|
||||
@Test |
||||
void mapsReceiptRow() { |
||||
Page<InboundReceipt> page = new FbaReceivedInventorySource().receipts( |
||||
call(transport, account(Platform.AMAZON_SC, 10001, "101")), |
||||
InboundReceiptQuery.builder() |
||||
.eventDate(LocalDate.parse("2026-04-01")) |
||||
.build()); |
||||
|
||||
assertEquals(1, page.size()); |
||||
assertNull(page.nextCursor()); |
||||
|
||||
InboundReceipt receipt = page.items().get(0); |
||||
assertEquals(Integer.valueOf(101), receipt.sid()); |
||||
assertEquals("FBA1Y4ZJFZ", receipt.shipmentId()); |
||||
assertEquals("X000123ABC", receipt.fnsku()); |
||||
assertEquals("MSKU-1", receipt.sku()); |
||||
assertEquals(-5, receipt.quantity()); |
||||
assertEquals("BHX4", receipt.fulfillmentCenterId()); |
||||
assertEquals("2026-04-01", receipt.receivedDateReport()); |
||||
assertEquals(Integer.valueOf(3), receipt.uniqueIndex()); |
||||
assertEquals("ad971e653ad89e2c94a939df63b8c884", receipt.uniqueMd5()); |
||||
assertNotNull(receipt.receivedAt()); |
||||
assertEquals(Instant.parse("2026-04-01T00:00:00Z"), receipt.receivedAt().utc()); |
||||
} |
||||
|
||||
@Test |
||||
void queryRequiresEventDateOrShipmentIds() { |
||||
assertThrows(IllegalArgumentException.class, () -> InboundReceiptQuery.builder().build()); |
||||
} |
||||
|
||||
@Test |
||||
void nonNumericSidIsRejected() { |
||||
assertThrows(ValidationException.class, () -> new FbaReceivedInventorySource().receipts( |
||||
call(transport, account(Platform.AMAZON_SC, 10001, "not-a-sid")), |
||||
InboundReceiptQuery.builder() |
||||
.eventDate(LocalDate.parse("2026-04-01")) |
||||
.build())); |
||||
} |
||||
} |
||||
@ -0,0 +1,113 @@
@@ -0,0 +1,113 @@
|
||||
package common.ecommerce.lingxing.platform.inbound; |
||||
|
||||
import common.ecommerce.error.ValidationException; |
||||
import common.ecommerce.lingxing.LingxingApi; |
||||
import common.ecommerce.model.Platform; |
||||
import common.ecommerce.model.inbound.InboundShipment; |
||||
import common.ecommerce.model.inbound.InboundShipmentQuery; |
||||
import common.ecommerce.model.inbound.InboundShipmentTimeType; |
||||
import common.ecommerce.model.support.Page; |
||||
import common.ecommerce.testkit.JsonFixture; |
||||
import common.ecommerce.testkit.RecordingTransport; |
||||
import common.ecommerce.testkit.Responses; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.time.Instant; |
||||
|
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.ENDPOINT; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.account; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.assertBodyContains; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.assertUrlStartsWith; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.call; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.lastBody; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.lastUrl; |
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
import static org.junit.jupiter.api.Assertions.assertNotNull; |
||||
import static org.junit.jupiter.api.Assertions.assertNull; |
||||
import static org.junit.jupiter.api.Assertions.assertThrows; |
||||
|
||||
/** 领星 FBT 货件列表:请求构造 + 响应映射 + 不支持的维度。 */ |
||||
class FbtCargoSourceTest { |
||||
|
||||
private final RecordingTransport transport = RecordingTransport.create() |
||||
.route(LingxingApi.INBOUND_SHIPMENT_FBT.path(), |
||||
r -> Responses.ok(JsonFixture.load("fixtures/lingxing/inbound/fbtCargo/success.json"))); |
||||
|
||||
private static InboundShipmentQuery.Builder baseQuery() { |
||||
return InboundShipmentQuery.builder() |
||||
.storeIds("134225003201380864") |
||||
.after(Instant.parse("2026-04-01T00:00:00Z")) |
||||
.before(Instant.parse("2026-04-02T00:00:00Z")); |
||||
} |
||||
|
||||
@Test |
||||
void requestCarriesTimeWindowStoreAndCargoFilter() { |
||||
new FbtCargoSource().shipments( |
||||
call(transport, account(Platform.TIKTOK, 10011, "134225003201380864")), |
||||
baseQuery() |
||||
.timeType(InboundShipmentTimeType.COMPLETED) |
||||
.statuses("1") |
||||
.shipmentNo("CARGO001") |
||||
.pageSize(100) |
||||
.build()); |
||||
|
||||
assertUrlStartsWith(lastUrl(transport), ENDPOINT + LingxingApi.INBOUND_SHIPMENT_FBT.path()); |
||||
String body = lastBody(transport); |
||||
assertBodyContains(body, "\"offset\":0"); |
||||
assertBodyContains(body, "\"length\":100"); |
||||
assertBodyContains(body, "\"storeIdList\":[134225003201380864]"); |
||||
assertBodyContains(body, "\"timeType\":1"); |
||||
assertBodyContains(body, "\"startTime\":\"2026-04-01\""); |
||||
assertBodyContains(body, "\"endTime\":\"2026-04-02\""); |
||||
assertBodyContains(body, "\"queryType\":3"); |
||||
assertBodyContains(body, "\"queryValue\":[\"CARGO001\"]"); |
||||
assertBodyContains(body, "\"cargoStatusList\":[1]"); |
||||
} |
||||
|
||||
@Test |
||||
void mapsCargoIntoShipmentWithLinesAndShippingRefs() { |
||||
Page<InboundShipment> page = new FbtCargoSource().shipments( |
||||
call(transport, account(Platform.TIKTOK, 10011, "134225003201380864")), |
||||
baseQuery().build()); |
||||
|
||||
assertEquals(1, page.size()); |
||||
assertNull(page.nextCursor()); |
||||
|
||||
InboundShipment shipment = page.items().get(0); |
||||
assertEquals("CARGO001", shipment.shipmentNo()); |
||||
assertEquals("1234567890", shipment.shipmentId()); |
||||
assertEquals("1", shipment.status()); |
||||
assertEquals("已完成", shipment.statusName()); |
||||
assertEquals("已发货", shipment.shipStatus()); |
||||
assertEquals("134225003201380864", shipment.storeId()); |
||||
assertEquals(2, shipment.storeIds().size()); |
||||
assertEquals("仓库A", shipment.warehouseName()); |
||||
assertNotNull(shipment.createdAt()); |
||||
assertNotNull(shipment.actualArrivalAt()); |
||||
|
||||
assertEquals(1, shipment.lines().size()); |
||||
assertEquals(100, shipment.lines().get(0).declaredQuantity()); |
||||
assertEquals(99, shipment.lines().get(0).shippedQuantity()); |
||||
assertEquals(98, shipment.lines().get(0).receivedQuantity()); |
||||
assertEquals(95, shipment.lines().get(0).normalQuantity()); |
||||
assertEquals(3, shipment.lines().get(0).defectiveQuantity()); |
||||
|
||||
assertEquals(1, shipment.shippingRefs().size()); |
||||
assertEquals("SHP001", shipment.shippingRefs().get(0).shippingListCode()); |
||||
assertEquals(100, shipment.shippingRefs().get(0).quantity()); |
||||
} |
||||
|
||||
@Test |
||||
void updatedTimeTypeIsRejected() { |
||||
assertThrows(ValidationException.class, () -> new FbtCargoSource().shipments( |
||||
call(transport, account(Platform.TIKTOK, 10011, "134225003201380864")), |
||||
baseQuery().timeType(InboundShipmentTimeType.UPDATED).build())); |
||||
} |
||||
|
||||
@Test |
||||
void inboundOrderNoIsRejected() { |
||||
assertThrows(ValidationException.class, () -> new FbtCargoSource().shipments( |
||||
call(transport, account(Platform.TIKTOK, 10011, "134225003201380864")), |
||||
baseQuery().inboundOrderNo("IN-1").build())); |
||||
} |
||||
} |
||||
@ -0,0 +1,122 @@
@@ -0,0 +1,122 @@
|
||||
package common.ecommerce.lingxing.platform.inbound; |
||||
|
||||
import common.ecommerce.error.ValidationException; |
||||
import common.ecommerce.lingxing.LingxingApi; |
||||
import common.ecommerce.model.Platform; |
||||
import common.ecommerce.model.inbound.InboundShipment; |
||||
import common.ecommerce.model.inbound.InboundShipmentQuery; |
||||
import common.ecommerce.model.inbound.InboundShipmentTimeType; |
||||
import common.ecommerce.model.support.Page; |
||||
import common.ecommerce.testkit.JsonFixture; |
||||
import common.ecommerce.testkit.RecordingTransport; |
||||
import common.ecommerce.testkit.Responses; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.time.Instant; |
||||
|
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.ENDPOINT; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.account; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.assertBodyContains; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.assertBodyNotContains; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.assertUrlStartsWith; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.call; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.lastBody; |
||||
import static common.ecommerce.lingxing.support.LingxingTestSupport.lastUrl; |
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
import static org.junit.jupiter.api.Assertions.assertNotNull; |
||||
import static org.junit.jupiter.api.Assertions.assertNull; |
||||
import static org.junit.jupiter.api.Assertions.assertThrows; |
||||
|
||||
/** 领星 WFS 货件列表:请求构造 + 响应映射 + 不支持的维度。 */ |
||||
class WfsCargoSourceTest { |
||||
|
||||
private final RecordingTransport transport = RecordingTransport.create() |
||||
.route(LingxingApi.INBOUND_SHIPMENT_WFS.path(), |
||||
r -> Responses.ok(JsonFixture.load("fixtures/lingxing/inbound/wfsCargo/success.json"))); |
||||
|
||||
private static InboundShipmentQuery.Builder baseQuery() { |
||||
return InboundShipmentQuery.builder() |
||||
.storeIds("110000000020008001") |
||||
.after(Instant.parse("2026-04-01T00:00:00Z")) |
||||
.before(Instant.parse("2026-04-02T00:00:00Z")); |
||||
} |
||||
|
||||
@Test |
||||
void createdTimeUsesDateRange() { |
||||
new WfsCargoSource().shipments( |
||||
call(transport, account(Platform.WALMART_SC, 10008, "110000000020008001")), |
||||
baseQuery() |
||||
.statuses("0") |
||||
.inboundOrderNo("lry-inbound-31") |
||||
.pageSize(50) |
||||
.build()); |
||||
|
||||
assertUrlStartsWith(lastUrl(transport), ENDPOINT + LingxingApi.INBOUND_SHIPMENT_WFS.path()); |
||||
String body = lastBody(transport); |
||||
assertBodyContains(body, "\"offset\":0"); |
||||
assertBodyContains(body, "\"length\":50"); |
||||
assertBodyContains(body, "\"store_id\":[\"110000000020008001\"]"); |
||||
assertBodyContains(body, "\"start_time\":\"2026-04-01\""); |
||||
assertBodyContains(body, "\"end_time\":\"2026-04-02\""); |
||||
assertBodyContains(body, "\"inbound_order_id\":\"lry-inbound-31\""); |
||||
assertBodyContains(body, "\"cargo_status_list\":[0]"); |
||||
assertBodyNotContains(body, "update_time_ge"); |
||||
} |
||||
|
||||
@Test |
||||
void updatedTimeUsesDateTimeRange() { |
||||
new WfsCargoSource().shipments( |
||||
call(transport, account(Platform.WALMART_SC, 10008, "110000000020008001")), |
||||
baseQuery().timeType(InboundShipmentTimeType.UPDATED).build()); |
||||
|
||||
String body = lastBody(transport); |
||||
assertBodyContains(body, "\"update_time_ge\":\"2026-04-01 08:00:00\""); |
||||
assertBodyContains(body, "\"update_time_le\":\"2026-04-02 08:00:00\""); |
||||
assertBodyNotContains(body, "start_time"); |
||||
} |
||||
|
||||
@Test |
||||
void mapsCargoIntoShipment() { |
||||
Page<InboundShipment> page = new WfsCargoSource().shipments( |
||||
call(transport, account(Platform.WALMART_SC, 10008, "110000000020008001")), |
||||
baseQuery().build()); |
||||
|
||||
assertEquals(1, page.size()); |
||||
assertNull(page.nextCursor()); |
||||
|
||||
InboundShipment shipment = page.items().get(0); |
||||
assertEquals("lry-shipment-31", shipment.shipmentNo()); |
||||
assertEquals("lry-inbound-31", shipment.inboundOrderNo()); |
||||
assertEquals("PENDING_SHIPMENT_DETAILS", shipment.status()); |
||||
assertEquals("等待发货明细", shipment.statusName()); |
||||
assertEquals("已申报", shipment.localStatus()); |
||||
assertEquals("LRY03", shipment.carrierCode()); |
||||
assertEquals("沃尔玛测试店", shipment.storeName()); |
||||
assertEquals("美国", shipment.countryName()); |
||||
assertNotNull(shipment.createdAt()); |
||||
assertNotNull(shipment.updatedAt()); |
||||
|
||||
assertEquals(1, shipment.lines().size()); |
||||
assertEquals(10, shipment.lines().get(0).declaredQuantity()); |
||||
assertEquals(8, shipment.lines().get(0).shippedQuantity()); |
||||
assertEquals(7, shipment.lines().get(0).receivedQuantity()); |
||||
assertEquals(1, shipment.lines().get(0).defectiveQuantity()); |
||||
assertEquals("006344827368521", shipment.lines().get(0).gtin()); |
||||
|
||||
assertEquals(2, shipment.shippingRefs().size()); |
||||
} |
||||
|
||||
@Test |
||||
void shipmentNoIsRejected() { |
||||
assertThrows(ValidationException.class, () -> new WfsCargoSource().shipments( |
||||
call(transport, account(Platform.WALMART_SC, 10008, "110000000020008001")), |
||||
baseQuery().shipmentNo("lry-shipment-31").build())); |
||||
} |
||||
|
||||
@Test |
||||
void completedTimeTypeIsRejected() { |
||||
assertThrows(ValidationException.class, () -> new WfsCargoSource().shipments( |
||||
call(transport, account(Platform.WALMART_SC, 10008, "110000000020008001")), |
||||
baseQuery().timeType(InboundShipmentTimeType.COMPLETED).build())); |
||||
} |
||||
} |
||||
@ -0,0 +1,73 @@
@@ -0,0 +1,73 @@
|
||||
{ |
||||
"code": 0, |
||||
"message": "Success", |
||||
"error_details": [], |
||||
"request_id": "c3d4e5f6-g7h8-i9j0-k1l2-m3n4o5p6q7r8", |
||||
"response_time": "2026-04-23T12:00:00Z", |
||||
"data": { |
||||
"current": 1, |
||||
"pages": 1, |
||||
"size": 10, |
||||
"total": 1, |
||||
"records": [ |
||||
{ |
||||
"orderId": "AWD20230715001", |
||||
"stockOrderId": "STOCK001", |
||||
"warehouseReferenceId": "PHX5", |
||||
"status": "SHIPPED", |
||||
"gmtCreate": "2026-04-01T10:00:00Z", |
||||
"gmtModified": "2026-04-02T14:30:00Z", |
||||
"shipBy": "2026-04-03", |
||||
"trackingId": "1Z1234567890123456", |
||||
"carrierCode": "UPS", |
||||
"sid": 123456789, |
||||
"remark": "易碎品", |
||||
"createByName": "API User", |
||||
"awdDeliveredGoodsBO": { |
||||
"destinationAddressLine1": "456 Distribution Ave", |
||||
"destinationAddressLine2": "Building 3", |
||||
"destinationCity": "Phoenix", |
||||
"destinationStateOrRegion": "AZ", |
||||
"destinationPostalCode": "85001", |
||||
"destinationCountryCode": "US" |
||||
}, |
||||
"awdShippingAddressBO": { |
||||
"addressLine1": "123 Main St", |
||||
"addressLine2": "Suite 100", |
||||
"city": "Seattle", |
||||
"stateOrProvinceCode": "WA", |
||||
"postalCode": "98101", |
||||
"countryCode": "US", |
||||
"shipperName": "Example Shipper", |
||||
"phoneNumber": "1234567890", |
||||
"zone": "Downtown" |
||||
}, |
||||
"awdDeliveredGoodsItemBOS": [ |
||||
{ |
||||
"asin": "B0ABCD1234", |
||||
"parentAsin": "B0PARENT12", |
||||
"fnsku": "X000123ABC", |
||||
"msku": "ABC123", |
||||
"sku": "SKU12345", |
||||
"productName": "示例商品", |
||||
"title": "示例商品标题", |
||||
"url": "https://example.com/product.jpg", |
||||
"receivedQuantity": 18, |
||||
"boxQuantity": "5", |
||||
"quantityInBox": "20", |
||||
"prepCategory": "NONE", |
||||
"prepOwner": "SELF", |
||||
"labelOwner": "AMAZON", |
||||
"length": 15.75, |
||||
"width": 8.25, |
||||
"height": 10.5, |
||||
"lengthUnit": "INCHES", |
||||
"weight": 12.3, |
||||
"weightUnit": "POUNDS", |
||||
"expiration": "2027-12-31" |
||||
} |
||||
] |
||||
} |
||||
] |
||||
} |
||||
} |
||||
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
{ |
||||
"code": 0, |
||||
"message": "success", |
||||
"error_details": "", |
||||
"request_id": "C3D9F541-8083-E376-EB5C-606A872F5C89", |
||||
"response_time": "2026-04-23 12:00:00", |
||||
"data": [ |
||||
{ |
||||
"sid": 101, |
||||
"received_date": "2026-04-01T00:00:00+00:00", |
||||
"received_date_locale": "2026-04-01T01:00:00+01:00", |
||||
"received_date_timestamp": 1743465600, |
||||
"fnsku": "X000123ABC", |
||||
"sku": "MSKU-1", |
||||
"product_name": "Product 1", |
||||
"quantity": -5, |
||||
"fba_shipment_id": "FBA1Y4ZJFZ", |
||||
"fulfillment_center_id": "BHX4", |
||||
"unique_index": 3, |
||||
"unique_md5": "ad971e653ad89e2c94a939df63b8c884", |
||||
"received_date_report": "2026-04-01" |
||||
} |
||||
], |
||||
"total": 1 |
||||
} |
||||
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
{ |
||||
"code": 0, |
||||
"message": "success", |
||||
"error_details": [], |
||||
"request_id": "a0d54debf93140f3b58d1ed81e8e3583", |
||||
"response_time": "2026-04-23 12:00:00", |
||||
"data": { |
||||
"list": [ |
||||
{ |
||||
"id": 1234567890, |
||||
"cargoCode": "CARGO001", |
||||
"shippingWarehouse": "仓库A", |
||||
"createTime": "2026-04-01 12:00:00", |
||||
"deliveryTime": "2026-04-02 12:00:00", |
||||
"expectedDeliveryTime": "2026-04-05 12:00:00", |
||||
"actualDeliveryTime": "2026-04-04 12:00:00", |
||||
"orderStatus": 1, |
||||
"orderStatusName": "已完成", |
||||
"shipStatus": "已发货", |
||||
"storeId": 134225003201380864, |
||||
"storeName": "示例店铺A", |
||||
"storeIds": [134225003201380864, 134225003201380865], |
||||
"storeNames": ["示例店铺A", "示例店铺B"], |
||||
"orderGoodList": [ |
||||
{ |
||||
"id": 9876543210, |
||||
"goodId": "GOOD001", |
||||
"productId": "PROD001", |
||||
"skuId": "SKUID001", |
||||
"sku": "SKU001", |
||||
"msku": "MSKU001", |
||||
"productName": "示例商品", |
||||
"imageUrl": "https://example.com/image.jpg", |
||||
"declarationQuantity": 100, |
||||
"shipmentQuantity": 99, |
||||
"signedQuantity": 98, |
||||
"normalQuantity": 95, |
||||
"defectiveQuantity": 3 |
||||
} |
||||
], |
||||
"shippingInfo": [ |
||||
{ |
||||
"shippingListCode": "SHP001", |
||||
"shippingNum": "100", |
||||
"shippingStatus": 1, |
||||
"shippingStatusName": "已发货", |
||||
"actualDeliveryTime": "2026-04-02 12:00:00", |
||||
"arrivalTime": "2026-04-04 12:00:00" |
||||
} |
||||
] |
||||
} |
||||
], |
||||
"offset": 0, |
||||
"length": 20, |
||||
"pages": 1 |
||||
}, |
||||
"total": 1 |
||||
} |
||||
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
{ |
||||
"code": 0, |
||||
"message": "success", |
||||
"error_details": [], |
||||
"request_id": "c4db3691436d4acbbda0f8b1dc53fe97", |
||||
"response_time": "2026-04-23 12:00:00", |
||||
"data": { |
||||
"total": "1", |
||||
"records": [ |
||||
{ |
||||
"id": "200498", |
||||
"cargo_code": "lry-shipment-31", |
||||
"in_bound_order_id": "lry-inbound-31", |
||||
"store_id": "110000000020008001", |
||||
"store_name": "沃尔玛测试店", |
||||
"country_name": "美国", |
||||
"creator": "张三", |
||||
"logistics_code": "LRY03", |
||||
"cargo_create_date": "2026-04-01 12:00:00", |
||||
"update_date": "2026-04-02 13:00:00", |
||||
"cargo_status": "PENDING_SHIPMENT_DETAILS", |
||||
"cargo_sync_status": "已申报", |
||||
"status": 0, |
||||
"status_name": "等待发货明细", |
||||
"distribution_addresses": "3 Sorbello Way,Pedricktown1,NJ9,美国,US,08067", |
||||
"return_addresses": "860 W California Ave,Sunnyvale,94086,美国,CA", |
||||
"shipping_list_codes": ["SP202307270010196", "SP202307270010197"], |
||||
"cargo_good_list": [ |
||||
{ |
||||
"msku": "test1_sku1", |
||||
"sku": "ueeshop1111", |
||||
"product_name": "测试商品", |
||||
"gtin": "006344827368521", |
||||
"shipments_num": "8", |
||||
"received_num": "7", |
||||
"declare_num": "10", |
||||
"dameged_qty": "1" |
||||
} |
||||
] |
||||
} |
||||
] |
||||
} |
||||
} |
||||
Loading…
Reference in new issue