diff --git a/core/src/main/java/common/ecommerce/model/Platform.java b/core/src/main/java/common/ecommerce/model/Platform.java index 4e04c23..d08b808 100644 --- a/core/src/main/java/common/ecommerce/model/Platform.java +++ b/core/src/main/java/common/ecommerce/model/Platform.java @@ -26,6 +26,8 @@ public enum Platform { SHEIN, /** Shopify(首期经领星接入) */ SHOPIFY, + /** AliExpress(首期经领星接入) */ + ALIEXPRESS, /** Mirakl 市场 */ MIRAKL, /** Target(领星平台码待确认) */ diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/LingxingApi.java b/lingxing/src/main/java/common/ecommerce/lingxing/LingxingApi.java index 4572f17..b132094 100644 --- a/lingxing/src/main/java/common/ecommerce/lingxing/LingxingApi.java +++ b/lingxing/src/main/java/common/ecommerce/lingxing/LingxingApi.java @@ -44,6 +44,15 @@ public enum LingxingApi { /** eBay 在线商品。POST,offset/length(上限 200),返回 data 数组。 */ LISTING_EBAY("/basicOpen/multiplatform/ebay/list", 1), + /** AliExpress 在线商品(托管模式)。POST,offset/length,返回 data.list。 */ + LISTING_ALIEXPRESS("/basicOpen/multiplatform/aliexpress/list/v2", 1), + + /** SHEIN 在线商品。POST,offset/length(上限 1000),返回 data.list。 */ + LISTING_SHEIN("/basicOpen/multiplatform/shein/list", 1), + + /** TikTok 在线商品。POST,offset/length(上限 1000),返回 data.list。 */ + LISTING_TIKTOK("/basicOpen/multiplatform/tiktok/list", 1), + /** 多平台订单列表;当前实现使用的跨平台接口。 */ ORDER_LIST("/pb/mp/order/v2/list", 10); diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapter.java b/lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapter.java index 00996d5..abfc443 100644 --- a/lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapter.java +++ b/lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapter.java @@ -104,7 +104,8 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable, @Override public Set platforms() { return EnumSet.of(Platform.AMAZON_SC, Platform.AMAZON_VC, Platform.WALMART_SC, Platform.TIKTOK, - Platform.TEMU, Platform.EBAY, Platform.SHEIN, Platform.SHOPIFY, Platform.MIRAKL, + Platform.TEMU, Platform.EBAY, Platform.SHEIN, Platform.SHOPIFY, + Platform.ALIEXPRESS, Platform.MIRAKL, Platform.CUSTOM); } diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapterFactory.java b/lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapterFactory.java index ef6ce2e..bb3063a 100644 --- a/lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapterFactory.java +++ b/lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapterFactory.java @@ -40,7 +40,8 @@ public final class LingxingAdapterFactory implements AdapterFactory { @Override public EnumSet platforms() { return EnumSet.of(Platform.AMAZON_SC, Platform.AMAZON_VC, Platform.WALMART_SC, Platform.TIKTOK, - Platform.TEMU, Platform.EBAY, Platform.SHEIN, Platform.SHOPIFY, Platform.MIRAKL, + Platform.TEMU, Platform.EBAY, Platform.SHEIN, Platform.SHOPIFY, + Platform.ALIEXPRESS, Platform.MIRAKL, Platform.CUSTOM); } diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatforms.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatforms.java index c4d681f..79e73a4 100644 --- a/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatforms.java +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatforms.java @@ -40,7 +40,13 @@ public final class LingxingSubPlatforms { SHARED_TRANSPORT, SHARED_JSON)); register(map, new common.ecommerce.lingxing.platform.ebay.EbaySubPlatform( SHARED_TRANSPORT, SHARED_JSON)); - // SHEIN… 落地后继续 register(...) + 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); } diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/AliexpressSubPlatform.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/AliexpressSubPlatform.java new file mode 100644 index 0000000..8cba475 --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/AliexpressSubPlatform.java @@ -0,0 +1,30 @@ +package common.ecommerce.lingxing.platform.aliexpress; + +import common.ecommerce.http.HttpTransport; +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.model.Platform; + +/** + * 领星 · AliExpress 子平台:只做能力组合。 + */ +public final class AliexpressSubPlatform implements LingxingSubPlatform { + + private final LingxingProductSource products; + + public AliexpressSubPlatform(HttpTransport transport, JacksonJsonCodec json) { + this.products = new AliexpressProductSource(); + } + + @Override + public Platform platform() { + return Platform.ALIEXPRESS; + } + + @Override + public LingxingProductSource productSource() { + return products; + } +} diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/dto/AliExpressWarehouseDto.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/dto/AliExpressWarehouseDto.java new file mode 100644 index 0000000..0bb4b6a --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/dto/AliExpressWarehouseDto.java @@ -0,0 +1,22 @@ +package common.ecommerce.lingxing.platform.aliexpress.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +/** AliExpress 仓库库存({@code wareHouseDataList[]})。 */ +@Getter +@Setter +@JsonIgnoreProperties(ignoreUnknown = true) +public class AliExpressWarehouseDto { + + @JsonProperty("quantity") + private Integer quantity; + + @JsonProperty("warehouseId") + private String warehouseId; + + @JsonProperty("warehouseName") + private String warehouseName; +} diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/dto/AliexpressListingDto.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/dto/AliexpressListingDto.java new file mode 100644 index 0000000..0be8826 --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/dto/AliexpressListingDto.java @@ -0,0 +1,224 @@ +package common.ecommerce.lingxing.platform.aliexpress.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +/** + * 领星 · AliExpress 在线商品(托管模式,{@code /basicOpen/multiplatform/aliexpress/list/v2} 的 + * {@code data.list[]})。 + * + *

字段为 camelCase。响应结构:{@code data.count} + {@code data.list}。

+ * + *

注意文档对 {@code price} 的说明是「单位分,需除以 100 万」,示例 99990000 + * 对应 {@code effectiveSupplyPrice} 59.99——实际换算需联调确认,这里只保留原值。

+ */ +@Getter +@Setter +@JsonIgnoreProperties(ignoreUnknown = true) +public class AliexpressListingDto { + + /** 记录 ID。 */ + @JsonProperty("id") + private Long id; + + /** 商品全局唯一 ID。 */ + @JsonProperty("productUniqueId") + private Long productUniqueId; + + /** 平台商品 ID。 */ + @JsonProperty("productId") + private String productId; + + /** 货品 ID。 */ + @JsonProperty("itemId") + private String itemId; + + /** 变体 MSKU,参与 canonicalKey。 */ + @JsonProperty("msku") + private String msku; + + /** 变体 MSKU ID。 */ + @JsonProperty("mskuId") + private String mskuId; + + /** SKU 编码。 */ + @JsonProperty("sku") + private String sku; + + /** 品名。 */ + @JsonProperty("pname") + private String pname; + + /** 商品标题。 */ + @JsonProperty("title") + private String title; + + /** 本地产品 ID。 */ + @JsonProperty("pid") + private Long pid; + + /** 变体属性名,如 颜色;尺寸。 */ + @JsonProperty("attributeName") + private String attributeName; + + /** 变体属性值,如 红色;L码。 */ + @JsonProperty("attributeValue") + private String attributeValue; + + /** 变体属性 JSON 字符串。 */ + @JsonProperty("attributes") + private String attributes; + + /** 父体图片 URL。 */ + @JsonProperty("imageUrls") + private String imageUrls; + + /** 变体图片地址。 */ + @JsonProperty("skuImage") + private String skuImage; + + /** 状态值。 */ + @JsonProperty("status") + private Integer status; + + /** 状态名,如 可售。 */ + @JsonProperty("statusName") + private String statusName; + + /** 是否删除。文档示例为字符串 "value",按 Object 接收避免解析失败。 */ + @JsonProperty("isDelete") + private Object isDelete; + + /** 子体货币代码。 */ + @JsonProperty("currencyCode") + private String currencyCode; + + /** 子体有效供货价。 */ + @JsonProperty("effectiveSupplyPrice") + private String effectiveSupplyPrice; + + /** 价格原值(文档说明单位为分)。 */ + @JsonProperty("price") + private Long price; + + /** 供货价列表(按时间区间)。 */ + @JsonProperty("supplyPriceList") + private List supplyPriceList = new ArrayList(); + + /** 店铺 ID。 */ + @JsonProperty("storeId") + private Long storeId; + + /** 店铺名称。 */ + @JsonProperty("storeName") + private String storeName; + + /** 平台编号,如 aliexpress。 */ + @JsonProperty("platformCode") + private String platformCode; + + /** 平台名称。 */ + @JsonProperty("platformName") + private String platformName; + + /** 发货模式,如 仓发。 */ + @JsonProperty("mode") + private String mode; + + /** 发货模式值:0 仓发 / 1 JIT / 2 海外备仓。 */ + @JsonProperty("productType") + private Integer productType; + + /** 发货模式名称。 */ + @JsonProperty("productTypeName") + private String productTypeName; + + /** 本地 SKU 型号。 */ + @JsonProperty("model") + private String model; + + /** 备注。 */ + @JsonProperty("notes") + private String notes; + + /** 品牌 ID。 */ + @JsonProperty("bid") + private Long bid; + + /** 品牌名称。 */ + @JsonProperty("bname") + private String bname; + + /** 分类 ID。 */ + @JsonProperty("cid") + private Long cid; + + /** 分类名称。 */ + @JsonProperty("cname") + private String cname; + + /** 企业 ID。 */ + @JsonProperty("companyId") + private Long companyId; + + /** listing 创建时间,北京时间。 */ + @JsonProperty("createTime") + private String createTime; + + /** 是否多子体:1 多子体 / 2 单子体。 */ + @JsonProperty("hasList") + private Integer hasList; + + /** 仓库总库存。 */ + @JsonProperty("inventoryQuantity") + private Integer inventoryQuantity; + + /** 仓库库存(字符串)。 */ + @JsonProperty("warehouseStock") + private String warehouseStock; + + /** 7 天销量。 */ + @JsonProperty("day7SaleCnt") + private Integer day7SaleCnt; + + /** 30 天销量。 */ + @JsonProperty("day30SaleCnt") + private Integer day30SaleCnt; + + /** 是否自动补货。 */ + @JsonProperty("autoRestock") + private String autoRestock; + + /** 负责人 UID 列表。 */ + @JsonProperty("principalUids") + private Object principalUids; + + /** 负责人名称。 */ + @JsonProperty("principalName") + private String principalName; + + /** 库存同步中信息,null 表示不在同步中。 */ + @JsonProperty("quantitySyn") + private Object quantitySyn; + + /** 仓库详情列表。 */ + @JsonProperty("wareHouseDataList") + private List wareHouseDataList = new ArrayList(); + + /** 唯一 ID。 */ + @JsonProperty("uniqueId") + private String uniqueId; + + /** 变体唯一 ID。 */ + @JsonProperty("variantUniqueId") + private String variantUniqueId; + + /** 仓库详情 JSON 字符串。 */ + @JsonProperty("extJson") + private String extJson; +} diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/dto/AliexpressSupplyPriceDto.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/dto/AliexpressSupplyPriceDto.java new file mode 100644 index 0000000..7151860 --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/dto/AliexpressSupplyPriceDto.java @@ -0,0 +1,31 @@ +package common.ecommerce.lingxing.platform.aliexpress.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +import java.math.BigDecimal; + +/** AliExpress 供货价({@code supplyPriceList[]}),按时间区间分段。 */ +@Getter +@Setter +@JsonIgnoreProperties(ignoreUnknown = true) +public class AliexpressSupplyPriceDto { + + /** 开始时间,Y-m-d。 */ + @JsonProperty("beginStr") + private String beginStr; + + /** 结束时间;null 表示至今。 */ + @JsonProperty("endStr") + private String endStr; + + /** 币种,如 USD。 */ + @JsonProperty("currency") + private String currency; + + /** 金额。 */ + @JsonProperty("price") + private BigDecimal price; +} diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/product/AliexpressProductSource.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/product/AliexpressProductSource.java new file mode 100644 index 0000000..a884d8c --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/product/AliexpressProductSource.java @@ -0,0 +1,289 @@ +package common.ecommerce.lingxing.platform.aliexpress.product; + +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.aliexpress.dto.AliexpressListingDto; +import common.ecommerce.lingxing.platform.aliexpress.dto.AliexpressSupplyPriceDto; +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.product.ProductStatus; +import common.ecommerce.model.support.Money; +import common.ecommerce.model.support.Page; +import common.ecommerce.model.support.PlatformTime; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 领星 · AliExpress 在线商品(托管模式)。 + * + *

接口 {@code /basicOpen/multiplatform/aliexpress/list/v2}:POST,{@code offset}/{@code length} + * 必填,返回 {@code data.list};令牌桶容量 1。

+ * + *

{@code isParent} 必填:本实现固定查子体(0),与统一模型的「一条 = 一个可售 SKU」对齐。

+ */ +public final class AliexpressProductSource implements LingxingProductSource { + + /** 接口没有明确上限,取与其它多平台商品接口一致的 1000。 */ + private static final int MAX_PAGE_SIZE = 1000; + + /** 是否父体:0 子体。 */ + private static final int IS_CHILD = 0; + + /** createTime 是北京时间。 */ + private static final ZoneId BEIJING = ZoneId.of("Asia/Shanghai"); + private static final DateTimeFormatter DATE_TIME = + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + @Override + public Page 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 body = new LinkedHashMap(); + body.put("isParent", IS_CHILD); + body.put("offset", offset); + body.put("length", length); + body.put("storeIds", + Collections.singletonList(parseStoreId(call.ctx().account().externalStoreId()))); + applyTimeWindow(body, query); + + HttpRequest req = call.signed(LingxingApi.LISTING_ALIEXPRESS, body, "products.pull"); + HttpResponse resp = call.execute(req); + LingxingEnvelope envelope = call.envelope(resp, "products.pull"); + + List dtos = + call.json().listAt(envelope.body(), "data.list", AliexpressListingDto.class); + List out = new ArrayList(dtos.size()); + for (AliexpressListingDto dto : dtos) { + out.add(toProductListing(dto, call)); + } + + int total = totalOf(call, envelope.body()); + int nextOffset = offset + dtos.size(); + boolean hasMore = dtos.size() >= length && (total < 0 || nextOffset < total); + return Page.of(out, hasMore ? String.valueOf(nextOffset) : null); + } + + /** storeIds 文档示例是数字数组;能解析成数字就传数字,否则原样传字符串。 */ + private static Object parseStoreId(String externalStoreId) { + try { + return Long.valueOf(externalStoreId); + } catch (RuntimeException e) { + return externalStoreId; + } + } + + /** 时间窗:start/end 为 yyyy-MM-dd(北京时间的日期)。 */ + private static void applyTimeWindow(Map body, ProductQuery query) { + Instant from = query.updatedAfter(); + Instant to = query.updatedBefore(); + if (from == null && to == null) { + return; + } + if (from != null) { + body.put("start", DATE.format(from.atZone(BEIJING).toLocalDate())); + } + if (to != null) { + body.put("end", DATE.format(to.atZone(BEIJING).toLocalDate())); + } + } + + private static int totalOf(LingxingCall call, String body) { + String raw = call.json().stringAt(body, "data.count"); + if (raw == null) { + raw = call.json().stringAt(body, "total"); + } + if (raw == null) { + return -1; + } + try { + return Integer.parseInt(raw.trim()); + } catch (NumberFormatException e) { + return -1; + } + } + + /** + * 领星 AliExpress 商品 → 统一模型。 + * + *

统一字段来源:

+ *
    + *
  • platformSku ← {@code msku}
  • + *
  • listingId ← {@code productUniqueId}
  • + *
  • title ← {@code title}
  • + *
  • imageUrls ← {@code skuImage},为空时用 {@code imageUrls}(父体图)
  • + *
  • status ← {@code status}(文档只给了「可售」=2,其余归 UNKNOWN)
  • + *
  • rawStatus ← {@code statusName} 原值(中文)
  • + *
  • price ← {@code effectiveSupplyPrice} + {@code currencyCode}
  • + *
  • listedAt ← {@code createTime}(北京时间,按 UTC 换算)
  • + *
  • updatedAt ← 无
  • + *
  • attributes ← 其余全部原始字段
  • + *
+ */ + private ProductListing toProductListing(AliexpressListingDto dto, LingxingCall call) { + ZoneId zone = ZoneId.of(call.ctx().account().marketplaceZone()); + String image = firstNonBlank(dto.getSkuImage(), dto.getImageUrls()); + String currency = trimToNull(dto.getCurrencyCode()); + String price = firstNonBlank(dto.getEffectiveSupplyPrice(), currentSupplyPrice(dto.getSupplyPriceList())); + + return ProductListing.builder() + .platform(call.ctx().platform()) + .omsStoreId(call.ctx().omsStoreId()) + .platformSku(dto.getMsku()) + .listingId(dto.getProductUniqueId() == null ? null : String.valueOf(dto.getProductUniqueId())) + .title(dto.getTitle()) + .imageUrls(image == null ? Collections.emptyList() : Collections.singletonList(image)) + .status(statusOf(dto.getStatus())) + .rawStatus(dto.getStatusName()) + .price(moneyOrNull(price, currency)) + .currency(currency) + .listedAt(beijingTime(dto.getCreateTime(), zone)) + .attributes(attributesOf(dto)) + .sourceProvider(ChannelProvider.LINGXING) + .build(); + } + + /** 当前生效供货价:优先 endStr 为空,否则取 beginStr 最大的一条。 */ + private static String currentSupplyPrice(List prices) { + if (prices == null || prices.isEmpty()) { + return null; + } + AliexpressSupplyPriceDto best = null; + for (AliexpressSupplyPriceDto p : prices) { + if (p == null || p.getPrice() == null) { + continue; + } + if (p.getEndStr() == null || p.getEndStr().trim().isEmpty()) { + return p.getPrice().toPlainString(); + } + if (best == null || compareBegin(p.getBeginStr(), best.getBeginStr()) > 0) { + best = p; + } + } + return best == null ? null : best.getPrice().toPlainString(); + } + + private static int compareBegin(String a, String b) { + if (a == null) { + return b == null ? 0 : -1; + } + if (b == null) { + return 1; + } + return a.compareTo(b); + } + + /** 文档只给了「2 可售」,其余归 UNKNOWN,保留原值在 rawStatus。 */ + private static ProductStatus statusOf(Integer status) { + if (status == null) { + return ProductStatus.UNKNOWN; + } + if (status == 2) { + return ProductStatus.ACTIVE; + } + return ProductStatus.UNKNOWN; + } + + private static Map attributesOf(AliexpressListingDto dto) { + Map attrs = new LinkedHashMap(); + attrs.put("id", dto.getId()); + attrs.put("productId", dto.getProductId()); + attrs.put("itemId", dto.getItemId()); + attrs.put("mskuId", dto.getMskuId()); + attrs.put("sku", dto.getSku()); + attrs.put("pname", dto.getPname()); + attrs.put("pid", dto.getPid()); + attrs.put("attributeName", dto.getAttributeName()); + attrs.put("attributeValue", dto.getAttributeValue()); + attrs.put("attributes", dto.getAttributes()); + attrs.put("isDelete", dto.getIsDelete()); + attrs.put("currencyCode", dto.getCurrencyCode()); + attrs.put("price", dto.getPrice()); + attrs.put("supplyPriceList", dto.getSupplyPriceList()); + attrs.put("storeId", dto.getStoreId()); + attrs.put("storeName", dto.getStoreName()); + attrs.put("platformCode", dto.getPlatformCode()); + attrs.put("platformName", dto.getPlatformName()); + attrs.put("mode", dto.getMode()); + attrs.put("productType", dto.getProductType()); + attrs.put("productTypeName", dto.getProductTypeName()); + attrs.put("model", dto.getModel()); + attrs.put("notes", dto.getNotes()); + attrs.put("bid", dto.getBid()); + attrs.put("bname", dto.getBname()); + attrs.put("cid", dto.getCid()); + attrs.put("cname", dto.getCname()); + attrs.put("companyId", dto.getCompanyId()); + attrs.put("hasList", dto.getHasList()); + attrs.put("inventoryQuantity", dto.getInventoryQuantity()); + attrs.put("warehouseStock", dto.getWarehouseStock()); + attrs.put("day7SaleCnt", dto.getDay7SaleCnt()); + attrs.put("day30SaleCnt", dto.getDay30SaleCnt()); + attrs.put("autoRestock", dto.getAutoRestock()); + attrs.put("principalUids", dto.getPrincipalUids()); + attrs.put("principalName", dto.getPrincipalName()); + attrs.put("quantitySyn", dto.getQuantitySyn()); + attrs.put("wareHouseDataList", dto.getWareHouseDataList()); + attrs.put("uniqueId", dto.getUniqueId()); + attrs.put("variantUniqueId", dto.getVariantUniqueId()); + attrs.put("extJson", dto.getExtJson()); + attrs.values().removeAll(Collections.singleton(null)); + return attrs; + } + + /** createTime 是北京时间,转成 UTC Instant 后按市场时区展示。 */ + private static PlatformTime beijingTime(String raw, ZoneId marketplaceZone) { + if (raw == null || raw.trim().isEmpty()) { + return null; + } + try { + Instant utc = LocalDateTime.parse(raw.trim(), DATE_TIME).atZone(BEIJING).toInstant(); + return PlatformTime.of(utc, marketplaceZone); + } catch (RuntimeException e) { + 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 firstNonBlank(String... values) { + for (String v : values) { + String trimmed = trimToNull(v); + if (trimmed != null) { + return trimmed; + } + } + return null; + } + + private static String trimToNull(String v) { + if (v == null) { + return null; + } + String trimmed = v.trim(); + return trimmed.isEmpty() ? null : trimmed; + } +} diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/SheinSubPlatform.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/SheinSubPlatform.java new file mode 100644 index 0000000..82856d0 --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/SheinSubPlatform.java @@ -0,0 +1,32 @@ +package common.ecommerce.lingxing.platform.shein; + +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.shein.product.SheinProductSource; +import common.ecommerce.model.Platform; + +/** + * 领星 · SHEIN 子平台:只做能力组合。 + * + *

10021 / 10027 / 10028 都映射到 {@link Platform#SHEIN}。

+ */ +public final class SheinSubPlatform implements LingxingSubPlatform { + + private final LingxingProductSource products; + + public SheinSubPlatform(HttpTransport transport, JacksonJsonCodec json) { + this.products = new SheinProductSource(); + } + + @Override + public Platform platform() { + return Platform.SHEIN; + } + + @Override + public LingxingProductSource productSource() { + return products; + } +} diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/dto/SheinListingDto.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/dto/SheinListingDto.java new file mode 100644 index 0000000..dc0723a --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/dto/SheinListingDto.java @@ -0,0 +1,188 @@ +package common.ecommerce.lingxing.platform.shein.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +/** + * 领星 · SHEIN 在线商品({@code /basicOpen/multiplatform/shein/list} 的 {@code data.list[]})。 + * + *

字段为 camelCase,响应结构 {@code data.count} + {@code data.list}。

+ */ +@Getter +@Setter +@JsonIgnoreProperties(ignoreUnknown = true) +public class SheinListingDto { + + /** 领星内部 id。 */ + @JsonProperty("id") + private String id; + + /** 商品 uid。 */ + @JsonProperty("productUniqueId") + private String productUniqueId; + + /** 负责人 uid 列表。 */ + @JsonProperty("principalUids") + private List principalUids = new ArrayList(); + + /** 负责人名称。 */ + @JsonProperty("principalName") + private String principalName; + + /** 企业 id。 */ + @JsonProperty("companyId") + private String companyId; + + /** 店铺 id。 */ + @JsonProperty("storeId") + private String storeId; + + /** 店铺名称。 */ + @JsonProperty("storeName") + private String storeName; + + /** 平台代码,如 10027。 */ + @JsonProperty("platformCode") + private String platformCode; + + /** MSKU ID。 */ + @JsonProperty("mskuId") + private String mskuId; + + /** 平台侧 MSKU,参与 canonicalKey。 */ + @JsonProperty("msku") + private String msku; + + /** 品名。 */ + @JsonProperty("pname") + private String pname; + + /** 本地 SKU。 */ + @JsonProperty("sku") + private String sku; + + /** 本地商品 id。 */ + @JsonProperty("pid") + private String pid; + + /** 标题。 */ + @JsonProperty("title") + private String title; + + /** 分类 id。 */ + @JsonProperty("cid") + private String cid; + + /** 品牌 id。 */ + @JsonProperty("bid") + private String bid; + + /** 7 天销量。 */ + @JsonProperty("day7SaleCnt") + private Integer day7SaleCnt; + + /** 30 天销量。 */ + @JsonProperty("day30SaleCnt") + private Integer day30SaleCnt; + + /** 各仓库存。 */ + @JsonProperty("wareHouseDataList") + private List wareHouseDataList = new ArrayList(); + + /** 备注。 */ + @JsonProperty("notes") + private String notes; + + /** 低质量图片。 */ + @JsonProperty("imgSmallUrl") + private String imgSmallUrl; + + /** 中质量图片。 */ + @JsonProperty("imgMediumUrl") + private String imgMediumUrl; + + /** 原质量图片。 */ + @JsonProperty("imgUrl") + private String imgUrl; + + /** SKC ID。 */ + @JsonProperty("skcId") + private String skcId; + + /** SKC。 */ + @JsonProperty("skc") + private String skc; + + /** SPU ID。 */ + @JsonProperty("spuId") + private String spuId; + + /** SPU。 */ + @JsonProperty("spu") + private String spu; + + /** 状态:0 删除 / 1 在售 / 2 停售。 */ + @JsonProperty("status") + private Integer status; + + /** 站点,逗号分隔。 */ + @JsonProperty("site") + private String site; + + /** 站点列表。 */ + @JsonProperty("siteList") + private List siteList; + + /** 是否在售。 */ + @JsonProperty("isOnSale") + private Boolean isOnSale; + + /** 属性,如 test-白色-test-均码。 */ + @JsonProperty("attribute") + private String attribute; + + /** 大分类名称。 */ + @JsonProperty("categoryName") + private String categoryName; + + /** 售价。 */ + @JsonProperty("salePrice") + private Object salePrice; + + /** 售价货币,可能是符号。 */ + @JsonProperty("saleCurrency") + private String saleCurrency; + + /** 总库存。 */ + @JsonProperty("inventoryQuantity") + private Integer inventoryQuantity; + + /** 出库中库存。 */ + @JsonProperty("lockedQuantity") + private Integer lockedQuantity; + + /** 待支付库存。 */ + @JsonProperty("tempLockQuantity") + private Integer tempLockQuantity; + + /** 可用库存。 */ + @JsonProperty("usableInventory") + private Integer usableInventory; + + /** 品牌名称。 */ + @JsonProperty("bname") + private String bname; + + /** 细分类名称。 */ + @JsonProperty("cname") + private String cname; + + /** 供货价列表。 */ + @JsonProperty("supplyPriceList") + private List supplyPriceList = new ArrayList(); +} diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/dto/SheinSiteDto.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/dto/SheinSiteDto.java new file mode 100644 index 0000000..ab51be5 --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/dto/SheinSiteDto.java @@ -0,0 +1,16 @@ +package common.ecommerce.lingxing.platform.shein.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +/** SHEIN 站点信息({@code siteList[]})。 */ +@Getter +@Setter +@JsonIgnoreProperties(ignoreUnknown = true) +public class SheinSiteDto { + + @JsonProperty("site") + private String site; +} diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/dto/SheinSupplyPriceDto.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/dto/SheinSupplyPriceDto.java new file mode 100644 index 0000000..1435e59 --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/dto/SheinSupplyPriceDto.java @@ -0,0 +1,30 @@ +package common.ecommerce.lingxing.platform.shein.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +import java.math.BigDecimal; + +/** SHEIN 供货价({@code supplyPriceList[]}),按时间区间分段。 */ +@Getter +@Setter +@JsonIgnoreProperties(ignoreUnknown = true) +public class SheinSupplyPriceDto { + + @JsonProperty("price") + private BigDecimal price; + + /** 货币,文档示例为符号「¥」。 */ + @JsonProperty("currency") + private String currency; + + /** 执行开始时间,Y-m-d。 */ + @JsonProperty("beginStr") + private String beginStr; + + /** 执行结束时间,Y-m-d。 */ + @JsonProperty("endStr") + private String endStr; +} diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/dto/SheinWarehouseDto.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/dto/SheinWarehouseDto.java new file mode 100644 index 0000000..936bff7 --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/dto/SheinWarehouseDto.java @@ -0,0 +1,22 @@ +package common.ecommerce.lingxing.platform.shein.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +/** SHEIN 仓库库存({@code wareHouseDataList[]})。 */ +@Getter +@Setter +@JsonIgnoreProperties(ignoreUnknown = true) +public class SheinWarehouseDto { + + @JsonProperty("warehouseId") + private String warehouseId; + + @JsonProperty("warehouseName") + private String warehouseName; + + @JsonProperty("quantity") + private Integer quantity; +} diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/product/SheinProductSource.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/product/SheinProductSource.java new file mode 100644 index 0000000..5dbb1d2 --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/product/SheinProductSource.java @@ -0,0 +1,267 @@ +package common.ecommerce.lingxing.platform.shein.product; + +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.product.LingxingProductSource; +import common.ecommerce.lingxing.platform.shein.dto.SheinListingDto; +import common.ecommerce.lingxing.platform.shein.dto.SheinSupplyPriceDto; +import common.ecommerce.model.ChannelProvider; +import common.ecommerce.model.product.ProductListing; +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 java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 领星 · SHEIN 在线商品。 + * + *

接口 {@code /basicOpen/multiplatform/shein/list}:POST,{@code offset}/{@code length} + * (上限 1000),返回 {@code data.list};令牌桶容量 1。

+ * + *

接口不支持时间窗过滤。

+ */ +public final class SheinProductSource implements LingxingProductSource { + + private static final int MAX_PAGE_SIZE = 1000; + + @Override + public Page 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 body = new LinkedHashMap(); + body.put("offset", offset); + body.put("length", length); + body.put("storeIds", + Collections.singletonList(call.ctx().account().externalStoreId())); + + HttpRequest req = call.signed(LingxingApi.LISTING_SHEIN, body, "products.pull"); + HttpResponse resp = call.execute(req); + LingxingEnvelope envelope = call.envelope(resp, "products.pull"); + + List dtos = call.json().listAt(envelope.body(), "data.list", SheinListingDto.class); + List out = new ArrayList(dtos.size()); + for (SheinListingDto dto : dtos) { + out.add(toProductListing(dto, call)); + } + + int total = totalOf(call, envelope.body()); + int nextOffset = offset + dtos.size(); + boolean hasMore = dtos.size() >= length && (total < 0 || nextOffset < total); + return Page.of(out, hasMore ? String.valueOf(nextOffset) : null); + } + + private static int totalOf(LingxingCall call, String body) { + String raw = call.json().stringAt(body, "data.count"); + if (raw == null) { + raw = call.json().stringAt(body, "total"); + } + if (raw == null) { + return -1; + } + try { + return Integer.parseInt(raw.trim()); + } catch (NumberFormatException e) { + return -1; + } + } + + /** + * 领星 SHEIN 商品 → 统一模型。 + * + *

统一字段来源:

+ *
    + *
  • platformSku ← {@code msku}
  • + *
  • listingId ← {@code productUniqueId}
  • + *
  • title ← {@code title}
  • + *
  • imageUrls ← {@code imgUrl},为空时依次回落 {@code imgMediumUrl} / {@code imgSmallUrl}
  • + *
  • status ← {@code status}(0 删除 / 1 在售 / 2 停售)
  • + *
  • rawStatus ← 原始 {@code status} 值
  • + *
  • price ← {@code salePrice} + {@code saleCurrency}(符号按约定映射)
  • + *
  • listedAt / updatedAt ← 无(接口不返回时间字段)
  • + *
  • attributes ← 其余全部原始字段
  • + *
+ */ + private ProductListing toProductListing(SheinListingDto dto, LingxingCall call) { + String image = firstNonBlank(dto.getImgUrl(), dto.getImgMediumUrl(), dto.getImgSmallUrl()); + String currency = currencyOf(dto.getSaleCurrency()); + String priceText = amountOf(dto.getSalePrice()); + if (priceText == null) { + priceText = currentSupplyPrice(dto.getSupplyPriceList()); + } + + return ProductListing.builder() + .platform(call.ctx().platform()) + .omsStoreId(call.ctx().omsStoreId()) + .platformSku(dto.getMsku()) + .listingId(trimToNull(dto.getProductUniqueId())) + .title(dto.getTitle()) + .imageUrls(image == null ? Collections.emptyList() : Collections.singletonList(image)) + .status(statusOf(dto.getStatus())) + .rawStatus(dto.getStatus() == null ? null : String.valueOf(dto.getStatus())) + .price(moneyOrNull(priceText, currency)) + .currency(currency) + .attributes(attributesOf(dto)) + .sourceProvider(ChannelProvider.LINGXING) + .build(); + } + + /** SHEIN:0 删除 / 1 在售 / 2 停售。 */ + private static ProductStatus statusOf(Integer status) { + if (status == null) { + return ProductStatus.UNKNOWN; + } + switch (status) { + case 1: + return ProductStatus.ACTIVE; + case 2: + return ProductStatus.INACTIVE; + case 0: + return ProductStatus.DELETED; + default: + return ProductStatus.UNKNOWN; + } + } + + /** 供货价兜底:优先 endStr 为空,否则取 beginStr 最大的一条。 */ + private static String currentSupplyPrice(List prices) { + if (prices == null || prices.isEmpty()) { + return null; + } + SheinSupplyPriceDto best = null; + for (SheinSupplyPriceDto p : prices) { + if (p == null || p.getPrice() == null) { + continue; + } + if (p.getEndStr() == null || p.getEndStr().trim().isEmpty()) { + return p.getPrice().toPlainString(); + } + if (best == null || compareBegin(p.getBeginStr(), best.getBeginStr()) > 0) { + best = p; + } + } + return best == null ? null : best.getPrice().toPlainString(); + } + + private static int compareBegin(String a, String b) { + if (a == null) { + return b == null ? 0 : -1; + } + if (b == null) { + return 1; + } + return a.compareTo(b); + } + + /** salePrice 文档为 number,但示例可能是字符串,统一转字符串。 */ + private static String amountOf(Object value) { + if (value == null) { + return null; + } + String s = String.valueOf(value).trim(); + return s.isEmpty() ? null : s; + } + + private static Map attributesOf(SheinListingDto dto) { + Map attrs = new LinkedHashMap(); + attrs.put("id", dto.getId()); + attrs.put("storeId", dto.getStoreId()); + attrs.put("storeName", dto.getStoreName()); + attrs.put("platformCode", dto.getPlatformCode()); + attrs.put("mskuId", dto.getMskuId()); + attrs.put("sku", dto.getSku()); + attrs.put("pid", dto.getPid()); + attrs.put("pname", dto.getPname()); + attrs.put("skcId", dto.getSkcId()); + attrs.put("skc", dto.getSkc()); + attrs.put("spuId", dto.getSpuId()); + attrs.put("spu", dto.getSpu()); + attrs.put("cid", dto.getCid()); + attrs.put("cname", dto.getCname()); + attrs.put("categoryName", dto.getCategoryName()); + attrs.put("bid", dto.getBid()); + attrs.put("bname", dto.getBname()); + attrs.put("attribute", dto.getAttribute()); + attrs.put("site", dto.getSite()); + attrs.put("siteList", dto.getSiteList()); + attrs.put("isOnSale", dto.getIsOnSale()); + attrs.put("inventoryQuantity", dto.getInventoryQuantity()); + attrs.put("lockedQuantity", dto.getLockedQuantity()); + attrs.put("tempLockQuantity", dto.getTempLockQuantity()); + attrs.put("usableInventory", dto.getUsableInventory()); + attrs.put("wareHouseDataList", dto.getWareHouseDataList()); + attrs.put("supplyPriceList", dto.getSupplyPriceList()); + attrs.put("day7SaleCnt", dto.getDay7SaleCnt()); + attrs.put("day30SaleCnt", dto.getDay30SaleCnt()); + attrs.put("principalUids", dto.getPrincipalUids()); + attrs.put("principalName", dto.getPrincipalName()); + attrs.put("companyId", dto.getCompanyId()); + attrs.put("notes", dto.getNotes()); + attrs.put("imgSmallUrl", dto.getImgSmallUrl()); + attrs.put("imgMediumUrl", dto.getImgMediumUrl()); + attrs.values().removeAll(Collections.singleton(null)); + return attrs; + } + + /** 货币符号 → ISO。约定 ¥ 符号视为日元,人民币以 CNY 返回。 */ + private static String currencyOf(String icon) { + if (icon == null) { + return null; + } + String s = icon.trim(); + if ("$".equals(s) || "US$".equals(s)) { + return "USD"; + } + if ("€".equals(s)) { + return "EUR"; + } + if ("£".equals(s)) { + return "GBP"; + } + if ("¥".equals(s) || "¥".equals(s)) { + return "JPY"; + } + if ("CNY".equalsIgnoreCase(s) || "RMB".equalsIgnoreCase(s)) { + return "CNY"; + } + 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 firstNonBlank(String... values) { + for (String v : values) { + String trimmed = trimToNull(v); + if (trimmed != null) { + return trimmed; + } + } + return null; + } + + private static String trimToNull(String v) { + if (v == null) { + return null; + } + String trimmed = v.trim(); + return trimmed.isEmpty() ? null : trimmed; + } +} diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/TiktokSubPlatform.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/TiktokSubPlatform.java new file mode 100644 index 0000000..dd5d769 --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/TiktokSubPlatform.java @@ -0,0 +1,30 @@ +package common.ecommerce.lingxing.platform.tiktok; + +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.tiktok.product.TiktokProductSource; +import common.ecommerce.model.Platform; + +/** + * 领星 · TikTok 子平台:只做能力组合。 + */ +public final class TiktokSubPlatform implements LingxingSubPlatform { + + private final LingxingProductSource products; + + public TiktokSubPlatform(HttpTransport transport, JacksonJsonCodec json) { + this.products = new TiktokProductSource(); + } + + @Override + public Platform platform() { + return Platform.TIKTOK; + } + + @Override + public LingxingProductSource productSource() { + return products; + } +} diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/dto/TiktokListingDto.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/dto/TiktokListingDto.java new file mode 100644 index 0000000..edfe53b --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/dto/TiktokListingDto.java @@ -0,0 +1,128 @@ +package common.ecommerce.lingxing.platform.tiktok.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +/** + * 领星 · TikTok 在线商品({@code /basicOpen/multiplatform/tiktok/list} 的 {@code data.list[]})。 + * + *

字段为 camelCase,响应结构 {@code data.count} + {@code data.list}。

+ */ +@Getter +@Setter +@JsonIgnoreProperties(ignoreUnknown = true) +public class TiktokListingDto { + + @JsonProperty("id") + private String id; + + @JsonProperty("productUniqueId") + private String productUniqueId; + + @JsonProperty("principalUids") + private List principalUids = new ArrayList(); + + @JsonProperty("principalName") + private String principalName; + + @JsonProperty("companyId") + private String companyId; + + @JsonProperty("storeId") + private String storeId; + + @JsonProperty("storeName") + private String storeName; + + @JsonProperty("platformCode") + private String platformCode; + + @JsonProperty("mskuId") + private String mskuId; + + /** 平台侧 MSKU,参与 canonicalKey。 */ + @JsonProperty("msku") + private String msku; + + @JsonProperty("pname") + private String pname; + + @JsonProperty("sku") + private String sku; + + @JsonProperty("pid") + private String pid; + + /** FBT 货品 ID。 */ + @JsonProperty("goodId") + private String goodId; + + @JsonProperty("title") + private String title; + + @JsonProperty("cid") + private String cid; + + @JsonProperty("bid") + private String bid; + + @JsonProperty("notes") + private String notes; + + @JsonProperty("imgUrl") + private String imgUrl; + + @JsonProperty("spu") + private String spu; + + @JsonProperty("spuId") + private String spuId; + + /** + * 平台状态:DRAFT / PENDING / FAILED / ACTIVATE / SELLER_DEACTIVATED / + * PLATFORM_DEACTIVATED / FREEZE / DELETED。 + * + *

注意示例里出现过 {@code SELLERDEACTIVATED}(无下划线),做容错处理。

+ */ + @JsonProperty("platformStatus") + private String platformStatus; + + @JsonProperty("categoryName") + private String categoryName; + + @JsonProperty("usableInventory") + private Integer usableInventory; + + @JsonProperty("waitOutboundQuantity") + private Integer waitOutboundQuantity; + + /** 站点代码,逗号分隔,如 US,UK。 */ + @JsonProperty("siteCode") + private String siteCode; + + /** 税前价格。 */ + @JsonProperty("taxExclusivePrice") + private Object taxExclusivePrice; + + /** 售价。 */ + @JsonProperty("salesPrice") + private String salesPrice; + + /** 货币单位,文档示例为符号 $。 */ + @JsonProperty("currency") + private String currency; + + @JsonProperty("bname") + private String bname; + + @JsonProperty("cname") + private String cname; + + @JsonProperty("wareHouseDataList") + private List wareHouseDataList = new ArrayList(); +} diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/dto/TiktokWarehouseDto.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/dto/TiktokWarehouseDto.java new file mode 100644 index 0000000..afbdb8f --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/dto/TiktokWarehouseDto.java @@ -0,0 +1,25 @@ +package common.ecommerce.lingxing.platform.tiktok.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +/** TikTok 仓库库存({@code wareHouseDataList[]})。 */ +@Getter +@Setter +@JsonIgnoreProperties(ignoreUnknown = true) +public class TiktokWarehouseDto { + + @JsonProperty("quantity") + private Integer quantity; + + @JsonProperty("warehouseId") + private String warehouseId; + + @JsonProperty("warehouseName") + private String warehouseName; + + @JsonProperty("waitOutboundQuantity") + private Integer waitOutboundQuantity; +} diff --git a/lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/product/TiktokProductSource.java b/lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/product/TiktokProductSource.java new file mode 100644 index 0000000..6260966 --- /dev/null +++ b/lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/product/TiktokProductSource.java @@ -0,0 +1,232 @@ +package common.ecommerce.lingxing.platform.tiktok.product; + +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.product.LingxingProductSource; +import common.ecommerce.lingxing.platform.tiktok.dto.TiktokListingDto; +import common.ecommerce.model.ChannelProvider; +import common.ecommerce.model.product.ProductListing; +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 java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +/** + * 领星 · TikTok 在线商品。 + * + *

接口 {@code /basicOpen/multiplatform/tiktok/list}:POST,{@code offset}/{@code length} + * (上限 1000),返回 {@code data.list};令牌桶容量 1。接口不支持时间窗过滤。

+ */ +public final class TiktokProductSource implements LingxingProductSource { + + private static final int MAX_PAGE_SIZE = 1000; + + @Override + public Page 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 body = new LinkedHashMap(); + body.put("offset", offset); + body.put("length", length); + body.put("storeIds", + Collections.singletonList(call.ctx().account().externalStoreId())); + + HttpRequest req = call.signed(LingxingApi.LISTING_TIKTOK, body, "products.pull"); + HttpResponse resp = call.execute(req); + LingxingEnvelope envelope = call.envelope(resp, "products.pull"); + + List dtos = call.json().listAt(envelope.body(), "data.list", TiktokListingDto.class); + List out = new ArrayList(dtos.size()); + for (TiktokListingDto dto : dtos) { + out.add(toProductListing(dto, call)); + } + + int total = totalOf(call, envelope.body()); + int nextOffset = offset + dtos.size(); + boolean hasMore = dtos.size() >= length && (total < 0 || nextOffset < total); + return Page.of(out, hasMore ? String.valueOf(nextOffset) : null); + } + + private static int totalOf(LingxingCall call, String body) { + String raw = call.json().stringAt(body, "data.count"); + if (raw == null) { + raw = call.json().stringAt(body, "total"); + } + if (raw == null) { + return -1; + } + try { + return Integer.parseInt(raw.trim()); + } catch (NumberFormatException e) { + return -1; + } + } + + /** + * 领星 TikTok 商品 → 统一模型。 + * + *

统一字段来源:

+ *
    + *
  • platformSku ← {@code msku}
  • + *
  • listingId ← {@code productUniqueId}
  • + *
  • title ← {@code title};为空时回落 {@code pname}(示例中 title 可能为 "")
  • + *
  • imageUrls ← {@code imgUrl}
  • + *
  • status ← {@code platformStatus} 字符串归一
  • + *
  • rawStatus ← {@code platformStatus} 原值
  • + *
  • price ← {@code salesPrice} + {@code currency}
  • + *
  • listedAt / updatedAt ← 无(接口不返回时间字段)
  • + *
  • attributes ← 其余全部原始字段
  • + *
+ */ + private ProductListing toProductListing(TiktokListingDto dto, LingxingCall call) { + String currency = currencyOf(dto.getCurrency()); + String title = firstNonBlank(dto.getTitle(), dto.getPname()); + + return ProductListing.builder() + .platform(call.ctx().platform()) + .omsStoreId(call.ctx().omsStoreId()) + .platformSku(dto.getMsku()) + .listingId(trimToNull(dto.getProductUniqueId())) + .title(title) + .imageUrls(isBlank(dto.getImgUrl()) + ? Collections.emptyList() + : Collections.singletonList(dto.getImgUrl().trim())) + .status(statusOf(dto.getPlatformStatus())) + .rawStatus(dto.getPlatformStatus()) + .price(moneyOrNull(dto.getSalesPrice(), currency)) + .currency(currency) + .attributes(attributesOf(dto)) + .sourceProvider(ChannelProvider.LINGXING) + .build(); + } + + /** + * TikTok 平台状态字符串归一。 + * + *

文档枚举:DRAFT / PENDING / FAILED / ACTIVATE / SELLER_DEACTIVATED / + * PLATFORM_DEACTIVATED / FREEZE / DELETED。示例中出现过无下划线写法 + * {@code SELLERDEACTIVATED},先去掉下划线再匹配。

+ */ + private static ProductStatus statusOf(String raw) { + if (raw == null) { + return ProductStatus.UNKNOWN; + } + String s = raw.trim().toUpperCase(Locale.ROOT).replace("_", "").replace(" ", ""); + if ("ACTIVATE".equals(s) || "ACTIVE".equals(s)) { + return ProductStatus.ACTIVE; + } + if ("SELLERDEACTIVATED".equals(s) + || "PLATFORMDEACTIVATED".equals(s) + || "FREEZE".equals(s) + || "DRAFT".equals(s) + || "PENDING".equals(s) + || "FAILED".equals(s)) { + return ProductStatus.INACTIVE; + } + if ("DELETED".equals(s)) { + return ProductStatus.DELETED; + } + return ProductStatus.UNKNOWN; + } + + private static Map attributesOf(TiktokListingDto dto) { + Map attrs = new LinkedHashMap(); + attrs.put("id", dto.getId()); + attrs.put("storeId", dto.getStoreId()); + attrs.put("storeName", dto.getStoreName()); + attrs.put("platformCode", dto.getPlatformCode()); + attrs.put("mskuId", dto.getMskuId()); + attrs.put("sku", dto.getSku()); + attrs.put("pid", dto.getPid()); + attrs.put("pname", dto.getPname()); + attrs.put("goodId", dto.getGoodId()); + attrs.put("spu", dto.getSpu()); + attrs.put("spuId", dto.getSpuId()); + attrs.put("cid", dto.getCid()); + attrs.put("cname", dto.getCname()); + attrs.put("categoryName", dto.getCategoryName()); + attrs.put("bid", dto.getBid()); + attrs.put("bname", dto.getBname()); + attrs.put("siteCode", dto.getSiteCode()); + attrs.put("usableInventory", dto.getUsableInventory()); + attrs.put("waitOutboundQuantity", dto.getWaitOutboundQuantity()); + attrs.put("wareHouseDataList", dto.getWareHouseDataList()); + attrs.put("taxExclusivePrice", dto.getTaxExclusivePrice()); + attrs.put("salesPrice", dto.getSalesPrice()); + attrs.put("currency", dto.getCurrency()); + attrs.put("principalUids", dto.getPrincipalUids()); + attrs.put("principalName", dto.getPrincipalName()); + attrs.put("companyId", dto.getCompanyId()); + attrs.put("notes", dto.getNotes()); + attrs.values().removeAll(Collections.singleton(null)); + return attrs; + } + + /** 货币符号 → ISO。约定 ¥ 符号视为日元,人民币以 CNY 返回。 */ + private static String currencyOf(String icon) { + if (icon == null) { + return null; + } + String s = icon.trim(); + if ("$".equals(s) || "US$".equals(s)) { + return "USD"; + } + if ("€".equals(s)) { + return "EUR"; + } + if ("£".equals(s)) { + return "GBP"; + } + if ("¥".equals(s) || "¥".equals(s)) { + return "JPY"; + } + if ("CNY".equalsIgnoreCase(s) || "RMB".equalsIgnoreCase(s)) { + return "CNY"; + } + 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 boolean isBlank(String v) { + return v == null || v.trim().isEmpty(); + } + + private static String firstNonBlank(String... values) { + for (String v : values) { + String trimmed = trimToNull(v); + if (trimmed != null) { + return trimmed; + } + } + return null; + } + + private static String trimToNull(String v) { + if (v == null) { + return null; + } + String trimmed = v.trim(); + return trimmed.isEmpty() ? null : trimmed; + } +}