Browse Source
- 新增 MultiPlatformShopSource: /pb/mp/shop/v2/getSellerList,offset/length 内部翻页, 按 platform_code + is_sync/status 过滤 - 新增 WalmartProductSource: /basicOpen/multiplatform/walmart/list,更新时间窗 ≤31 天, 兼容 data.list 与 data[] 两种响应 - WalmartSubPlatform 装配 shopSource / productSource - LingxingApi 增加两个接口枚举,常量补分页与窗口上限 - smoke 增加 Walmart 店铺 → 商品链路 说明: - Walmart 商品接口没有返回更新时间,ProductListing.updatedAt 暂为 null - listing 日期参数文档未标时区,按北京时间解析,待真实报文核对feature/supplier-lingxing
8 changed files with 463 additions and 0 deletions
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
package common.ecommerce.lingxing.platform.multiplatform.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
/** |
||||
* 领星 · 多平台店铺({@code /pb/mp/shop/v2/getSellerList} 的 {@code data.list[]})。 |
||||
* |
||||
* <p>{@code store_id} 是多平台店铺唯一键;{@code sid} 只有亚马逊店铺才有意义。</p> |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public class MultiPlatformShopDto { |
||||
|
||||
/** 店铺 ID,多平台唯一键。 */ |
||||
@JsonProperty("store_id") |
||||
private String storeId; |
||||
|
||||
/** 亚马逊店铺 sid,非亚马逊平台为空。 */ |
||||
@JsonProperty("sid") |
||||
private String sid; |
||||
|
||||
/** 店铺名称。 */ |
||||
@JsonProperty("store_name") |
||||
private String storeName; |
||||
|
||||
/** 平台 code;响应里可能是字符串,用 Integer 接收。 */ |
||||
@JsonProperty("platform_code") |
||||
private Integer platformCode; |
||||
|
||||
/** 平台名称,如 Walmart。 */ |
||||
@JsonProperty("platform_name") |
||||
private String platformName; |
||||
|
||||
/** 店铺币种。 */ |
||||
@JsonProperty("currency") |
||||
private String currency; |
||||
|
||||
/** 店铺同步状态:1 启用、0 停用。 */ |
||||
@JsonProperty("is_sync") |
||||
private Integer isSync; |
||||
|
||||
/** 店铺授权状态:1 正常授权、0 授权失败。 */ |
||||
@JsonProperty("status") |
||||
private Integer status; |
||||
} |
||||
@ -0,0 +1,83 @@
@@ -0,0 +1,83 @@
|
||||
package common.ecommerce.lingxing.platform.multiplatform.shop; |
||||
|
||||
import common.ecommerce.capability.AggregatorCapable.SubChannel; |
||||
import common.ecommerce.http.HttpRequest; |
||||
import common.ecommerce.http.HttpResponse; |
||||
import common.ecommerce.lingxing.LingxingApi; |
||||
import common.ecommerce.lingxing.LingxingConstants; |
||||
import common.ecommerce.lingxing.http.LingxingEnvelope; |
||||
import common.ecommerce.lingxing.platform.LingxingCall; |
||||
import common.ecommerce.lingxing.platform.multiplatform.dto.MultiPlatformShopDto; |
||||
import common.ecommerce.lingxing.platform.shop.LingxingShopSource; |
||||
import common.ecommerce.model.Platform; |
||||
import common.ecommerce.model.account.ChannelAccount; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 领星 · 多平台店铺列表。 |
||||
* |
||||
* <p>接口 {@code /pb/mp/shop/v2/getSellerList}:POST,{@code offset}/{@code length} |
||||
* 分页(上限 200),令牌桶 10 req/s。</p> |
||||
* |
||||
* <p>只返回当前账户 {@code platformCode} 对应的店铺,并过滤为「启用 + 正常授权」。 |
||||
* 响应结构是 {@code data.list[]} + {@code data.total}。</p> |
||||
*/ |
||||
public final class MultiPlatformShopSource implements LingxingShopSource { |
||||
|
||||
private static final int SYNC_ENABLED = 1; |
||||
private static final int STATUS_AUTHORIZED = 1; |
||||
|
||||
private static final String OP = "shops.list.multi"; |
||||
|
||||
@Override |
||||
public List<SubChannel> shops(LingxingCall call) { |
||||
ChannelAccount account = call.ctx().account(); |
||||
int length = LingxingConstants.MULTI_PLATFORM_MAX_PAGE_SIZE; |
||||
int offset = 0; |
||||
List<SubChannel> out = new ArrayList<SubChannel>(); |
||||
|
||||
while (true) { |
||||
Map<String, Object> body = new LinkedHashMap<String, Object>(); |
||||
body.put("offset", offset); |
||||
body.put("length", length); |
||||
body.put("is_sync", SYNC_ENABLED); |
||||
body.put("status", STATUS_AUTHORIZED); |
||||
if (account.platformCode() != null) { |
||||
body.put("platform_code", Collections.singletonList(account.platformCode())); |
||||
} |
||||
|
||||
HttpRequest req = call.signed(LingxingApi.SHOP_LIST_MULTI_PLATFORM, body, OP); |
||||
HttpResponse resp = call.execute(req); |
||||
LingxingEnvelope envelope = call.envelope(resp, OP); |
||||
|
||||
List<MultiPlatformShopDto> shops = |
||||
call.json().listAt(envelope.body(), "data.list", MultiPlatformShopDto.class); |
||||
for (MultiPlatformShopDto shop : shops) { |
||||
if (shop.getStoreId() == null || shop.getStoreId().trim().isEmpty()) { |
||||
continue; |
||||
} |
||||
Integer code = shop.getPlatformCode(); |
||||
Platform platform = LingxingConstants.toPlatform(code); |
||||
out.add(new SubChannel( |
||||
code == null ? 0 : code, |
||||
shop.getStoreId(), |
||||
platform == null ? Platform.CUSTOM : platform, |
||||
shop.getStoreName())); |
||||
} |
||||
|
||||
offset += shops.size(); |
||||
boolean exhausted = shops.size() < length |
||||
|| (envelope.total() >= 0 && offset >= envelope.total()); |
||||
if (exhausted) { |
||||
break; |
||||
} |
||||
} |
||||
|
||||
return Collections.unmodifiableList(out); |
||||
} |
||||
} |
||||
@ -0,0 +1,99 @@
@@ -0,0 +1,99 @@
|
||||
package common.ecommerce.lingxing.platform.walmart.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
/** |
||||
* 领星 · Walmart 在线商品 |
||||
* ({@code /basicOpen/multiplatform/walmart/list} 的 {@code data[]} / {@code data.list[]})。 |
||||
* |
||||
* <p>平台 SKU 是 {@code msku};{@code item_id} 是 Walmart 商品 ID。</p> |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public class WalmartListingDto { |
||||
|
||||
/** 产品跳转链接。 */ |
||||
@JsonProperty("item_url") |
||||
private String itemUrl; |
||||
|
||||
/** Walmart 商品 ID。 */ |
||||
@JsonProperty("item_id") |
||||
private String itemId; |
||||
|
||||
/** 图片链接。 */ |
||||
@JsonProperty("picture_url") |
||||
private String pictureUrl; |
||||
|
||||
/** 平台 MSKU,参与 canonicalKey。 */ |
||||
@JsonProperty("msku") |
||||
private String msku; |
||||
|
||||
@JsonProperty("title") |
||||
private String title; |
||||
|
||||
/** 领星本地品名。 */ |
||||
@JsonProperty("local_name") |
||||
private String localName; |
||||
|
||||
/** 领星本地 SKU。 */ |
||||
@JsonProperty("local_sku") |
||||
private String localSku; |
||||
|
||||
/** 状态名:PUBLISHED / READY TO PUBLISH / IN PROGRESS / UNPUBLISHED 等。 */ |
||||
@JsonProperty("status_name") |
||||
private String statusName; |
||||
|
||||
@JsonProperty("store_id") |
||||
private String storeId; |
||||
|
||||
@JsonProperty("store_name") |
||||
private String storeName; |
||||
|
||||
@JsonProperty("currency_icon") |
||||
private String currencyIcon; |
||||
|
||||
@JsonProperty("price") |
||||
private String price; |
||||
|
||||
/** 非 WFS 可售数量。 */ |
||||
@JsonProperty("available_quantity") |
||||
private Integer availableQuantity; |
||||
|
||||
/** WFS 可售数量。 */ |
||||
@JsonProperty("wfs_available_quantity") |
||||
private Integer wfsAvailableQuantity; |
||||
|
||||
@JsonProperty("buy_box_price") |
||||
private String buyBoxPrice; |
||||
|
||||
@JsonProperty("gtin") |
||||
private String gtin; |
||||
|
||||
@JsonProperty("upc") |
||||
private String upc; |
||||
|
||||
@JsonProperty("brand") |
||||
private String brand; |
||||
|
||||
/** 发货方式:0 WFS Eligible、1 Walmart Fulfilled、2 Seller Fulfilled。 */ |
||||
@JsonProperty("fulfillment_type") |
||||
private Integer fulfillmentType; |
||||
|
||||
@JsonProperty("fulfillment_type_name") |
||||
private String fulfillmentTypeName; |
||||
|
||||
/** 创建时间。 */ |
||||
@JsonProperty("listing_start_time") |
||||
private String listingStartTime; |
||||
|
||||
/** 销售结束时间。 */ |
||||
@JsonProperty("listing_end_time") |
||||
private String listingEndTime; |
||||
|
||||
@JsonProperty("variant_unique_id") |
||||
private String variantUniqueId; |
||||
} |
||||
@ -0,0 +1,146 @@
@@ -0,0 +1,146 @@
|
||||
package common.ecommerce.lingxing.platform.walmart.product; |
||||
|
||||
import common.ecommerce.http.HttpRequest; |
||||
import common.ecommerce.http.HttpResponse; |
||||
import common.ecommerce.lingxing.LingxingApi; |
||||
import common.ecommerce.lingxing.LingxingConstants; |
||||
import common.ecommerce.lingxing.http.LingxingEnvelope; |
||||
import common.ecommerce.lingxing.platform.LingxingCall; |
||||
import common.ecommerce.lingxing.platform.product.LingxingProductSource; |
||||
import common.ecommerce.lingxing.platform.walmart.dto.WalmartListingDto; |
||||
import common.ecommerce.model.ChannelProvider; |
||||
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.model.support.PlatformTime; |
||||
|
||||
import java.time.Instant; |
||||
import java.time.LocalDate; |
||||
import java.time.LocalDateTime; |
||||
import java.time.ZoneId; |
||||
import java.time.format.DateTimeFormatter; |
||||
import java.time.temporal.ChronoUnit; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 领星 · Walmart 在线商品。 |
||||
* |
||||
* <p>接口 {@code /basicOpen/multiplatform/walmart/list}:POST,{@code offset}/{@code length} |
||||
* 分页(上限 200),令牌桶 1 req/s;时间窗按「创建时间 / 更新时间」过滤,最多 31 天。</p> |
||||
* |
||||
* <p>响应有两种形态:文档字段树写 {@code data.list[]},示例又给 {@code data[]}, |
||||
* 这里先按 {@code data.list} 解析,为空再回退 {@code data},两种都能吃。</p> |
||||
* |
||||
* <p><b>时区待核对</b>:{@code listing_start_time}/{@code listing_end_time} 只到日期且未标时区, |
||||
* 这里按领星系统时间(北京时间)换算。</p> |
||||
*/ |
||||
public final class WalmartProductSource implements LingxingProductSource { |
||||
|
||||
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
||||
|
||||
/** 文档未注明时区,按 ERP 系统时间(北京时间)解释,待真实报文核对。 */ |
||||
private static final ZoneId SYSTEM_ZONE = PlatformTime.BEIJING_ZONE; |
||||
|
||||
/** listing_time_field:2 = 更新时间。 */ |
||||
private static final int TIME_FIELD_UPDATE = 2; |
||||
|
||||
private static final String OP = "products.pull.walmart"; |
||||
|
||||
@Override |
||||
public Page<ProductListing> products(LingxingCall call, ProductQuery query) { |
||||
ChannelAccount account = call.ctx().account(); |
||||
|
||||
int length = Math.min(query.pageSize() <= 0 ? 20 : query.pageSize(), |
||||
LingxingConstants.WALMART_MAX_PAGE_SIZE); |
||||
int offset = query.cursor() == null ? 0 : Integer.parseInt(query.cursor()); |
||||
|
||||
Map<String, Object> body = new LinkedHashMap<String, Object>(); |
||||
body.put("offset", offset); |
||||
body.put("length", length); |
||||
if (trimToNull(account.externalStoreId()) != null) { |
||||
body.put("store_ids", Collections.singletonList(account.externalStoreId().trim())); |
||||
} |
||||
|
||||
Instant from = query.updatedAfter(); |
||||
if (from != null) { |
||||
LocalDate endDate = query.updatedBefore() != null |
||||
? LocalDateTime.ofInstant(query.updatedBefore(), SYSTEM_ZONE).toLocalDate() |
||||
: LocalDateTime.ofInstant(Instant.now(call.ctx().clock()), SYSTEM_ZONE).toLocalDate(); |
||||
LocalDate startDate = LocalDateTime.ofInstant(from, SYSTEM_ZONE).toLocalDate(); |
||||
// 文档:开始结束时间不超过 31 天,双闭区间
|
||||
if (ChronoUnit.DAYS.between(startDate, endDate) > LingxingConstants.WALMART_MAX_QUERY_DAYS) { |
||||
startDate = endDate.minusDays(LingxingConstants.WALMART_MAX_QUERY_DAYS); |
||||
} |
||||
body.put("listing_time_field", TIME_FIELD_UPDATE); |
||||
body.put("listing_start_time", DATE.format(startDate)); |
||||
body.put("listing_end_time", DATE.format(endDate)); |
||||
} |
||||
|
||||
HttpRequest req = call.signed(LingxingApi.LISTING_WALMART, body, OP); |
||||
HttpResponse resp = call.execute(req); |
||||
LingxingEnvelope envelope = call.envelope(resp, OP); |
||||
|
||||
List<WalmartListingDto> dtos = call.json().listAt(envelope.body(), "data.list", WalmartListingDto.class); |
||||
if (dtos.isEmpty()) { |
||||
dtos = call.json().listAt(envelope.body(), "data", WalmartListingDto.class); |
||||
} |
||||
|
||||
List<ProductListing> out = new ArrayList<ProductListing>(dtos.size()); |
||||
for (WalmartListingDto dto : dtos) { |
||||
ProductListing listing = toProductListing(dto, call); |
||||
if (listing != null) { |
||||
out.add(listing); |
||||
} |
||||
} |
||||
|
||||
int nextOffset = offset + dtos.size(); |
||||
boolean hasMore = dtos.size() >= length |
||||
&& (envelope.total() < 0 || nextOffset < envelope.total()); |
||||
return Page.of(out, hasMore ? String.valueOf(nextOffset) : null); |
||||
} |
||||
|
||||
private ProductListing toProductListing(WalmartListingDto dto, LingxingCall call) { |
||||
// MSKU 是平台 SKU;缺失时退回商品 ID / 本地 SKU
|
||||
String platformSku = firstNonBlank(dto.getMsku(), dto.getItemId(), dto.getLocalSku()); |
||||
if (platformSku == null) { |
||||
return null; |
||||
} |
||||
List<String> images = trimToNull(dto.getPictureUrl()) == null |
||||
? Collections.<String>emptyList() |
||||
: Collections.singletonList(dto.getPictureUrl().trim()); |
||||
|
||||
return ProductListing.builder() |
||||
.omsStoreId(call.ctx().omsStoreId()) |
||||
.platformSku(platformSku) |
||||
.title(firstNonBlank(dto.getTitle(), dto.getLocalName())) |
||||
.imageUrls(images) |
||||
.status(trimToNull(dto.getStatusName())) |
||||
// 接口没有返回更新时间;listing_start_time 是创建时间,不能冒充更新时间
|
||||
.updatedAt(null) |
||||
.sourceProvider(ChannelProvider.LINGXING) |
||||
.build(); |
||||
} |
||||
|
||||
private static String firstNonBlank(String... values) { |
||||
for (String value : values) { |
||||
String trimmed = trimToNull(value); |
||||
if (trimmed != null) { |
||||
return trimmed; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
private static String trimToNull(String value) { |
||||
if (value == null) { |
||||
return null; |
||||
} |
||||
String trimmed = value.trim(); |
||||
return trimmed.isEmpty() ? null : trimmed; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue