From 2472cba6f010c8c544c46533aa35a78903219453 Mon Sep 17 00:00:00 2001 From: chenchuchuan <13554600537@163.com> Date: Mon, 9 Nov 2026 16:32:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(yqn):=20=E6=8C=89=20API=20107=20=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=E6=89=B9=E9=87=8F=E5=BA=93=E5=AD=98=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 路径 /inventory/BatchQueryInventory → /v2/inventory/get_inventory_by_page - 方法是 GET,但文档把参数写在 Body 里;按重复 query 参数下发 (query.warehouseCodes=a&query.warehouseCodes=b),待联调核对 - 响应是 Spring Data 分页结构,翻页以 data.last 为准 - 该接口的 code 是字符串,其它接口是数字;信封按数值解析,两种都能过 库存模型补齐 API 107 的维度: - InventorySnapshot 补 inventoryType(可售/不可售) / parentSku / saleType / standardQuantity / 箱套四个库存字段 - InventoryQuery 补 warehouseCodes / inventoryType 两条防护: - warehouseCodes 必填;没给时用账户配置的仓,都没有直接拒绝, 空列表会把整个租户的库存都拉下来 - inventory_current 文档标为 string,按 BigDecimal 解析,脏值归 0 同步策略固定 FULL_PULL_DIFF:运去哪没有按时间增量查的接口。 Co-Authored-By: Claude --- .../ecommerce/warehouse/model/InventoryQuery.java | 37 +++++ .../warehouse/model/InventorySnapshot.java | 110 +++++++++++++ .../java/common/ecommerce/yqn/YqnConstants.java | 4 +- .../common/ecommerce/yqn/adapter/YqnAdapter.java | 41 ++++- .../ecommerce/yqn/adapter/YqnInventoryMapper.java | 180 +++++++++++++++++++++ .../java/common/ecommerce/yqn/dto/YqnDtos.java | 82 ++++++++++ .../ecommerce/yqn/http/YqnRequestFactory.java | 37 +++++ 7 files changed, 487 insertions(+), 4 deletions(-) create mode 100644 warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnInventoryMapper.java diff --git a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/InventoryQuery.java b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/InventoryQuery.java index 20d4cba..a53cbc5 100644 --- a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/InventoryQuery.java +++ b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/InventoryQuery.java @@ -9,12 +9,17 @@ import java.util.List; public final class InventoryQuery { private final List providerSkus; + private final List warehouseCodes; + /** 库存类型:null 不限 / 0 可售 / 1 不可售。 */ + private final Integer inventoryType; private final Instant updatedAfter; private final int pageSize; private final String cursor; private InventoryQuery(Builder b) { this.providerSkus = Collections.unmodifiableList(new ArrayList(b.providerSkus)); + this.warehouseCodes = Collections.unmodifiableList(new ArrayList(b.warehouseCodes)); + this.inventoryType = b.inventoryType; this.updatedAfter = b.updatedAfter; this.pageSize = b.pageSize; this.cursor = b.cursor; @@ -28,6 +33,16 @@ public final class InventoryQuery { return providerSkus; } + /** 仓 code 列表;空表示用账户配置的仓。 */ + public List warehouseCodes() { + return warehouseCodes; + } + + /** 库存类型:null 不限 / 0 可售 / 1 不可售。 */ + public Integer inventoryType() { + return inventoryType; + } + /** 增量起点;仓不支持按时间查时适配器忽略并走全量。 */ public Instant updatedAfter() { return updatedAfter; @@ -43,6 +58,8 @@ public final class InventoryQuery { public static final class Builder { private final List providerSkus = new ArrayList(); + private final List warehouseCodes = new ArrayList(); + private Integer inventoryType; private Instant updatedAfter; private int pageSize = 100; private String cursor; @@ -61,6 +78,26 @@ public final class InventoryQuery { return this; } + public Builder warehouseCode(String v) { + if (v != null) { + this.warehouseCodes.add(v); + } + return this; + } + + public Builder warehouseCodes(List v) { + if (v != null) { + this.warehouseCodes.addAll(v); + } + return this; + } + + /** 0 可售 / 1 不可售;null 不限。 */ + public Builder inventoryType(Integer v) { + this.inventoryType = v; + return this; + } + public Builder updatedAfter(Instant v) { this.updatedAfter = v; return this; diff --git a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/InventorySnapshot.java b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/InventorySnapshot.java index b60d78e..d54ad5d 100644 --- a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/InventorySnapshot.java +++ b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/InventorySnapshot.java @@ -15,6 +15,19 @@ public final class InventorySnapshot { private final int inTransit; private final int reserved; private final Instant asOfUtc; + /** 库存类型:0 可售 / 1 不可售。 */ + private final int inventoryType; + /** 父 SKU;套装 / 箱产品才有。 */ + private final String parentSku; + /** SKU 形态:0 单一产品 / 1 套装 / 2 箱产品。 */ + private final int saleType; + /** 箱套标准件数。 */ + private final int standardQuantity; + /** 箱套可用 / 预留 / 在途 / 当前库存;非箱套为 0。 */ + private final int packageAvailable; + private final int packageReserved; + private final int packageInTransit; + private final int packageCurrent; private InventorySnapshot(Builder b) { this.warehouseCode = require(b.warehouseCode, "warehouseCode"); @@ -25,6 +38,14 @@ public final class InventorySnapshot { this.inTransit = b.inTransit; this.reserved = b.reserved; this.asOfUtc = java.util.Objects.requireNonNull(b.asOfUtc, "asOfUtc"); + this.inventoryType = b.inventoryType; + this.parentSku = b.parentSku; + this.saleType = b.saleType; + this.standardQuantity = b.standardQuantity; + this.packageAvailable = b.packageAvailable; + this.packageReserved = b.packageReserved; + this.packageInTransit = b.packageInTransit; + this.packageCurrent = b.packageCurrent; } public static Builder builder() { @@ -63,6 +84,47 @@ public final class InventorySnapshot { return asOfUtc; } + /** 库存类型:0 可售 / 1 不可售。 */ + public int inventoryType() { + return inventoryType; + } + + /** 是否可售库存。 */ + public boolean sellable() { + return inventoryType == 0; + } + + /** 父 SKU;非套装 / 箱产品为 null。 */ + public String parentSku() { + return parentSku; + } + + /** SKU 形态:0 单一产品 / 1 套装 / 2 箱产品。 */ + public int saleType() { + return saleType; + } + + /** 箱套标准件数。 */ + public int standardQuantity() { + return standardQuantity; + } + + public int packageAvailable() { + return packageAvailable; + } + + public int packageReserved() { + return packageReserved; + } + + public int packageInTransit() { + return packageInTransit; + } + + public int packageCurrent() { + return packageCurrent; + } + private static String require(String v, String n) { if (v == null || v.trim().isEmpty()) { throw new IllegalArgumentException(n + " must not be blank"); @@ -79,6 +141,14 @@ public final class InventorySnapshot { private int inTransit; private int reserved; private Instant asOfUtc; + private int inventoryType; + private String parentSku; + private int saleType; + private int standardQuantity; + private int packageAvailable; + private int packageReserved; + private int packageInTransit; + private int packageCurrent; public Builder warehouseCode(String v) { this.warehouseCode = v; @@ -120,6 +190,46 @@ public final class InventorySnapshot { return this; } + public Builder inventoryType(int v) { + this.inventoryType = v; + return this; + } + + public Builder parentSku(String v) { + this.parentSku = v; + return this; + } + + public Builder saleType(int v) { + this.saleType = v; + return this; + } + + public Builder standardQuantity(int v) { + this.standardQuantity = v; + return this; + } + + public Builder packageAvailable(int v) { + this.packageAvailable = v; + return this; + } + + public Builder packageReserved(int v) { + this.packageReserved = v; + return this; + } + + public Builder packageInTransit(int v) { + this.packageInTransit = v; + return this; + } + + public Builder packageCurrent(int v) { + this.packageCurrent = v; + return this; + } + public InventorySnapshot build() { return new InventorySnapshot(this); } diff --git a/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/YqnConstants.java b/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/YqnConstants.java index 4e9cac8..e04010a 100644 --- a/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/YqnConstants.java +++ b/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/YqnConstants.java @@ -32,8 +32,8 @@ public final class YqnConstants { public static final String PATH_ORDER_FIND_ONE = "/v1/saleOrder/findOne"; /** 取消销售订单(API 122)。 */ public static final String PATH_ORDER_CANCEL = "/v1/saleOrder/cancel"; - /** 批量库存查询。 */ - public static final String PATH_INVENTORY_BATCH = "/inventory/BatchQueryInventory"; + /** 批量查询库存(API 107),GET + 分页。 */ + public static final String PATH_INVENTORY_PAGE = "/v2/inventory/get_inventory_by_page"; /** 库存调拨出库计划。 */ public static final String PATH_TRANSFER_OUTBOUND = "/transferoutboundplan/TransferOutboundPlanCreate"; /** 头程入库创建。 */ diff --git a/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnAdapter.java b/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnAdapter.java index 724da2e..b847b51 100644 --- a/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnAdapter.java +++ b/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnAdapter.java @@ -11,7 +11,11 @@ import common.ecommerce.warehouse.WarehouseProvider; import common.ecommerce.warehouse.capability.OutboundCapable; import common.ecommerce.warehouse.model.BillingDocument; import common.ecommerce.warehouse.model.FeeQuery; +import common.ecommerce.warehouse.model.InventoryQuery; +import common.ecommerce.warehouse.model.InventorySnapshot; +import common.ecommerce.warehouse.model.InventorySyncStrategy; import common.ecommerce.warehouse.capability.WarehouseProduct; +import common.ecommerce.warehouse.capability.InventoryCapable; import common.ecommerce.warehouse.capability.WarehouseFeeCapable; import common.ecommerce.warehouse.capability.WarehouseProductCapable; import common.ecommerce.warehouse.error.OutboundCancelBlockedException; @@ -50,7 +54,7 @@ import java.util.Map; * 字段差异收敛在 {@link YqnDtos} 与 {@link YqnOutboundMapper}。

*/ public final class YqnAdapter implements OutboundCapable, WarehouseProductCapable, - WarehouseFeeCapable { + WarehouseFeeCapable, InventoryCapable { /** 运去哪请求里的时间格式;待核对。 */ private static final DateTimeFormatter REQUEST_TIME_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @@ -83,7 +87,8 @@ public final class YqnAdapter implements OutboundCapable, WarehouseProductCapabl WarehouseCapability.PRODUCT, WarehouseCapability.OUTBOUND, WarehouseCapability.SPLIT, - WarehouseCapability.FEE_SETTLEMENT); + WarehouseCapability.FEE_SETTLEMENT, + WarehouseCapability.INVENTORY_QUERY); } // ------------------------------------------------------------------ 商品 @@ -282,6 +287,38 @@ public final class YqnAdapter implements OutboundCapable, WarehouseProductCapabl return out; } + // ------------------------------------------------------------------ 库存 + + /** + * 运去哪只能全量分页拉,没有按时间增量。 + * + *

宿主按 {@link #syncStrategy()} 决定落库策略:这里永远是 + * {@link InventorySyncStrategy#FULL_PULL_DIFF},不要按 updatedAfter 做增量。

+ */ + @Override + public InventorySyncStrategy syncStrategy() { + return InventorySyncStrategy.FULL_PULL_DIFF; + } + + /** + * 批量查询库存(API 107)。 + * + *

文档把参数写在「Body 参数」里,但方法是 GET;这里按重复 query 参数下发 + * (见 {@link YqnRequestFactory#getMulti})。

+ */ + @Override + public Page query(WarehouseContext ctx, InventoryQuery query) { + Map> params = YqnInventoryMapper.toParams(query, ctx.providerWarehouseId()); + rateLimiter.acquire(YqnConstants.PATH_INVENTORY_PAGE, YqnConstants.PERMITS_PER_SECOND); + HttpRequest req = requestFactory.getMulti(ctx.endpointBaseUrl(), YqnConstants.PATH_INVENTORY_PAGE, + params, ctx.secret(), ctx, "warehouse.inventory.query"); + HttpResponse resp = transport.execute(req); + String raw = YqnEnvelope.of(resp, json, "warehouse.inventory.query", + ctx.warehouseCode(), ctx.requestId()).body(); + YqnDtos.InventoryPage page = json.fromJson(raw, YqnDtos.InventoryPage.class); + return YqnInventoryMapper.toPage(page, ctx.providerWarehouseId(), zoneOf(ctx), query.cursor()); + } + // ------------------------------------------------------------------ internals /** 面单模式必须与仓能力匹配;不支持时拒绝,不静默降级。 */ diff --git a/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnInventoryMapper.java b/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnInventoryMapper.java new file mode 100644 index 0000000..332456b --- /dev/null +++ b/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/adapter/YqnInventoryMapper.java @@ -0,0 +1,180 @@ +package common.ecommerce.yqn.adapter; + +import common.ecommerce.shared.support.Page; +import common.ecommerce.warehouse.model.InventoryQuery; +import common.ecommerce.warehouse.model.InventorySnapshot; +import common.ecommerce.yqn.dto.YqnDtos; + +import java.time.Instant; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 运去哪库存报文映射(API 107)。 + */ +public final class YqnInventoryMapper { + + /** 页面大小上限;文档写「默认最高 500」。 */ + static final int MAX_ROWS = 500; + + private static final DateTimeFormatter TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + private static final ZoneId DEFAULT_ZONE = ZoneId.of("Asia/Shanghai"); + + private YqnInventoryMapper() { + } + + /** + * 统一查询条件 → GET 参数。 + * + *

运去哪要求 {@code warehouseCodes} 必填;没给时用账户配置的仓, + * 两者都没有就拒绝——空列表会把整个租户的库存都拉下来。

+ */ + public static Map> toParams(InventoryQuery query, String defaultWarehouseCode) { + List codes = new ArrayList(); + if (query.warehouseCodes() != null && !query.warehouseCodes().isEmpty()) { + codes.addAll(query.warehouseCodes()); + } else if (defaultWarehouseCode != null && !defaultWarehouseCode.trim().isEmpty()) { + codes.add(defaultWarehouseCode.trim()); + } + if (codes.isEmpty()) { + throw new IllegalArgumentException( + "yqn inventory query requires warehouseCodes; refusing to query without a warehouse"); + } + + Map> params = new LinkedHashMap>(); + params.put("query.warehouseCodes", codes); + if (query.inventoryType() != null) { + params.put("query.inventoryType", single(String.valueOf(query.inventoryType()))); + } + if (query.pageSize() > 0) { + params.put("query.rows", single(String.valueOf(Math.min(query.pageSize(), MAX_ROWS)))); + } + if (query.cursor() != null && !query.cursor().trim().isEmpty()) { + params.put("query.page", single(query.cursor().trim())); + } + return params; + } + + /** 一条库存记录 → 统一快照。 */ + public static InventorySnapshot toSnapshot(YqnDtos.InventoryRow row, String fallbackWarehouseCode, + ZoneId zone) { + String warehouseCode = hasText(row.warehouseCode) ? row.warehouseCode.trim() + : fallbackWarehouseCode; + String sku = row.sku == null ? null : row.sku.trim(); + if (!hasText(sku)) { + // 没有 SKU 的库存行无法落库,跳过比抛异常更合适:整页不该被一行脏数据废掉 + return null; + } + Instant updatedAt = parseTime(row.updatedAt, zone); + return InventorySnapshot.builder() + .warehouseCode(warehouseCode) + .providerSku(sku) + .omsSku(sku) + .available(intOf(row.inventoryAvailable)) + .onHand(intOf(row.inventoryCurrent)) + .inTransit(intOf(row.inventoryTransport)) + .reserved(intOf(row.inventoryReserved)) + .inventoryType(intOf(row.inventoryType)) + .parentSku(row.parentSku) + .saleType(intOf(row.saleType)) + .standardQuantity(intOf(row.standardQuantity)) + .packageAvailable(intOf(row.inventoryPcsAvailable)) + .packageReserved(intOf(row.inventoryPcsReserved)) + .packageInTransit(intOf(row.inventoryPcsTransport)) + .packageCurrent(intOf(row.inventoryPcsCurrent)) + // 没有更新时间时用查询时刻兜底:快照必须带 asOfUtc 才能与逻辑库存对齐 + .asOfUtc(updatedAt == null ? Instant.now() : updatedAt) + .build(); + } + + /** 解析一整页。 */ + public static Page toPage(YqnDtos.InventoryPage page, String fallbackWarehouseCode, + ZoneId zone, String requestedPage) { + if (page == null || page.data == null || page.data.content == null) { + return Page.empty(); + } + List items = new ArrayList(page.data.content.size()); + for (YqnDtos.InventoryRow row : page.data.content) { + InventorySnapshot snapshot = toSnapshot(row, fallbackWarehouseCode, zone); + if (snapshot != null) { + items.add(snapshot); + } + } + String next = nextCursor(page, requestedPage); + return next == null ? Page.last(items) : Page.of(items, next); + } + + /** 翻页:以仓返回的 {@code last} 为准;缺失时用页码与总页数比较。 */ + private static String nextCursor(YqnDtos.InventoryPage page, String requestedPage) { + if (page.data.last != null && page.data.last) { + return null; + } + int currentPage = pageOf(requestedPage); + if (page.data.totalPages != null) { + return currentPage >= page.data.totalPages ? null : String.valueOf(currentPage + 1); + } + // 没有分页元数据时按「本页是否满页」推断,避免死循环 + int size = page.data.content == null ? 0 : page.data.content.size(); + int pageSize = page.data.size == null ? size : page.data.size; + return size == 0 || size < pageSize ? null : String.valueOf(currentPage + 1); + } + + static int pageOf(String cursor) { + if (cursor == null || cursor.trim().isEmpty()) { + return 1; + } + try { + return Integer.parseInt(cursor.trim()); + } catch (NumberFormatException e) { + return 1; + } + } + + /** {@code inventory_current} 在文档里是 string,可能是小数或带单位,按数值截断。 */ + static int intOf(String value) { + if (value == null || value.trim().isEmpty()) { + return 0; + } + try { + return new java.math.BigDecimal(value.trim()).intValue(); + } catch (NumberFormatException e) { + return 0; + } + } + + static int intOf(Integer value) { + return value == null ? 0 : value; + } + + static Instant parseTime(String value, ZoneId zone) { + if (value == null || value.trim().isEmpty()) { + return null; + } + String v = value.trim(); + try { + return java.time.LocalDateTime.parse(v, TIME) + .atZone(zone == null ? DEFAULT_ZONE : zone).toInstant(); + } catch (DateTimeParseException e) { + try { + return Instant.parse(v); + } catch (DateTimeParseException ignored) { + return null; + } + } + } + + private static List single(String v) { + List list = new ArrayList(1); + list.add(v); + return list; + } + + private static boolean hasText(String v) { + return v != null && !v.trim().isEmpty(); + } +} diff --git a/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/dto/YqnDtos.java b/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/dto/YqnDtos.java index c7edff2..e24fc16 100644 --- a/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/dto/YqnDtos.java +++ b/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/dto/YqnDtos.java @@ -472,4 +472,86 @@ public final class YqnDtos { /** 1 实际结算 / 2 预估结算。 */ public Integer settlementType; } + + /** 库存查询的查询体(API 107 的 {@code query} 对象)。 */ + @JsonInclude(JsonInclude.Include.NON_NULL) + public static final class InventoryQueryParam { + + /** 仓库 CODE 列表,必填。 */ + public List warehouseCodes; + /** 0 可售 / 1 不可售。 */ + public Integer inventoryType; + /** 页码,字符串。 */ + public String page; + /** 页面大小,默认最高 500。 */ + public Integer rows; + public String sidx; + /** asc / desc。 */ + public String sort; + } + + /** + * 库存分页响应(API 107)。 + * + *

响应是 Spring Data 的分页结构:{@code data.content[]} 是数据, + * 翻页看 {@code data.last}。外层 {@code code} 在这个接口里是字符串。

+ */ + @JsonInclude(JsonInclude.Include.NON_NULL) + public static final class InventoryPage { + + public InventoryPageData data; + + /** 分页载荷。 */ + @JsonInclude(JsonInclude.Include.NON_NULL) + public static final class InventoryPageData { + public List content; + public Integer totalElements; + public Integer totalPages; + public Boolean last; + public Integer size; + public Integer number; + } + } + + /** 一条库存记录(字段名是下划线风格,运去哪原样返回)。 */ + @JsonInclude(JsonInclude.Include.NON_NULL) + public static final class InventoryRow { + + @com.fasterxml.jackson.annotation.JsonProperty("warehouse_code") + public String warehouseCode; + @com.fasterxml.jackson.annotation.JsonProperty("line_name") + public String lineName; + public String sku; + /** 0 可售 / 1 不可售。 */ + @com.fasterxml.jackson.annotation.JsonProperty("inventory_type") + public Integer inventoryType; + @com.fasterxml.jackson.annotation.JsonProperty("inventory_available") + public Integer inventoryAvailable; + @com.fasterxml.jackson.annotation.JsonProperty("inventory_reserved") + public Integer inventoryReserved; + @com.fasterxml.jackson.annotation.JsonProperty("inventory_transport") + public Integer inventoryTransport; + /** 当前总库存;文档标为 string。 */ + @com.fasterxml.jackson.annotation.JsonProperty("inventory_current") + public String inventoryCurrent; + @com.fasterxml.jackson.annotation.JsonProperty("updated_at") + public String updatedAt; + @com.fasterxml.jackson.annotation.JsonProperty("is_over_warehouse") + public Integer isOverWarehouse; + @com.fasterxml.jackson.annotation.JsonProperty("parent_sku") + public String parentSku; + /** 0 单一产品 / 1 套装 / 2 箱产品。 */ + @com.fasterxml.jackson.annotation.JsonProperty("sale_type") + public Integer saleType; + @com.fasterxml.jackson.annotation.JsonProperty("standard_quantity") + public Integer standardQuantity; + @com.fasterxml.jackson.annotation.JsonProperty("inventory_pcs_available") + public Integer inventoryPcsAvailable; + @com.fasterxml.jackson.annotation.JsonProperty("inventory_pcs_reserved") + public Integer inventoryPcsReserved; + @com.fasterxml.jackson.annotation.JsonProperty("inventory_pcs_transport") + public Integer inventoryPcsTransport; + @com.fasterxml.jackson.annotation.JsonProperty("inventory_pcs_current") + public Integer inventoryPcsCurrent; + } } diff --git a/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/http/YqnRequestFactory.java b/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/http/YqnRequestFactory.java index 0c8852b..11ac71b 100644 --- a/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/http/YqnRequestFactory.java +++ b/warehouse-sdk-yqn/src/main/java/common/ecommerce/yqn/http/YqnRequestFactory.java @@ -8,6 +8,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Collection; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; /** @@ -76,6 +77,42 @@ public final class YqnRequestFactory { .build(); } + /** + * GET:支持同名参数重复出现,如 {@code query.warehouseCodes=a&query.warehouseCodes=b}。 + * + *

运去哪的库存接口是 GET 但在文档里以「Body 参数」描述数组; + * HTTP GET 带 body 在 OkHttp 里不被允许,所以这里按重复 query 参数下发。 + * 待联调核对:若网关实际要求 GET + JSON body,改这一处即可。

+ */ + public common.ecommerce.http.HttpRequest getMulti(String baseUrl, String path, + Map> params, + ChannelSecret secret, CallScope ctx, String operation) { + StringBuilder url = new StringBuilder(baseUrl).append(path); + boolean first = true; + if (params != null) { + for (Map.Entry> e : params.entrySet()) { + List values = e.getValue(); + if (values == null || values.isEmpty()) { + continue; + } + for (String value : values) { + if (value == null) { + continue; + } + url.append(first ? '?' : '&'); + first = false; + url.append(urlEncode(e.getKey())).append('=').append(urlEncode(value)); + } + } + } + return common.ecommerce.http.HttpRequest.builder() + .method("GET") + .url(url.toString()) + .headers(headers(secret, ctx)) + .operation(operation) + .build(); + } + /** 本次调用统一携带的请求头:固定 token + 链路 ID。 */ private static Map headers(ChannelSecret secret, CallScope ctx) { Map out = new LinkedHashMap();