Browse Source
接口(官方文档核对): - SHOP_LIST_AMAZON_VC /basicOpen/platformAuth/vcSeller/pageList POST, qps 1, 上限 200 - LISTING_AMAZON_VC /basicOpen/listingManage/vcListing/pageList POST, qps 1, 上限 200 实现: - AmazonVcShopSource:自动翻页拉全部店铺,过滤 status != 1,platform_code 10035, externalStoreId 取 vc_store_id - AmazonVcProductSource:vc_store_ids 传数组;msku 作为 platformSku; on_sale_time 是 Y-m-d,按市场当地时区零点解析 - AmazonVcSubPlatform 注册到 LingxingSubPlatforms 注意:VC Listing 接口无时间窗参数,只能全量翻页后由调用方比对。 Co-Authored-By: Claude <noreply@anthropic.com>feature/supplier-lingxing
7 changed files with 339 additions and 0 deletions
@ -0,0 +1,101 @@ |
|||||||
|
package common.ecommerce.lingxing.platform.amazon.vc; |
||||||
|
|
||||||
|
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.amazon.vc.dto.AmazonVcListingDto; |
||||||
|
import common.ecommerce.lingxing.platform.product.LingxingProductSource; |
||||||
|
import common.ecommerce.model.ChannelProvider; |
||||||
|
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.ZoneId; |
||||||
|
import java.time.format.DateTimeFormatter; |
||||||
|
import java.time.format.DateTimeParseException; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collections; |
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* 领星 · 亚马逊 VC 商品 / Listing 列表。 |
||||||
|
* |
||||||
|
* <p>接口 {@code /basicOpen/listingManage/vcListing/pageList}:POST, |
||||||
|
* {@code offset}/{@code length} 分页(上限 200),{@code vc_store_ids} 为数组; |
||||||
|
* 令牌桶容量 1。</p> |
||||||
|
* |
||||||
|
* <p>注意:该接口<b>不支持按时间窗过滤</b>,只能全量翻页后由调用方比对。</p> |
||||||
|
*/ |
||||||
|
public final class AmazonVcProductSource implements LingxingProductSource { |
||||||
|
|
||||||
|
private static final int MAX_PAGE_SIZE = 200; |
||||||
|
|
||||||
|
/** on_sale_time 是 Y-m-d 日期。 */ |
||||||
|
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
||||||
|
|
||||||
|
@Override |
||||||
|
public Page<ProductListing> products(LingxingCall call, ProductQuery query) { |
||||||
|
int length = Math.min(query.pageSize() <= 0 ? 20 : query.pageSize(), MAX_PAGE_SIZE); |
||||||
|
int offset = query.cursor() == null ? 0 : Integer.parseInt(query.cursor()); |
||||||
|
|
||||||
|
Map<String, Object> body = new LinkedHashMap<String, Object>(); |
||||||
|
body.put("offset", offset); |
||||||
|
body.put("length", length); |
||||||
|
body.put("vc_store_ids", |
||||||
|
Collections.singletonList(call.ctx().account().externalStoreId())); |
||||||
|
|
||||||
|
HttpRequest req = call.signed(LingxingApi.LISTING_AMAZON_VC, body, "products.pull"); |
||||||
|
HttpResponse resp = call.execute(req); |
||||||
|
LingxingEnvelope envelope = call.envelope(resp, "products.pull"); |
||||||
|
|
||||||
|
List<AmazonVcListingDto> dtos = call.json().listAt(envelope.body(), "data", AmazonVcListingDto.class); |
||||||
|
List<ProductListing> out = new ArrayList<ProductListing>(dtos.size()); |
||||||
|
for (AmazonVcListingDto dto : dtos) { |
||||||
|
out.add(toProductListing(dto, call)); |
||||||
|
} |
||||||
|
|
||||||
|
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(AmazonVcListingDto dto, LingxingCall call) { |
||||||
|
List<String> images = dto.getSmallMinImageUrl() == null |
||||||
|
? Collections.<String>emptyList() |
||||||
|
: Collections.singletonList(dto.getSmallMinImageUrl()); |
||||||
|
|
||||||
|
return ProductListing.builder() |
||||||
|
.omsStoreId(call.ctx().omsStoreId()) |
||||||
|
// msku 是平台侧 SKU,参与 canonicalKey
|
||||||
|
.platformSku(dto.getMsku()) |
||||||
|
.title(dto.getItemName()) |
||||||
|
.imageUrls(images) |
||||||
|
// -1 已删除 / 0 停售 / 1 在售;保留原值,由宿主解释
|
||||||
|
.status(dto.getStatus() == null ? null : String.valueOf(dto.getStatus())) |
||||||
|
.updatedAt(onSaleTime(dto.getOnSaleTime(), call)) |
||||||
|
.sourceProvider(ChannelProvider.LINGXING) |
||||||
|
.build(); |
||||||
|
} |
||||||
|
|
||||||
|
/** on_sale_time 只有日期,按市场当地时区零点解析;缺失或非法时返回 null。 */ |
||||||
|
private static PlatformTime onSaleTime(String raw, LingxingCall call) { |
||||||
|
if (raw == null || raw.trim().isEmpty()) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
try { |
||||||
|
ZoneId zone = ZoneId.of(call.ctx().account().marketplaceZone()); |
||||||
|
Instant utc = LocalDate.parse(raw.trim(), DATE).atStartOfDay(zone).toInstant(); |
||||||
|
return PlatformTime.of(utc, zone); |
||||||
|
} catch (DateTimeParseException e) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,70 @@ |
|||||||
|
package common.ecommerce.lingxing.platform.amazon.vc; |
||||||
|
|
||||||
|
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.http.LingxingEnvelope; |
||||||
|
import common.ecommerce.lingxing.platform.LingxingCall; |
||||||
|
import common.ecommerce.lingxing.platform.amazon.vc.dto.AmazonVcShopDto; |
||||||
|
import common.ecommerce.lingxing.platform.shop.LingxingShopSource; |
||||||
|
import common.ecommerce.model.Platform; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collections; |
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* 领星 · 亚马逊 VC 店铺列表。 |
||||||
|
* |
||||||
|
* <p>接口 {@code /basicOpen/platformAuth/vcSeller/pageList}:POST,{@code offset}/{@code length} |
||||||
|
* 分页,{@code length} 上限 200,令牌桶容量 1。</p> |
||||||
|
*/ |
||||||
|
public final class AmazonVcShopSource implements LingxingShopSource { |
||||||
|
|
||||||
|
/** 领星侧 Amazon VC 的 platform_code。 */ |
||||||
|
private static final int AMAZON_VC_PLATFORM_CODE = 10035; |
||||||
|
|
||||||
|
/** 店铺授权服务状态:1 = 正常同步。 */ |
||||||
|
private static final int STATUS_ACTIVE = 1; |
||||||
|
|
||||||
|
private static final int MAX_PAGE_SIZE = 200; |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<SubChannel> shops(LingxingCall call) { |
||||||
|
List<SubChannel> out = new ArrayList<SubChannel>(); |
||||||
|
int offset = 0; |
||||||
|
while (true) { |
||||||
|
Map<String, Object> body = new LinkedHashMap<String, Object>(); |
||||||
|
body.put("offset", offset); |
||||||
|
body.put("length", MAX_PAGE_SIZE); |
||||||
|
|
||||||
|
HttpRequest req = call.signed(LingxingApi.SHOP_LIST_AMAZON_VC, body, "shops.list"); |
||||||
|
HttpResponse resp = call.execute(req); |
||||||
|
LingxingEnvelope envelope = call.envelope(resp, "shops.list"); |
||||||
|
|
||||||
|
List<AmazonVcShopDto> page = call.json().listAt(envelope.body(), "data", AmazonVcShopDto.class); |
||||||
|
for (AmazonVcShopDto shop : page) { |
||||||
|
if (shop.getVcStoreId() == null || shop.getStatus() == null |
||||||
|
|| shop.getStatus() != STATUS_ACTIVE) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
out.add(new SubChannel( |
||||||
|
AMAZON_VC_PLATFORM_CODE, |
||||||
|
shop.getVcStoreId(), |
||||||
|
Platform.AMAZON_VC, |
||||||
|
shop.getName() == null ? shop.getSellerId() : shop.getName())); |
||||||
|
} |
||||||
|
|
||||||
|
offset += page.size(); |
||||||
|
boolean hasMore = page.size() >= MAX_PAGE_SIZE |
||||||
|
&& (envelope.total() < 0 || offset < envelope.total()); |
||||||
|
if (!hasMore) { |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
return Collections.unmodifiableList(out); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,37 @@ |
|||||||
|
package common.ecommerce.lingxing.platform.amazon.vc; |
||||||
|
|
||||||
|
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.shop.LingxingShopSource; |
||||||
|
import common.ecommerce.model.Platform; |
||||||
|
|
||||||
|
/** |
||||||
|
* 领星 · 亚马逊 VC 子平台:只做能力组合,不写业务逻辑。 |
||||||
|
*/ |
||||||
|
public final class AmazonVcSubPlatform implements LingxingSubPlatform { |
||||||
|
|
||||||
|
private final LingxingProductSource products; |
||||||
|
private final LingxingShopSource shops; |
||||||
|
|
||||||
|
public AmazonVcSubPlatform(HttpTransport transport, JacksonJsonCodec json) { |
||||||
|
this.products = new AmazonVcProductSource(); |
||||||
|
this.shops = new AmazonVcShopSource(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Platform platform() { |
||||||
|
return Platform.AMAZON_VC; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public LingxingProductSource productSource() { |
||||||
|
return products; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public LingxingShopSource shopSource() { |
||||||
|
return shops; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,70 @@ |
|||||||
|
package common.ecommerce.lingxing.platform.amazon.vc.dto; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
|
||||||
|
/** |
||||||
|
* 领星 · 亚马逊 VC Listing({@code /basicOpen/listingManage/vcListing/pageList} 的 {@code data[]})。 |
||||||
|
* |
||||||
|
* <p>只保留映射到统一模型所需的字段。VC 的 SKU 字段是 {@code msku}(平台侧), |
||||||
|
* 本地 SKU 是 {@code local_sku},对齐直连时应优先用 {@code msku}。</p> |
||||||
|
*/ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true) |
||||||
|
public class AmazonVcListingDto { |
||||||
|
|
||||||
|
/** VC 店铺 id。 */ |
||||||
|
@JsonProperty("vc_store_id") |
||||||
|
private String vcStoreId; |
||||||
|
|
||||||
|
/** 在线商品缩略图地址。 */ |
||||||
|
@JsonProperty("small_min_image_url") |
||||||
|
private String smallMinImageUrl; |
||||||
|
|
||||||
|
/** ASIN。 */ |
||||||
|
@JsonProperty("asin") |
||||||
|
private String asin; |
||||||
|
|
||||||
|
/** 平台 SKU(MSKU),参与 canonicalKey。 */ |
||||||
|
@JsonProperty("msku") |
||||||
|
private String msku; |
||||||
|
|
||||||
|
/** 标题。 */ |
||||||
|
@JsonProperty("item_name") |
||||||
|
private String itemName; |
||||||
|
|
||||||
|
/** 父 ASIN,可能为空串。 */ |
||||||
|
@JsonProperty("parent_asin") |
||||||
|
private String parentAsin; |
||||||
|
|
||||||
|
/** 本地 SKU。 */ |
||||||
|
@JsonProperty("local_sku") |
||||||
|
private String localSku; |
||||||
|
|
||||||
|
/** 本地品名。 */ |
||||||
|
@JsonProperty("local_name") |
||||||
|
private String localName; |
||||||
|
|
||||||
|
/** 在线商品状态:-1 已删除,0 停售,1 在售。 */ |
||||||
|
@JsonProperty("status") |
||||||
|
private Integer status; |
||||||
|
|
||||||
|
/** 优惠金额。 */ |
||||||
|
@JsonProperty("price") |
||||||
|
private String price; |
||||||
|
|
||||||
|
/** 优惠金额货币符号,如 $。 */ |
||||||
|
@JsonProperty("price_currency_icon") |
||||||
|
private String priceCurrencyIcon; |
||||||
|
|
||||||
|
/** 开售时间,格式 {@code Y-m-d}。 */ |
||||||
|
@JsonProperty("on_sale_time") |
||||||
|
private String onSaleTime; |
||||||
|
|
||||||
|
/** 备注。 */ |
||||||
|
@JsonProperty("remark") |
||||||
|
private String remark; |
||||||
|
} |
||||||
@ -0,0 +1,53 @@ |
|||||||
|
package common.ecommerce.lingxing.platform.amazon.vc.dto; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
|
||||||
|
/** |
||||||
|
* 领星 · 亚马逊 VC 店铺({@code /basicOpen/platformAuth/vcSeller/pageList} 的 {@code data[]})。 |
||||||
|
* |
||||||
|
* <p>唯一键 {@code vc_store_id},后续查 VC Listing 时用它指定店铺。</p> |
||||||
|
*/ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true) |
||||||
|
public class AmazonVcShopDto { |
||||||
|
|
||||||
|
/** 账号 ID。 */ |
||||||
|
@JsonProperty("account_id") |
||||||
|
private Long accountId; |
||||||
|
|
||||||
|
/** SELLER_ID。 */ |
||||||
|
@JsonProperty("seller_id") |
||||||
|
private String sellerId; |
||||||
|
|
||||||
|
/** 账号名称。 */ |
||||||
|
@JsonProperty("account_name") |
||||||
|
private String accountName; |
||||||
|
|
||||||
|
/** 站点简称,如 na。 */ |
||||||
|
@JsonProperty("region") |
||||||
|
private String region; |
||||||
|
|
||||||
|
/** 站点名称,如 北美洲。 */ |
||||||
|
@JsonProperty("region_name") |
||||||
|
private String regionName; |
||||||
|
|
||||||
|
/** VC 店铺 id,后续接口的入参。 */ |
||||||
|
@JsonProperty("vc_store_id") |
||||||
|
private String vcStoreId; |
||||||
|
|
||||||
|
/** 店铺名称。 */ |
||||||
|
@JsonProperty("name") |
||||||
|
private String name; |
||||||
|
|
||||||
|
/** 店铺授权服务状态:-1 删除,0 暂停同步,1 正常同步,2 授权异常。 */ |
||||||
|
@JsonProperty("status") |
||||||
|
private Integer status; |
||||||
|
|
||||||
|
/** 站点 id。 */ |
||||||
|
@JsonProperty("mid") |
||||||
|
private Integer mid; |
||||||
|
} |
||||||
Loading…
Reference in new issue