Browse Source
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
13 changed files with 23 additions and 571 deletions
@ -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; |
||||
} |
||||
} |
||||
@ -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>(); |
||||
} |
||||
@ -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; |
||||
} |
||||
@ -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; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue