|
|
|
@ -6,7 +6,6 @@ import common.ecommerce.lingxing.LingxingApi; |
|
|
|
import common.ecommerce.lingxing.http.LingxingEnvelope; |
|
|
|
import common.ecommerce.lingxing.http.LingxingEnvelope; |
|
|
|
import common.ecommerce.lingxing.platform.LingxingCall; |
|
|
|
import common.ecommerce.lingxing.platform.LingxingCall; |
|
|
|
import common.ecommerce.lingxing.platform.aliexpress.dto.AliexpressListingDto; |
|
|
|
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.lingxing.platform.product.LingxingProductSource; |
|
|
|
import common.ecommerce.model.ChannelProvider; |
|
|
|
import common.ecommerce.model.ChannelProvider; |
|
|
|
import common.ecommerce.model.product.ProductListing; |
|
|
|
import common.ecommerce.model.product.ProductListing; |
|
|
|
@ -44,8 +43,7 @@ public final class AliexpressProductSource implements LingxingProductSource { |
|
|
|
|
|
|
|
|
|
|
|
/** createTime 是北京时间。 */ |
|
|
|
/** createTime 是北京时间。 */ |
|
|
|
private static final ZoneId BEIJING = ZoneId.of("Asia/Shanghai"); |
|
|
|
private static final ZoneId BEIJING = ZoneId.of("Asia/Shanghai"); |
|
|
|
private static final DateTimeFormatter DATE_TIME = |
|
|
|
private static final DateTimeFormatter DATE_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
|
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
|
|
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|
|
|
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@ -57,16 +55,14 @@ public final class AliexpressProductSource implements LingxingProductSource { |
|
|
|
body.put("isParent", IS_CHILD); |
|
|
|
body.put("isParent", IS_CHILD); |
|
|
|
body.put("offset", offset); |
|
|
|
body.put("offset", offset); |
|
|
|
body.put("length", length); |
|
|
|
body.put("length", length); |
|
|
|
body.put("storeIds", |
|
|
|
body.put("storeIds", Collections.singletonList(parseStoreId(call.ctx().account().externalStoreId()))); |
|
|
|
Collections.singletonList(parseStoreId(call.ctx().account().externalStoreId()))); |
|
|
|
|
|
|
|
applyTimeWindow(body, query); |
|
|
|
applyTimeWindow(body, query); |
|
|
|
|
|
|
|
|
|
|
|
HttpRequest req = call.signed(LingxingApi.LISTING_ALIEXPRESS, body, "products.pull"); |
|
|
|
HttpRequest req = call.signed(LingxingApi.LISTING_ALIEXPRESS, body, "products.pull"); |
|
|
|
HttpResponse resp = call.execute(req); |
|
|
|
HttpResponse resp = call.execute(req); |
|
|
|
LingxingEnvelope envelope = call.envelope(resp, "products.pull"); |
|
|
|
LingxingEnvelope envelope = call.envelope(resp, "products.pull"); |
|
|
|
|
|
|
|
|
|
|
|
List<AliexpressListingDto> dtos = |
|
|
|
List<AliexpressListingDto> dtos = call.json().listAt(envelope.body(), "data.list", AliexpressListingDto.class); |
|
|
|
call.json().listAt(envelope.body(), "data.list", AliexpressListingDto.class); |
|
|
|
|
|
|
|
List<ProductListing> out = new ArrayList<ProductListing>(dtos.size()); |
|
|
|
List<ProductListing> out = new ArrayList<ProductListing>(dtos.size()); |
|
|
|
for (AliexpressListingDto dto : dtos) { |
|
|
|
for (AliexpressListingDto dto : dtos) { |
|
|
|
out.add(toProductListing(dto, call)); |
|
|
|
out.add(toProductListing(dto, call)); |
|
|
|
@ -128,9 +124,7 @@ public final class AliexpressProductSource implements LingxingProductSource { |
|
|
|
* <li>imageUrls ← {@code skuImage},为空时用 {@code imageUrls}(父体图)</li> |
|
|
|
* <li>imageUrls ← {@code skuImage},为空时用 {@code imageUrls}(父体图)</li> |
|
|
|
* <li>status ← {@code status}(文档只给了「可售」=2,其余归 UNKNOWN)</li> |
|
|
|
* <li>status ← {@code status}(文档只给了「可售」=2,其余归 UNKNOWN)</li> |
|
|
|
* <li>rawStatus ← {@code statusName} 原值(中文)</li> |
|
|
|
* <li>rawStatus ← {@code statusName} 原值(中文)</li> |
|
|
|
* <li>price ← 优先 {@code effectiveSupplyPrice}(已格式化的字符串); |
|
|
|
* <li>price ← {@code price}(<b>单位:分</b>)除以 100 转成标准金额</li> |
|
|
|
* 缺失时用 {@code price}(<b>单位:分</b>)除以 100 转成标准金额; |
|
|
|
|
|
|
|
* 再缺失时取当前生效的 {@code supplyPriceList} 条目</li> |
|
|
|
|
|
|
|
* <li>listedAt ← {@code createTime}(北京时间,按 UTC 换算)</li> |
|
|
|
* <li>listedAt ← {@code createTime}(北京时间,按 UTC 换算)</li> |
|
|
|
* <li>updatedAt ← 无</li> |
|
|
|
* <li>updatedAt ← 无</li> |
|
|
|
* <li>attributes ← 其余全部原始字段</li> |
|
|
|
* <li>attributes ← 其余全部原始字段</li> |
|
|
|
@ -140,10 +134,7 @@ public final class AliexpressProductSource implements LingxingProductSource { |
|
|
|
ZoneId zone = ZoneId.of(call.ctx().account().marketplaceZone()); |
|
|
|
ZoneId zone = ZoneId.of(call.ctx().account().marketplaceZone()); |
|
|
|
String image = firstNonBlank(dto.getSkuImage(), dto.getImageUrls()); |
|
|
|
String image = firstNonBlank(dto.getSkuImage(), dto.getImageUrls()); |
|
|
|
String currency = trimToNull(dto.getCurrencyCode()); |
|
|
|
String currency = trimToNull(dto.getCurrencyCode()); |
|
|
|
String price = firstNonBlank( |
|
|
|
String price = centsToAmount(dto.getPrice()); |
|
|
|
dto.getEffectiveSupplyPrice(), |
|
|
|
|
|
|
|
centsToAmount(dto.getPrice()), |
|
|
|
|
|
|
|
currentSupplyPrice(dto.getSupplyPriceList())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ProductListing.builder() |
|
|
|
return ProductListing.builder() |
|
|
|
.platform(call.ctx().platform()) |
|
|
|
.platform(call.ctx().platform()) |
|
|
|
@ -165,8 +156,8 @@ public final class AliexpressProductSource implements LingxingProductSource { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 接口的 {@code price} 单位是<b>分</b>,统一模型用标准金额(元),此处除以 100。 |
|
|
|
* 接口的 {@code price} 单位是<b>分</b>,统一模型用标准金额(元),此处除以 100。 |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>文档示例 99990000 与 effectiveSupplyPrice 59.99 不一致,属于文档笔误; |
|
|
|
* <p>只做单位换算,不使用 {@code effectiveSupplyPrice} 或 {@code supplyPriceList} |
|
|
|
* 以「单位分」为准做换算。</p> |
|
|
|
* 作为替代来源。</p> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static String centsToAmount(Long cents) { |
|
|
|
private static String centsToAmount(Long cents) { |
|
|
|
if (cents == null) { |
|
|
|
if (cents == null) { |
|
|
|
@ -175,36 +166,6 @@ public final class AliexpressProductSource implements LingxingProductSource { |
|
|
|
return java.math.BigDecimal.valueOf(cents, 2).toPlainString(); |
|
|
|
return java.math.BigDecimal.valueOf(cents, 2).toPlainString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 当前生效供货价:优先 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。 */ |
|
|
|
/** 文档只给了「2 可售」,其余归 UNKNOWN,保留原值在 rawStatus。 */ |
|
|
|
private static ProductStatus statusOf(Integer status) { |
|
|
|
private static ProductStatus statusOf(Integer status) { |
|
|
|
if (status == null) { |
|
|
|
if (status == null) { |
|
|
|
|