Browse Source

style(lingxing): 单行语句不再硬拆多行;AliExpress price 只做单位换算

代码风格:
- 按用户要求,能放一行的语句不拆成两行
  (listAt(...)、body.put(...)、字段初始化等 11 处)

AliExpress 价格:
- 统一模型 price 只取接口自身的 price 字段(单位:分)÷ 100
- 不再用 effectiveSupplyPrice 或 supplyPriceList 替代 / 兜底
- 删除不再使用的 currentSupplyPrice 辅助方法

约定已记入项目记忆:价格只做单位换算,缺字段给 null,原始值留在 attributes。

Co-Authored-By: Claude <noreply@anthropic.com>
feature/supplier-lingxing
chenchuchuan 2 weeks ago
parent
commit
f832091558
  1. 3
      lingxing/src/main/java/common/ecommerce/lingxing/dto/LingxingOrderDto.java
  2. 53
      lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/product/AliexpressProductSource.java
  3. 3
      lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/sc/product/AmazonScProductSource.java
  4. 4
      lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/vc/product/AmazonVcProductSource.java
  5. 3
      lingxing/src/main/java/common/ecommerce/lingxing/platform/ebay/product/EbayProductSource.java
  6. 4
      lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/product/SheinProductSource.java
  7. 7
      lingxing/src/main/java/common/ecommerce/lingxing/platform/shopify/product/ShopifyProductSource.java
  8. 3
      lingxing/src/main/java/common/ecommerce/lingxing/platform/temu/dto/TemuListingDto.java
  9. 7
      lingxing/src/main/java/common/ecommerce/lingxing/platform/temu/product/TemuProductSource.java
  10. 4
      lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/product/TiktokProductSource.java
  11. 3
      lingxing/src/main/java/common/ecommerce/lingxing/platform/walmart/product/WalmartProductSource.java

3
lingxing/src/main/java/common/ecommerce/lingxing/dto/LingxingOrderDto.java

@ -74,6 +74,5 @@ public class LingxingOrderDto { @@ -74,6 +74,5 @@ public class LingxingOrderDto {
/** 交易信息。 */
@JsonProperty("transaction_info")
private List<LingxingTransactionInfoDto> transactionInfo =
new ArrayList<LingxingTransactionInfoDto>();
private List<LingxingTransactionInfoDto> transactionInfo = new ArrayList<LingxingTransactionInfoDto>();
}

53
lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/product/AliexpressProductSource.java

@ -6,7 +6,6 @@ import common.ecommerce.lingxing.LingxingApi; @@ -6,7 +6,6 @@ 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;
@ -44,8 +43,7 @@ public final class AliexpressProductSource implements LingxingProductSource { @@ -44,8 +43,7 @@ public final class AliexpressProductSource implements LingxingProductSource {
/** 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_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@Override
@ -57,16 +55,14 @@ public final class AliexpressProductSource implements LingxingProductSource { @@ -57,16 +55,14 @@ public final class AliexpressProductSource implements LingxingProductSource {
body.put("isParent", IS_CHILD);
body.put("offset", offset);
body.put("length", length);
body.put("storeIds",
Collections.singletonList(parseStoreId(call.ctx().account().externalStoreId())));
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<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));
@ -128,9 +124,7 @@ public final class AliexpressProductSource implements LingxingProductSource { @@ -128,9 +124,7 @@ public final class AliexpressProductSource implements LingxingProductSource {
* <li>imageUrls ← {@code skuImage},为空时用 {@code imageUrls}(父体图)</li>
* <li>status ← {@code status}(文档只给了「可售」=2,其余归 UNKNOWN)</li>
* <li>rawStatus ← {@code statusName} 原值(中文)</li>
* <li>price ← 优先 {@code effectiveSupplyPrice}(已格式化的字符串);
* 缺失时用 {@code price}(<b>单位:分</b>)除以 100 转成标准金额;
* 再缺失时取当前生效的 {@code supplyPriceList} 条目</li>
* <li>price ← {@code price}(<b>单位:分</b>)除以 100 转成标准金额</li>
* <li>listedAt ← {@code createTime}(北京时间,按 UTC 换算)</li>
* <li>updatedAt ← 无</li>
* <li>attributes ← 其余全部原始字段</li>
@ -140,10 +134,7 @@ public final class AliexpressProductSource implements LingxingProductSource { @@ -140,10 +134,7 @@ public final class AliexpressProductSource implements LingxingProductSource {
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(),
centsToAmount(dto.getPrice()),
currentSupplyPrice(dto.getSupplyPriceList()));
String price = centsToAmount(dto.getPrice());
return ProductListing.builder()
.platform(call.ctx().platform())
@ -165,8 +156,8 @@ public final class AliexpressProductSource implements LingxingProductSource { @@ -165,8 +156,8 @@ public final class AliexpressProductSource implements LingxingProductSource {
/**
* 接口的 {@code price} 单位是<b>分</b>,统一模型用标准金额(元),此处除以 100。
*
* <p>文档示例 99990000 与 effectiveSupplyPrice 59.99 不一致,属于文档笔误;
* 以「单位分」为准做换算。</p>
* <p>只做单位换算,不使用 {@code effectiveSupplyPrice} 或 {@code supplyPriceList}
* 作为替代来源。</p>
*/
private static String centsToAmount(Long cents) {
if (cents == null) {
@ -175,36 +166,6 @@ public final class AliexpressProductSource implements LingxingProductSource { @@ -175,36 +166,6 @@ public final class AliexpressProductSource implements LingxingProductSource {
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。 */
private static ProductStatus statusOf(Integer status) {
if (status == null) {

3
lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/sc/product/AmazonScProductSource.java

@ -38,8 +38,7 @@ public final class AmazonScProductSource implements LingxingProductSource { @@ -38,8 +38,7 @@ public final class AmazonScProductSource implements LingxingProductSource {
private static final int MAX_PAGE_SIZE = 1000;
/** listing_update_date 是零时区时间,格式 Y-m-d H:i:s。 */
private static final DateTimeFormatter LISTING_TIME =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private static final DateTimeFormatter LISTING_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
/** 只有日期的字段,如 on_sale_time / first_order_time。 */
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd");

4
lingxing/src/main/java/common/ecommerce/lingxing/platform/amazon/vc/product/AmazonVcProductSource.java

@ -49,9 +49,7 @@ public final class AmazonVcProductSource implements LingxingProductSource { @@ -49,9 +49,7 @@ public final class AmazonVcProductSource implements LingxingProductSource {
Map<String, Object> body = new LinkedHashMap<String, Object>();
body.put("offset", offset);
body.put("length", length);
body.put("vc_store_ids",
Collections.singletonList(call.ctx().account().externalStoreId()));
body.put("vc_store_ids", Collections.singletonList(call.ctx().account().externalStoreId()));
HttpRequest req = call.signed(LingxingApi.LISTING_AMAZON_VC, body, "products.pull");
HttpResponse resp = call.execute(req);
LingxingEnvelope envelope = call.envelope(resp, "products.pull");

3
lingxing/src/main/java/common/ecommerce/lingxing/platform/ebay/product/EbayProductSource.java

@ -55,8 +55,7 @@ public final class EbayProductSource implements LingxingProductSource { @@ -55,8 +55,7 @@ public final class EbayProductSource implements LingxingProductSource {
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()));
body.put("store_ids", Collections.singletonList(call.ctx().account().externalStoreId()));
applyTimeWindow(body, query);
HttpRequest req = call.signed(LingxingApi.LISTING_EBAY, body, "products.pull");

4
lingxing/src/main/java/common/ecommerce/lingxing/platform/shein/product/SheinProductSource.java

@ -41,9 +41,7 @@ public final class SheinProductSource implements LingxingProductSource { @@ -41,9 +41,7 @@ public final class SheinProductSource implements LingxingProductSource {
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()));
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");

7
lingxing/src/main/java/common/ecommerce/lingxing/platform/shopify/product/ShopifyProductSource.java

@ -37,9 +37,7 @@ public final class ShopifyProductSource implements LingxingProductSource { @@ -37,9 +37,7 @@ 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");
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);
@ -48,8 +46,7 @@ public final class ShopifyProductSource implements LingxingProductSource { @@ -48,8 +46,7 @@ public final class ShopifyProductSource implements LingxingProductSource {
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()));
body.put("store_ids", Collections.singletonList(call.ctx().account().externalStoreId()));
applyTimeWindow(body, query);
HttpRequest req = call.signed(LingxingApi.LISTING_SHOPIFY, body, "products.pull");

3
lingxing/src/main/java/common/ecommerce/lingxing/platform/temu/dto/TemuListingDto.java

@ -164,6 +164,5 @@ public class TemuListingDto { @@ -164,6 +164,5 @@ public class TemuListingDto {
/** 活动价详情。 */
@JsonProperty("promotionalPriceDataList")
private List<TemuPromotionalPriceDto> promotionalPriceDataList =
new ArrayList<TemuPromotionalPriceDto>();
private List<TemuPromotionalPriceDto> promotionalPriceDataList = new ArrayList<TemuPromotionalPriceDto>();
}

7
lingxing/src/main/java/common/ecommerce/lingxing/platform/temu/product/TemuProductSource.java

@ -37,9 +37,7 @@ public final class TemuProductSource implements LingxingProductSource { @@ -37,9 +37,7 @@ 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");
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);
@ -49,8 +47,7 @@ public final class TemuProductSource implements LingxingProductSource { @@ -49,8 +47,7 @@ public final class TemuProductSource implements LingxingProductSource {
body.put("offset", offset);
body.put("length", length);
body.put("useCursor", Boolean.FALSE);
body.put("storeIds",
Collections.singletonList(call.ctx().account().externalStoreId()));
body.put("storeIds", Collections.singletonList(call.ctx().account().externalStoreId()));
applyTimeWindow(body, query);
HttpRequest req = call.signed(LingxingApi.LISTING_TEMU, body, "products.pull");

4
lingxing/src/main/java/common/ecommerce/lingxing/platform/tiktok/product/TiktokProductSource.java

@ -39,9 +39,7 @@ public final class TiktokProductSource implements LingxingProductSource { @@ -39,9 +39,7 @@ public final class TiktokProductSource implements LingxingProductSource {
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()));
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");

3
lingxing/src/main/java/common/ecommerce/lingxing/platform/walmart/product/WalmartProductSource.java

@ -59,8 +59,7 @@ public final class WalmartProductSource implements LingxingProductSource { @@ -59,8 +59,7 @@ public final class WalmartProductSource implements LingxingProductSource {
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()));
body.put("store_ids", Collections.singletonList(call.ctx().account().externalStoreId()));
applyTimeWindow(body, query);
HttpRequest req = call.signed(LingxingApi.LISTING_WALMART, body, "products.pull");

Loading…
Cancel
Save