|
|
|
@ -39,13 +39,34 @@ import java.util.Map; |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>{@code store_ids} 是<b>非必填</b>项:文档未标必填,不传时返回该 app 下所有店铺的商品。 |
|
|
|
* <p>{@code store_ids} 是<b>非必填</b>项:文档未标必填,不传时返回该 app 下所有店铺的商品。 |
|
|
|
* 这里按账户的 {@code externalStoreId} 过滤,避免把其它店铺的商品混进同一个 omsStoreId。</p> |
|
|
|
* 这里按账户的 {@code externalStoreId} 过滤,避免把其它店铺的商品混进同一个 omsStoreId。</p> |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p><b>时间窗(实测)</b>:{@code listing_time_field} + {@code listing_start_time} + |
|
|
|
|
|
|
|
* {@code listing_end_time} 必须三者同时填或同时不填;日期精度 {@code Y-m-d}, |
|
|
|
|
|
|
|
* 不支持 {@code HH:mm:ss} 与 epoch;单边窗口返回 400。实测窗口跨度 1 年内均可用。</p> |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p><b>搜索(实测)</b>:{@code search_field=1} 对应 {@code msku}, |
|
|
|
|
|
|
|
* {@code search_field=2} 对应 {@code item_id},{@code search_field=4} 对应标题(模糊); |
|
|
|
|
|
|
|
* 多值 {@code search_values} 返回 400,只支持单值。该 app 下 {@code local_sku} 恒为空, |
|
|
|
|
|
|
|
* 本地 SKU 搜索无编码可用,显式不支持。</p> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public final class TargetProductSource implements LingxingProductSource { |
|
|
|
public final class TargetProductSource implements LingxingProductSource { |
|
|
|
|
|
|
|
|
|
|
|
private static final int MAX_PAGE_SIZE = 1000; |
|
|
|
private static final int MAX_PAGE_SIZE = 1000; |
|
|
|
|
|
|
|
|
|
|
|
/** 时间字段格式,文档未给出示例值格式,按 Y-m-d H:i:s 发送。 */ |
|
|
|
/** |
|
|
|
|
|
|
|
* 时间字段取值:1 创建时间、2 更新时间。用 2 才符合 |
|
|
|
|
|
|
|
* {@link common.ecommerce.model.product.ProductQuery#updatedAfter()} 的语义。 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static final int TIME_FIELD_UPDATE = 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 时间字段只接受 Y-m-d。 */ |
|
|
|
|
|
|
|
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 响应里的 listing_start_time / listing_end_time 带时分秒。 */ |
|
|
|
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 int DEFAULT_QUERY_DAYS = 30; |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Page<ProductListing> products(LingxingCall call, ProductQuery query) { |
|
|
|
public Page<ProductListing> products(LingxingCall call, ProductQuery query) { |
|
|
|
int length = Math.min(query.pageSize() <= 0 ? 100 : query.pageSize(), MAX_PAGE_SIZE); |
|
|
|
int length = Math.min(query.pageSize() <= 0 ? 100 : query.pageSize(), MAX_PAGE_SIZE); |
|
|
|
@ -80,7 +101,10 @@ public final class TargetProductSource implements LingxingProductSource { |
|
|
|
return Page.of(out, hasMore ? String.valueOf(nextOffset) : null); |
|
|
|
return Page.of(out, hasMore ? String.valueOf(nextOffset) : null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 时间窗:按 UTC 发送,未给终点时不发终点。 */ |
|
|
|
/** |
|
|
|
|
|
|
|
* 时间窗:三个字段必须同时出现,日期精度 Y-m-d(按 UTC 取日期)。 |
|
|
|
|
|
|
|
* 只传了一边时补齐另一边:起点缺失取终点前 30 天,终点缺失取当前时间。 |
|
|
|
|
|
|
|
*/ |
|
|
|
private static void applyTimeWindow(Map<String, Object> body, ProductQuery query) { |
|
|
|
private static void applyTimeWindow(Map<String, Object> body, ProductQuery query) { |
|
|
|
Instant from = query.updatedAfter(); |
|
|
|
Instant from = query.updatedAfter(); |
|
|
|
Instant to = query.updatedBefore(); |
|
|
|
Instant to = query.updatedBefore(); |
|
|
|
@ -88,12 +112,15 @@ public final class TargetProductSource implements LingxingProductSource { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
ZoneId utc = ZoneId.of("UTC"); |
|
|
|
ZoneId utc = ZoneId.of("UTC"); |
|
|
|
if (from != null) { |
|
|
|
if (to == null) { |
|
|
|
body.put("listing_start_time", DATE_TIME.format(from.atZone(utc))); |
|
|
|
to = Instant.now(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (to != null) { |
|
|
|
if (from == null) { |
|
|
|
body.put("listing_end_time", DATE_TIME.format(to.atZone(utc))); |
|
|
|
from = to.minus(java.time.Duration.ofDays(DEFAULT_QUERY_DAYS)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
body.put("listing_time_field", TIME_FIELD_UPDATE); |
|
|
|
|
|
|
|
body.put("listing_start_time", DATE.format(from.atZone(utc).toLocalDate())); |
|
|
|
|
|
|
|
body.put("listing_end_time", DATE.format(to.atZone(utc).toLocalDate())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 总数取 data.count;没有时用顶层 total;都没有返回 -1。 */ |
|
|
|
/** 总数取 data.count;没有时用顶层 total;都没有返回 -1。 */ |
|
|
|
@ -286,6 +313,7 @@ public final class TargetProductSource implements LingxingProductSource { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 统一 SKU 搜索 → shopify/target 的字段形态;未带搜索条件时什么也不做。 */ |
|
|
|
/** 统一 SKU 搜索 → shopify/target 的字段形态;未带搜索条件时什么也不做。 */ |
|
|
|
|
|
|
|
/** 统一 SKU 搜索 → Target 的字段形态;未带搜索条件时什么也不做。 */ |
|
|
|
private static void applySearch(java.util.Map<String, Object> body, |
|
|
|
private static void applySearch(java.util.Map<String, Object> body, |
|
|
|
ProductQuery query) { |
|
|
|
ProductQuery query) { |
|
|
|
if (query == null || !query.hasSearch()) { |
|
|
|
if (query == null || !query.hasSearch()) { |
|
|
|
@ -293,11 +321,11 @@ public final class TargetProductSource implements LingxingProductSource { |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
Object fieldValue = LingxingProductSearchMapper.target(query.searchField()); |
|
|
|
Object fieldValue = LingxingProductSearchMapper.target(query.searchField()); |
|
|
|
LingxingProductSearchBody.snakeCase(body, query, fieldValue); |
|
|
|
// 实测:多值 search_values 返回 400,只支持单值。
|
|
|
|
|
|
|
|
LingxingProductSearchBody.snakeCaseSingle(body, query, fieldValue); |
|
|
|
} catch (UnsupportedOperationException e) { |
|
|
|
} catch (UnsupportedOperationException e) { |
|
|
|
ChannelException.Builder b = ChannelException.builder() |
|
|
|
ChannelException.Builder b = ChannelException.builder() |
|
|
|
.message("target listing does not support search field " |
|
|
|
.message("target listing does not support " + e.getMessage()) |
|
|
|
+ query.searchField()) |
|
|
|
|
|
|
|
.operation("products.pull") |
|
|
|
.operation("products.pull") |
|
|
|
.retryable(false); |
|
|
|
.retryable(false); |
|
|
|
throw new ValidationException(b); |
|
|
|
throw new ValidationException(b); |
|
|
|
|