|
|
|
@ -7,12 +7,10 @@ import common.ecommerce.lingxing.http.LingxingEnvelope; |
|
|
|
import common.ecommerce.lingxing.platform.LingxingCall; |
|
|
|
import common.ecommerce.lingxing.platform.LingxingCall; |
|
|
|
import common.ecommerce.lingxing.platform.product.LingxingProductSource; |
|
|
|
import common.ecommerce.lingxing.platform.product.LingxingProductSource; |
|
|
|
import common.ecommerce.lingxing.platform.temu.dto.TemuListingDto; |
|
|
|
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.ChannelProvider; |
|
|
|
import common.ecommerce.model.product.ProductListing; |
|
|
|
import common.ecommerce.model.product.ProductListing; |
|
|
|
import common.ecommerce.model.product.ProductQuery; |
|
|
|
import common.ecommerce.model.product.ProductQuery; |
|
|
|
import common.ecommerce.model.product.ProductStatus; |
|
|
|
import common.ecommerce.model.product.ProductStatus; |
|
|
|
import common.ecommerce.model.support.Money; |
|
|
|
|
|
|
|
import common.ecommerce.model.support.Page; |
|
|
|
import common.ecommerce.model.support.Page; |
|
|
|
|
|
|
|
|
|
|
|
import java.time.Instant; |
|
|
|
import java.time.Instant; |
|
|
|
@ -110,19 +108,15 @@ public final class TemuProductSource implements LingxingProductSource { |
|
|
|
* <li>imageUrls ← {@code imgUrl}(单张,可能为空串)</li> |
|
|
|
* <li>imageUrls ← {@code imgUrl}(单张,可能为空串)</li> |
|
|
|
* <li>status ← {@code status}(0 删除 / 2 正常)</li> |
|
|
|
* <li>status ← {@code status}(0 删除 / 2 正常)</li> |
|
|
|
* <li>rawStatus ← 原始 {@code status} 值</li> |
|
|
|
* <li>rawStatus ← 原始 {@code status} 值</li> |
|
|
|
* <li>price / currency ← 当前生效的 {@code supplyPriceList} 条目(见下)</li> |
|
|
|
* <li>price / currency ← 接口不返回商品价格字段,一律为 null; |
|
|
|
|
|
|
|
* 申报价与活动价原值在 {@code attributes} 中</li> |
|
|
|
* <li>listedAt / updatedAt ← 无(接口不返回时间字段)</li> |
|
|
|
* <li>listedAt / updatedAt ← 无(接口不返回时间字段)</li> |
|
|
|
* <li>attributes ← 其余全部原始字段(SKC/SPU、仓库库存、活动价、JIT 模式等)</li> |
|
|
|
* <li>attributes ← 其余全部原始字段(SKC/SPU、仓库库存、活动价、JIT 模式等)</li> |
|
|
|
* </ul> |
|
|
|
* </ul> |
|
|
|
* |
|
|
|
* |
|
|
|
* <p><b>价格说明</b>:Temu 要求上报「申报价」,{@code supplyPriceList} 按时间区间分段, |
|
|
|
* <p>SDK 只做转发,不挑选生效区间、不做价格计算。</p> |
|
|
|
* 取 {@code endStr} 为空(当前生效)或开始时间最晚的一条。 |
|
|
|
|
|
|
|
* 币种按约定:{@code ¥} 符号视为日元,ISO 代码 {@code CNY} 视为人民币。</p> |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private ProductListing toProductListing(TemuListingDto dto, LingxingCall call) { |
|
|
|
private ProductListing toProductListing(TemuListingDto dto, LingxingCall call) { |
|
|
|
TemuSupplyPriceDto price = currentSupplyPrice(dto.getSupplyPriceList()); |
|
|
|
|
|
|
|
String currency = price == null ? null : currencyOf(price.getCurrency()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ProductListing.builder() |
|
|
|
return ProductListing.builder() |
|
|
|
.platform(call.ctx().platform()) |
|
|
|
.platform(call.ctx().platform()) |
|
|
|
.omsStoreId(call.ctx().omsStoreId()) |
|
|
|
.omsStoreId(call.ctx().omsStoreId()) |
|
|
|
@ -134,43 +128,13 @@ public final class TemuProductSource implements LingxingProductSource { |
|
|
|
: Collections.singletonList(dto.getImgUrl().trim())) |
|
|
|
: Collections.singletonList(dto.getImgUrl().trim())) |
|
|
|
.status(statusOf(dto.getStatus())) |
|
|
|
.status(statusOf(dto.getStatus())) |
|
|
|
.rawStatus(dto.getStatus() == null ? null : String.valueOf(dto.getStatus())) |
|
|
|
.rawStatus(dto.getStatus() == null ? null : String.valueOf(dto.getStatus())) |
|
|
|
.price(price == null ? null : moneyOrNull(price.getPrice(), currency)) |
|
|
|
.price(null) |
|
|
|
.currency(currency) |
|
|
|
.currency(null) |
|
|
|
.attributes(attributesOf(dto)) |
|
|
|
.attributes(attributesOf(dto)) |
|
|
|
.sourceProvider(ChannelProvider.LINGXING) |
|
|
|
.sourceProvider(ChannelProvider.LINGXING) |
|
|
|
.build(); |
|
|
|
.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 正常。 */ |
|
|
|
/** Temu 状态:0 删除,2 正常。 */ |
|
|
|
private static ProductStatus statusOf(Integer status) { |
|
|
|
private static ProductStatus statusOf(Integer status) { |
|
|
|
if (status == null) { |
|
|
|
if (status == null) { |
|
|
|
@ -222,38 +186,6 @@ public final class TemuProductSource implements LingxingProductSource { |
|
|
|
return attrs; |
|
|
|
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"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if ("¥".equals(s) || "¥".equals(s)) { |
|
|
|
|
|
|
|
// 约定:¥ 符号按日元处理;人民币由平台以 ISO 代码 CNY 返回
|
|
|
|
|
|
|
|
return "JPY"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if ("CNY".equalsIgnoreCase(s) || "RMB".equalsIgnoreCase(s)) { |
|
|
|
|
|
|
|
return "CNY"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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) { |
|
|
|
private static boolean isBlank(String v) { |
|
|
|
return v == null || v.trim().isEmpty(); |
|
|
|
return v == null || v.trim().isEmpty(); |
|
|
|
} |
|
|
|
} |
|
|
|
|