|
|
|
@ -10,6 +10,8 @@ import common.ecommerce.lingxing.platform.product.LingxingProductSource; |
|
|
|
import common.ecommerce.model.ChannelProvider; |
|
|
|
import common.ecommerce.model.ChannelProvider; |
|
|
|
import common.ecommerce.model.product.ProductListing; |
|
|
|
import common.ecommerce.model.product.ProductListing; |
|
|
|
import common.ecommerce.model.product.ProductQuery; |
|
|
|
import common.ecommerce.model.product.ProductQuery; |
|
|
|
|
|
|
|
import common.ecommerce.model.product.ProductStatus; |
|
|
|
|
|
|
|
import common.ecommerce.model.support.Money; |
|
|
|
import common.ecommerce.model.support.Page; |
|
|
|
import common.ecommerce.model.support.Page; |
|
|
|
import common.ecommerce.model.support.PlatformTime; |
|
|
|
import common.ecommerce.model.support.PlatformTime; |
|
|
|
|
|
|
|
|
|
|
|
@ -38,6 +40,8 @@ public final class AmazonScProductSource implements LingxingProductSource { |
|
|
|
/** listing_update_date 是零时区时间,格式 Y-m-d H:i:s。 */ |
|
|
|
/** listing_update_date 是零时区时间,格式 Y-m-d H:i:s。 */ |
|
|
|
private static final DateTimeFormatter LISTING_TIME = |
|
|
|
private static final DateTimeFormatter LISTING_TIME = |
|
|
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
|
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
|
|
/** 只有日期的字段,如 on_sale_time / first_order_time。 */ |
|
|
|
|
|
|
|
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Page<ProductListing> products(LingxingCall call, ProductQuery query) { |
|
|
|
public Page<ProductListing> products(LingxingCall call, ProductQuery query) { |
|
|
|
@ -50,7 +54,6 @@ public final class AmazonScProductSource implements LingxingProductSource { |
|
|
|
body.put("length", length); |
|
|
|
body.put("length", length); |
|
|
|
Instant from = query.updatedAfter(); |
|
|
|
Instant from = query.updatedAfter(); |
|
|
|
if (from != null) { |
|
|
|
if (from != null) { |
|
|
|
// 网关要求零时区时间字符串
|
|
|
|
|
|
|
|
body.put("listing_update_start_time", LISTING_TIME.format( |
|
|
|
body.put("listing_update_start_time", LISTING_TIME.format( |
|
|
|
LocalDateTime.ofInstant(from, ZoneOffset.UTC))); |
|
|
|
LocalDateTime.ofInstant(from, ZoneOffset.UTC))); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -76,34 +79,154 @@ public final class AmazonScProductSource implements LingxingProductSource { |
|
|
|
return Page.of(out, hasMore ? String.valueOf(nextOffset) : null); |
|
|
|
return Page.of(out, hasMore ? String.valueOf(nextOffset) : null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 领星 SC Listing → 统一模型。 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p>统一字段的来源:</p> |
|
|
|
|
|
|
|
* <ul> |
|
|
|
|
|
|
|
* <li>platformSku ← {@code seller_sku}(平台 MSKU)</li> |
|
|
|
|
|
|
|
* <li>listingId ← {@code listing_id}</li> |
|
|
|
|
|
|
|
* <li>asin / parentAsin ← {@code asin} / {@code parent_asin}</li> |
|
|
|
|
|
|
|
* <li>gtin ← 无(SC 接口不返回 UPC/EAN)</li> |
|
|
|
|
|
|
|
* <li>title ← {@code item_name}</li> |
|
|
|
|
|
|
|
* <li>imageUrls ← {@code small_image_url}(单张)</li> |
|
|
|
|
|
|
|
* <li>status ← {@code status}(0 停售 / 1 在售),{@code is_delete=1} 时视为已删除</li> |
|
|
|
|
|
|
|
* <li>rawStatus ← 原始 {@code status} 值</li> |
|
|
|
|
|
|
|
* <li>price / currency ← {@code price} / {@code currency_code}</li> |
|
|
|
|
|
|
|
* <li>listedAt ← {@code on_sale_time}(仅日期)</li> |
|
|
|
|
|
|
|
* <li>updatedAt ← {@code listing_update_date}(零时区)</li> |
|
|
|
|
|
|
|
* <li>attributes ← 其余全部原始字段(本地 SKU、库存、费用、排名、尺寸等)</li> |
|
|
|
|
|
|
|
* </ul> |
|
|
|
|
|
|
|
*/ |
|
|
|
private ProductListing toProductListing(AmazonScListingDto dto, LingxingCall call) { |
|
|
|
private ProductListing toProductListing(AmazonScListingDto dto, LingxingCall call) { |
|
|
|
List<String> images = dto.getSmallImageUrl() == null |
|
|
|
String currency = trimToNull(dto.getCurrencyCode()); |
|
|
|
? Collections.<String>emptyList() |
|
|
|
ZoneId zone = ZoneId.of(call.ctx().account().marketplaceZone()); |
|
|
|
: Collections.singletonList(dto.getSmallImageUrl()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ProductListing.builder() |
|
|
|
return ProductListing.builder() |
|
|
|
|
|
|
|
.platform(call.ctx().platform()) |
|
|
|
.omsStoreId(call.ctx().omsStoreId()) |
|
|
|
.omsStoreId(call.ctx().omsStoreId()) |
|
|
|
// seller_sku 是平台侧 SKU,参与 canonicalKey
|
|
|
|
|
|
|
|
.platformSku(dto.getSellerSku()) |
|
|
|
.platformSku(dto.getSellerSku()) |
|
|
|
|
|
|
|
.listingId(trimToNull(dto.getListingId())) |
|
|
|
|
|
|
|
.asin(trimToNull(dto.getAsin())) |
|
|
|
|
|
|
|
.parentAsin(trimToNull(dto.getParentAsin())) |
|
|
|
.title(dto.getItemName()) |
|
|
|
.title(dto.getItemName()) |
|
|
|
.imageUrls(images) |
|
|
|
.imageUrls(dto.getSmallImageUrl() == null |
|
|
|
// 0 停售 / 1 在售;保留原值,由宿主解释
|
|
|
|
? Collections.<String>emptyList() |
|
|
|
.status(dto.getStatus() == null ? null : String.valueOf(dto.getStatus())) |
|
|
|
: Collections.singletonList(dto.getSmallImageUrl())) |
|
|
|
.updatedAt(listingTime(dto.getListingUpdateDate(), call)) |
|
|
|
.status(statusOf(dto)) |
|
|
|
|
|
|
|
.rawStatus(dto.getStatus() == null ? null : String.valueOf(dto.getStatus())) |
|
|
|
|
|
|
|
.price(moneyOrNull(dto.getPrice(), currency)) |
|
|
|
|
|
|
|
.currency(currency) |
|
|
|
|
|
|
|
.listedAt(dateTime(dto.getOnSaleTime(), zone, true)) |
|
|
|
|
|
|
|
.updatedAt(dateTime(dto.getListingUpdateDate(), zone, false)) |
|
|
|
|
|
|
|
.attributes(attributesOf(dto)) |
|
|
|
.sourceProvider(ChannelProvider.LINGXING) |
|
|
|
.sourceProvider(ChannelProvider.LINGXING) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 报表更新时间是零时区时间,按 UTC 解析;缺失时返回 null。 */ |
|
|
|
/** is_delete=1 优先判为已删除;否则按 status 映射。 */ |
|
|
|
private static PlatformTime listingTime(String raw, LingxingCall call) { |
|
|
|
private static ProductStatus statusOf(AmazonScListingDto dto) { |
|
|
|
|
|
|
|
if (dto.getIsDelete() != null && dto.getIsDelete() == 1) { |
|
|
|
|
|
|
|
return ProductStatus.DELETED; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (dto.getStatus() == null) { |
|
|
|
|
|
|
|
return ProductStatus.UNKNOWN; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
switch (dto.getStatus()) { |
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
return ProductStatus.ACTIVE; |
|
|
|
|
|
|
|
case 0: |
|
|
|
|
|
|
|
return ProductStatus.INACTIVE; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return ProductStatus.UNKNOWN; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 未标准化的原始字段统一放进 attributes,键名与领星一致。 */ |
|
|
|
|
|
|
|
private static Map<String, Object> attributesOf(AmazonScListingDto dto) { |
|
|
|
|
|
|
|
Map<String, Object> attrs = new LinkedHashMap<String, Object>(); |
|
|
|
|
|
|
|
attrs.put("sid", dto.getSid()); |
|
|
|
|
|
|
|
attrs.put("fnsku", dto.getFnsku()); |
|
|
|
|
|
|
|
attrs.put("local_sku", dto.getLocalSku()); |
|
|
|
|
|
|
|
attrs.put("local_name", dto.getLocalName()); |
|
|
|
|
|
|
|
attrs.put("remark", dto.getRemark()); |
|
|
|
|
|
|
|
attrs.put("list_price", dto.getListPrice()); |
|
|
|
|
|
|
|
attrs.put("landed_price", dto.getLandedPrice()); |
|
|
|
|
|
|
|
attrs.put("listing_price", dto.getListingPrice()); |
|
|
|
|
|
|
|
attrs.put("shipping", dto.getShipping()); |
|
|
|
|
|
|
|
attrs.put("points", dto.getPoints()); |
|
|
|
|
|
|
|
attrs.put("quantity", dto.getQuantity()); |
|
|
|
|
|
|
|
attrs.put("afn_fulfillable_quantity", dto.getAfnFulfillableQuantity()); |
|
|
|
|
|
|
|
attrs.put("afn_unsellable_quantity", dto.getAfnUnsellableQuantity()); |
|
|
|
|
|
|
|
attrs.put("reserved_fc_transfers", dto.getReservedFcTransfers()); |
|
|
|
|
|
|
|
attrs.put("reserved_fc_processing", dto.getReservedFcProcessing()); |
|
|
|
|
|
|
|
attrs.put("reserved_customerorders", dto.getReservedCustomerorders()); |
|
|
|
|
|
|
|
attrs.put("afn_inbound_shipped_quantity", dto.getAfnInboundShippedQuantity()); |
|
|
|
|
|
|
|
attrs.put("afn_inbound_working_quantity", dto.getAfnInboundWorkingQuantity()); |
|
|
|
|
|
|
|
attrs.put("afn_inbound_receiving_quantity", dto.getAfnInboundReceivingQuantity()); |
|
|
|
|
|
|
|
attrs.put("fba_fee", dto.getFbaFee()); |
|
|
|
|
|
|
|
attrs.put("fba_fee_update_time", dto.getFbaFeeUpdateTime()); |
|
|
|
|
|
|
|
attrs.put("report_fba_fee", dto.getReportFbaFee()); |
|
|
|
|
|
|
|
attrs.put("report_fba_fee_update_time", dto.getReportFbaFeeUpdateTime()); |
|
|
|
|
|
|
|
attrs.put("estimated_referral_fee", dto.getEstimatedReferralFee()); |
|
|
|
|
|
|
|
attrs.put("estimated_referral_fee_rate", dto.getEstimatedReferralFeeRate()); |
|
|
|
|
|
|
|
attrs.put("seller_brand", dto.getSellerBrand()); |
|
|
|
|
|
|
|
attrs.put("seller_category", dto.getSellerCategory()); |
|
|
|
|
|
|
|
attrs.put("seller_category_new", dto.getSellerCategoryNew()); |
|
|
|
|
|
|
|
attrs.put("seller_rank", dto.getSellerRank()); |
|
|
|
|
|
|
|
attrs.put("small_rank", dto.getSmallRank()); |
|
|
|
|
|
|
|
attrs.put("review_num", dto.getReviewNum()); |
|
|
|
|
|
|
|
attrs.put("last_star", dto.getLastStar()); |
|
|
|
|
|
|
|
attrs.put("open_date", dto.getOpenDate()); |
|
|
|
|
|
|
|
attrs.put("open_date_display", dto.getOpenDateDisplay()); |
|
|
|
|
|
|
|
attrs.put("first_order_time", dto.getFirstOrderTime()); |
|
|
|
|
|
|
|
attrs.put("pair_update_time", dto.getPairUpdateTime()); |
|
|
|
|
|
|
|
attrs.put("store_type", dto.getStoreType()); |
|
|
|
|
|
|
|
attrs.put("dimension_info", dto.getDimensionInfo()); |
|
|
|
|
|
|
|
attrs.put("global_tags", dto.getGlobalTags()); |
|
|
|
|
|
|
|
attrs.put("variant", dto.getVariant()); |
|
|
|
|
|
|
|
attrs.put("principal_info", dto.getPrincipalInfo()); |
|
|
|
|
|
|
|
attrs.put("total_volume", dto.getTotalVolume()); |
|
|
|
|
|
|
|
attrs.put("yesterday_volume", dto.getYesterdayVolume()); |
|
|
|
|
|
|
|
attrs.put("yesterday_amount", dto.getYesterdayAmount()); |
|
|
|
|
|
|
|
attrs.put("fulfillment_channel_type", dto.getFulfillmentChannelType()); |
|
|
|
|
|
|
|
attrs.put("marketplace", dto.getMarketplace()); |
|
|
|
|
|
|
|
attrs.values().removeAll(Collections.singleton(null)); |
|
|
|
|
|
|
|
return attrs; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 零时区时间(updated)或仅日期(listed,按市场当地零点)。 */ |
|
|
|
|
|
|
|
private static PlatformTime dateTime(String raw, ZoneId zone, boolean dateOnly) { |
|
|
|
if (raw == null || raw.trim().isEmpty()) { |
|
|
|
if (raw == null || raw.trim().isEmpty()) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
Instant utc = LocalDateTime.parse(raw.trim(), LISTING_TIME).toInstant(ZoneOffset.UTC); |
|
|
|
String value = raw.trim(); |
|
|
|
return PlatformTime.of(utc, ZoneId.of(call.ctx().account().marketplaceZone())); |
|
|
|
Instant utc = dateOnly |
|
|
|
|
|
|
|
? java.time.LocalDate.parse(value, DATE).atStartOfDay(zone).toInstant() |
|
|
|
|
|
|
|
: LocalDateTime.parse(value, LISTING_TIME).toInstant(ZoneOffset.UTC); |
|
|
|
|
|
|
|
return PlatformTime.of(utc, zone); |
|
|
|
} catch (DateTimeParseException e) { |
|
|
|
} catch (DateTimeParseException e) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Money moneyOrNull(String value, String currency) { |
|
|
|
|
|
|
|
if (value == null || value.trim().isEmpty() || currency == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
return Money.of(value.trim(), currency); |
|
|
|
|
|
|
|
} catch (RuntimeException e) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String trimToNull(String v) { |
|
|
|
|
|
|
|
if (v == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String trimmed = v.trim(); |
|
|
|
|
|
|
|
return trimmed.isEmpty() ? null : trimmed; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|