Browse Source
Temu(/basicOpen/multiplatform/temu/list, POST, qps 1, 上限 1000): - TemuListingDto 全字段 + 嵌套 wareHouseDataList / supplyPriceList / promotionalPriceDataList - 固定 offset 分页(useCursor=false);总数取 data.count - 时间窗 updateStartTime/updateEndTime 按 UTC 发送 - 映射:msku→platformSku、productUniqueId→listingId、imgUrl→imageUrls、 status(0 删除/2 正常)、当前生效申报价→price(币种符号 ¥ 无法判定时不填金额) - 其余进 attributes(SKC/SPU、仓库库存、活动价、JIT、selectStatus 等) Shopify(/basicOpen/multiplatform/shopify/variantList, POST, qps 1, 上限 1000): - ShopifyListingDto 全字段 + location_infos 嵌套 - 映射:msku→platformSku、product_unique_id→listingId、 picture_url||parent_picture_url→imageUrls、status 1/2/3/4 归一、 price + currency_icon、listing_start_time→listedAt - 其余进 attributes Platform 新增 SHOPIFY,并在适配器与工厂的 platforms() 中登记; LingxingSubPlatforms 注册 TemuSubPlatform / ShopifySubPlatform。 Co-Authored-By: Claude <noreply@anthropic.com>feature/supplier-lingxing
15 changed files with 1087 additions and 2 deletions
@ -0,0 +1,30 @@ |
|||||||
|
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.product.LingxingProductSource; |
||||||
|
import common.ecommerce.lingxing.platform.shopify.product.ShopifyProductSource; |
||||||
|
import common.ecommerce.model.Platform; |
||||||
|
|
||||||
|
/** |
||||||
|
* 领星 · Shopify 子平台:只做能力组合。 |
||||||
|
*/ |
||||||
|
public final class ShopifySubPlatform implements LingxingSubPlatform { |
||||||
|
|
||||||
|
private final LingxingProductSource products; |
||||||
|
|
||||||
|
public ShopifySubPlatform(HttpTransport transport, JacksonJsonCodec json) { |
||||||
|
this.products = new ShopifyProductSource(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Platform platform() { |
||||||
|
return Platform.SHOPIFY; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public LingxingProductSource productSource() { |
||||||
|
return products; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,166 @@ |
|||||||
|
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>(); |
||||||
|
} |
||||||
@ -0,0 +1,49 @@ |
|||||||
|
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; |
||||||
|
} |
||||||
@ -0,0 +1,268 @@ |
|||||||
|
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.product.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;¥/¥ 无法区分人民币与日元,返回 null。 */ |
||||||
|
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"; |
||||||
|
} |
||||||
|
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; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,32 @@ |
|||||||
|
package common.ecommerce.lingxing.platform.temu; |
||||||
|
|
||||||
|
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.temu.product.TemuProductSource; |
||||||
|
import common.ecommerce.model.Platform; |
||||||
|
|
||||||
|
/** |
||||||
|
* 领星 · Temu 子平台:只做能力组合。 |
||||||
|
* |
||||||
|
* <p>10022 / 10024 都映射到 {@link Platform#TEMU},本实现同时服务两者。</p> |
||||||
|
*/ |
||||||
|
public final class TemuSubPlatform implements LingxingSubPlatform { |
||||||
|
|
||||||
|
private final LingxingProductSource products; |
||||||
|
|
||||||
|
public TemuSubPlatform(HttpTransport transport, JacksonJsonCodec json) { |
||||||
|
this.products = new TemuProductSource(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Platform platform() { |
||||||
|
return Platform.TEMU; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public LingxingProductSource productSource() { |
||||||
|
return products; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,169 @@ |
|||||||
|
package common.ecommerce.lingxing.platform.temu.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; |
||||||
|
|
||||||
|
/** |
||||||
|
* 领星 · Temu 在线商品({@code /basicOpen/multiplatform/temu/list} 的 {@code data.list[]})。 |
||||||
|
* |
||||||
|
* <p>字段名以官方文档为准(camelCase)。响应结构:{@code data.count} + {@code data.list}, |
||||||
|
* 顶层另有 {@code total}(文档示例为 0,实际以 data.count 为准)。</p> |
||||||
|
* |
||||||
|
* <p>SKU 语义:{@code msku} 是平台侧 MSKU,{@code sku} / {@code pmsku} 是本地 SKU, |
||||||
|
* 对齐时应优先用 {@code msku}。</p> |
||||||
|
*/ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true) |
||||||
|
public class TemuListingDto { |
||||||
|
|
||||||
|
/** 领星内部 id。 */ |
||||||
|
@JsonProperty("id") |
||||||
|
private String id; |
||||||
|
|
||||||
|
/** 商品 uid。 */ |
||||||
|
@JsonProperty("productUniqueId") |
||||||
|
private String productUniqueId; |
||||||
|
|
||||||
|
/** 负责人 uid 列表。 */ |
||||||
|
@JsonProperty("principalUids") |
||||||
|
private List<String> principalUids = new ArrayList<String>(); |
||||||
|
|
||||||
|
/** 负责人名称。 */ |
||||||
|
@JsonProperty("principalName") |
||||||
|
private String principalName; |
||||||
|
|
||||||
|
/** 企业 id。 */ |
||||||
|
@JsonProperty("companyId") |
||||||
|
private String companyId; |
||||||
|
|
||||||
|
/** 店铺 id。 */ |
||||||
|
@JsonProperty("storeId") |
||||||
|
private String storeId; |
||||||
|
|
||||||
|
/** 店铺名称。 */ |
||||||
|
@JsonProperty("storeName") |
||||||
|
private String storeName; |
||||||
|
|
||||||
|
/** 平台代码,如 10024。 */ |
||||||
|
@JsonProperty("platformCode") |
||||||
|
private String platformCode; |
||||||
|
|
||||||
|
/** MSKU ID。 */ |
||||||
|
@JsonProperty("mskuId") |
||||||
|
private String mskuId; |
||||||
|
|
||||||
|
/** 平台侧 SKU(MSKU),参与 canonicalKey。 */ |
||||||
|
@JsonProperty("msku") |
||||||
|
private String msku; |
||||||
|
|
||||||
|
/** 品名。 */ |
||||||
|
@JsonProperty("pname") |
||||||
|
private String pname; |
||||||
|
|
||||||
|
/** 本地 SKU(配对的)。 */ |
||||||
|
@JsonProperty("pmsku") |
||||||
|
private String pmsku; |
||||||
|
|
||||||
|
/** 本地 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<TemuWarehouseDto> wareHouseDataList = new ArrayList<TemuWarehouseDto>(); |
||||||
|
|
||||||
|
/** 备注。 */ |
||||||
|
@JsonProperty("notes") |
||||||
|
private String notes; |
||||||
|
|
||||||
|
/** 图片链接。 */ |
||||||
|
@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; |
||||||
|
|
||||||
|
/** 上架状态:0 删除,2 正常。 */ |
||||||
|
@JsonProperty("status") |
||||||
|
private Integer status; |
||||||
|
|
||||||
|
/** SKU 规格。 */ |
||||||
|
@JsonProperty("attribute") |
||||||
|
private String attribute; |
||||||
|
|
||||||
|
/** JIT 发货模式:0 无,1 Jit,2 非 Jit。 */ |
||||||
|
@JsonProperty("jitMode") |
||||||
|
private Integer jitMode; |
||||||
|
|
||||||
|
/** 叶子类目。 */ |
||||||
|
@JsonProperty("catName") |
||||||
|
private String catName; |
||||||
|
|
||||||
|
/** 商品状态枚举(生命周期),取值见文档附加说明。 */ |
||||||
|
@JsonProperty("selectStatus") |
||||||
|
private String selectStatus; |
||||||
|
|
||||||
|
/** 虚拟库存。 */ |
||||||
|
@JsonProperty("virtualQuantity") |
||||||
|
private Integer virtualQuantity; |
||||||
|
|
||||||
|
/** 可用库存。 */ |
||||||
|
@JsonProperty("usableInventory") |
||||||
|
private String usableInventory; |
||||||
|
|
||||||
|
/** 品牌名称。 */ |
||||||
|
@JsonProperty("bname") |
||||||
|
private String bname; |
||||||
|
|
||||||
|
/** 分类名称。 */ |
||||||
|
@JsonProperty("cname") |
||||||
|
private String cname; |
||||||
|
|
||||||
|
/** 申报价列表(按生效区间)。 */ |
||||||
|
@JsonProperty("supplyPriceList") |
||||||
|
private List<TemuSupplyPriceDto> supplyPriceList = new ArrayList<TemuSupplyPriceDto>(); |
||||||
|
|
||||||
|
/** 活动价详情。 */ |
||||||
|
@JsonProperty("promotionalPriceDataList") |
||||||
|
private List<TemuPromotionalPriceDto> promotionalPriceDataList = |
||||||
|
new ArrayList<TemuPromotionalPriceDto>(); |
||||||
|
} |
||||||
@ -0,0 +1,37 @@ |
|||||||
|
package common.ecommerce.lingxing.platform.temu.dto; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
|
||||||
|
/** Temu 活动价({@code promotionalPriceDataList[]})。 */ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true) |
||||||
|
public class TemuPromotionalPriceDto { |
||||||
|
|
||||||
|
/** 活动状态:0 报名失败,1 报名成功待开始,2 进行中,3 活动已结束。 */ |
||||||
|
@JsonProperty("activeStatus") |
||||||
|
private String activeStatus; |
||||||
|
|
||||||
|
/** Temu 活动主题名。 */ |
||||||
|
@JsonProperty("activeType") |
||||||
|
private String activeType; |
||||||
|
|
||||||
|
/** 币种,文档示例为 ISO 代码(CNY)。 */ |
||||||
|
@JsonProperty("currency") |
||||||
|
private String currency; |
||||||
|
|
||||||
|
/** 活动价。 */ |
||||||
|
@JsonProperty("promotionalPrice") |
||||||
|
private String promotionalPrice; |
||||||
|
|
||||||
|
/** 报名结果:0 失败,1 成功待开始,2 进行中,3 已结束。 */ |
||||||
|
@JsonProperty("result") |
||||||
|
private String result; |
||||||
|
|
||||||
|
/** 活动价唯一键。 */ |
||||||
|
@JsonProperty("uniqueId") |
||||||
|
private String uniqueId; |
||||||
|
} |
||||||
@ -0,0 +1,31 @@ |
|||||||
|
package common.ecommerce.lingxing.platform.temu.dto; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
|
||||||
|
/** Temu 申报价({@code supplyPriceList[]}),按生效区间分段。 */ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true) |
||||||
|
public class TemuSupplyPriceDto { |
||||||
|
|
||||||
|
/** 申报价。 */ |
||||||
|
@JsonProperty("price") |
||||||
|
private BigDecimal price; |
||||||
|
|
||||||
|
/** 货币,文档示例为符号「¥」,不是 ISO 代码。 */ |
||||||
|
@JsonProperty("currency") |
||||||
|
private String currency; |
||||||
|
|
||||||
|
/** 执行开始时间,Y-m-d。 */ |
||||||
|
@JsonProperty("beginStr") |
||||||
|
private String beginStr; |
||||||
|
|
||||||
|
/** 执行结束时间,Y-m-d;为空表示当前生效。 */ |
||||||
|
@JsonProperty("endStr") |
||||||
|
private String endStr; |
||||||
|
} |
||||||
@ -0,0 +1,25 @@ |
|||||||
|
package common.ecommerce.lingxing.platform.temu.dto; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
|
||||||
|
/** Temu 商品各仓库存({@code wareHouseDataList[]})。 */ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true) |
||||||
|
public class TemuWarehouseDto { |
||||||
|
|
||||||
|
/** 仓库 id。 */ |
||||||
|
@JsonProperty("warehouseId") |
||||||
|
private String warehouseId; |
||||||
|
|
||||||
|
/** 仓库名称。 */ |
||||||
|
@JsonProperty("warehouseName") |
||||||
|
private String warehouseName; |
||||||
|
|
||||||
|
/** 库存数量。 */ |
||||||
|
@JsonProperty("quantity") |
||||||
|
private Integer quantity; |
||||||
|
} |
||||||
@ -0,0 +1,264 @@ |
|||||||
|
package common.ecommerce.lingxing.platform.temu.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.temu.dto.TemuListingDto; |
||||||
|
import common.ecommerce.lingxing.platform.temu.dto.TemuSupplyPriceDto; |
||||||
|
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.time.Instant; |
||||||
|
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; |
||||||
|
|
||||||
|
/** |
||||||
|
* 领星 · Temu 在线商品。 |
||||||
|
* |
||||||
|
* <p>接口 {@code /basicOpen/multiplatform/temu/list}:POST,{@code offset}/{@code length} |
||||||
|
* (上限 1000)或 {@code cursorId} 游标分页,返回 {@code data.list};令牌桶容量 1。</p> |
||||||
|
* |
||||||
|
* <p>本实现固定走 offset 分页({@code useCursor=false}),游标以 offset 字符串表示。</p> |
||||||
|
*/ |
||||||
|
public final class TemuProductSource implements LingxingProductSource { |
||||||
|
|
||||||
|
private static final int MAX_PAGE_SIZE = 1000; |
||||||
|
|
||||||
|
/** 更新时间区间格式。 */ |
||||||
|
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("useCursor", Boolean.FALSE); |
||||||
|
body.put("storeIds", |
||||||
|
Collections.singletonList(call.ctx().account().externalStoreId())); |
||||||
|
applyTimeWindow(body, query); |
||||||
|
|
||||||
|
HttpRequest req = call.signed(LingxingApi.LISTING_TEMU, body, "products.pull"); |
||||||
|
HttpResponse resp = call.execute(req); |
||||||
|
LingxingEnvelope envelope = call.envelope(resp, "products.pull"); |
||||||
|
|
||||||
|
List<TemuListingDto> dtos = call.json().listAt(envelope.body(), "data.list", TemuListingDto.class); |
||||||
|
List<ProductListing> out = new ArrayList<ProductListing>(dtos.size()); |
||||||
|
for (TemuListingDto dto : dtos) { |
||||||
|
out.add(toProductListing(dto, call)); |
||||||
|
} |
||||||
|
|
||||||
|
// Temu 的 total 在 data.count(游标模式下不返回)
|
||||||
|
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("updateStartTime", DATE_TIME.format(from.atZone(utc))); |
||||||
|
} |
||||||
|
if (to != null) { |
||||||
|
body.put("updateEndTime", DATE_TIME.format(to.atZone(utc))); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** 总数取 data.count;没有时返回 -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; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 领星 Temu 商品 → 统一模型。 |
||||||
|
* |
||||||
|
* <p>统一字段来源:</p> |
||||||
|
* <ul> |
||||||
|
* <li>platformSku ← {@code msku}</li> |
||||||
|
* <li>listingId ← {@code productUniqueId}</li> |
||||||
|
* <li>title ← {@code title}</li> |
||||||
|
* <li>imageUrls ← {@code imgUrl}(单张,可能为空串)</li> |
||||||
|
* <li>status ← {@code status}(0 删除 / 2 正常)</li> |
||||||
|
* <li>rawStatus ← 原始 {@code status} 值</li> |
||||||
|
* <li>price / currency ← 当前生效的 {@code supplyPriceList} 条目(见下)</li> |
||||||
|
* <li>listedAt / updatedAt ← 无(接口不返回时间字段)</li> |
||||||
|
* <li>attributes ← 其余全部原始字段(SKC/SPU、仓库库存、活动价、JIT 模式等)</li> |
||||||
|
* </ul> |
||||||
|
* |
||||||
|
* <p><b>价格说明</b>:Temu 要求上报「申报价」,{@code supplyPriceList} 按时间区间分段, |
||||||
|
* 取 {@code endStr} 为空(当前生效)或开始时间最晚的一条。币种字段是符号「¥」, |
||||||
|
* 无法区分人民币/日元,按符号映射为 null 时不填金额。</p> |
||||||
|
*/ |
||||||
|
private ProductListing toProductListing(TemuListingDto dto, LingxingCall call) { |
||||||
|
TemuSupplyPriceDto price = currentSupplyPrice(dto.getSupplyPriceList()); |
||||||
|
String currency = price == null ? null : currencyOf(price.getCurrency()); |
||||||
|
|
||||||
|
return ProductListing.builder() |
||||||
|
.platform(call.ctx().platform()) |
||||||
|
.omsStoreId(call.ctx().omsStoreId()) |
||||||
|
.platformSku(dto.getMsku()) |
||||||
|
.listingId(trimToNull(dto.getProductUniqueId())) |
||||||
|
.title(dto.getTitle()) |
||||||
|
.imageUrls(isBlank(dto.getImgUrl()) |
||||||
|
? Collections.<String>emptyList() |
||||||
|
: Collections.singletonList(dto.getImgUrl().trim())) |
||||||
|
.status(statusOf(dto.getStatus())) |
||||||
|
.rawStatus(dto.getStatus() == null ? null : String.valueOf(dto.getStatus())) |
||||||
|
.price(price == null ? null : moneyOrNull(price.getPrice(), currency)) |
||||||
|
.currency(currency) |
||||||
|
.attributes(attributesOf(dto)) |
||||||
|
.sourceProvider(ChannelProvider.LINGXING) |
||||||
|
.build(); |
||||||
|
} |
||||||
|
|
||||||
|
/** 当前生效的申报价:优先 endStr 为空,否则取 beginStr 最大的一条。 */ |
||||||
|
private static TemuSupplyPriceDto currentSupplyPrice(List<TemuSupplyPriceDto> prices) { |
||||||
|
if (prices == null || prices.isEmpty()) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
TemuSupplyPriceDto best = null; |
||||||
|
for (TemuSupplyPriceDto p : prices) { |
||||||
|
if (p == null || p.getPrice() == null) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
if (isBlank(p.getEndStr())) { |
||||||
|
return p; |
||||||
|
} |
||||||
|
if (best == null || compareBegin(p.getBeginStr(), best.getBeginStr()) > 0) { |
||||||
|
best = p; |
||||||
|
} |
||||||
|
} |
||||||
|
return best; |
||||||
|
} |
||||||
|
|
||||||
|
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); |
||||||
|
} |
||||||
|
|
||||||
|
/** Temu 状态:0 删除,2 正常。 */ |
||||||
|
private static ProductStatus statusOf(Integer status) { |
||||||
|
if (status == null) { |
||||||
|
return ProductStatus.UNKNOWN; |
||||||
|
} |
||||||
|
if (status == 2) { |
||||||
|
return ProductStatus.ACTIVE; |
||||||
|
} |
||||||
|
if (status == 0) { |
||||||
|
return ProductStatus.DELETED; |
||||||
|
} |
||||||
|
return ProductStatus.UNKNOWN; |
||||||
|
} |
||||||
|
|
||||||
|
private static Map<String, Object> attributesOf(TemuListingDto dto) { |
||||||
|
Map<String, Object> attrs = new LinkedHashMap<String, Object>(); |
||||||
|
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("pmsku", dto.getPmsku()); |
||||||
|
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("cid", dto.getCid()); |
||||||
|
attrs.put("cname", dto.getCname()); |
||||||
|
attrs.put("catName", dto.getCatName()); |
||||||
|
attrs.put("bid", dto.getBid()); |
||||||
|
attrs.put("bname", dto.getBname()); |
||||||
|
attrs.put("attribute", dto.getAttribute()); |
||||||
|
attrs.put("jitMode", dto.getJitMode()); |
||||||
|
attrs.put("selectStatus", dto.getSelectStatus()); |
||||||
|
attrs.put("virtualQuantity", dto.getVirtualQuantity()); |
||||||
|
attrs.put("usableInventory", dto.getUsableInventory()); |
||||||
|
attrs.put("wareHouseDataList", dto.getWareHouseDataList()); |
||||||
|
attrs.put("supplyPriceList", dto.getSupplyPriceList()); |
||||||
|
attrs.put("promotionalPriceDataList", dto.getPromotionalPriceDataList()); |
||||||
|
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.values().removeAll(Collections.singleton(null)); |
||||||
|
return attrs; |
||||||
|
} |
||||||
|
|
||||||
|
/** 货币符号 → ISO;¥/¥ 人民币与日元无法区分,返回 null。 */ |
||||||
|
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"; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
private static Money moneyOrNull(java.math.BigDecimal amount, String currency) { |
||||||
|
if (amount == null || currency == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
return Money.of(amount, currency); |
||||||
|
} |
||||||
|
|
||||||
|
private static boolean isBlank(String v) { |
||||||
|
return v == null || v.trim().isEmpty(); |
||||||
|
} |
||||||
|
|
||||||
|
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