diff --git a/core/src/main/java/common/ecommerce/capability/OutboundCapable.java b/core/src/main/java/common/ecommerce/capability/OutboundCapable.java
new file mode 100644
index 0000000..d122df5
--- /dev/null
+++ b/core/src/main/java/common/ecommerce/capability/OutboundCapable.java
@@ -0,0 +1,25 @@
+package common.ecommerce.capability;
+
+import common.ecommerce.model.fulfillment.OutboundPackage;
+import common.ecommerce.model.fulfillment.OutboundResult;
+import common.ecommerce.sdk.ChannelContext;
+
+import java.util.List;
+
+/**
+ * 快速出库能力:提交出库任务 + 查询任务结果。
+ *
+ *
出库是异步的:{@link #submit} 只表示任务已受理,真正的成功/失败
+ * 要用 {@link #results} 按系统单号回查。
+ *
+ * 写操作,必须经 {@code IdempotencyGuard} 执行;幂等键按系统单号,
+ * 与领星「一个订单只能出库一次」的约束一致。
+ */
+public interface OutboundCapable extends PlatformAdapter {
+
+ /** 提交出库任务;返回是否受理。 */
+ boolean submit(ChannelContext ctx, List packages);
+
+ /** 按系统单号查询出库结果。 */
+ OutboundResult results(ChannelContext ctx, List globalOrderNos);
+}
diff --git a/core/src/main/java/common/ecommerce/capability/Outbounds.java b/core/src/main/java/common/ecommerce/capability/Outbounds.java
new file mode 100644
index 0000000..4267a7c
--- /dev/null
+++ b/core/src/main/java/common/ecommerce/capability/Outbounds.java
@@ -0,0 +1,42 @@
+package common.ecommerce.capability;
+
+import common.ecommerce.error.ChannelException;
+import common.ecommerce.model.Capability;
+import common.ecommerce.model.account.ChannelAccount;
+import common.ecommerce.model.fulfillment.OutboundPackage;
+import common.ecommerce.model.fulfillment.OutboundResult;
+import common.ecommerce.sdk.ChannelContext;
+
+import java.util.List;
+
+/**
+ * 门面持有的出库视图。调用前做能力检查,缺失时显式拒绝。
+ */
+public final class Outbounds {
+
+ private final PlatformAdapter adapter;
+ private final ChannelAccount account;
+ private final ChannelContext ctx;
+
+ public Outbounds(PlatformAdapter adapter, ChannelAccount account, ChannelContext ctx) {
+ this.adapter = adapter;
+ this.account = account;
+ this.ctx = ctx;
+ }
+
+ public boolean submit(List packages) {
+ requireOutboundCapable();
+ return ((OutboundCapable) adapter).submit(ctx, packages);
+ }
+
+ public OutboundResult results(List globalOrderNos) {
+ requireOutboundCapable();
+ return ((OutboundCapable) adapter).results(ctx, globalOrderNos);
+ }
+
+ private void requireOutboundCapable() {
+ if (!adapter.supports(account, Capability.MARK_SHIPPED) || !(adapter instanceof OutboundCapable)) {
+ throw new ChannelException.UnsupportedCapabilityException(Capability.MARK_SHIPPED);
+ }
+ }
+}
diff --git a/core/src/main/java/common/ecommerce/model/fulfillment/OutboundPackage.java b/core/src/main/java/common/ecommerce/model/fulfillment/OutboundPackage.java
new file mode 100644
index 0000000..90231c8
--- /dev/null
+++ b/core/src/main/java/common/ecommerce/model/fulfillment/OutboundPackage.java
@@ -0,0 +1,101 @@
+package common.ecommerce.model.fulfillment;
+
+import java.util.Objects;
+
+/**
+ * 一次快速出库请求中的单个包裹。
+ *
+ * 字段以领星「快速出库」接口为准;各平台接入时由各自 Source 翻译。
+ * {@code globalOrderNo} 是平台系统单号(领星侧 {@code global_order_no}),
+ * 也是出库结果的查询键。
+ */
+public final class OutboundPackage {
+
+ private final String globalOrderNo;
+ private final Long warehouseId;
+ private final String logisticsTypeId;
+ private final String waybillNo;
+ private final String trackingNo;
+ private final String weightUnit;
+ private final String realWeight;
+ private final String sizeUnit;
+ private final String length;
+ private final String width;
+ private final String height;
+ private final String feeWeight;
+ private final String logisticsFreight;
+ private final String logisticsFreightCurrency;
+
+ private OutboundPackage(Builder b) {
+ this.globalOrderNo = Objects.requireNonNull(b.globalOrderNo, "globalOrderNo");
+ this.warehouseId = b.warehouseId;
+ this.logisticsTypeId = b.logisticsTypeId;
+ this.waybillNo = b.waybillNo;
+ this.trackingNo = b.trackingNo;
+ this.weightUnit = b.weightUnit;
+ this.realWeight = b.realWeight;
+ this.sizeUnit = b.sizeUnit;
+ this.length = b.length;
+ this.width = b.width;
+ this.height = b.height;
+ this.feeWeight = b.feeWeight;
+ this.logisticsFreight = b.logisticsFreight;
+ this.logisticsFreightCurrency = b.logisticsFreightCurrency;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public String globalOrderNo() { return globalOrderNo; }
+ public Long warehouseId() { return warehouseId; }
+ public String logisticsTypeId() { return logisticsTypeId; }
+ public String waybillNo() { return waybillNo; }
+ public String trackingNo() { return trackingNo; }
+ public String weightUnit() { return weightUnit; }
+ public String realWeight() { return realWeight; }
+ public String sizeUnit() { return sizeUnit; }
+ public String length() { return length; }
+ public String width() { return width; }
+ public String height() { return height; }
+ public String feeWeight() { return feeWeight; }
+ public String logisticsFreight() { return logisticsFreight; }
+ public String logisticsFreightCurrency() { return logisticsFreightCurrency; }
+
+ public static final class Builder {
+
+ private String globalOrderNo;
+ private Long warehouseId;
+ private String logisticsTypeId;
+ private String waybillNo;
+ private String trackingNo;
+ private String weightUnit;
+ private String realWeight;
+ private String sizeUnit;
+ private String length;
+ private String width;
+ private String height;
+ private String feeWeight;
+ private String logisticsFreight;
+ private String logisticsFreightCurrency;
+
+ public Builder globalOrderNo(String v) { this.globalOrderNo = v; return this; }
+ public Builder warehouseId(Long v) { this.warehouseId = v; return this; }
+ public Builder logisticsTypeId(String v) { this.logisticsTypeId = v; return this; }
+ public Builder waybillNo(String v) { this.waybillNo = v; return this; }
+ public Builder trackingNo(String v) { this.trackingNo = v; return this; }
+ public Builder weightUnit(String v) { this.weightUnit = v; return this; }
+ public Builder realWeight(String v) { this.realWeight = v; return this; }
+ public Builder sizeUnit(String v) { this.sizeUnit = v; return this; }
+ public Builder length(String v) { this.length = v; return this; }
+ public Builder width(String v) { this.width = v; return this; }
+ public Builder height(String v) { this.height = v; return this; }
+ public Builder feeWeight(String v) { this.feeWeight = v; return this; }
+ public Builder logisticsFreight(String v) { this.logisticsFreight = v; return this; }
+ public Builder logisticsFreightCurrency(String v) { this.logisticsFreightCurrency = v; return this; }
+
+ public OutboundPackage build() {
+ return new OutboundPackage(this);
+ }
+ }
+}
diff --git a/core/src/main/java/common/ecommerce/model/fulfillment/OutboundResult.java b/core/src/main/java/common/ecommerce/model/fulfillment/OutboundResult.java
new file mode 100644
index 0000000..44331ed
--- /dev/null
+++ b/core/src/main/java/common/ecommerce/model/fulfillment/OutboundResult.java
@@ -0,0 +1,57 @@
+package common.ecommerce.model.fulfillment;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * 快速出库结果:成功与失败两组,按系统单号对应。
+ */
+public final class OutboundResult {
+
+ private final List success;
+ private final List failure;
+
+ private OutboundResult(List success, List failure) {
+ this.success = Collections.unmodifiableList(new ArrayList(success));
+ this.failure = Collections.unmodifiableList(new ArrayList(failure));
+ }
+
+ public static OutboundResult of(List success, List failure) {
+ return new OutboundResult(success, failure);
+ }
+
+ public List success() { return success; }
+ public List failure() { return failure; }
+
+ /** 出库成功的单。 */
+ public static final class Success {
+
+ private final String globalOrderNo;
+ private final String woNumber;
+
+ public Success(String globalOrderNo, String woNumber) {
+ this.globalOrderNo = globalOrderNo;
+ this.woNumber = woNumber;
+ }
+
+ public String globalOrderNo() { return globalOrderNo; }
+ /** 销售出库单号。 */
+ public String woNumber() { return woNumber; }
+ }
+
+ /** 出库失败的单及原因。 */
+ public static final class Failure {
+
+ private final String globalOrderNo;
+ private final String errorMessage;
+
+ public Failure(String globalOrderNo, String errorMessage) {
+ this.globalOrderNo = globalOrderNo;
+ this.errorMessage = errorMessage;
+ }
+
+ public String globalOrderNo() { return globalOrderNo; }
+ public String errorMessage() { return errorMessage; }
+ }
+}
diff --git a/core/src/main/java/common/ecommerce/sdk/ChannelSdk.java b/core/src/main/java/common/ecommerce/sdk/ChannelSdk.java
index 83ace37..3429374 100644
--- a/core/src/main/java/common/ecommerce/sdk/ChannelSdk.java
+++ b/core/src/main/java/common/ecommerce/sdk/ChannelSdk.java
@@ -9,6 +9,7 @@ import common.ecommerce.capability.CapabilityReport;
import common.ecommerce.capability.PlatformAdapter;
import common.ecommerce.capability.Products;
import common.ecommerce.capability.SalesOrders;
+import common.ecommerce.capability.Outbounds;
import common.ecommerce.capability.Settlements;
import common.ecommerce.idempotency.IdempotencyGuard;
import common.ecommerce.model.account.AccountKey;
@@ -86,6 +87,12 @@ public final class ChannelSdk implements ProviderResolver {
return new Settlements(resolve(key), account, newContext(account, connection));
}
+ /** 履约 / 出库视图。 */
+ public Outbounds outbounds(AccountKey key, ChannelConnection connection) {
+ ChannelAccount account = requireAccount(key);
+ return new Outbounds(resolve(key), account, newContext(account, connection));
+ }
+
/**
* 聚合器的子店铺列表(如领星下已授权的亚马逊 / 沃尔玛店铺)。
*
diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/LingxingApi.java b/lingxing/src/main/java/common/ecommerce/lingxing/LingxingApi.java
index d4587bf..2c7fc1b 100644
--- a/lingxing/src/main/java/common/ecommerce/lingxing/LingxingApi.java
+++ b/lingxing/src/main/java/common/ecommerce/lingxing/LingxingApi.java
@@ -88,6 +88,12 @@ public enum LingxingApi {
/** 亚马逊结算中心交易明细。POST,offset/length 分页,上限 10000。 */
SETTLEMENT_TRANSACTION_LIST("/bd/sp/api/open/settlement/transaction/detail/list", 10),
+ /** 快速出库(创建异步出库任务)。POST,qps 10,多平台通用。 */
+ FAST_OUTBOUND("/pb/mp/order/v2/fastOutbound", 10),
+
+ /** 快速出库结果查询。POST,qps 10,多平台通用。 */
+ FAST_OUTBOUND_RESULT("/pb/mp/order/v2/getFastOutboundResult", 10),
+
/** 多平台订单列表;当前实现使用的跨平台接口。 */
ORDER_LIST("/pb/mp/order/v2/list", 10);
diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapter.java b/lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapter.java
index fde0a4d..a6cbf91 100644
--- a/lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapter.java
+++ b/lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapter.java
@@ -1,6 +1,7 @@
package common.ecommerce.lingxing.adapter;
import common.ecommerce.capability.AggregatorCapable;
+import common.ecommerce.capability.OutboundCapable;
import common.ecommerce.capability.ProductCapable;
import common.ecommerce.capability.SalesOrderCapable;
import common.ecommerce.capability.SettlementCapable;
@@ -15,6 +16,8 @@ import common.ecommerce.lingxing.http.LingxingRateLimiter;
import common.ecommerce.lingxing.http.LingxingRequestFactory;
import common.ecommerce.lingxing.platform.LingxingCall;
import common.ecommerce.lingxing.platform.LingxingSubPlatform;
+import common.ecommerce.lingxing.platform.LingxingSubPlatformDefaults;
+import common.ecommerce.lingxing.platform.outbound.LingxingOutboundSource;
import common.ecommerce.lingxing.platform.LingxingSubPlatforms;
import common.ecommerce.model.Capability;
import common.ecommerce.model.ChannelProvider;
@@ -23,6 +26,8 @@ import common.ecommerce.model.account.ChannelAccount;
import common.ecommerce.model.order.SalesOrder;
import common.ecommerce.model.order.SalesOrderQuery;
import common.ecommerce.model.order.SalesOrderRef;
+import common.ecommerce.model.fulfillment.OutboundPackage;
+import common.ecommerce.model.fulfillment.OutboundResult;
import common.ecommerce.model.product.ProductListing;
import common.ecommerce.model.product.ProductQuery;
import common.ecommerce.model.product.ProductRef;
@@ -52,19 +57,32 @@ import java.util.Set;
* {@link LingxingSubPlatform}。
*/
public final class LingxingAdapter implements SalesOrderCapable, ProductCapable, SettlementCapable,
- AggregatorCapable {
+ OutboundCapable, AggregatorCapable {
private final HttpTransport transport;
private final JacksonJsonCodec json;
private final TokenManager tokenManager;
private final LingxingRateLimiter rateLimiter;
private final LingxingRequestFactory requestFactory;
+ private final LingxingSubPlatforms subPlatforms;
/**
* 适配器只持有协议与基础设施,不持有端点与凭据——两者随每次调用传入。
+ *
+ * 子平台装配默认用 {@code LingxingSubPlatformDefaults.all(...)};
+ * 需要替换或只装一部分时用另一个构造器。
*/
public LingxingAdapter(HttpTransport transport, JacksonJsonCodec json,
TokenStore tokenStore, LockProvider lockProvider, Clock clock) {
+ this(transport, json, tokenStore, lockProvider, clock, null);
+ }
+
+ /**
+ * @param subPlatforms 子平台注册表;传 {@code null} 表示装配全部已实现子平台
+ */
+ public LingxingAdapter(HttpTransport transport, JacksonJsonCodec json,
+ TokenStore tokenStore, LockProvider lockProvider, Clock clock,
+ LingxingSubPlatforms subPlatforms) {
this.transport = transport;
this.json = json;
final LingxingTokenClient tokenClient = new LingxingTokenClient(transport, json, clock);
@@ -90,6 +108,8 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
};
this.rateLimiter = new LingxingRateLimiter();
this.requestFactory = new LingxingRequestFactory(json, clock);
+ this.subPlatforms = subPlatforms != null ? subPlatforms
+ : LingxingSubPlatformDefaults.all(transport, json);
}
@Override
@@ -112,7 +132,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
@Override
public EnumSet capabilities() {
- return EnumSet.of(Capability.SALES_ORDER, Capability.PRODUCT, Capability.BILLING);
+ return EnumSet.of(Capability.SALES_ORDER, Capability.PRODUCT, Capability.BILLING, Capability.MARK_SHIPPED);
}
/**
@@ -127,10 +147,10 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
return false;
}
Platform p = LingxingConstants.toPlatform(account.platformCode());
- if (p == null || !LingxingSubPlatforms.isRegistered(p)) {
+ if (p == null || !subPlatforms.isRegistered(p)) {
return false;
}
- LingxingSubPlatform impl = LingxingSubPlatforms.of(p);
+ LingxingSubPlatform impl = subPlatforms.of(p);
if (capability == Capability.SALES_ORDER) {
return impl.orderSource() != null;
}
@@ -140,6 +160,9 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
if (capability == Capability.BILLING) {
return impl.settlementSource() != null;
}
+ if (capability == Capability.MARK_SHIPPED) {
+ return impl.outboundSource() != null;
+ }
return false;
}
@@ -148,7 +171,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
*/
@Override
public List listSubChannels(ChannelContext ctx) {
- LingxingSubPlatform impl = LingxingSubPlatforms.of(ctx.platform());
+ LingxingSubPlatform impl = subPlatforms.of(ctx.platform());
if (impl.shopSource() == null) {
throw ChannelException.builder()
.message("lingxing shop list is not supported for " + ctx.platform())
@@ -165,7 +188,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
@Override
public Page pull(ChannelContext ctx, SalesOrderQuery query) {
requireCapability();
- LingxingSubPlatform impl = LingxingSubPlatforms.of(ctx.platform());
+ LingxingSubPlatform impl = subPlatforms.of(ctx.platform());
if (impl.orderSource() == null) {
throw new ChannelException.UnsupportedCapabilityException(Capability.SALES_ORDER);
}
@@ -174,7 +197,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
@Override
public SalesOrder get(ChannelContext ctx, SalesOrderRef ref) {
- LingxingSubPlatform impl = LingxingSubPlatforms.of(ctx.platform());
+ LingxingSubPlatform impl = subPlatforms.of(ctx.platform());
if (impl.orderSource() == null) {
throw new ChannelException.UnsupportedCapabilityException(Capability.SALES_ORDER);
}
@@ -189,7 +212,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
* 跨渠道同步仍用标准订单路由。
*/
public Page pullFbmOrders(ChannelContext ctx, SalesOrderQuery query) {
- LingxingSubPlatform impl = LingxingSubPlatforms.of(ctx.platform());
+ LingxingSubPlatform impl = subPlatforms.of(ctx.platform());
if (impl.fbmOrderSource() == null) {
throw new ChannelException.UnsupportedCapabilityException(Capability.SALES_ORDER);
}
@@ -202,7 +225,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
* @param orderNumber 领星系统单号,不是平台订单号
*/
public SalesOrder getFbmOrder(ChannelContext ctx, String orderNumber) {
- LingxingSubPlatform impl = LingxingSubPlatforms.of(ctx.platform());
+ LingxingSubPlatform impl = subPlatforms.of(ctx.platform());
if (impl.fbmOrderSource() == null) {
throw new ChannelException.UnsupportedCapabilityException(Capability.SALES_ORDER);
}
@@ -211,7 +234,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
@Override
public Page pull(ChannelContext ctx, SettlementQuery query) {
- LingxingSubPlatform impl = LingxingSubPlatforms.of(ctx.platform());
+ LingxingSubPlatform impl = subPlatforms.of(ctx.platform());
if (impl.settlementSource() == null) {
throw new ChannelException.UnsupportedCapabilityException(Capability.BILLING);
}
@@ -219,6 +242,24 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
}
@Override
+ public boolean submit(ChannelContext ctx, List packages) {
+ return outboundSource(ctx).submit(call(ctx), packages);
+ }
+
+ @Override
+ public OutboundResult results(ChannelContext ctx, List globalOrderNos) {
+ return outboundSource(ctx).results(call(ctx), globalOrderNos);
+ }
+
+ private LingxingOutboundSource outboundSource(ChannelContext ctx) {
+ LingxingOutboundSource source = subPlatforms.of(ctx.platform()).outboundSource();
+ if (source == null) {
+ throw new ChannelException.UnsupportedCapabilityException(Capability.MARK_SHIPPED);
+ }
+ return source;
+ }
+
+ @Override
public ProductSyncStrategy syncStrategy() {
// 亚马逊 Listing 支持按「All Listing 报表更新时间」增量;其它子平台接入时再各自声明
return ProductSyncStrategy.INCREMENTAL_TIME_WINDOW;
@@ -226,7 +267,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
@Override
public Page pull(ChannelContext ctx, ProductQuery query) {
- LingxingSubPlatform impl = LingxingSubPlatforms.of(ctx.platform());
+ LingxingSubPlatform impl = subPlatforms.of(ctx.platform());
if (impl.productSource() == null) {
throw new ChannelException.UnsupportedCapabilityException(Capability.PRODUCT);
}
diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatform.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatform.java
index 43035a2..8929945 100644
--- a/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatform.java
+++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatform.java
@@ -1,6 +1,7 @@
package common.ecommerce.lingxing.platform;
import common.ecommerce.lingxing.platform.order.LingxingOrderSource;
+import common.ecommerce.lingxing.platform.outbound.LingxingOutboundSource;
import common.ecommerce.lingxing.platform.product.LingxingProductSource;
import common.ecommerce.lingxing.platform.settlement.LingxingSettlementSource;
import common.ecommerce.lingxing.platform.shop.LingxingShopSource;
@@ -47,4 +48,9 @@ public interface LingxingSubPlatform {
default LingxingSettlementSource settlementSource() {
return null;
}
+
+ /** 快速出库能力;不支持时为 null。多平台通用接口。 */
+ default LingxingOutboundSource outboundSource() {
+ return null;
+ }
}
diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatformDefaults.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatformDefaults.java
new file mode 100644
index 0000000..d6b8c64
--- /dev/null
+++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatformDefaults.java
@@ -0,0 +1,40 @@
+package common.ecommerce.lingxing.platform;
+
+import common.ecommerce.http.JacksonJsonCodec;
+import common.ecommerce.http.HttpTransport;
+import common.ecommerce.lingxing.platform.aliexpress.AliexpressSubPlatform;
+import common.ecommerce.lingxing.platform.amazon.sc.AmazonScSubPlatform;
+import common.ecommerce.lingxing.platform.amazon.vc.AmazonVcSubPlatform;
+import common.ecommerce.lingxing.platform.ebay.EbaySubPlatform;
+import common.ecommerce.lingxing.platform.shein.SheinSubPlatform;
+import common.ecommerce.lingxing.platform.shopify.ShopifySubPlatform;
+import common.ecommerce.lingxing.platform.temu.TemuSubPlatform;
+import common.ecommerce.lingxing.platform.tiktok.TiktokSubPlatform;
+import common.ecommerce.lingxing.platform.walmart.WalmartSubPlatform;
+
+/**
+ * 领星子平台的默认装配:把当前已实现的子平台全部注册进来。
+ *
+ * 要把某个子平台换掉或只装一部分(测试、灰度),直接用
+ * {@link LingxingSubPlatforms#builder()} 自行组装,不要改这里。
+ */
+public final class LingxingSubPlatformDefaults {
+
+ private LingxingSubPlatformDefaults() {
+ }
+
+ /** 用给定的传输与编解码装配全部已实现子平台。 */
+ public static LingxingSubPlatforms all(HttpTransport transport, JacksonJsonCodec json) {
+ return LingxingSubPlatforms.builder()
+ .register(new AmazonScSubPlatform(transport, json))
+ .register(new AmazonVcSubPlatform(transport, json))
+ .register(new WalmartSubPlatform(transport, json))
+ .register(new TemuSubPlatform(transport, json))
+ .register(new SheinSubPlatform(transport, json))
+ .register(new ShopifySubPlatform(transport, json))
+ .register(new EbaySubPlatform(transport, json))
+ .register(new AliexpressSubPlatform(transport, json))
+ .register(new TiktokSubPlatform(transport, json))
+ .build();
+ }
+}
diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatforms.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatforms.java
index 059cbd6..370b782 100644
--- a/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatforms.java
+++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatforms.java
@@ -1,71 +1,40 @@
package common.ecommerce.lingxing.platform;
import common.ecommerce.error.ChannelException;
-import common.ecommerce.http.JacksonJsonCodec;
-import common.ecommerce.http.OkHttpTransport;
-import common.ecommerce.lingxing.platform.amazon.sc.AmazonScSubPlatform;
-import common.ecommerce.lingxing.platform.amazon.vc.AmazonVcSubPlatform;
import common.ecommerce.model.Platform;
-import common.ecommerce.lingxing.platform.walmart.WalmartSubPlatform;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
/**
* 子平台注册表:业务平台 → 领星侧实现。
*
- * 新增一个子平台 = 写一个 {@link LingxingSubPlatform} 实现 + 在这里登记一行。
- * 未登记的平台在调用时显式失败,不静默返回空。
+ * 注册表按适配器实例组装(见 {@link #builder()}),不是全局静态:
+ * 多个 SDK 实例互不干扰,测试可以只装配部分子平台。
+ * 路由的第一层仍由调用方传入的 {@code AccountKey} 决定(provider + platform),
+ * 这里只回答「该 platform 用哪个实现」。
+ *
+ * 未登记的平台在调用时显式失败,不静默返回空;同一平台重复注册在
+ * {@link Builder#build()} 时直接抛异常,避免静默覆盖。
*/
public final class LingxingSubPlatforms {
- private static final Map BY_PLATFORM;
-
- /**
- * 子平台实现共享同一套传输与编解码;端点与凭据不在这里,随每次调用传入。
- */
- private static final OkHttpTransport SHARED_TRANSPORT = new OkHttpTransport("common-ecommerce/1.0.0 (lingxing)");
- private static final JacksonJsonCodec SHARED_JSON = new JacksonJsonCodec();
-
- static {
- Map map = new EnumMap(Platform.class);
- register(map, new WalmartSubPlatform(SHARED_TRANSPORT, SHARED_JSON));
- register(map, new AmazonScSubPlatform(SHARED_TRANSPORT, SHARED_JSON));
- register(map, new AmazonVcSubPlatform(SHARED_TRANSPORT, SHARED_JSON));
- register(map, new common.ecommerce.lingxing.platform.amazon.sc.AmazonScSubPlatform(
- SHARED_TRANSPORT, SHARED_JSON));
- register(map, new common.ecommerce.lingxing.platform.amazon.vc.AmazonVcSubPlatform(
- SHARED_TRANSPORT, SHARED_JSON));
- register(map, new common.ecommerce.lingxing.platform.temu.TemuSubPlatform(
- SHARED_TRANSPORT, SHARED_JSON));
- register(map, new common.ecommerce.lingxing.platform.shopify.ShopifySubPlatform(
- SHARED_TRANSPORT, SHARED_JSON));
- register(map, new common.ecommerce.lingxing.platform.ebay.EbaySubPlatform(
- SHARED_TRANSPORT, SHARED_JSON));
- register(map, new common.ecommerce.lingxing.platform.aliexpress.AliexpressSubPlatform(
- SHARED_TRANSPORT, SHARED_JSON));
- register(map, new common.ecommerce.lingxing.platform.shein.SheinSubPlatform(
- SHARED_TRANSPORT, SHARED_JSON));
- register(map, new common.ecommerce.lingxing.platform.tiktok.TiktokSubPlatform(
- SHARED_TRANSPORT, SHARED_JSON));
- // 其它平台落地后继续 register(...)
- BY_PLATFORM = Collections.unmodifiableMap(map);
- }
+ private final Map byPlatform;
- private static void register(Map map, LingxingSubPlatform impl) {
- map.put(impl.platform(), impl);
+ private LingxingSubPlatforms(Map byPlatform) {
+ this.byPlatform = Collections.unmodifiableMap(byPlatform);
}
- private LingxingSubPlatforms() {
+ public static Builder builder() {
+ return new Builder();
}
- /**
- * 按业务平台取实现;未登记时抛带平台信息的异常,便于定位是哪个子平台还没接。
- */
- public static LingxingSubPlatform of(Platform platform) {
- LingxingSubPlatform impl = BY_PLATFORM.get(platform);
+ /** 按业务平台取实现;未登记时抛带平台信息的异常。 */
+ public LingxingSubPlatform of(Platform platform) {
+ LingxingSubPlatform impl = byPlatform.get(platform);
if (impl == null) {
throw ChannelException.builder()
.message("lingxing sub platform not implemented: " + platform)
@@ -78,12 +47,42 @@ public final class LingxingSubPlatforms {
return impl;
}
- public static boolean isRegistered(Platform platform) {
- return BY_PLATFORM.containsKey(platform);
+ public boolean isRegistered(Platform platform) {
+ return byPlatform.containsKey(platform);
}
/** 已登记的平台,便于能力报告与日志。 */
- public static Set registered() {
- return BY_PLATFORM.keySet();
+ public Set registered() {
+ return byPlatform.keySet();
+ }
+
+ public static final class Builder {
+
+ private final Map map =
+ new EnumMap(Platform.class);
+
+ public Builder register(LingxingSubPlatform impl) {
+ Objects.requireNonNull(impl, "subPlatform");
+ Platform platform = Objects.requireNonNull(impl.platform(), "platform");
+ LingxingSubPlatform previous = map.put(platform, impl);
+ if (previous != null && previous != impl) {
+ throw new IllegalStateException("duplicate lingxing sub platform for " + platform
+ + ": " + previous.getClass().getName() + " / " + impl.getClass().getName());
+ }
+ return this;
+ }
+
+ public Builder registerAll(Iterable extends LingxingSubPlatform> impls) {
+ if (impls != null) {
+ for (LingxingSubPlatform impl : impls) {
+ register(impl);
+ }
+ }
+ return this;
+ }
+
+ public LingxingSubPlatforms build() {
+ return new LingxingSubPlatforms(map);
+ }
}
}
diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/AliexpressSubPlatform.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/AliexpressSubPlatform.java
index 8cba475..75def5c 100644
--- a/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/AliexpressSubPlatform.java
+++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/AliexpressSubPlatform.java
@@ -5,6 +5,8 @@ import common.ecommerce.http.JacksonJsonCodec;
import common.ecommerce.lingxing.platform.LingxingSubPlatform;
import common.ecommerce.lingxing.platform.aliexpress.product.AliexpressProductSource;
import common.ecommerce.lingxing.platform.product.LingxingProductSource;
+import common.ecommerce.lingxing.platform.multiplatform.outbound.MultiPlatformOutboundSource;
+import common.ecommerce.lingxing.platform.outbound.LingxingOutboundSource;
import common.ecommerce.model.Platform;
/**
@@ -12,6 +14,9 @@ import common.ecommerce.model.Platform;
*/
public final class AliexpressSubPlatform implements LingxingSubPlatform {
+ /** 快速出库是多平台通用接口,各子平台共用。 */
+ private static final MultiPlatformOutboundSource OUTBOUND = new MultiPlatformOutboundSource();
+
private final LingxingProductSource products;
public AliexpressSubPlatform(HttpTransport transport, JacksonJsonCodec json) {
@@ -27,4 +32,9 @@ public final class AliexpressSubPlatform implements LingxingSubPlatform {
public LingxingProductSource productSource() {
return products;
}
+
+ @Override
+ public LingxingOutboundSource outboundSource() {
+ return OUTBOUND;
+ }
}
diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/sc/AmazonScSubPlatform.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/sc/AmazonScSubPlatform.java
index 36aed4f..308d4ed 100644
--- a/lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/sc/AmazonScSubPlatform.java
+++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/sc/AmazonScSubPlatform.java
@@ -8,6 +8,8 @@ import common.ecommerce.lingxing.platform.amazon.order.AmazonOrderSource;
import common.ecommerce.lingxing.platform.amazon.settlement.AmazonSettlementSource;
import common.ecommerce.lingxing.platform.order.LingxingOrderSource;
import common.ecommerce.lingxing.platform.product.LingxingProductSource;
+import common.ecommerce.lingxing.platform.multiplatform.outbound.MultiPlatformOutboundSource;
+import common.ecommerce.lingxing.platform.outbound.LingxingOutboundSource;
import common.ecommerce.lingxing.platform.settlement.LingxingSettlementSource;
import common.ecommerce.lingxing.platform.shop.LingxingShopSource;
import common.ecommerce.lingxing.platform.amazon.sc.product.AmazonScProductSource;
@@ -19,6 +21,9 @@ import common.ecommerce.model.Platform;
*/
public final class AmazonScSubPlatform implements LingxingSubPlatform {
+ /** 快速出库是多平台通用接口,各子平台共用。 */
+ private static final MultiPlatformOutboundSource OUTBOUND = new MultiPlatformOutboundSource();
+
private final LingxingOrderSource orders;
private final LingxingOrderSource fbmOrders;
private final LingxingProductSource products;
@@ -62,4 +67,9 @@ public final class AmazonScSubPlatform implements LingxingSubPlatform {
public LingxingSettlementSource settlementSource() {
return settlements;
}
+
+ @Override
+ public LingxingOutboundSource outboundSource() {
+ return OUTBOUND;
+ }
}
diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/vc/AmazonVcSubPlatform.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/vc/AmazonVcSubPlatform.java
index 43af041..dc09643 100644
--- a/lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/vc/AmazonVcSubPlatform.java
+++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/vc/AmazonVcSubPlatform.java
@@ -6,6 +6,8 @@ import common.ecommerce.lingxing.platform.LingxingSubPlatform;
import common.ecommerce.lingxing.platform.amazon.vc.order.VcOrderSource;
import common.ecommerce.lingxing.platform.order.LingxingOrderSource;
import common.ecommerce.lingxing.platform.product.LingxingProductSource;
+import common.ecommerce.lingxing.platform.multiplatform.outbound.MultiPlatformOutboundSource;
+import common.ecommerce.lingxing.platform.outbound.LingxingOutboundSource;
import common.ecommerce.lingxing.platform.shop.LingxingShopSource;
import common.ecommerce.lingxing.platform.amazon.vc.product.AmazonVcProductSource;
import common.ecommerce.lingxing.platform.amazon.vc.shop.VcShopSource;
@@ -16,6 +18,9 @@ import common.ecommerce.model.Platform;
*/
public final class AmazonVcSubPlatform implements LingxingSubPlatform {
+ /** 快速出库是多平台通用接口,各子平台共用。 */
+ private static final MultiPlatformOutboundSource OUTBOUND = new MultiPlatformOutboundSource();
+
private final LingxingOrderSource orders;
private final LingxingProductSource products;
private final LingxingShopSource shops;
@@ -45,4 +50,9 @@ public final class AmazonVcSubPlatform implements LingxingSubPlatform {
public LingxingShopSource shopSource() {
return shops;
}
+
+ @Override
+ public LingxingOutboundSource outboundSource() {
+ return OUTBOUND;
+ }
}
diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/ebay/EbaySubPlatform.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/ebay/EbaySubPlatform.java
index 9a46c47..d7a2826 100644
--- a/lingxing/src/main/java/common/ecommerce/lingxing/platform/ebay/EbaySubPlatform.java
+++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/ebay/EbaySubPlatform.java
@@ -5,6 +5,8 @@ import common.ecommerce.http.JacksonJsonCodec;
import common.ecommerce.lingxing.platform.LingxingSubPlatform;
import common.ecommerce.lingxing.platform.ebay.product.EbayProductSource;
import common.ecommerce.lingxing.platform.product.LingxingProductSource;
+import common.ecommerce.lingxing.platform.multiplatform.outbound.MultiPlatformOutboundSource;
+import common.ecommerce.lingxing.platform.outbound.LingxingOutboundSource;
import common.ecommerce.model.Platform;
/**
@@ -12,6 +14,9 @@ import common.ecommerce.model.Platform;
*/
public final class EbaySubPlatform implements LingxingSubPlatform {
+ /** 快速出库是多平台通用接口,各子平台共用。 */
+ private static final MultiPlatformOutboundSource OUTBOUND = new MultiPlatformOutboundSource();
+
private final LingxingProductSource products;
public EbaySubPlatform(HttpTransport transport, JacksonJsonCodec json) {
@@ -27,4 +32,9 @@ public final class EbaySubPlatform implements LingxingSubPlatform {
public LingxingProductSource productSource() {
return products;
}
+
+ @Override
+ public LingxingOutboundSource outboundSource() {
+ return OUTBOUND;
+ }
}
diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/multiplatform/outbound/MultiPlatformOutboundSource.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/multiplatform/outbound/MultiPlatformOutboundSource.java
new file mode 100644
index 0000000..21f40b4
--- /dev/null
+++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/multiplatform/outbound/MultiPlatformOutboundSource.java
@@ -0,0 +1,112 @@
+package common.ecommerce.lingxing.platform.multiplatform.outbound;
+
+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.outbound.LingxingOutboundSource;
+import common.ecommerce.model.fulfillment.OutboundPackage;
+import common.ecommerce.model.fulfillment.OutboundResult;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 领星 · 快速出库(多平台通用)。
+ *
+ * 两个接口都不带平台维度,靠领星系统单号 {@code global_order_no} 定位订单,
+ * 因此所有子平台共用同一实现。
+ *
+ *
+ * - {@code POST /pb/mp/order/v2/fastOutbound}:创建异步出库任务,返回 {@code data: true}
+ * - {@code POST /pb/mp/order/v2/getFastOutboundResult}:按单号数组查结果,
+ * 返回 {@code data.success[]} 与 {@code data.failure[]}
+ *
+ *
+ * 两个接口的令牌桶都是 10 req/s。
+ */
+public final class MultiPlatformOutboundSource implements LingxingOutboundSource {
+
+ /** 单次最多 1000 单(两个接口一致)。 */
+ private static final int MAX_BATCH = 1000;
+
+ private static final String OP_SUBMIT = "outbound.submit";
+ private static final String OP_RESULTS = "outbound.results";
+
+ @Override
+ public boolean submit(LingxingCall call, List packages) {
+ if (packages == null || packages.isEmpty()) {
+ throw new IllegalArgumentException("packages must not be empty");
+ }
+ if (packages.size() > MAX_BATCH) {
+ throw new IllegalArgumentException("at most " + MAX_BATCH + " packages per call, got " + packages.size());
+ }
+
+ List