Browse Source

feat(edayun): 对接仓库清单(权限内 / 全量激活)

两个接口用途不同,不要混用:
- POST /webApi/warehouse/listWarehouseHasPerm → warehouses(ctx)
  当前客户有权限的仓(实测 69 条,跳过 -999 后 68)
- POST /webApi/warehouse/listActive → activeWarehouses(ctx, inbound)
  平台全量激活仓(118 条),**含当前客户没授权的**

有权限的 68 个仓里有 50 个不在 listActive 结果里,所以给客户选仓必须用前者。

-999 是「智能分仓」哨兵值(divideWarehouse),不是真实仓,映射时跳过——
和物流产品接口的 -998 是同一套路。

listActive 的 warehouseOperationType:0 尾程 111 条 / 1 头程 7 条 /
不传 118 条(文档说必填,实测不传也通)。

统一模型口径:warehouseCode 放仓编码(USLA),数字 id 进 providerWarehouseId。
listActive 比 listWarehouseHasPerm 多 30 个字段(容量 / 营业时间 / 负责人邮箱等),
DTO 只声明统一模型用得上的十几个,其余由 Jackson 忽略。

顺带把之前 warehouses() 的显式拒绝换成真实实现,DIRECTORY 能力位从此完整。

Co-Authored-By: Claude <noreply@anthropic.com>
master
chenchuchuan 4 days ago
parent
commit
f66720f6be
  1. 62
      docs-warehouse/edayun/README.md
  2. 5
      docs-warehouse/edayun/TODO.md
  3. 6
      warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/EdayunConstants.java
  4. 48
      warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunAdapter.java
  5. 112
      warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunWarehouseMapper.java
  6. 95
      warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunWarehouseDtos.java
  7. 3
      warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunAdapterTest.java
  8. 184
      warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunWarehouseTest.java
  9. 102
      warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/probe/EdayunWarehouseProbeTest.java

62
docs-warehouse/edayun/README.md

@ -30,6 +30,7 @@
| 打印箱唛 | ✅ 已对接(`POST /webApi/skuInfo/v2/printBarcode`) | | 打印箱唛 | ✅ 已对接(`POST /webApi/skuInfo/v2/printBarcode`) |
| 打印 SKU 标 | ⚠️ 已实现(`POST /webApi/entryInfo/v1/newPrintCaseMarkContentType`),**真机未启用** | | 打印 SKU 标 | ⚠️ 已实现(`POST /webApi/entryInfo/v1/newPrintCaseMarkContentType`),**真机未启用** |
| 承运商清单(客户自有物流) | ✅ 已对接(`POST /webApi/carrier/v1/listCarrierByWarehouse`) | | 承运商清单(客户自有物流) | ✅ 已对接(`POST /webApi/carrier/v1/listCarrierByWarehouse`) |
| 仓库清单 | ✅ 已对接(`warehouse/listWarehouseHasPerm` + `warehouse/listActive`) |
| 其它业务接口 | ⬜ 等文档 | | 其它业务接口 | ⬜ 等文档 |
| 回调 | ⬜ 等文档 | | 回调 | ⬜ 等文档 |
| 真机验证 | ⬜ 等测试环境 | | 真机验证 | ⬜ 等测试环境 |
@ -1257,11 +1258,64 @@ DTO 按 `List` 收。
| 不传仓 | 22 个承运商 | | 不传仓 | 22 个承运商 |
| `countryCode=US` | 10 个承运商 | | `countryCode=US` | 10 个承运商 |
### 仓库列表接口没有 ### 仓库清单
易达云文档没给「查仓库列表」,所以 `warehouses()` 显式抛 见下面的「仓库清单」一节——`warehouses()` 现在有实现了。
`WarehouseUnsupportedCapabilityException`——不返回空列表,免得和「没有仓」混淆。
能力位 `DIRECTORY` 只覆盖承运商这一半。 ## 仓库清单
两个接口用途完全不同,**不要混用**:
| 接口 | 含义 | 实测条数 | 我们的方法 |
|---|---|---|---|
| `warehouse/listWarehouseHasPerm` | 当前客户**有权限**的仓 | 69(跳过 -999 后 68) | `warehouses(ctx)` |
| `warehouse/listActive` | 平台**全量**激活仓 | 118 | `activeWarehouses(ctx, inbound)` |
`listActive` 含当前客户**没授权**的仓(68 个有权限的仓里,有 50 个不在里面),
所以**给客户选仓必须用 `warehouses()`**。
### `-999` 是「智能分仓」哨兵值
`listWarehouseHasPerm` 最后一条固定是:
```json
{"warehouseId":"-999","warehouseName":"使用分仓规则","warehouseNameEn":"divideWarehouse",
"warehouseCode":"USMC", ...其余全 null}
```
不是真实仓,映射时跳过——和物流产品接口的 `-998` 是同一套路。
### `listActive` 的 `warehouseOperationType`
| 值 | 含义 | 实测 |
|---|---|---|
| 0 | 尾程仓 | 111 条 |
| 1 | 头程仓 | 7 条 |
| 不传 | 两者之和 | 118 条 |
文档说必填,实测不传也能通。`activeWarehouses(ctx, inboundWarehouse)` 会明确传 0 或 1。
### 统一模型的口径
`WarehouseFacility.warehouseCode()` 放的是**仓编码**(`USLA` / `USALA-Q031`),
数字 id(`2` / `40269`)进 `providerWarehouseId()`——两者不能互换。
字段映射:
| 易达云 | 统一模型 | 备注 |
|---|---|---|
| `warehouseCode` | `warehouseCode` | 下单用 |
| `warehouseId` | `providerWarehouseId` | 数字,字符串形式 |
| `warehouseName` | `name` | 缺失回退英文名 |
| `address` | `address1` | 仓方只给单行地址 |
| `provinceCode` | `province` / `state` | 两个字段都填 |
| `warehouseManagerName` / `Tel` | `contactName` / `mobilePhone` | 仅 `listActive` 有 |
### 两个接口的字段数差很多
`listActive` 返回 47 个字段(容量、营业时间、负责人邮箱、地图链接等),
`listWarehouseHasPerm` 只有 17 个。DTO 只声明统一模型用得上的十几个——
Jackson 会忽略未知字段。
## 待确认(问易达云) ## 待确认(问易达云)

5
docs-warehouse/edayun/TODO.md

@ -71,7 +71,10 @@
| 69 | SKU 标纸张码值 4/2/5 不连续 | 独立枚举 `EdayunSkuLabelPaper`,按映射表走 | 无(已规避) | | 69 | SKU 标纸张码值 4/2/5 不连续 | 独立枚举 `EdayunSkuLabelPaper`,按映射表走 | 无(已规避) |
| 72 | **`printBarcode` 的 pageSize=2 / pageSize=3 文档标称与实际相反**(文档 2=6×4cm、3=A4;实测 2=100×150mm、3=60×40mm) | 枚举按实测尺寸命名,码值不变 | 按文档标称选纸会打错 | | 72 | **`printBarcode` 的 pageSize=2 / pageSize=3 文档标称与实际相反**(文档 2=6×4cm、3=A4;实测 2=100×150mm、3=60×40mm) | 枚举按实测尺寸命名,码值不变 | 按文档标称选纸会打错 |
| 73 | 两个端点名与实际语义相反(printBarcode=箱唛、newPrintCaseMark=SKU 标) | 代码按实际语义命名并在 javadoc 标注 | 无(已规避) | | 73 | 两个端点名与实际语义相反(printBarcode=箱唛、newPrintCaseMark=SKU 标) | 代码按实际语义命名并在 javadoc 标注 | 无(已规避) |
| 74 | 易达云**没有仓库列表接口** | `warehouses()` 显式拒绝;`DIRECTORY` 只覆盖承运商 | 宿主不能从仓方拉仓库清单 | | 74 | 仓库清单有两个接口,`listActive` 含未授权仓 | `warehouses()` 只走 `listWarehouseHasPerm` | 用错会给出客户没权限的仓 |
| 77 | `listWarehouseHasPerm` 末条固定是 `-999`(智能分仓) | 映射时跳过 | 无(已规避) |
| 78 | `warehouseRegionType` / `warehouseStatus` / `privateFlag` 码表只部分确认 | 只在 DTO,不进统一模型 | 宿主想按区域类型筛选时缺依据 |
| 79 | `listActive` 比 `listWarehouseHasPerm` 多 30 个字段(容量 / 营业时间 / 负责人邮箱等) | 不声明,Jackson 忽略 | 想用这些字段需扩展 DTO |
| 75 | 承运商接口的 `countryCode` 过滤统一模型没有对应字段 | 不下发 | 宿主想按国家筛承运商得用扩展方法 | | 75 | 承运商接口的 `countryCode` 过滤统一模型没有对应字段 | 不下发 | 宿主想按国家筛承运商得用扩展方法 |
| 76 | `ownLogisticList` 文档写成对象、真机是数组 | DTO 按 List 收 | 无(已兼容) | | 76 | `ownLogisticList` 文档写成对象、真机是数组 | DTO 按 List 收 | 无(已兼容) |
| 70 | 箱唛的 `madeInChina` / `separation` 统一模型没有语义 | 默认关 | 需要打「Made in China」时得走扩展重载 | | 70 | 箱唛的 `madeInChina` / `separation` 统一模型没有语义 | 默认关 | 需要打「Made in China」时得走扩展重载 |

6
warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/EdayunConstants.java

@ -118,6 +118,12 @@ public final class EdayunConstants {
/** 查询客户自有物流服务(承运商)({@code POST /webApi/carrier/v1/listCarrierByWarehouse})。 */ /** 查询客户自有物流服务(承运商)({@code POST /webApi/carrier/v1/listCarrierByWarehouse})。 */
public static final String PATH_CARRIERS = "/webApi/carrier/v1/listCarrierByWarehouse"; public static final String PATH_CARRIERS = "/webApi/carrier/v1/listCarrierByWarehouse";
/** 获取激活仓库列表({@code POST /webApi/warehouse/listActive})。 */
public static final String PATH_WAREHOUSE_ACTIVE = "/webApi/warehouse/listActive";
/** 获取权限内仓库({@code POST /webApi/warehouse/listWarehouseHasPerm})。 */
public static final String PATH_WAREHOUSE_PERMITTED = "/webApi/warehouse/listWarehouseHasPerm";
/** 物流增值:签收服务。 */ /** 物流增值:签收服务。 */
public static final String ADD_SERVICE_SIGNATURE = "is_signature"; public static final String ADD_SERVICE_SIGNATURE = "is_signature";

48
warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunAdapter.java

@ -24,6 +24,7 @@ import common.ecommerce.edayun.dto.EdayunReturnDtos;
import common.ecommerce.edayun.dto.EdayunRmaListDtos; import common.ecommerce.edayun.dto.EdayunRmaListDtos;
import common.ecommerce.edayun.dto.EdayunSkuLabelDtos; import common.ecommerce.edayun.dto.EdayunSkuLabelDtos;
import common.ecommerce.edayun.dto.EdayunTrackDtos; import common.ecommerce.edayun.dto.EdayunTrackDtos;
import common.ecommerce.edayun.dto.EdayunWarehouseDtos;
import common.ecommerce.edayun.enums.EdayunCancelStatus; import common.ecommerce.edayun.enums.EdayunCancelStatus;
import common.ecommerce.edayun.http.EdayunRequestFactory; import common.ecommerce.edayun.http.EdayunRequestFactory;
import common.ecommerce.http.HttpRequest; import common.ecommerce.http.HttpRequest;
@ -1080,14 +1081,53 @@ public final class EdayunAdapter implements WarehouseAdapter, WarehouseProductCa
// ------------------------------------------------------------------ 承运商 // ------------------------------------------------------------------ 承运商
/** /**
* 客户名下的仓库列表。 * 客户名下有权限的仓库列表
* ({@code POST /webApi/warehouse/listWarehouseHasPerm})。
* *
* <p><b>易达云文档没给仓库列表接口</b>,显式拒绝而不是返回空列表—— * <p><b>用这个,不要用 listActive</b>:listActive 是平台全量激活仓(118 条),
* 空列表和「不支持」调用方分不清。</p> * 含当前客户没授权的;这个只返回有权限的(69 条)。</p>
*
* <p>{@code -999}(智能分仓)是哨兵值,映射时已跳过。</p>
*/ */
@Override @Override
public List<WarehouseFacility> warehouses(WarehouseContext ctx) { public List<WarehouseFacility> warehouses(WarehouseContext ctx) {
throw new WarehouseUnsupportedCapabilityException(WarehouseCapability.DIRECTORY); EdayunWarehouseDtos.ListPermittedRequest body =
EdayunWarehouseMapper.toListPermittedRequest();
String bodyJson = json.toJson(body);
HttpResponse resp = send(ctx, EdayunConstants.PATH_WAREHOUSE_PERMITTED, bodyJson,
"warehouse.directory.warehouses");
EdayunWarehouseDtos.ListWarehouseResponse parsed =
json.fromJson(resp.body(), EdayunWarehouseDtos.ListWarehouseResponse.class);
requireSuccess(ctx, parsed == null ? null : parsed.code,
parsed == null ? null : parsed.msg, resp, "warehouse.directory.warehouses");
return EdayunWarehouseMapper.toFacilities(parsed == null ? null : parsed.data);
}
/**
* 平台侧全量激活仓({@code POST /webApi/warehouse/listActive})。
*
* <p>与 {@link #warehouses} 的区别:那个只返回<b>有权限</b>的仓;这个是平台
* 全量(实测 118 条 vs 69 条),<b>含当前客户没授权的</b>——不要用它给客户选仓。</p>
*
* <p>实测:{@code warehouseOperationType=0} 尾程仓 111 条、{@code =1} 头程仓 7 条、
* 不传则两者之和 118 条(文档说必填,实际不传也通)。</p>
*/
public List<WarehouseFacility> activeWarehouses(WarehouseContext ctx,
boolean inboundWarehouse) {
EdayunWarehouseDtos.ListActiveRequest body =
EdayunWarehouseMapper.toListActiveRequest(inboundWarehouse);
String bodyJson = json.toJson(body);
HttpResponse resp = send(ctx, EdayunConstants.PATH_WAREHOUSE_ACTIVE, bodyJson,
"warehouse.directory.warehouses.active");
EdayunWarehouseDtos.ListWarehouseResponse parsed =
json.fromJson(resp.body(), EdayunWarehouseDtos.ListWarehouseResponse.class);
requireSuccess(ctx, parsed == null ? null : parsed.code,
parsed == null ? null : parsed.msg, resp, "warehouse.directory.warehouses.active");
return EdayunWarehouseMapper.toFacilities(parsed == null ? null : parsed.data);
} }

112
warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunWarehouseMapper.java

@ -0,0 +1,112 @@
package common.ecommerce.edayun.adapter;
import common.ecommerce.edayun.dto.EdayunWarehouseDtos;
import common.ecommerce.warehouse.enums.WarehouseProvider;
import common.ecommerce.warehouse.model.WarehouseFacility;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* 易达云仓库清单映射
* ({@code warehouse/listActive} 与 {@code warehouse/listWarehouseHasPerm})。
*
* <p><b>两个接口用途不同</b>:</p>
* <ul>
* <li>{@code listWarehouseHasPerm} = 当前客户<b>有权限</b>的仓(69 条)——下单用这个</li>
* <li>{@code listActive} = 平台侧<b>全量</b>激活仓(118 条)——含未授权的仓</li>
* </ul>
*
* <p>{@code -999} 是「智能分仓」的哨兵值(名称 {@code divideWarehouse}),
* 不是真实仓,映射时跳过。</p>
*/
public final class EdayunWarehouseMapper {
/** 「智能分仓」哨兵值。 */
static final String ID_SMART_SPLIT = "-999";
/** 仓库类型:头程仓。 */
static final int OPERATION_TYPE_INBOUND = 1;
/** 仓库类型:尾程仓。 */
static final int OPERATION_TYPE_OUTBOUND = 0;
private EdayunWarehouseMapper() {
}
/** 激活仓库请求。 */
public static EdayunWarehouseDtos.ListActiveRequest toListActiveRequest(
boolean inboundWarehouse) {
EdayunWarehouseDtos.ListActiveRequest req =
new EdayunWarehouseDtos.ListActiveRequest();
req.warehouseOperationType = inboundWarehouse
? OPERATION_TYPE_INBOUND : OPERATION_TYPE_OUTBOUND;
return req;
}
/** 权限内仓库请求(接口无参数)。 */
public static EdayunWarehouseDtos.ListPermittedRequest toListPermittedRequest() {
return new EdayunWarehouseDtos.ListPermittedRequest();
}
/** 响应 → 统一模型;跳过 {@code -999} 与缺 code 的行。 */
public static List<WarehouseFacility> toFacilities(
List<EdayunWarehouseDtos.WarehouseRow> rows) {
if (rows == null || rows.isEmpty()) {
return Collections.emptyList();
}
List<WarehouseFacility> out = new ArrayList<WarehouseFacility>(rows.size());
for (EdayunWarehouseDtos.WarehouseRow row : rows) {
WarehouseFacility facility = toFacility(row);
if (facility != null) {
out.add(facility);
}
}
return out;
}
/**
* 一行 → 统一仓资料。
*
* <p>统一模型的口径:{@code warehouseCode} 用<b>仓编码</b>(如 {@code USLA}),
* 不是数字 id——那个进 {@code providerWarehouseId}。</p>
*/
static WarehouseFacility toFacility(EdayunWarehouseDtos.WarehouseRow row) {
if (row == null || !hasText(row.warehouseCode)) {
return null;
}
if (ID_SMART_SPLIT.equals(trim(row.warehouseId))) {
return null;
}
return WarehouseFacility.builder()
.sourceProvider(WarehouseProvider.EDAYUN)
.providerWarehouseId(trim(row.warehouseId))
.warehouseCode(row.warehouseCode.trim())
.name(firstNonBlank(row.warehouseName, row.warehouseNameEn))
.country(row.countryCode)
.province(row.provinceCode)
.city(row.cityName)
.state(row.provinceCode)
// 仓方只给单行地址,落在 address1
.address1(row.address)
.postcode(row.zipCode)
.contactName(row.warehouseManagerName)
.mobilePhone(row.warehouseManagerTel)
.build();
}
private static String firstNonBlank(String a, String b) {
if (hasText(a)) {
return a.trim();
}
return hasText(b) ? b.trim() : null;
}
private static String trim(String v) {
return v == null ? null : v.trim();
}
private static boolean hasText(String v) {
return v != null && !v.trim().isEmpty();
}
}

95
warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunWarehouseDtos.java

@ -0,0 +1,95 @@
package common.ecommerce.edayun.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.List;
/**
* 易达云报文结构:获取激活仓库列表
* ({@code POST /webApi/warehouse/listActive})。
*
* <p>返回的是<b>平台侧全量仓库</b>(含未授权给当前客户的),字段比
* 「权限内仓库」多得多(47 个 vs 17 个)。下单要用的是
* {@code listWarehouseHasPerm}——那个才是当前客户可用的仓。</p>
*/
public final class EdayunWarehouseDtos {
private EdayunWarehouseDtos() {
}
/** 激活仓库查询请求。 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public static final class ListActiveRequest {
/**
* 仓库类型:0 尾程仓 / 1 头程仓。
*
* <p>文档标必填,实测不传会返回两者之和(118 条 vs 0 类型 111 条 + 1 类型 7 条)。</p>
*/
public Integer warehouseOperationType;
}
/** 权限内仓库查询请求:无参数。 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public static final class ListPermittedRequest {
// 接口不收参数,保留空类是为了和「一个接口一个 DTO」的约定一致
}
/** 两个接口共用同一个响应结构。 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public static final class ListWarehouseResponse {
public Integer code;
public String msg;
public List<WarehouseRow> data;
public String traceId;
}
/**
* 一个仓库。
*
* <p>只声明两个接口都会返回的字段;{@code listActive} 多出来的 30 个字段
* (容量、营业时间、负责人邮箱等)统一模型用不到,不声明——Jackson 会忽略未知字段。</p>
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public static final class WarehouseRow {
/** 仓 id(字符串形式,如 {@code "40269"})。 */
public String warehouseId;
/** 仓名称(中文)。 */
public String warehouseName;
/** 仓名称(英文)。 */
public String warehouseNameEn;
/** 仓编码,如 {@code USALA-Q031}。 */
public String warehouseCode;
/** 仓库位置编码(权限内接口给 {@code WH-<id>})。 */
public String warehouseLocationCode;
public String countryCode;
/** 地址原文(单行)。 */
public String address;
/** 仓库区域类型:0 普通 / 1 分区(码表未给全)。 */
public Integer warehouseRegionType;
/** 当前时间(毫秒);权限内接口实测恒为 null。 */
public Long currentTime;
/** 时区,如 {@code America/Los_Angeles}。 */
public String timeZone;
// ---- 仅 listActive 返回,权限内接口没有 ----
/** 州 / 省编码,如 {@code US01}。 */
public String provinceCode;
/** 城市编码 / 名称。 */
public String cityCode;
public String cityName;
public String zipCode;
/** 仓库类型:0 尾程仓 / 1 头程仓。 */
public Integer warehouseOperationType;
/** 仓状态;实测全是 0。 */
public Integer warehouseStatus;
/** 父仓 id(子仓才有)。 */
public String parentWarehouseId;
/** 是否私有仓。 */
public Integer privateFlag;
/** 仓库负责人。 */
public String warehouseManagerName;
public String warehouseManagerTel;
}
}

3
warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunAdapterTest.java

@ -106,8 +106,9 @@ class EdayunAdapterTest {
EdayunConstants.PR_BASE_URL, EdayunConstants.PR_BASE_URL,
common.ecommerce.shared.spi.ChannelSecret.builder().appSecret("k").build()); common.ecommerce.shared.spi.ChannelSecret.builder().appSecret("k").build());
// 调拨易达云不声明
assertThrows(WarehouseUnsupportedCapabilityException.class, assertThrows(WarehouseUnsupportedCapabilityException.class,
() -> sdk.warehouses(WH, conn).warehouses()); () -> sdk.warehouses(WH, conn).getTransfer("T-1"));
} }
/** 能力矩阵查询本身可用(不触发真实 API)。 */ /** 能力矩阵查询本身可用(不触发真实 API)。 */

184
warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunWarehouseTest.java

@ -0,0 +1,184 @@
package common.ecommerce.edayun.adapter;
import common.ecommerce.edayun.dto.EdayunWarehouseDtos;
import common.ecommerce.http.JacksonJsonCodec;
import common.ecommerce.shared.spi.ChannelSecret;
import common.ecommerce.shared.testkit.RecordingTransport;
import common.ecommerce.shared.testkit.Responses;
import common.ecommerce.warehouse.enums.WarehouseProvider;
import common.ecommerce.warehouse.model.WarehouseFacility;
import common.ecommerce.warehouse.sdk.WarehouseConnection;
import common.ecommerce.warehouse.sdk.WarehouseContext;
import org.junit.jupiter.api.Test;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneOffset;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* 仓库清单({@code listActive} / {@code listWarehouseHasPerm})。
*
* <p>重点:-999(智能分仓)要跳过、warehouseCode 用仓编码不是数字 id、
* listActive 与 listWarehouseHasPerm 用途不同。</p>
*/
class EdayunWarehouseTest {
private static final Clock CLOCK = Clock.fixed(Instant.parse("2026-11-16T00:00:00Z"), ZoneOffset.UTC);
private static WarehouseContext ctx() {
return WarehouseContext.of("EDY-WH", WarehouseProvider.EDAYUN, "2",
WarehouseConnection.of("https://test.example/openapi",
ChannelSecret.builder().appKey("k").appSecret("s")
.clientId("c").clientSecret("cs").build()),
"req-wh", CLOCK);
}
private static RecordingTransport stub(String path, String body) {
return RecordingTransport.create()
.route(common.ecommerce.edayun.EdayunConstants.PATH_TOKEN, req -> Responses.ok(
"{\"access_token\":\"T1\",\"token_type\":\"bearer\"}"))
.route(path, req -> Responses.ok(body));
}
// ------------------------------------------------------------ 请求
/** 头程 / 尾程映射到 1 / 0。 */
@Test
void operationTypeMaps() {
assertEquals(Integer.valueOf(1),
EdayunWarehouseMapper.toListActiveRequest(true).warehouseOperationType);
assertEquals(Integer.valueOf(0),
EdayunWarehouseMapper.toListActiveRequest(false).warehouseOperationType);
}
// ------------------------------------------------------------ 响应
private static EdayunWarehouseDtos.WarehouseRow row() {
EdayunWarehouseDtos.WarehouseRow r = new EdayunWarehouseDtos.WarehouseRow();
r.warehouseId = "2";
r.warehouseName = "美西1仓";
r.warehouseNameEn = "Los Angeles Warehouse";
r.warehouseCode = "USLA";
r.warehouseLocationCode = "WH-2";
r.countryCode = "US";
r.address = "1251 S Rockefeller Ave, Unit B";
r.warehouseRegionType = 0;
r.timeZone = "America/Los_Angeles";
return r;
}
private static EdayunWarehouseDtos.WarehouseRow sentinel() {
EdayunWarehouseDtos.WarehouseRow r = new EdayunWarehouseDtos.WarehouseRow();
r.warehouseId = "-999";
r.warehouseName = "使用分仓规则";
r.warehouseNameEn = "divideWarehouse";
r.warehouseCode = "USMC";
return r;
}
@Test
void mapsFacility() {
WarehouseFacility f = EdayunWarehouseMapper.toFacility(row());
// 统一模型的口径:warehouseCode 是仓编码,数字 id 进 providerWarehouseId
assertEquals("USLA", f.warehouseCode());
assertEquals("2", f.providerWarehouseId());
assertEquals("美西1仓", f.name());
assertEquals("US", f.country());
assertEquals("1251 S Rockefeller Ave, Unit B", f.address1());
assertEquals(WarehouseProvider.EDAYUN, f.sourceProvider());
// 权限内接口没有 zipCode / 负责人
assertNull(f.postcode());
assertNull(f.contactName());
}
/** listActive 多给的字段也要能映射。 */
@Test
void mapsExtraFieldsFromListActive() {
EdayunWarehouseDtos.WarehouseRow r = row();
r.provinceCode = "US01";
r.cityName = "Los Angeles";
r.zipCode = "91761";
r.warehouseManagerName = "Bo-LA6";
r.warehouseManagerTel = "1234567";
WarehouseFacility f = EdayunWarehouseMapper.toFacility(r);
assertEquals("US01", f.province());
assertEquals("US01", f.state());
assertEquals("Los Angeles", f.city());
assertEquals("91761", f.postcode());
assertEquals("Bo-LA6", f.contactName());
assertEquals("1234567", f.mobilePhone());
}
/** -999 是「使用分仓规则」的哨兵值,不是真实仓。 */
@Test
void smartSplitSentinelIsSkipped() {
List<WarehouseFacility> list = EdayunWarehouseMapper.toFacilities(
java.util.Arrays.asList(row(), sentinel()));
assertEquals(1, list.size());
assertEquals("USLA", list.get(0).warehouseCode());
}
/** 没有仓编码的行跳过——统一模型要求 warehouseCode 非空。 */
@Test
void rowsWithoutCodeAreSkipped() {
EdayunWarehouseDtos.WarehouseRow bad = row();
bad.warehouseCode = " ";
assertEquals(1, EdayunWarehouseMapper.toFacilities(
java.util.Arrays.asList(bad, row())).size());
assertNull(EdayunWarehouseMapper.toFacility(null));
}
@Test
void emptyRowsYieldEmptyList() {
assertTrue(EdayunWarehouseMapper.toFacilities(null).isEmpty());
assertTrue(EdayunWarehouseMapper.toFacilities(
java.util.Collections.<EdayunWarehouseDtos.WarehouseRow>emptyList()).isEmpty());
}
// ------------------------------------------------------------ 门面
@Test
void adapterQueriesPermittedWarehouses() {
RecordingTransport transport = stub(
common.ecommerce.edayun.EdayunConstants.PATH_WAREHOUSE_PERMITTED,
"{\"code\":200,\"msg\":\"操作成功\",\"data\":["
+ "{\"warehouseId\":\"2\",\"warehouseName\":\"美西1仓\","
+ "\"warehouseCode\":\"USLA\",\"countryCode\":\"US\"},"
+ "{\"warehouseId\":\"-999\",\"warehouseName\":\"使用分仓规则\","
+ "\"warehouseCode\":\"USMC\"}]}");
List<WarehouseFacility> list = new EdayunAdapter(transport, new JacksonJsonCodec())
.warehouses(ctx());
assertEquals(1, list.size());
assertEquals("USLA", list.get(0).warehouseCode());
}
/** listActive 要带 warehouseOperationType,且同样跳过 -999。 */
@Test
void adapterQueriesActiveWarehouses() {
RecordingTransport transport = stub(
common.ecommerce.edayun.EdayunConstants.PATH_WAREHOUSE_ACTIVE,
"{\"code\":200,\"msg\":\"操作成功\",\"data\":["
+ "{\"warehouseId\":\"40222\",\"warehouseName\":\"上海浦东新区实体仓\","
+ "\"warehouseCode\":\"LS1130\",\"warehouseOperationType\":1}]}");
List<WarehouseFacility> list = new EdayunAdapter(transport, new JacksonJsonCodec())
.activeWarehouses(ctx(), true);
assertEquals(1, list.size());
assertEquals("LS1130", list.get(0).warehouseCode());
assertTrue(transport.lastDataRequest().body()
.contains("\"warehouseOperationType\":1"));
}
}

102
warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/probe/EdayunWarehouseProbeTest.java

@ -0,0 +1,102 @@
package common.ecommerce.edayun.probe;
import common.ecommerce.edayun.EdayunConstants;
import common.ecommerce.edayun.adapter.EdayunAdapter;
import common.ecommerce.http.JacksonJsonCodec;
import common.ecommerce.http.OkHttpTransport;
import common.ecommerce.shared.error.ChannelException;
import common.ecommerce.shared.spi.ChannelSecret;
import common.ecommerce.warehouse.enums.WarehouseProvider;
import common.ecommerce.warehouse.model.WarehouseFacility;
import common.ecommerce.warehouse.sdk.WarehouseConnection;
import common.ecommerce.warehouse.sdk.WarehouseContext;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import java.time.Clock;
import java.util.List;
import java.util.UUID;
/**
* 仓库清单联调探针:<b>只读</b>。
*
* <pre>
* # 只看报文(不联网)
* mvn -pl warehouse-sdk-edayun -DfailIfNoTests=false \
* -Dedayun.probe.warehouse=true -Dtest=EdayunWarehouseProbeTest test
*
* # 真查(只读)
* ... -Dedayun.probe.warehouse=true -Dedayun.probe.call=true \
* -Dedayun.probe.clientId=... -Dedayun.probe.clientSecret=... \
* -Dedayun.probe.appKey=... -Dedayun.probe.appSecret=...
* </pre>
*
* <p>两个接口都查:权限内(下单用这个)与全量激活仓(含未授权的)。</p>
*/
@EnabledIfSystemProperty(named = "edayun.probe.warehouse", matches = "true")
class EdayunWarehouseProbeTest {
private static final String BASE_URL = opt("edayun.probe.baseUrl", EdayunConstants.PR_BASE_URL);
private static final String CLIENT_ID = System.getProperty("edayun.probe.clientId", "");
private static final String CLIENT_SECRET = System.getProperty("edayun.probe.clientSecret", "");
private static final String APP_KEY = System.getProperty("edayun.probe.appKey", "");
private static final String APP_SECRET = System.getProperty("edayun.probe.appSecret", "");
private static final boolean CALL = Boolean.getBoolean("edayun.probe.call");
@Test
void probeWarehouses() {
System.out.println("\n================ edayun / POST "
+ EdayunConstants.PATH_WAREHOUSE_PERMITTED + " (权限内) ================");
System.out.println("[request] {}");
System.out.println("\n================ edayun / POST "
+ EdayunConstants.PATH_WAREHOUSE_ACTIVE + " (全量) ================");
System.out.println("[request] {\"warehouseOperationType\":0}");
Assumptions.assumeTrue(CALL, "dry-run:未加 -Dedayun.probe.call=true,不实际调用");
Assumptions.assumeTrue(!CLIENT_ID.trim().isEmpty() && !CLIENT_SECRET.trim().isEmpty()
&& !APP_KEY.trim().isEmpty() && !APP_SECRET.trim().isEmpty(),
"真查需要 -Dedayun.probe.clientId / clientSecret / appKey / appSecret");
try {
WarehouseContext ctx = WarehouseContext.of("EDY-PROBE", WarehouseProvider.EDAYUN, null,
WarehouseConnection.of(BASE_URL,
ChannelSecret.builder()
.appKey(APP_KEY).appSecret(APP_SECRET)
.clientId(CLIENT_ID).clientSecret(CLIENT_SECRET)
.build()),
"probe-" + UUID.randomUUID(), Clock.systemUTC());
EdayunAdapter adapter = new EdayunAdapter(
new OkHttpTransport("common-ecommerce/1.0.0 (edayun-probe)", 10_000, 60_000),
new JacksonJsonCodec());
print("权限内", adapter.warehouses(ctx));
print("全量尾程", adapter.activeWarehouses(ctx, false));
print("全量头程", adapter.activeWarehouses(ctx, true));
} catch (RuntimeException e) {
String msg = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage();
System.out.println("[ERROR] " + e.getClass().getSimpleName() + ": "
+ (msg.length() <= 800 ? msg : msg.substring(0, 800) + "…"));
if (e instanceof ChannelException) {
ChannelException ce = (ChannelException) e;
System.out.println(" platformCode=" + ce.platformCode()
+ " retryable=" + ce.retryable());
}
}
}
private static void print(String label, List<WarehouseFacility> list) {
System.out.println("[OK] " + label + " warehouses=" + list.size());
for (int i = 0; i < Math.min(5, list.size()); i++) {
WarehouseFacility f = list.get(i);
System.out.println(" " + f.providerWarehouseId() + " " + f.warehouseCode()
+ " " + f.name() + " " + f.country());
}
}
private static String opt(String name, String fallback) {
String value = System.getProperty(name, "");
String trimmed = value == null ? "" : value.trim();
return trimmed.isEmpty() ? fallback : trimmed;
}
}
Loading…
Cancel
Save