Browse Source

refactor(lingxing): 删除 Shopify 平台,Target 独占 listing 接口

Shopify 与 Target 走同一个领星接口(/basicOpen/multiplatform/shopify/variantList),
DTO 字段完全一致,保留两套实现属于重复代码。

- 删除 platform/shopify/ 整包(SubPlatform + DTO + ProductSource,约 520 行)
- Platform.SHOPIFY 枚举移除
- LingxingSubPlatformDefaults 不再注册 Shopify
- LingxingConstants:10002(SPF-*)改为 CUSTOM,等确认业务平台后再补
- LingxingProductSearchMapper.shopify → target,本地 SKU 仍显式不支持
- 适配器 platforms() 去掉 SHOPIFY

领星接口路径里的 shopify 是历史命名,与业务平台无关,枚举名 LISTING_SHOPIFY 保留。

Co-Authored-By: Claude <noreply@anthropic.com>
feature/supplier-lingxing
chenchuchuan 2 weeks ago
parent
commit
62150c64ba
  1. 6
      core/src/main/java/common/ecommerce/model/Platform.java
  2. 3
      lingxing/src/main/java/common/ecommerce/lingxing/LingxingApi.java
  3. 8
      lingxing/src/main/java/common/ecommerce/lingxing/LingxingConstants.java
  4. 2
      lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapter.java
  5. 2
      lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatformDefaults.java
  6. 4
      lingxing/src/main/java/common/ecommerce/lingxing/platform/multiplatform/product/LingxingProductSearchBody.java
  7. 10
      lingxing/src/main/java/common/ecommerce/lingxing/platform/multiplatform/product/LingxingProductSearchMapper.java
  8. 58
      lingxing/src/main/java/common/ecommerce/lingxing/platform/shopify/ShopifySubPlatform.java
  9. 166
      lingxing/src/main/java/common/ecommerce/lingxing/platform/shopify/dto/ShopifyListingDto.java
  10. 49
      lingxing/src/main/java/common/ecommerce/lingxing/platform/shopify/dto/ShopifyLocationDto.java
  11. 272
      lingxing/src/main/java/common/ecommerce/lingxing/platform/shopify/product/ShopifyProductSource.java
  12. 10
      lingxing/src/main/java/common/ecommerce/lingxing/platform/target/TargetSubPlatform.java
  13. 4
      lingxing/src/main/java/common/ecommerce/lingxing/platform/target/product/TargetProductSource.java

6
core/src/main/java/common/ecommerce/model/Platform.java

@ -24,8 +24,6 @@ public enum Platform { @@ -24,8 +24,6 @@ public enum Platform {
EBAY,
/** SHEIN(首期经领星接入) */
SHEIN,
/** Shopify(领星 platform_code 10002)。 */
SHOPIFY,
/** AliExpress(首期经领星接入) */
ALIEXPRESS,
/** Mirakl 市场 */
@ -33,8 +31,8 @@ public enum Platform { @@ -33,8 +31,8 @@ public enum Platform {
/**
* Target。
*
* <p>领星侧没有独立的 Target 商品接口,商品走 Shopify 的
* {@code /basicOpen/multiplatform/shopify/variantList}。</p>
* <p>领星侧没有独立的 Target 商品接口,商品走
* {@code /basicOpen/multiplatform/shopify/variantList}(路径名是领星的历史命名)。</p>
*/
TARGET,
/** BestBuy。实测在领星 10034(Mirakl)下以 BSB-* 店铺出现。 */

3
lingxing/src/main/java/common/ecommerce/lingxing/LingxingApi.java

@ -51,7 +51,8 @@ public enum LingxingApi { @@ -51,7 +51,8 @@ public enum LingxingApi {
LISTING_TEMU("/basicOpen/multiplatform/temu/list", 1),
/**
* 在线商品(变体维度),<b>Shopify(10002)与 Target 共用此接口</b>。
* 在线商品(变体维度),<b>Target 使用此接口</b>;
* 路径里的 shopify 是领星的历史命名,与业务平台无关。
* POST,offset/length(上限 1000),返回 data.list。
*/
LISTING_SHOPIFY("/basicOpen/multiplatform/shopify/variantList", 1),

8
lingxing/src/main/java/common/ecommerce/lingxing/LingxingConstants.java

@ -82,8 +82,7 @@ public final class LingxingConstants { @@ -82,8 +82,7 @@ public final class LingxingConstants {
* <table summary="platform_code 实测对照">
* <tr><th>code</th><th>实测店铺</th><th>Platform</th></tr>
* <tr><td>10001</td><td>AMZ-*</td><td>AMAZON_SC</td></tr>
* <tr><td>10002</td><td>SPF-*</td><td>SHOPIFY</td></tr>
* <tr><td>10003</td><td>EBA-*</td><td>EBAY</td></tr>
* <tr><td>10003</td><td>EBA-*</td><td>EBAY</td></tr>
* <tr><td>10005 / 10031</td><td>AEP-* / AEPH-*</td><td>AEPH</td></tr>
* <tr><td>10008</td><td>WMT-*</td><td>WALMART_SC</td></tr>
* <tr><td>10010</td><td>WAY-*</td><td>WAYFAIR</td></tr>
@ -105,7 +104,7 @@ public final class LingxingConstants { @@ -105,7 +104,7 @@ public final class LingxingConstants {
* <p>Target / BestBuy / AEPH / Michaels / ECHO / LOS-DLI-US 在领星侧没有独立平台码
* (多为自定义平台或共用 Mirakl)。<b>业务平台以账户的 {@code AccountKey.platform} 为准,
* 本方法只用于从响应行反推</b>。Target 没有独立的领星商品接口,
* 它的商品走 Shopify 的 {@code /basicOpen/multiplatform/shopify/variantList}。</p>
* 它的商品走 {@code /basicOpen/multiplatform/shopify/variantList}(领星的历史路径命名)。</p>
*/
public static Platform toPlatform(Integer platformCode) {
if (platformCode == null) {
@ -115,7 +114,8 @@ public final class LingxingConstants { @@ -115,7 +114,8 @@ public final class LingxingConstants {
case 10001:
return Platform.AMAZON_SC;
case 10002:
return Platform.SHOPIFY;
// 领星侧 10002 的店铺(SPF-*)在统一模型里暂无对应平台
return Platform.CUSTOM;
case 10003:
return Platform.EBAY;
case 10005:

2
lingxing/src/main/java/common/ecommerce/lingxing/adapter/LingxingAdapter.java

@ -162,7 +162,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable, @@ -162,7 +162,7 @@ public final class LingxingAdapter implements SalesOrderCapable, ProductCapable,
@Override
public Set<Platform> platforms() {
return EnumSet.of(Platform.AMAZON_SC, Platform.AMAZON_VC, Platform.WALMART_SC, Platform.TIKTOK,
Platform.TEMU, Platform.EBAY, Platform.SHEIN, Platform.SHOPIFY,
Platform.TEMU, Platform.EBAY, Platform.SHEIN,
Platform.ALIEXPRESS, Platform.MIRAKL, Platform.WAYFAIR,
Platform.TARGET, Platform.BESTBUY, Platform.AEPH, Platform.MICHAELS,
Platform.ECHO, Platform.LOSDLIUS,

2
lingxing/src/main/java/common/ecommerce/lingxing/platform/LingxingSubPlatformDefaults.java

@ -14,7 +14,6 @@ import common.ecommerce.lingxing.platform.losdlius.LosDliUsSubPlatform; @@ -14,7 +14,6 @@ import common.ecommerce.lingxing.platform.losdlius.LosDliUsSubPlatform;
import common.ecommerce.lingxing.platform.michaels.MichaelsSubPlatform;
import common.ecommerce.lingxing.platform.mirakl.MiraklSubPlatform;
import common.ecommerce.lingxing.platform.shein.SheinSubPlatform;
import common.ecommerce.lingxing.platform.shopify.ShopifySubPlatform;
import common.ecommerce.lingxing.platform.target.TargetSubPlatform;
import common.ecommerce.lingxing.platform.temu.TemuSubPlatform;
import common.ecommerce.lingxing.platform.tiktok.TiktokSubPlatform;
@ -40,7 +39,6 @@ public final class LingxingSubPlatformDefaults { @@ -40,7 +39,6 @@ public final class LingxingSubPlatformDefaults {
.register(new WalmartSubPlatform(transport, json))
.register(new TemuSubPlatform(transport, json))
.register(new SheinSubPlatform(transport, json))
.register(new ShopifySubPlatform(transport, json))
.register(new EbaySubPlatform(transport, json))
.register(new AliexpressSubPlatform(transport, json))
.register(new TiktokSubPlatform(transport, json))

4
lingxing/src/main/java/common/ecommerce/lingxing/platform/multiplatform/product/LingxingProductSearchBody.java

@ -11,7 +11,7 @@ import java.util.List; @@ -11,7 +11,7 @@ import java.util.List;
* <ul>
* <li>沃尔玛 / eBay / Temu / SHEIN / TikTok / AliExpress:{@code searchField}(数字)
* + {@code searchSingleValue}(单值模糊)+ {@code searchValues}(多值精确)</li>
* <li>Shopify / Target:{@code search_field} + {@code search_single_value} + {@code search_values}</li>
* <li>Target(走领星 shopify 路径):{@code search_field} + {@code search_single_value} + {@code search_values}</li>
* <li>亚马逊 SC:{@code search_field}(字符串)+ {@code search_value}(数组)+ {@code exact_search}</li>
* </ul>
*/
@ -36,7 +36,7 @@ public final class LingxingProductSearchBody { @@ -36,7 +36,7 @@ public final class LingxingProductSearchBody {
/**
* snake_case 形态:search_field / search_single_value / search_values。
*
* <p>用于 Shopify、Target。</p>
* <p>用于 Target(领星 shopify 路径)。</p>
*/
public static void snakeCase(java.util.Map<String, Object> body, ProductQuery query, Object fieldValue) {
if (query == null || !query.hasSearch()) {

10
lingxing/src/main/java/common/ecommerce/lingxing/platform/multiplatform/product/LingxingProductSearchMapper.java

@ -14,7 +14,7 @@ import common.ecommerce.model.product.ProductSearchField; @@ -14,7 +14,7 @@ import common.ecommerce.model.product.ProductSearchField;
* Temu 9 8
* SHEIN 9 8
* TikTok 9 8
* Shopify/Target 1 待核对(样本 local_sku 为空)
* Target 1 待核对(样本 local_sku 为空)
* 亚马逊 SC "seller_sku" "sku" ← 字符串,不是数字
* 亚马逊 VC 不支持搜索
* </pre>
@ -62,16 +62,16 @@ public final class LingxingProductSearchMapper { @@ -62,16 +62,16 @@ public final class LingxingProductSearchMapper {
}
/**
* Shopify / Target:1 = msku。
* Target:1 = msku(实测)。
*
* <p>本地 SKU 的编码文档未给出,实测样本 {@code local_sku} 也为空,
* 暂时返回 null 表示不支持;联调时用探针确认后再补。</p>
* 暂时抛异常表示不支持;联调时用探针确认后再补。</p>
*/
public static Object shopify(ProductSearchField field) {
public static Object target(ProductSearchField field) {
if (field == ProductSearchField.PLATFORM_SKU) {
return 1;
}
throw new UnsupportedOperationException("shopify/target listing does not support local sku search yet");
throw new UnsupportedOperationException("target listing does not support local sku search yet");
}
/** 亚马逊 SC:字符串 "seller_sku" / "sku"。 */

58
lingxing/src/main/java/common/ecommerce/lingxing/platform/shopify/ShopifySubPlatform.java

@ -1,58 +0,0 @@ @@ -1,58 +0,0 @@
package common.ecommerce.lingxing.platform.shopify;
import common.ecommerce.http.HttpTransport;
import common.ecommerce.http.JacksonJsonCodec;
import common.ecommerce.lingxing.platform.LingxingSubPlatform;
import common.ecommerce.lingxing.platform.LingxingOrderSource;
import common.ecommerce.lingxing.platform.LingxingProductSource;
import common.ecommerce.lingxing.platform.LingxingShopSource;
import common.ecommerce.lingxing.platform.multiplatform.order.MultiPlatformOrderSource;
import common.ecommerce.lingxing.platform.multiplatform.outbound.MultiPlatformOutboundSource;
import common.ecommerce.lingxing.platform.multiplatform.shop.MultiPlatformShopSource;
import common.ecommerce.lingxing.platform.LingxingOutboundSource;
import common.ecommerce.lingxing.platform.shopify.product.ShopifyProductSource;
import common.ecommerce.model.Platform;
/**
* 领星 · Shopify 子平台:只做能力组合。
*/
public final class ShopifySubPlatform implements LingxingSubPlatform {
/** 快速出库是多平台通用接口,各子平台共用。 */
private static final MultiPlatformOutboundSource OUTBOUND = new MultiPlatformOutboundSource();
private final LingxingOrderSource orders;
private final LingxingProductSource products;
private final LingxingShopSource shops;
public ShopifySubPlatform(HttpTransport transport, JacksonJsonCodec json) {
this.orders = new MultiPlatformOrderSource(transport, json);
this.products = new ShopifyProductSource();
this.shops = new MultiPlatformShopSource(Platform.SHOPIFY);
}
@Override
public Platform platform() {
return Platform.SHOPIFY;
}
@Override
public LingxingOrderSource orderSource() {
return orders;
}
@Override
public LingxingProductSource productSource() {
return products;
}
@Override
public LingxingShopSource shopSource() {
return shops;
}
@Override
public LingxingOutboundSource outboundSource() {
return OUTBOUND;
}
}

166
lingxing/src/main/java/common/ecommerce/lingxing/platform/shopify/dto/ShopifyListingDto.java

@ -1,166 +0,0 @@ @@ -1,166 +0,0 @@
package common.ecommerce.lingxing.platform.shopify.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;
/**
* 领星 · Shopify 在线商品({@code /basicOpen/multiplatform/shopify/variantList} 的 {@code data.list[]})。
*
* <p>文档字段是 snake_case;这里用 camelCase 的 Java 字段 + {@code @JsonProperty} 映射。</p>
*
* <p>Shopify 按<b>变体(variant)</b>返回,{@code msku} 是平台侧 SKU。</p>
*/
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class ShopifyListingDto {
/** 商品 ID。 */
@JsonProperty("item_id")
private String itemId;
/** 商品链接。 */
@JsonProperty("item_url")
private String itemUrl;
/** 产品 uid。 */
@JsonProperty("product_unique_id")
private String productUniqueId;
/** 子体 uid。 */
@JsonProperty("variant_unique_id")
private String variantUniqueId;
/** 企业 ID。 */
@JsonProperty("company_id")
private String companyId;
/** 父图链接。 */
@JsonProperty("parent_picture_url")
private String parentPictureUrl;
/** 图片链接。 */
@JsonProperty("picture_url")
private String pictureUrl;
/** 父 MSKU。 */
@JsonProperty("parent_msku")
private String parentMsku;
/** 平台侧 MSKU,参与 canonicalKey。 */
@JsonProperty("msku")
private String msku;
/** 母体属性,如 Size/Color。 */
@JsonProperty("parent_attribute")
private String parentAttribute;
/** 变体属性,如 42 / red。 */
@JsonProperty("attribute")
private String attribute;
/** 标题。 */
@JsonProperty("title")
private String title;
/** 本地 SKU。 */
@JsonProperty("local_sku")
private String localSku;
/** 本地商品 id。 */
@JsonProperty("pid")
private String pid;
/** 本地品名。 */
@JsonProperty("local_name")
private String localName;
/** 店铺 id。 */
@JsonProperty("store_id")
private String storeId;
/** 店铺名称。 */
@JsonProperty("store_name")
private String storeName;
/** 售价。 */
@JsonProperty("price")
private String price;
/** 库存。 */
@JsonProperty("quantity")
private String quantity;
/** 货币符号,如 ¥。 */
@JsonProperty("currency_icon")
private String currencyIcon;
/** 是否有子体。 */
@JsonProperty("has_variant")
private Boolean hasVariant;
/** 开始时间,Y-m-d H:i:s。 */
@JsonProperty("listing_start_time")
private String listingStartTime;
/** 结束时间,Y-m-d H:i:s。 */
@JsonProperty("listing_end_time")
private String listingEndTime;
/** 商品状态:1 active,2 draft,3 archived,4 deleted。 */
@JsonProperty("status")
private Integer status;
/** 商品状态名。 */
@JsonProperty("status_name")
private String statusName;
/** 库存策略:1 不跟踪,2 缺货停止销售,3 缺货继续销售。 */
@JsonProperty("inventory_policy")
private Integer inventoryPolicy;
/** 库存策略名。 */
@JsonProperty("inventory_policy_name")
private String inventoryPolicyName;
/** 商品分类 ID。 */
@JsonProperty("type_id")
private String typeId;
/** 商品分类名。 */
@JsonProperty("type_name")
private String typeName;
/** 是否需要运输。 */
@JsonProperty("requires_shipping")
private Boolean requiresShipping;
/** 是否要征税。 */
@JsonProperty("taxable")
private Boolean taxable;
/** 最小重量。 */
@JsonProperty("min_weight")
private Integer minWeight;
/** 最大重量。 */
@JsonProperty("max_weight")
private Integer maxWeight;
/** 重量单位。 */
@JsonProperty("weight_unit")
private String weightUnit;
/** 重量。 */
@JsonProperty("weight")
private String weight;
/** 各仓位信息。 */
@JsonProperty("location_infos")
private List<ShopifyLocationDto> locationInfos = new ArrayList<ShopifyLocationDto>();
}

49
lingxing/src/main/java/common/ecommerce/lingxing/platform/shopify/dto/ShopifyLocationDto.java

@ -1,49 +0,0 @@ @@ -1,49 +0,0 @@
package common.ecommerce.lingxing.platform.shopify.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
/** Shopify 商品仓位信息({@code location_infos[]})。 */
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class ShopifyLocationDto {
/** 仓位 id。 */
@JsonProperty("location_id")
private String locationId;
/** 仓位名称。 */
@JsonProperty("location_name")
private String locationName;
/** 该仓位库存。 */
@JsonProperty("location_quantity")
private String locationQuantity;
/** 库存调整后的值。 */
@JsonProperty("quantity_adjust_after")
private String quantityAdjustAfter;
/** 库存调整前的值。 */
@JsonProperty("quantity_adjust_before")
private String quantityAdjustBefore;
/** 库存调整操作人 id。 */
@JsonProperty("quantity_user_id")
private String quantityUserId;
/** 库存调整操作人名字。 */
@JsonProperty("quantity_user_id_name")
private String quantityUserIdName;
/** 库存队列类型。 */
@JsonProperty("quantity_queue_type")
private Integer quantityQueueType;
/** 库存队列状态。 */
@JsonProperty("quantity_queue_status")
private String quantityQueueStatus;
}

272
lingxing/src/main/java/common/ecommerce/lingxing/platform/shopify/product/ShopifyProductSource.java

@ -1,272 +0,0 @@ @@ -1,272 +0,0 @@
package common.ecommerce.lingxing.platform.shopify.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.LingxingProductSource;
import common.ecommerce.lingxing.platform.shopify.dto.ShopifyListingDto;
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.Locale;
import java.util.Map;
/**
* 领星 · Shopify 在线商品(变体维度)。
*
* <p>接口 {@code /basicOpen/multiplatform/shopify/variantList}:POST,{@code offset}/{@code length}
* (上限 1000),返回 {@code data.list};令牌桶容量 1。</p>
*/
public final class ShopifyProductSource implements LingxingProductSource {
private static final int MAX_PAGE_SIZE = 1000;
/** 时间字段格式,文档未给出示例值格式,按 Y-m-d H:i:s 发送。 */
private static final DateTimeFormatter DATE_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@Override
public Page<ProductListing> products(LingxingCall call, ProductQuery query) {
int length = Math.min(query.pageSize() <= 0 ? 100 : 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("store_ids", Collections.singletonList(call.ctx().account().externalStoreId()));
applyTimeWindow(body, query);
HttpRequest req = call.signed(LingxingApi.LISTING_SHOPIFY, body, "products.pull");
HttpResponse resp = call.execute(req);
LingxingEnvelope envelope = call.envelope(resp, "products.pull");
List<ShopifyListingDto> dtos = call.json().listAt(envelope.body(), "data.list", ShopifyListingDto.class);
List<ProductListing> out = new ArrayList<ProductListing>(dtos.size());
for (ShopifyListingDto 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);
}
/** 时间窗:按 UTC 发送,未给终点时不发终点。 */
private static void applyTimeWindow(Map<String, Object> body, ProductQuery query) {
Instant from = query.updatedAfter();
Instant to = query.updatedBefore();
if (from == null && to == null) {
return;
}
ZoneId utc = ZoneId.of("UTC");
if (from != null) {
body.put("listing_start_time", DATE_TIME.format(from.atZone(utc)));
}
if (to != null) {
body.put("listing_end_time", DATE_TIME.format(to.atZone(utc)));
}
}
/** 总数取 data.count;没有时用顶层 total;都没有返回 -1。 */
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;
}
}
/**
* 领星 Shopify 商品 → 统一模型。
*
* <p>统一字段来源:</p>
* <ul>
* <li>platformSku ← {@code msku}</li>
* <li>listingId ← {@code product_unique_id}</li>
* <li>gtin ← 无</li>
* <li>title ← {@code title}</li>
* <li>imageUrls ← {@code picture_url},为空时用 {@code parent_picture_url}</li>
* <li>status ← {@code status}(1 active / 2 draft / 3 archived / 4 deleted)</li>
* <li>rawStatus ← {@code status_name} 原值</li>
* <li>price ← {@code price};currency 由 {@code currency_icon} 反推</li>
* <li>listedAt ← {@code listing_start_time}</li>
* <li>updatedAt ← 无(接口没有内容更新时间)</li>
* <li>attributes ← 其余全部原始字段</li>
* </ul>
*/
private ProductListing toProductListing(ShopifyListingDto dto, LingxingCall call) {
ZoneId zone = ZoneId.of(call.ctx().account().marketplaceZone());
String currency = currencyOf(dto.getCurrencyIcon());
String image = firstNonBlank(dto.getPictureUrl(), dto.getParentPictureUrl());
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.<String>emptyList()
: Collections.singletonList(image))
.status(statusOf(dto))
.rawStatus(dto.getStatusName())
.price(moneyOrNull(dto.getPrice(), currency))
.currency(currency)
.listedAt(dateTime(dto.getListingStartTime(), zone))
.attributes(attributesOf(dto))
.sourceProvider(ChannelProvider.LINGXING)
.build();
}
/** Shopify:1 active / 2 draft / 3 archived / 4 deleted。 */
private static ProductStatus statusOf(ShopifyListingDto dto) {
if (dto.getStatus() == null) {
String name = dto.getStatusName();
if (name != null) {
String s = name.trim().toUpperCase(Locale.ROOT);
if ("ACTIVE".equals(s)) {
return ProductStatus.ACTIVE;
}
if ("DELETED".equals(s)) {
return ProductStatus.DELETED;
}
if ("DRAFT".equals(s) || "ARCHIVED".equals(s)) {
return ProductStatus.INACTIVE;
}
}
return ProductStatus.UNKNOWN;
}
switch (dto.getStatus()) {
case 1:
return ProductStatus.ACTIVE;
case 2:
case 3:
return ProductStatus.INACTIVE;
case 4:
return ProductStatus.DELETED;
default:
return ProductStatus.UNKNOWN;
}
}
private static Map<String, Object> attributesOf(ShopifyListingDto dto) {
Map<String, Object> attrs = new LinkedHashMap<String, Object>();
attrs.put("item_id", dto.getItemId());
attrs.put("item_url", dto.getItemUrl());
attrs.put("variant_unique_id", dto.getVariantUniqueId());
attrs.put("company_id", dto.getCompanyId());
attrs.put("parent_picture_url", dto.getParentPictureUrl());
attrs.put("parent_msku", dto.getParentMsku());
attrs.put("parent_attribute", dto.getParentAttribute());
attrs.put("attribute", dto.getAttribute());
attrs.put("local_sku", dto.getLocalSku());
attrs.put("pid", dto.getPid());
attrs.put("local_name", dto.getLocalName());
attrs.put("store_id", dto.getStoreId());
attrs.put("store_name", dto.getStoreName());
attrs.put("quantity", dto.getQuantity());
attrs.put("currency_icon", dto.getCurrencyIcon());
attrs.put("has_variant", dto.getHasVariant());
attrs.put("listing_end_time", dto.getListingEndTime());
attrs.put("inventory_policy", dto.getInventoryPolicy());
attrs.put("inventory_policy_name", dto.getInventoryPolicyName());
attrs.put("type_id", dto.getTypeId());
attrs.put("type_name", dto.getTypeName());
attrs.put("requires_shipping", dto.getRequiresShipping());
attrs.put("taxable", dto.getTaxable());
attrs.put("min_weight", dto.getMinWeight());
attrs.put("max_weight", dto.getMaxWeight());
attrs.put("weight", dto.getWeight());
attrs.put("weight_unit", dto.getWeightUnit());
attrs.put("location_infos", dto.getLocationInfos());
attrs.values().removeAll(Collections.singleton(null));
return attrs;
}
/** 货币符号 → ISO;约定 ¥ 符号视为日元,人民币以 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)) {
// 约定:¥ 符号按日元处理;人民币由平台以 ISO 代码 CNY 返回
return "JPY";
}
if ("CNY".equalsIgnoreCase(s) || "RMB".equalsIgnoreCase(s)) {
return "CNY";
}
return null;
}
private static PlatformTime dateTime(String raw, ZoneId zone) {
if (raw == null || raw.trim().isEmpty()) {
return null;
}
try {
Instant utc = LocalDateTime.parse(raw.trim(), DATE_TIME).atZone(zone).toInstant();
return PlatformTime.of(utc, zone);
} 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;
}
}

10
lingxing/src/main/java/common/ecommerce/lingxing/platform/target/TargetSubPlatform.java

@ -10,7 +10,7 @@ import common.ecommerce.lingxing.platform.LingxingSubPlatform; @@ -10,7 +10,7 @@ import common.ecommerce.lingxing.platform.LingxingSubPlatform;
import common.ecommerce.lingxing.platform.multiplatform.order.MultiPlatformOrderSource;
import common.ecommerce.lingxing.platform.multiplatform.outbound.MultiPlatformOutboundSource;
import common.ecommerce.lingxing.platform.multiplatform.shop.MultiPlatformShopSource;
import common.ecommerce.lingxing.platform.shopify.product.ShopifyProductSource;
import common.ecommerce.lingxing.platform.target.product.TargetProductSource;
import common.ecommerce.model.Platform;
/**
@ -19,9 +19,9 @@ import common.ecommerce.model.Platform; @@ -19,9 +19,9 @@ import common.ecommerce.model.Platform;
* <p>领星文档没有给出 Target 的独立 platform_code(多见于自定义平台或 Mirakl)。
* 订单与店铺都按<b>账户</b>的 platform_code 查询多平台接口,不按平台码反推。</p>
*
* <p>Target 没有独立的商品接口,商品走 Shopify 的
* {@code /basicOpen/multiplatform/shopify/variantList},因此复用
* {@link ShopifyProductSource}。</p>
* <p>Target 没有独立的商品接口,商品走领星的
* {@code /basicOpen/multiplatform/shopify/variantList}(路径名是领星的历史命名,
* 与业务平台无关),由 {@link TargetProductSource} 实现。</p>
*/
public final class TargetSubPlatform implements LingxingSubPlatform {
@ -34,7 +34,7 @@ public final class TargetSubPlatform implements LingxingSubPlatform { @@ -34,7 +34,7 @@ public final class TargetSubPlatform implements LingxingSubPlatform {
public TargetSubPlatform(HttpTransport transport, JacksonJsonCodec json) {
this.orders = new MultiPlatformOrderSource(transport, json);
this.products = new ShopifyProductSource();
this.products = new TargetProductSource();
this.shops = new MultiPlatformShopSource(Platform.TARGET);
}

4
lingxing/src/main/java/common/ecommerce/lingxing/platform/target/product/TargetProductSource.java

@ -292,11 +292,11 @@ public final class TargetProductSource implements LingxingProductSource { @@ -292,11 +292,11 @@ public final class TargetProductSource implements LingxingProductSource {
return;
}
try {
Object fieldValue = LingxingProductSearchMapper.shopify(query.searchField());
Object fieldValue = LingxingProductSearchMapper.target(query.searchField());
LingxingProductSearchBody.snakeCase(body, query, fieldValue);
} catch (UnsupportedOperationException e) {
ChannelException.Builder b = ChannelException.builder()
.message("shopify/target listing does not support search field "
.message("target listing does not support search field "
+ query.searchField())
.operation("products.pull")
.retryable(false);

Loading…
Cancel
Save