From d4f334ff29c798301fc277787608ea15150e5402 Mon Sep 17 00:00:00 2001 From: lml <1297555865@qq.com> Date: Thu, 5 Nov 2026 09:50:00 +0800 Subject: [PATCH] =?UTF-8?q?test(lingxing):=20=E5=86=92=E7=83=9F=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=97=A0=E5=B9=B3=E5=8F=B0=E7=A0=81=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=B9=B6=E6=89=93=E5=8D=B0=E7=9C=9F=E5=AE=9E=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - pullsOnePageOfOrders 支持 PLATFORM_CODE 置 null / 0:只按 store_id 查询 - 无码时店铺列表不带 platform_code,返回全部店铺并打印真实 platform_code / platform_name - 无码时业务平台兜底 Platform.CUSTOM,保证能力路由可用 - 凭证改为从环境变量读取,不再硬编码 --- .../lingxing/adapter/LingxingLiveSmokeTest.java | 82 ++++++++++++++++++---- 1 file changed, 70 insertions(+), 12 deletions(-) diff --git a/lingxing/src/test/java/common/ecommerce/lingxing/adapter/LingxingLiveSmokeTest.java b/lingxing/src/test/java/common/ecommerce/lingxing/adapter/LingxingLiveSmokeTest.java index 17b3d3c..0197d7b 100644 --- a/lingxing/src/test/java/common/ecommerce/lingxing/adapter/LingxingLiveSmokeTest.java +++ b/lingxing/src/test/java/common/ecommerce/lingxing/adapter/LingxingLiveSmokeTest.java @@ -68,9 +68,14 @@ class LingxingLiveSmokeTest { // ================================================ /** - * 10008 = Walmart;TikTok 10011、eBay 10003、Amazon SC 10001,按需改。 + * 领星平台码:10008 = Walmart;TikTok 10011、eBay 10003、Amazon SC 10001,按需改。 + * + *

Target / BestBuy / AEPH / Michaels / ECHO / LOS-DLI-US 等平台在领星侧 + * 没有独立平台码。这类平台把本常量置为 {@code null} 或 {@code 0} 即可: + * 请求体不带 {@code platform_code},店铺与订单都只按 {@code store_id} 过滤, + * 业务平台由 {@link #smokePlatform()} 兜底成 {@link Platform#CUSTOM}。

*/ - private static final int PLATFORM_CODE = 10034; + private static final Integer PLATFORM_CODE = 0; private static final String BASE_URL = LingxingConstants.PRODUCTION_BASE_URL; /** @@ -102,12 +107,18 @@ class LingxingLiveSmokeTest { *

订单接口按店铺 id 过滤,而各子平台的 id 口径不同(亚马逊 SC 是数字 {@code sid}, * 多平台是 {@code store_id})。所以这里直接从店铺列表取,和亚马逊 SC/VC 的做法一致; * {@code STORE_ID} 填了则优先用它,仅作为「指定某一家店」的覆盖手段。

+ * + *

没有平台码的平台(Target / BestBuy / AEPH / Michaels / ECHO / + * LOS-DLI-US 等):把 {@link #PLATFORM_CODE} 置为 {@code null} 或 {@code 0}。 + * 此时店铺列表不带 {@code platform_code} 过滤,会返回该领星账号下所有平台的店铺, + * 每行都打印了真实的 {@code platform_code};订单查询只发 {@code store_id}, + * 照样能拉到数据。想固定到某一家店时,从打印结果里挑一个 {@code store_id} + * 填到 {@link #STORE_ID} 即可。

*/ @Test void pullsOnePageOfOrders() { requireCredentials(); LingxingAdapter adapter = adapter(); - List shops = listShops(adapter); String storeId = resolveStoreId(shops); if (storeId == null) { @@ -124,7 +135,7 @@ class LingxingLiveSmokeTest { .pageSize(20) .build()); - System.out.println("[orders] platform_code=" + PLATFORM_CODE + System.out.println("[orders] platform_code=" + platformCodeLabel() + " store_id=" + storeId + " window=" + from + " .. " + to + " items=" + page.size() + " nextCursor=" + page.nextCursor()); @@ -517,16 +528,24 @@ class LingxingLiveSmokeTest { } /** - * 按 platform_code 列店铺,并打印该子平台下已授权的店铺。 + * 按 {@code PLATFORM_CODE} 列店铺,并打印该子平台下已授权的店铺。 + * + *

没有平台码时不带 {@code platform_code} 过滤,会返回该领星账号下所有平台的店铺; + * 每行打印响应里的真实 {@code platform_code},方便挑出目标店铺并回填。

*/ private List listShops(LingxingAdapter adapter) { - ChannelAccount discovery = account(LingxingConstants.toPlatform(LingxingLiveSmokeTest.PLATFORM_CODE), LingxingLiveSmokeTest.PLATFORM_CODE, "0"); + ChannelAccount discovery = account("0"); List shops = adapter.listSubChannels(context(discovery, "smoke-shops-")); - System.out.println("[shops] platform_code=" + LingxingLiveSmokeTest.PLATFORM_CODE + " count=" + shops.size()); + System.out.println("[shops] platform_code=" + platformCodeLabel() + + " count=" + shops.size() + + (hasPlatformCode() ? "" : "(未按平台过滤,返回账号下全部店铺)")); for (SubChannel shop : shops) { + Object platformName = shop.attributes().get("platform_name"); System.out.println(" store_id=" + shop.externalStoreId() - + " name=" + shop.name() - + " platform=" + shop.platform()); + + " platform_code=" + shop.platformCode() + + " platform=" + shop.platform() + + " platform_name=" + (platformName == null ? "-" : platformName) + + " name=" + shop.name()); } return shops; } @@ -551,7 +570,12 @@ class LingxingLiveSmokeTest { System.out.println("[orders] 没有已授权店铺,跳过(也可在 STORE_ID 里直接填 store_id)"); return null; } - return shops.get(0).externalStoreId(); + String storeId = shops.get(0).externalStoreId(); + if (!hasPlatformCode()) { + System.out.println("[orders] 未指定 platform_code,取店铺列表第一条 store_id=" + + storeId + "(真实 platform_code=" + shops.get(0).platformCode() + ")"); + } + return storeId; } private static boolean containsStore(List shops, String storeId) { @@ -607,10 +631,41 @@ class LingxingLiveSmokeTest { } /** + * 是否配置了平台码。{@code null} 与 {@code 0} 都表示领星侧没有独立平台码。 + */ + private static boolean hasPlatformCode() { + return PLATFORM_CODE != null && PLATFORM_CODE != 0; + } + + /** + * 没有平台码时 {@code ChannelAccount.platformCode} 显式传 null, + * 让订单 / 店铺请求体省略 {@code platform_code},只按 {@code store_id} 过滤。 + */ + private static Integer platformCodeOrNull() { + return hasPlatformCode() ? PLATFORM_CODE : null; + } + + /** + * 业务平台:有平台码时按码映射;没有码时兜底 {@link Platform#CUSTOM}。 + * + *

{@code AccountKey} 不接受 null 平台,而且能力路由正是按业务平台选子平台, + * 所以必须有个具体值;{@code CUSTOM} 对应领星自定义平台(10009)的实现, + * 订单与店铺走同一套多平台接口,不影响查询。

+ */ + private static Platform smokePlatform() { + return hasPlatformCode() ? LingxingConstants.toPlatform(PLATFORM_CODE) : Platform.CUSTOM; + } + + /** 日志展示用:无平台码时说明这次只按 store_id 过滤。 */ + private static String platformCodeLabel() { + return hasPlatformCode() ? String.valueOf(PLATFORM_CODE) : "未指定(仅按 store_id 过滤)"; + } + + /** * 按 {@code PLATFORM_CODE} 构造账户,店铺 id 由调用方决定。 */ private ChannelAccount account(String storeId) { - return account(LingxingConstants.toPlatform(PLATFORM_CODE), PLATFORM_CODE, storeId); + return account(smokePlatform(), platformCodeOrNull(), storeId); } private ChannelAccount amazonAccount(String sid) { @@ -625,7 +680,10 @@ class LingxingLiveSmokeTest { return account(Platform.WALMART_SC, 10008, storeId); } - private ChannelAccount account(Platform platform, int platformCode, String storeId) { + /** + * @param platformCode 领星 platform_code;null 表示不带该过滤条件 + */ + private ChannelAccount account(Platform platform, Integer platformCode, String storeId) { return ChannelAccount.builder() .key(AccountKey.of(ChannelProvider.LINGXING, platform, "oms-smoke-001")) .externalStoreId(storeId)