Browse Source
接口(均为 POST、qps 1、返回 data.list): - AliExpress /basicOpen/multiplatform/aliexpress/list/v2(托管模式,isParent=0 子体) - SHEIN /basicOpen/multiplatform/shein/list(上限 1000) - TikTok /basicOpen/multiplatform/tiktok/list(上限 1000) 映射要点: - 三者 platformSku 均取 msku,listingId 取 productUniqueId - AliExpress:price 取 effectiveSupplyPrice + currencyCode; createTime 是北京时间,按 Asia/Shanghai 解析;storeIds 尽量传数字 - SHEIN:salePrice + saleCurrency;图片依次回落 imgUrl/imgMediumUrl/imgSmallUrl; status 0 删除 / 1 在售 / 2 停售 - TikTok:salesPrice + currency;title 为空时回落 pname; platformStatus 字符串归一,兼容示例中的无下划线写法 SELLERDEACTIVATED Platform 新增 ALIEXPRESS,适配器与工厂的 platforms() 同步; LingxingSubPlatforms 注册三个子平台。 其余字段全部进 attributes。 Co-Authored-By: Claude <noreply@anthropic.com>feature/supplier-lingxing
20 changed files with 1588 additions and 3 deletions
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
@ -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; |
||||||
|
} |
||||||
@ -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[]})。 |
||||||
|
* |
||||||
|
* <p>字段为 camelCase。响应结构:{@code data.count} + {@code data.list}。</p> |
||||||
|
* |
||||||
|
* <p>注意文档对 {@code price} 的说明是「单位分,需除以 100 万」,示例 99990000 |
||||||
|
* 对应 {@code effectiveSupplyPrice} 59.99——实际换算需联调确认,这里只保留原值。</p> |
||||||
|
*/ |
||||||
|
@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<AliexpressSupplyPriceDto> supplyPriceList = new ArrayList<AliexpressSupplyPriceDto>(); |
||||||
|
|
||||||
|
/** 店铺 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<AliExpressWarehouseDto> wareHouseDataList = new ArrayList<AliExpressWarehouseDto>(); |
||||||
|
|
||||||
|
/** 唯一 ID。 */ |
||||||
|
@JsonProperty("uniqueId") |
||||||
|
private String uniqueId; |
||||||
|
|
||||||
|
/** 变体唯一 ID。 */ |
||||||
|
@JsonProperty("variantUniqueId") |
||||||
|
private String variantUniqueId; |
||||||
|
|
||||||
|
/** 仓库详情 JSON 字符串。 */ |
||||||
|
@JsonProperty("extJson") |
||||||
|
private String extJson; |
||||||
|
} |
||||||
@ -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; |
||||||
|
} |
||||||
@ -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 在线商品(托管模式)。 |
||||||
|
* |
||||||
|
* <p>接口 {@code /basicOpen/multiplatform/aliexpress/list/v2}:POST,{@code offset}/{@code length} |
||||||
|
* 必填,返回 {@code data.list};令牌桶容量 1。</p> |
||||||
|
* |
||||||
|
* <p>{@code isParent} 必填:本实现固定查子体(0),与统一模型的「一条 = 一个可售 SKU」对齐。</p> |
||||||
|
*/ |
||||||
|
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<ProductListing> 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<String, Object> body = new LinkedHashMap<String, Object>(); |
||||||
|
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<AliexpressListingDto> dtos = |
||||||
|
call.json().listAt(envelope.body(), "data.list", AliexpressListingDto.class); |
||||||
|
List<ProductListing> out = new ArrayList<ProductListing>(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<String, Object> 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 商品 → 统一模型。 |
||||||
|
* |
||||||
|
* <p>统一字段来源:</p> |
||||||
|
* <ul> |
||||||
|
* <li>platformSku ← {@code msku}</li> |
||||||
|
* <li>listingId ← {@code productUniqueId}</li> |
||||||
|
* <li>title ← {@code title}</li> |
||||||
|
* <li>imageUrls ← {@code skuImage},为空时用 {@code imageUrls}(父体图)</li> |
||||||
|
* <li>status ← {@code status}(文档只给了「可售」=2,其余归 UNKNOWN)</li> |
||||||
|
* <li>rawStatus ← {@code statusName} 原值(中文)</li> |
||||||
|
* <li>price ← {@code effectiveSupplyPrice} + {@code currencyCode}</li> |
||||||
|
* <li>listedAt ← {@code createTime}(北京时间,按 UTC 换算)</li> |
||||||
|
* <li>updatedAt ← 无</li> |
||||||
|
* <li>attributes ← 其余全部原始字段</li> |
||||||
|
* </ul> |
||||||
|
*/ |
||||||
|
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.<String>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<AliexpressSupplyPriceDto> 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<String, Object> attributesOf(AliexpressListingDto dto) { |
||||||
|
Map<String, Object> attrs = new LinkedHashMap<String, Object>(); |
||||||
|
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; |
||||||
|
} |
||||||
|
} |
||||||
@ -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 子平台:只做能力组合。 |
||||||
|
* |
||||||
|
* <p>10021 / 10027 / 10028 都映射到 {@link Platform#SHEIN}。</p> |
||||||
|
*/ |
||||||
|
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; |
||||||
|
} |
||||||
|
} |
||||||
@ -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[]})。 |
||||||
|
* |
||||||
|
* <p>字段为 camelCase,响应结构 {@code data.count} + {@code data.list}。</p> |
||||||
|
*/ |
||||||
|
@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<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; |
||||||
|
|
||||||
|
/** 平台代码,如 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<SheinWarehouseDto> wareHouseDataList = new ArrayList<SheinWarehouseDto>(); |
||||||
|
|
||||||
|
/** 备注。 */ |
||||||
|
@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<SheinSiteDto> 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<SheinSupplyPriceDto> supplyPriceList = new ArrayList<SheinSupplyPriceDto>(); |
||||||
|
} |
||||||
@ -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; |
||||||
|
} |
||||||
@ -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; |
||||||
|
} |
||||||
@ -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; |
||||||
|
} |
||||||
@ -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 在线商品。 |
||||||
|
* |
||||||
|
* <p>接口 {@code /basicOpen/multiplatform/shein/list}:POST,{@code offset}/{@code length} |
||||||
|
* (上限 1000),返回 {@code data.list};令牌桶容量 1。</p> |
||||||
|
* |
||||||
|
* <p>接口不支持时间窗过滤。</p> |
||||||
|
*/ |
||||||
|
public final class SheinProductSource implements LingxingProductSource { |
||||||
|
|
||||||
|
private static final int MAX_PAGE_SIZE = 1000; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Page<ProductListing> 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<String, Object> body = new LinkedHashMap<String, Object>(); |
||||||
|
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<SheinListingDto> dtos = call.json().listAt(envelope.body(), "data.list", SheinListingDto.class); |
||||||
|
List<ProductListing> out = new ArrayList<ProductListing>(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 商品 → 统一模型。 |
||||||
|
* |
||||||
|
* <p>统一字段来源:</p> |
||||||
|
* <ul> |
||||||
|
* <li>platformSku ← {@code msku}</li> |
||||||
|
* <li>listingId ← {@code productUniqueId}</li> |
||||||
|
* <li>title ← {@code title}</li> |
||||||
|
* <li>imageUrls ← {@code imgUrl},为空时依次回落 {@code imgMediumUrl} / {@code imgSmallUrl}</li> |
||||||
|
* <li>status ← {@code status}(0 删除 / 1 在售 / 2 停售)</li> |
||||||
|
* <li>rawStatus ← 原始 {@code status} 值</li> |
||||||
|
* <li>price ← {@code salePrice} + {@code saleCurrency}(符号按约定映射)</li> |
||||||
|
* <li>listedAt / updatedAt ← 无(接口不返回时间字段)</li> |
||||||
|
* <li>attributes ← 其余全部原始字段</li> |
||||||
|
* </ul> |
||||||
|
*/ |
||||||
|
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.<String>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<SheinSupplyPriceDto> 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<String, Object> attributesOf(SheinListingDto 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("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; |
||||||
|
} |
||||||
|
} |
||||||
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
@ -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[]})。 |
||||||
|
* |
||||||
|
* <p>字段为 camelCase,响应结构 {@code data.count} + {@code data.list}。</p> |
||||||
|
*/ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true) |
||||||
|
public class TiktokListingDto { |
||||||
|
|
||||||
|
@JsonProperty("id") |
||||||
|
private String id; |
||||||
|
|
||||||
|
@JsonProperty("productUniqueId") |
||||||
|
private String productUniqueId; |
||||||
|
|
||||||
|
@JsonProperty("principalUids") |
||||||
|
private List<String> principalUids = new ArrayList<String>(); |
||||||
|
|
||||||
|
@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。 |
||||||
|
* |
||||||
|
* <p>注意示例里出现过 {@code SELLERDEACTIVATED}(无下划线),做容错处理。</p> |
||||||
|
*/ |
||||||
|
@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<TiktokWarehouseDto> wareHouseDataList = new ArrayList<TiktokWarehouseDto>(); |
||||||
|
} |
||||||
@ -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; |
||||||
|
} |
||||||
@ -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 在线商品。 |
||||||
|
* |
||||||
|
* <p>接口 {@code /basicOpen/multiplatform/tiktok/list}:POST,{@code offset}/{@code length} |
||||||
|
* (上限 1000),返回 {@code data.list};令牌桶容量 1。接口不支持时间窗过滤。</p> |
||||||
|
*/ |
||||||
|
public final class TiktokProductSource implements LingxingProductSource { |
||||||
|
|
||||||
|
private static final int MAX_PAGE_SIZE = 1000; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Page<ProductListing> 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<String, Object> body = new LinkedHashMap<String, Object>(); |
||||||
|
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<TiktokListingDto> dtos = call.json().listAt(envelope.body(), "data.list", TiktokListingDto.class); |
||||||
|
List<ProductListing> out = new ArrayList<ProductListing>(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 商品 → 统一模型。 |
||||||
|
* |
||||||
|
* <p>统一字段来源:</p> |
||||||
|
* <ul> |
||||||
|
* <li>platformSku ← {@code msku}</li> |
||||||
|
* <li>listingId ← {@code productUniqueId}</li> |
||||||
|
* <li>title ← {@code title};为空时回落 {@code pname}(示例中 title 可能为 "")</li> |
||||||
|
* <li>imageUrls ← {@code imgUrl}</li> |
||||||
|
* <li>status ← {@code platformStatus} 字符串归一</li> |
||||||
|
* <li>rawStatus ← {@code platformStatus} 原值</li> |
||||||
|
* <li>price ← {@code salesPrice} + {@code currency}</li> |
||||||
|
* <li>listedAt / updatedAt ← 无(接口不返回时间字段)</li> |
||||||
|
* <li>attributes ← 其余全部原始字段</li> |
||||||
|
* </ul> |
||||||
|
*/ |
||||||
|
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.<String>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 平台状态字符串归一。 |
||||||
|
* |
||||||
|
* <p>文档枚举:DRAFT / PENDING / FAILED / ACTIVATE / SELLER_DEACTIVATED / |
||||||
|
* PLATFORM_DEACTIVATED / FREEZE / DELETED。示例中出现过无下划线写法 |
||||||
|
* {@code SELLERDEACTIVATED},先去掉下划线再匹配。</p> |
||||||
|
*/ |
||||||
|
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<String, Object> attributesOf(TiktokListingDto 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("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; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue