Browse Source

refactor(lingxing): 子平台注册表改为实例级;接入快速出库

注册表(方案 A):
- LingxingSubPlatforms 从全局静态改成 builder().register(...).build()
- 同一平台重复注册在 build() 时抛异常,不再静默覆盖
- 新增 LingxingSubPlatformDefaults.all(transport, json) 装配默认实现
- LingxingAdapter 持有注册表实例;新增可注入注册表的构造器,
  传 null 时用默认装配
- 路由第一层仍由调用方传入的 AccountKey(provider + platform)决定

快速出库(多平台通用,qps 10):
- LingxingApi 新增 FAST_OUTBOUND / FAST_OUTBOUND_RESULT
- core 新增 OutboundCapable / Outbounds / OutboundPackage / OutboundResult
- ChannelSdk 新增 outbounds(key, conn)
- 新增 platform/outbound/LingxingOutboundSource 能力接口
- 新增 platform/multiplatform/outbound/MultiPlatformOutboundSource
  (两个接口都不带平台维度,所有子平台共用)
- 九个多平台子平台声明 outboundSource()
- 适配器 capabilities() 增加 MARK_SHIPPED,supports() 按 outboundSource 判定

注意:submit 仅表示任务受理,结果需用 results() 回查。

Co-Authored-By: Claude <noreply@anthropic.com>
feature/supplier-lingxing
chenchuchuan 2 weeks ago
parent
commit
f3aefee1d3
  1. 25
      core/src/main/java/common/ecommerce/capability/OutboundCapable.java
  2. 42
      core/src/main/java/common/ecommerce/capability/Outbounds.java
  3. 101
      core/src/main/java/common/ecommerce/model/fulfillment/OutboundPackage.java
  4. 57
      core/src/main/java/common/ecommerce/model/fulfillment/OutboundResult.java
  5. 7
      core/src/main/java/common/ecommerce/sdk/ChannelSdk.java
  6. 6
      lingxing/src/main/java/common/ecommerce/lingxing/LingxingApi.java
  7. 63
      lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapter.java
  8. 6
      lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatform.java
  9. 40
      lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatformDefaults.java
  10. 101
      lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatforms.java
  11. 10
      lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/AliexpressSubPlatform.java
  12. 10
      lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/sc/AmazonScSubPlatform.java
  13. 10
      lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/vc/AmazonVcSubPlatform.java
  14. 10
      lingxing/src/main/java/common/ecommerce/lingxing/platform/ebay/EbaySubPlatform.java
  15. 112
      lingxing/src/main/java/common/ecommerce/lingxing/platform/multiplatform/outbound/MultiPlatformOutboundSource.java
  16. 21
      lingxing/src/main/java/common/ecommerce/lingxing/platform/multiplatform/outbound/OutboundFailDto.java
  17. 21
      lingxing/src/main/java/common/ecommerce/lingxing/platform/multiplatform/outbound/OutboundOkDto.java
  18. 21
      lingxing/src/main/java/common/ecommerce/lingxing/platform/outbound/LingxingOutboundSource.java
  19. 10
      lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/SheinSubPlatform.java
  20. 10
      lingxing/src/main/java/common/ecommerce/lingxing/platform/shopify/ShopifySubPlatform.java
  21. 10
      lingxing/src/main/java/common/ecommerce/lingxing/platform/temu/TemuSubPlatform.java
  22. 10
      lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/TiktokSubPlatform.java
  23. 11
      lingxing/src/main/java/common/ecommerce/lingxing/platform/walmart/WalmartSubPlatform.java
  24. 229
      lingxing/src/test/java/common/ecommerce/lingxing/platform/amazon/sc/AmazonScProductLiveTest.java

25
core/src/main/java/common/ecommerce/capability/OutboundCapable.java

@ -0,0 +1,25 @@ @@ -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;
/**
* 快速出库能力:提交出库任务 + 查询任务结果。
*
* <p>出库是<b>异步</b>的:{@link #submit} 只表示任务已受理,真正的成功/失败
* 要用 {@link #results} 按系统单号回查。</p>
*
* <p>写操作,必须经 {@code IdempotencyGuard} 执行;幂等键按系统单号,
* 与领星「一个订单只能出库一次」的约束一致。</p>
*/
public interface OutboundCapable extends PlatformAdapter {
/** 提交出库任务;返回是否受理。 */
boolean submit(ChannelContext ctx, List<OutboundPackage> packages);
/** 按系统单号查询出库结果。 */
OutboundResult results(ChannelContext ctx, List<String> globalOrderNos);
}

42
core/src/main/java/common/ecommerce/capability/Outbounds.java

@ -0,0 +1,42 @@ @@ -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<OutboundPackage> packages) {
requireOutboundCapable();
return ((OutboundCapable) adapter).submit(ctx, packages);
}
public OutboundResult results(List<String> 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);
}
}
}

101
core/src/main/java/common/ecommerce/model/fulfillment/OutboundPackage.java

@ -0,0 +1,101 @@ @@ -0,0 +1,101 @@
package common.ecommerce.model.fulfillment;
import java.util.Objects;
/**
* 一次快速出库请求中的单个包裹。
*
* <p>字段以领星「快速出库」接口为准;各平台接入时由各自 Source 翻译。
* {@code globalOrderNo} 是平台系统单号(领星侧 {@code global_order_no}),
* 也是出库结果的查询键。</p>
*/
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);
}
}
}

57
core/src/main/java/common/ecommerce/model/fulfillment/OutboundResult.java

@ -0,0 +1,57 @@ @@ -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> success;
private final List<Failure> failure;
private OutboundResult(List<Success> success, List<Failure> failure) {
this.success = Collections.unmodifiableList(new ArrayList<Success>(success));
this.failure = Collections.unmodifiableList(new ArrayList<Failure>(failure));
}
public static OutboundResult of(List<Success> success, List<Failure> failure) {
return new OutboundResult(success, failure);
}
public List<Success> success() { return success; }
public List<Failure> 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; }
}
}

7
core/src/main/java/common/ecommerce/sdk/ChannelSdk.java

@ -9,6 +9,7 @@ import common.ecommerce.capability.CapabilityReport; @@ -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 { @@ -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));
}
/**
* 聚合器的子店铺列表(如领星下已授权的亚马逊 / 沃尔玛店铺)。
*

6
lingxing/src/main/java/common/ecommerce/lingxing/LingxingApi.java

@ -88,6 +88,12 @@ public enum LingxingApi { @@ -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);

63
lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapter.java

@ -1,6 +1,7 @@ @@ -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; @@ -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; @@ -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; @@ -52,19 +57,32 @@ import java.util.Set;
* {@link LingxingSubPlatform}。</p>
*/
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;
/**
* 适配器只持有协议与基础设施,不持有端点与凭据——两者随每次调用传入。
*
* <p>子平台装配默认用 {@code LingxingSubPlatformDefaults.all(...)};
* 需要替换或只装一部分时用另一个构造器。</p>
*/
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, @@ -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, @@ -112,7 +132,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
@Override
public EnumSet<Capability> 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, @@ -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, @@ -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, @@ -148,7 +171,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
*/
@Override
public List<SubChannel> 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, @@ -165,7 +188,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
@Override
public Page<SalesOrder> 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, @@ -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, @@ -189,7 +212,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
* 跨渠道同步仍用标准订单路由。</p>
*/
public Page<SalesOrder> 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, @@ -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, @@ -211,7 +234,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
@Override
public Page<SettlementTransaction> 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, @@ -219,6 +242,24 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
}
@Override
public boolean submit(ChannelContext ctx, List<OutboundPackage> packages) {
return outboundSource(ctx).submit(call(ctx), packages);
}
@Override
public OutboundResult results(ChannelContext ctx, List<String> 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, @@ -226,7 +267,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
@Override
public Page<ProductListing> 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);
}

6
lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatform.java

@ -1,6 +1,7 @@ @@ -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 { @@ -47,4 +48,9 @@ public interface LingxingSubPlatform {
default LingxingSettlementSource settlementSource() {
return null;
}
/** 快速出库能力;不支持时为 null。多平台通用接口。 */
default LingxingOutboundSource outboundSource() {
return null;
}
}

40
lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatformDefaults.java

@ -0,0 +1,40 @@ @@ -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;
/**
* 领星子平台的默认装配:把当前已实现的子平台全部注册进来。
*
* <p>要把某个子平台换掉或只装一部分(测试、灰度),直接用
* {@link LingxingSubPlatforms#builder()} 自行组装,不要改这里。</p>
*/
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();
}
}

101
lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatforms.java

@ -1,71 +1,40 @@ @@ -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;
/**
* 子平台注册表:业务平台 → 领星侧实现。
*
* <p>新增一个子平台 = 写一个 {@link LingxingSubPlatform} 实现 + 在这里登记一行。
* 未登记的平台在调用时显式失败,不静默返回空。</p>
* <p>注册表<b>按适配器实例组装</b>(见 {@link #builder()}),不是全局静态:
* 多个 SDK 实例互不干扰,测试可以只装配部分子平台。
* 路由的第一层仍由调用方传入的 {@code AccountKey} 决定(provider + platform),
* 这里只回答「该 platform 用哪个实现」。</p>
*
* <p>未登记的平台在调用时显式失败,不静默返回空;同一平台重复注册在
* {@link Builder#build()} 时直接抛异常,避免静默覆盖。</p>
*/
public final class LingxingSubPlatforms {
private static final Map<Platform, LingxingSubPlatform> 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<Platform, LingxingSubPlatform> map = new EnumMap<Platform, LingxingSubPlatform>(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<Platform, LingxingSubPlatform> byPlatform;
private static void register(Map<Platform, LingxingSubPlatform> map, LingxingSubPlatform impl) {
map.put(impl.platform(), impl);
private LingxingSubPlatforms(Map<Platform, LingxingSubPlatform> 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 { @@ -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<Platform> registered() {
return BY_PLATFORM.keySet();
public Set<Platform> registered() {
return byPlatform.keySet();
}
public static final class Builder {
private final Map<Platform, LingxingSubPlatform> map =
new EnumMap<Platform, LingxingSubPlatform>(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);
}
}
}

10
lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/AliexpressSubPlatform.java

@ -5,6 +5,8 @@ import common.ecommerce.http.JacksonJsonCodec; @@ -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; @@ -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 { @@ -27,4 +32,9 @@ public final class AliexpressSubPlatform implements LingxingSubPlatform {
public LingxingProductSource productSource() {
return products;
}
@Override
public LingxingOutboundSource outboundSource() {
return OUTBOUND;
}
}

10
lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/sc/AmazonScSubPlatform.java

@ -8,6 +8,8 @@ import common.ecommerce.lingxing.platform.amazon.order.AmazonOrderSource; @@ -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; @@ -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 { @@ -62,4 +67,9 @@ public final class AmazonScSubPlatform implements LingxingSubPlatform {
public LingxingSettlementSource settlementSource() {
return settlements;
}
@Override
public LingxingOutboundSource outboundSource() {
return OUTBOUND;
}
}

10
lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/vc/AmazonVcSubPlatform.java

@ -6,6 +6,8 @@ import common.ecommerce.lingxing.platform.LingxingSubPlatform; @@ -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; @@ -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 { @@ -45,4 +50,9 @@ public final class AmazonVcSubPlatform implements LingxingSubPlatform {
public LingxingShopSource shopSource() {
return shops;
}
@Override
public LingxingOutboundSource outboundSource() {
return OUTBOUND;
}
}

10
lingxing/src/main/java/common/ecommerce/lingxing/platform/ebay/EbaySubPlatform.java

@ -5,6 +5,8 @@ import common.ecommerce.http.JacksonJsonCodec; @@ -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; @@ -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 { @@ -27,4 +32,9 @@ public final class EbaySubPlatform implements LingxingSubPlatform {
public LingxingProductSource productSource() {
return products;
}
@Override
public LingxingOutboundSource outboundSource() {
return OUTBOUND;
}
}

112
lingxing/src/main/java/common/ecommerce/lingxing/platform/multiplatform/outbound/MultiPlatformOutboundSource.java

@ -0,0 +1,112 @@ @@ -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;
/**
* 领星 · 快速出库(多平台通用)。
*
* <p>两个接口都不带平台维度,靠领星系统单号 {@code global_order_no} 定位订单,
* 因此所有子平台共用同一实现。</p>
*
* <ul>
* <li>{@code POST /pb/mp/order/v2/fastOutbound}:创建异步出库任务,返回 {@code data: true}</li>
* <li>{@code POST /pb/mp/order/v2/getFastOutboundResult}:按单号数组查结果,
* 返回 {@code data.success[]} 与 {@code data.failure[]}</li>
* </ul>
*
* <p>两个接口的令牌桶都是 10 req/s。</p>
*/
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<OutboundPackage> 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<Map<String, Object>> body = new ArrayList<Map<String, Object>>(packages.size());
for (OutboundPackage p : packages) {
body.add(toBody(p));
}
Map<String, Object> payload = new LinkedHashMap<String, Object>();
payload.put("package", body);
HttpRequest req = call.signed(LingxingApi.FAST_OUTBOUND, payload, OP_SUBMIT);
HttpResponse resp = call.execute(req);
LingxingEnvelope envelope = call.envelope(resp, OP_SUBMIT);
// 该接口 data 是 boolean,true 表示任务已受理(不代表出库成功)
return "true".equalsIgnoreCase(call.json().stringAt(envelope.body(), "data"));
}
@Override
public OutboundResult results(LingxingCall call, List<String> globalOrderNos) {
if (globalOrderNos == null || globalOrderNos.isEmpty()) {
throw new IllegalArgumentException("globalOrderNos must not be empty");
}
if (globalOrderNos.size() > MAX_BATCH) {
throw new IllegalArgumentException("at most " + MAX_BATCH + " orders per call, got " + globalOrderNos.size());
}
Map<String, Object> payload = new LinkedHashMap<String, Object>();
payload.put("global_order_no", new ArrayList<String>(globalOrderNos));
HttpRequest req = call.signed(LingxingApi.FAST_OUTBOUND_RESULT, payload, OP_RESULTS);
HttpResponse resp = call.execute(req);
LingxingEnvelope envelope = call.envelope(resp, OP_RESULTS);
List<OutboundOkDto> ok = call.json().listAt(envelope.body(), "data.success", OutboundOkDto.class);
List<OutboundFailDto> fail = call.json().listAt(envelope.body(), "data.failure", OutboundFailDto.class);
List<OutboundResult.Success> success = new ArrayList<OutboundResult.Success>(ok.size());
for (OutboundOkDto dto : ok) {
success.add(new OutboundResult.Success(dto.getGlobalOrderNo(), dto.getWoNumber()));
}
List<OutboundResult.Failure> failure = new ArrayList<OutboundResult.Failure>(fail.size());
for (OutboundFailDto dto : fail) {
failure.add(new OutboundResult.Failure(dto.getGlobalOrderNo(), dto.getErrorMessage()));
}
return OutboundResult.of(success, failure);
}
/** 统一模型 → 领星出库请求体;值为 null 的字段不发送。 */
private static Map<String, Object> toBody(OutboundPackage p) {
Map<String, Object> item = new LinkedHashMap<String, Object>();
item.put("global_order_no", p.globalOrderNo());
item.put("wid", p.warehouseId());
item.put("logistics_type_id", p.logisticsTypeId());
item.put("waybill_no", p.waybillNo());
item.put("tracking_no", p.trackingNo());
item.put("weight_unit", p.weightUnit());
item.put("real_weight", p.realWeight());
item.put("size_unit", p.sizeUnit());
item.put("length", p.length());
item.put("width", p.width());
item.put("height", p.height());
item.put("fee_weight", p.feeWeight());
item.put("logistics_freight", p.logisticsFreight());
item.put("logistics_freight_currency_code", p.logisticsFreightCurrency());
item.values().removeAll(java.util.Collections.singleton(null));
return item;
}
}

21
lingxing/src/main/java/common/ecommerce/lingxing/platform/multiplatform/outbound/OutboundFailDto.java

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
package common.ecommerce.lingxing.platform.multiplatform.outbound;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
/** 快速出库结果 · 失败项({@code data.failure[]})。 */
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class OutboundFailDto {
/** 系统单号。 */
@JsonProperty("global_order_no")
private String globalOrderNo;
/** 失败原因,如「正在处理」「库存不足」「订单没提交快速出库」。 */
@JsonProperty("error_message")
private String errorMessage;
}

21
lingxing/src/main/java/common/ecommerce/lingxing/platform/multiplatform/outbound/OutboundOkDto.java

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
package common.ecommerce.lingxing.platform.multiplatform.outbound;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
/** 快速出库结果 · 成功项({@code data.success[]})。 */
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class OutboundOkDto {
/** 系统单号。 */
@JsonProperty("global_order_no")
private String globalOrderNo;
/** 销售出库单号。 */
@JsonProperty("wo_number")
private String woNumber;
}

21
lingxing/src/main/java/common/ecommerce/lingxing/platform/outbound/LingxingOutboundSource.java

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
package common.ecommerce.lingxing.platform.outbound;
import common.ecommerce.lingxing.platform.LingxingCall;
import common.ecommerce.model.fulfillment.OutboundPackage;
import common.ecommerce.model.fulfillment.OutboundResult;
import java.util.List;
/**
* 子平台的出库能力。
*
* <p>出库是异步的:{@code submit} 只表示任务受理,结果用 {@code results} 回查。</p>
*/
public interface LingxingOutboundSource {
/** 提交出库任务;返回是否受理。 */
boolean submit(LingxingCall call, List<OutboundPackage> packages);
/** 按系统单号查询出库结果。 */
OutboundResult results(LingxingCall call, List<String> globalOrderNos);
}

10
lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/SheinSubPlatform.java

@ -4,6 +4,8 @@ import common.ecommerce.http.HttpTransport; @@ -4,6 +4,8 @@ import common.ecommerce.http.HttpTransport;
import common.ecommerce.http.JacksonJsonCodec;
import common.ecommerce.lingxing.platform.LingxingSubPlatform;
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.shein.product.SheinProductSource;
import common.ecommerce.model.Platform;
@ -14,6 +16,9 @@ import common.ecommerce.model.Platform; @@ -14,6 +16,9 @@ import common.ecommerce.model.Platform;
*/
public final class SheinSubPlatform implements LingxingSubPlatform {
/** 快速出库是多平台通用接口,各子平台共用。 */
private static final MultiPlatformOutboundSource OUTBOUND = new MultiPlatformOutboundSource();
private final LingxingProductSource products;
public SheinSubPlatform(HttpTransport transport, JacksonJsonCodec json) {
@ -29,4 +34,9 @@ public final class SheinSubPlatform implements LingxingSubPlatform { @@ -29,4 +34,9 @@ public final class SheinSubPlatform implements LingxingSubPlatform {
public LingxingProductSource productSource() {
return products;
}
@Override
public LingxingOutboundSource outboundSource() {
return OUTBOUND;
}
}

10
lingxing/src/main/java/common/ecommerce/lingxing/platform/shopify/ShopifySubPlatform.java

@ -4,6 +4,8 @@ import common.ecommerce.http.HttpTransport; @@ -4,6 +4,8 @@ import common.ecommerce.http.HttpTransport;
import common.ecommerce.http.JacksonJsonCodec;
import common.ecommerce.lingxing.platform.LingxingSubPlatform;
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.shopify.product.ShopifyProductSource;
import common.ecommerce.model.Platform;
@ -12,6 +14,9 @@ import common.ecommerce.model.Platform; @@ -12,6 +14,9 @@ import common.ecommerce.model.Platform;
*/
public final class ShopifySubPlatform implements LingxingSubPlatform {
/** 快速出库是多平台通用接口,各子平台共用。 */
private static final MultiPlatformOutboundSource OUTBOUND = new MultiPlatformOutboundSource();
private final LingxingProductSource products;
public ShopifySubPlatform(HttpTransport transport, JacksonJsonCodec json) {
@ -27,4 +32,9 @@ public final class ShopifySubPlatform implements LingxingSubPlatform { @@ -27,4 +32,9 @@ public final class ShopifySubPlatform implements LingxingSubPlatform {
public LingxingProductSource productSource() {
return products;
}
@Override
public LingxingOutboundSource outboundSource() {
return OUTBOUND;
}
}

10
lingxing/src/main/java/common/ecommerce/lingxing/platform/temu/TemuSubPlatform.java

@ -4,6 +4,8 @@ import common.ecommerce.http.HttpTransport; @@ -4,6 +4,8 @@ import common.ecommerce.http.HttpTransport;
import common.ecommerce.http.JacksonJsonCodec;
import common.ecommerce.lingxing.platform.LingxingSubPlatform;
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.temu.product.TemuProductSource;
import common.ecommerce.model.Platform;
@ -14,6 +16,9 @@ import common.ecommerce.model.Platform; @@ -14,6 +16,9 @@ import common.ecommerce.model.Platform;
*/
public final class TemuSubPlatform implements LingxingSubPlatform {
/** 快速出库是多平台通用接口,各子平台共用。 */
private static final MultiPlatformOutboundSource OUTBOUND = new MultiPlatformOutboundSource();
private final LingxingProductSource products;
public TemuSubPlatform(HttpTransport transport, JacksonJsonCodec json) {
@ -29,4 +34,9 @@ public final class TemuSubPlatform implements LingxingSubPlatform { @@ -29,4 +34,9 @@ public final class TemuSubPlatform implements LingxingSubPlatform {
public LingxingProductSource productSource() {
return products;
}
@Override
public LingxingOutboundSource outboundSource() {
return OUTBOUND;
}
}

10
lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/TiktokSubPlatform.java

@ -4,6 +4,8 @@ import common.ecommerce.http.HttpTransport; @@ -4,6 +4,8 @@ import common.ecommerce.http.HttpTransport;
import common.ecommerce.http.JacksonJsonCodec;
import common.ecommerce.lingxing.platform.LingxingSubPlatform;
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.tiktok.product.TiktokProductSource;
import common.ecommerce.model.Platform;
@ -12,6 +14,9 @@ import common.ecommerce.model.Platform; @@ -12,6 +14,9 @@ import common.ecommerce.model.Platform;
*/
public final class TiktokSubPlatform implements LingxingSubPlatform {
/** 快速出库是多平台通用接口,各子平台共用。 */
private static final MultiPlatformOutboundSource OUTBOUND = new MultiPlatformOutboundSource();
private final LingxingProductSource products;
public TiktokSubPlatform(HttpTransport transport, JacksonJsonCodec json) {
@ -27,4 +32,9 @@ public final class TiktokSubPlatform implements LingxingSubPlatform { @@ -27,4 +32,9 @@ public final class TiktokSubPlatform implements LingxingSubPlatform {
public LingxingProductSource productSource() {
return products;
}
@Override
public LingxingOutboundSource outboundSource() {
return OUTBOUND;
}
}

11
lingxing/src/main/java/common/ecommerce/lingxing/platform/walmart/WalmartSubPlatform.java

@ -6,7 +6,8 @@ import common.ecommerce.lingxing.platform.LingxingSubPlatform; @@ -6,7 +6,8 @@ import common.ecommerce.lingxing.platform.LingxingSubPlatform;
import common.ecommerce.lingxing.platform.multiplatform.shop.MultiPlatformShopSource;
import common.ecommerce.lingxing.platform.order.LingxingOrderSource;
import common.ecommerce.lingxing.platform.product.LingxingProductSource;
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.walmart.order.WalmartOrderSource;
import common.ecommerce.lingxing.platform.walmart.product.WalmartProductSource;
@ -20,6 +21,9 @@ import common.ecommerce.model.Platform; @@ -20,6 +21,9 @@ import common.ecommerce.model.Platform;
*/
public final class WalmartSubPlatform implements LingxingSubPlatform {
/** 快速出库是多平台通用接口,各子平台共用。 */
private static final MultiPlatformOutboundSource OUTBOUND = new MultiPlatformOutboundSource();
private final LingxingOrderSource orders;
private final LingxingProductSource products;
private final LingxingShopSource shops;
@ -49,4 +53,9 @@ public final class WalmartSubPlatform implements LingxingSubPlatform { @@ -49,4 +53,9 @@ public final class WalmartSubPlatform implements LingxingSubPlatform {
public LingxingShopSource shopSource() {
return shops;
}
@Override
public LingxingOutboundSource outboundSource() {
return OUTBOUND;
}
}

229
lingxing/src/test/java/common/ecommerce/lingxing/platform/amazon/sc/AmazonScProductLiveTest.java

@ -0,0 +1,229 @@ @@ -0,0 +1,229 @@
package common.ecommerce.lingxing.platform.amazon.sc;
import common.ecommerce.capability.AggregatorCapable.SubChannel;
import common.ecommerce.http.HttpRequest;
import common.ecommerce.http.HttpResponse;
import common.ecommerce.http.HttpTransport;
import common.ecommerce.http.JacksonJsonCodec;
import common.ecommerce.http.OkHttpTransport;
import common.ecommerce.lingxing.LingxingConstants;
import common.ecommerce.lingxing.adapter.LingxingAdapter;
import common.ecommerce.model.ChannelProvider;
import common.ecommerce.model.Platform;
import common.ecommerce.model.account.AccountKey;
import common.ecommerce.model.account.ChannelAccount;
import common.ecommerce.model.product.ProductListing;
import common.ecommerce.model.product.ProductQuery;
import common.ecommerce.model.support.Page;
import common.ecommerce.sdk.ChannelConnection;
import common.ecommerce.sdk.ChannelContext;
import common.ecommerce.spi.ChannelSecret;
import common.ecommerce.testkit.InMemoryLockProvider;
import common.ecommerce.testkit.InMemoryTokenStore;
import org.junit.jupiter.api.Test;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* 领星 · 亚马逊 SC 真实环境测试:先查店铺列表拿 sid,再用 sid 拉 Listing。
*
* <p><b>跑之前填 APP_KEY / APP_SECRET 即可</b>;SID 留空时会自动从店铺列表取第一个。</p>
* <pre>
* mvn -pl lingxing -am test -Dtest=AmazonScProductLiveTest
* </pre>
*
* <p>调用前确认出口 IP 已加入领星白名单。本类只用于联调,不要把真实凭证提交到仓库。</p>
*
* <p>两个接口的令牌桶容量都是 1,且按「账户 + path」共享,必须串行调用。</p>
*/
class AmazonScProductLiveTest {
// ==================== 填写这里 ====================
/** 领星 ERP 开放接口的 AppID。 */
private static final String APP_KEY = "ak_MWoHJz2tcIwKF";
/** 领星 ERP 开放接口的 AppSecret。 */
private static final String APP_SECRET = "YOUkd5efWJSK71jLvDyz+g==";
/**
* 亚马逊店铺的领星 sid。
* 留空则自动调用店铺列表接口,取第一个正常状态的店铺。
*/
private static final String SID = "13839";
// ================================================
private static final String BASE_URL = LingxingConstants.PRODUCTION_BASE_URL;
private final JacksonJsonCodec json = new JacksonJsonCodec();
private final LoggingTransport transport =
new LoggingTransport(new OkHttpTransport("common-ecommerce-smoke"));
/**
* 店铺列表:一次性返回企业已授权到领星的全部亚马逊 SC 店铺。
*
* <p>接口 {@code GET /erp/sc/data/seller/lists},非分页。打印每个店铺的 sid 与名称,
* 同时打印请求与响应原始报文(见 LoggingTransport),便于核对字段名。</p>
*/
@Test
void listsAmazonShops() {
requireConfigured();
List<SubChannel> channels = adapter().listSubChannels(shopListContext());
System.out.println("[shops] subChannels size=" + channels.size());
for (SubChannel c : channels) {
System.out.println(" platformCode=" + c.platformCode()
+ " sid=" + c.externalStoreId()
+ " platform=" + c.platform()
+ " name=" + c.name());
}
assertNotNull(channels);
}
/** 拿第一个正常店铺的 sid,调 Listing 接口。 */
@Test
void pullsOnePageOfListings() {
requireConfigured();
String sid = resolveSid();
System.out.println("[listings] 使用 sid=" + sid);
ChannelContext ctx = ChannelContext.of(amazonAccount(sid), connection(),
"smoke-" + System.currentTimeMillis(), Clock.systemUTC());
Instant to = Instant.now();
Instant from = to.minus(Duration.ofDays(7));
Page<ProductListing> page = adapter().pull(ctx, ProductQuery.builder()
.updatedAfter(from)
.updatedBefore(to)
.pageSize(20)
.build());
System.out.println("[listings] window=" + from + " .. " + to
+ " items=" + page.size() + " nextCursor=" + page.nextCursor());
for (ProductListing p : page.items()) {
System.out.println(" sku=" + p.platformSku()
+ " title=" + p.title()
+ " status=" + p.status()
+ " images=" + p.imageUrls().size()
+ " updatedAt=" + (p.updatedAt() == null ? null : p.updatedAt().utc()));
}
assertFalse(page.size() > 20, "pageSize 未被平台遵守");
}
/** 不带时间窗,确认默认分页与解析也能走通。 */
@Test
void pullsFirstPageWithoutTimeWindow() {
requireConfigured();
String sid = resolveSid();
ChannelContext ctx = ChannelContext.of(amazonAccount(sid), connection(),
"smoke-" + System.currentTimeMillis(), Clock.systemUTC());
Page<ProductListing> page = adapter().pull(ctx, ProductQuery.builder().pageSize(10).build());
System.out.println("[listings/no-window] sid=" + sid + " items=" + page.size()
+ " nextCursor=" + page.nextCursor());
for (ProductListing p : page.items()) {
System.out.println(" sku=" + p.platformSku() + " status=" + p.status());
}
// 店铺可能没有商品,空列表也算通过
assertNotNull(page);
}
// ---------------------------------------------------------------- helpers
private static void requireConfigured() {
org.junit.jupiter.api.Assumptions.assumeTrue(
!APP_KEY.startsWith("在这里填") && !APP_SECRET.startsWith("在这里填"),
"请先填写 AmazonScProductLiveTest 顶部的 APP_KEY / APP_SECRET");
}
/** 优先用常量里的 SID;留空则从店铺列表取第一个。 */
private String resolveSid() {
if (SID != null && !SID.trim().isEmpty() && !SID.startsWith("在这里填")) {
return SID.trim();
}
List<SubChannel> channels = adapter().listSubChannels(shopListContext());
if (channels.isEmpty()) {
throw new AssertionError("店铺列表为空:该企业没有已授权且状态正常的亚马逊 SC 店铺");
}
return channels.get(0).externalStoreId();
}
private LingxingAdapter adapter() {
return new LingxingAdapter(transport, json,
new InMemoryTokenStore(), new InMemoryLockProvider(), Clock.systemUTC());
}
private ChannelConnection connection() {
return ChannelConnection.of(BASE_URL, ChannelSecret.builder()
.appKey(APP_KEY).appSecret(APP_SECRET).build());
}
/** 店铺列表所用的上下文:店铺维度此时还不存在,用占位 omsStoreId。 */
private ChannelContext shopListContext() {
return ChannelContext.of(placeholderAccount(), connection(),
"smoke-shops-" + System.currentTimeMillis(), Clock.systemUTC());
}
private ChannelAccount placeholderAccount() {
return ChannelAccount.builder()
.key(AccountKey.of(ChannelProvider.LINGXING, Platform.AMAZON_SC, "oms-amz-discovery"))
.externalStoreId("discovery")
.platformCode(10001)
.credentialRef("smoke")
.marketplaceZone("America/Los_Angeles")
.currency("USD")
.build();
}
private ChannelAccount amazonAccount(String sid) {
return ChannelAccount.builder()
.key(AccountKey.of(ChannelProvider.LINGXING, Platform.AMAZON_SC, "oms-amz-smoke"))
.externalStoreId(sid)
.platformCode(10001)
.credentialRef("smoke")
.marketplaceZone("America/Los_Angeles")
.currency("USD")
.build();
}
/** 打印真实请求与响应,签名/字段名不对时靠这个定位。Authorization 只打指纹。 */
static final class LoggingTransport implements HttpTransport {
private static final int MAX_BODY = 2000;
private final HttpTransport delegate;
LoggingTransport(HttpTransport delegate) {
this.delegate = delegate;
}
@Override
public HttpResponse execute(HttpRequest request) {
System.out.println("--> " + request.method() + " " + request.url());
System.out.println(" headers " + mask(request.headers().toString()));
System.out.println(" body " + truncate(request.body()));
HttpResponse response = delegate.execute(request);
System.out.println("<-- " + response.statusCode() + " (" + response.latencyMillis() + " ms) "
+ truncate(response.body()));
return response;
}
private static String mask(String headers) {
return headers.replaceAll("(?i)(bearer\\s+)[^,\\]]+", "$1***");
}
private static String truncate(String body) {
if (body == null) {
return "null";
}
return body.length() <= MAX_BODY ? body : body.substring(0, MAX_BODY) + "...(" + body.length() + " chars)";
}
}
}
Loading…
Cancel
Save