31 changed files with 3397 additions and 55 deletions
@ -0,0 +1,251 @@ |
|||||||
|
# 信仓(XinCang)接入汇总 |
||||||
|
|
||||||
|
## 1. 基本信息 |
||||||
|
|
||||||
|
| 项 | 值 | |
||||||
|
|---|---| |
||||||
|
| 适配器 ID | `xincang` | |
||||||
|
| 测试 / 联调环境 | `http://test.api.oms.13u3.com/oms` | |
||||||
|
| 生产环境 | `https://oms.xincang-tech.com/oms/` | |
||||||
|
| 鉴权 | 先 `GET /api.login?appkey=&secret=` 换 token;业务请求把 token 放 **query 参数 `token`**,不是 `Authorization` 头 | |
||||||
|
| token 有效期 | 2 小时,**没有 refresh 接口**,到期只能重新登录 | |
||||||
|
| token 维度 | 客户级(同一 appkey 下多仓共用一个 token) | |
||||||
|
| 限流 | 保守默认 2 req/s(仓方未公开) | |
||||||
|
| 成功判定 | 顶层 `errno=0`;业务接口还要 `rst.code="0"`(登录响应没有 `rst.code`) | |
||||||
|
| 时间口径 | 北京时间(`yyyy-MM-dd HH:mm:ss` / 日期 `yyyy-MM-dd`) | |
||||||
|
| 单位 | 金额美元、尺寸英寸、重量磅(统一模型是 cm/g,适配器内换算) | |
||||||
|
|
||||||
|
## 2. 接口清单(19 个已对接) |
||||||
|
|
||||||
|
| # | 接口 | 路径 | 能力位 | |
||||||
|
|---|---|---|---| |
||||||
|
| 1 | 登录 | `GET /api.login` | — | |
||||||
|
| 2 | 新增产品 | `POST /api.add_product` | `PRODUCT` | |
||||||
|
| 3 | 更新产品 | `POST /api.update_product` | `PRODUCT` | |
||||||
|
| 4 | 产品列表(查重用) | `GET /api.productlist` | `PRODUCT` | |
||||||
|
| 5 | 新增订单一单多件 | `POST /api.add_order_multiple` | `OUTBOUND` | |
||||||
|
| 6 | 订单详情 | `GET /api.get_order` | `OUTBOUND` | |
||||||
|
| 7 | 删除订单 | `POST /api.delete_order` | `OUTBOUND` | |
||||||
|
| 8 | 新增转运 | `POST /fba.do_fba` | `TRANSFER` | |
||||||
|
| 9 | 转运审核 | `POST /fba.do_approve` | `TRANSFER` | |
||||||
|
| 10 | 转运详情 | `GET /fba.fba_detail` | `TRANSFER` | |
||||||
|
| 11 | 删除转运 | `POST /fba.delete_fba` | `TRANSFER` | |
||||||
|
| 12 | 新增预报 | `POST /forecast.do_forecast` | `INBOUND` | |
||||||
|
| 13 | 完善资料 | `POST /forecast.do_improve_forecast` | `INBOUND` | |
||||||
|
| 14 | 预报提交 | `POST /forecast.done_forecast` | `INBOUND` | |
||||||
|
| 15 | 预报详情 | `GET /forecast.forecast_detail` | `INBOUND` | |
||||||
|
| 16 | 实时库存 | `GET /api.stocklist` | `INVENTORY_QUERY` | |
||||||
|
| 17 | 库龄列表 | `GET /api.stockagelist` | `INVENTORY_QUERY` | |
||||||
|
| 18 | 最优渠道 | `POST /api.calculate_order_v3` | `CHANNEL_RECOMMEND` | |
||||||
|
| 19 | 客户仓库 / 承运商 | `GET /api.get_customer_warehouses`、`/api.get_customer_logistics` | `DIRECTORY` | |
||||||
|
|
||||||
|
### 已声明但未接入 |
||||||
|
|
||||||
|
| 常量 | 说明 | |
||||||
|
|---|---| |
||||||
|
| `PATH_PRODUCT_PUBLISH`(`/api.pub_product`) | 临时产品 → 正式产品,未接;建档结果仍是临时产品 | |
||||||
|
| `PATH_TRANSFER_LIST`(`/fba.fbalist`) | 转运列表,未接 | |
||||||
|
| `api.orderlist` / `forecast.forecastlist` | 列表查询均未接 | |
||||||
|
|
||||||
|
## 3. 业务流程 |
||||||
|
|
||||||
|
### 出库 |
||||||
|
|
||||||
|
``` |
||||||
|
① 查仓库 / 承运商(拿 warehouse_code、logistics_type) |
||||||
|
GET /api.get_customer_warehouses |
||||||
|
GET /api.get_customer_logistics |
||||||
|
② 可选:最优渠道询价 |
||||||
|
POST /api.calculate_order_v3 |
||||||
|
③ 下单(multipart/form-data) |
||||||
|
POST /api.add_order_multiple |
||||||
|
④ 查详情 / 回读状态 |
||||||
|
GET /api.get_order?order_no= (或 ckh=) |
||||||
|
⑤ 删除(按状态分流:待审核→删除、待发货→已取消、拣货/已拣货→已拦截) |
||||||
|
POST /api.delete_order |
||||||
|
``` |
||||||
|
|
||||||
|
### 转运(仓 → 平台仓) |
||||||
|
|
||||||
|
``` |
||||||
|
① 建转运(application/json) POST /fba.do_fba → order_no |
||||||
|
② 查详情 GET /fba.fba_detail?order_no= |
||||||
|
③ 审核 POST /fba.do_approve?order_no= |
||||||
|
④ 删除(仅待审核可删) POST /fba.delete_fba?order_no= |
||||||
|
``` |
||||||
|
|
||||||
|
### 头程入库(预报) |
||||||
|
|
||||||
|
``` |
||||||
|
① 建空单(只给单头) POST /forecast.do_forecast → order_no |
||||||
|
② 补明细(整段覆盖) POST /forecast.do_improve_forecast |
||||||
|
③ 提交 POST /forecast.done_forecast (query + body 都带 forecast_no) |
||||||
|
④ 查详情 GET /forecast.forecast_detail |
||||||
|
``` |
||||||
|
|
||||||
|
> ①②③ 是三步,不是一次调用。① 不需要商品明细(`referenceSkuCount` 必填)。 |
||||||
|
|
||||||
|
### 商品 |
||||||
|
|
||||||
|
``` |
||||||
|
① 查临时产品(决定 add 还是 update) |
||||||
|
GET /api.productlist?state=0&key=<sku> |
||||||
|
② 新增(临时产品) POST /api.add_product |
||||||
|
或 更新(仅临时产品可更新) POST /api.update_product |
||||||
|
``` |
||||||
|
|
||||||
|
## 4. 枚举映射(信仓是两套码表,core 是第三套) |
||||||
|
|
||||||
|
### 订单状态 `state` |
||||||
|
|
||||||
|
| 信仓码 | 含义 | core `OutboundStatus` | |
||||||
|
|---|---|---| |
||||||
|
| 0 | 待审核 | `PENDING_REVIEW` | |
||||||
|
| 1 | 待发货 | `PENDING_SHIPMENT` | |
||||||
|
| 2 | 拣货中 | `PICKING` | |
||||||
|
| 3 | 已拣货 | `PICKED` | |
||||||
|
| 4 | 已贴单 | `LABEL_READY` | |
||||||
|
| 5 | 已发货 | `SHIPPED` | |
||||||
|
| 6 | 已拦截 | `INTERCEPTED` | |
||||||
|
| 7 | 缺货 | `OUT_OF_STOCK` | |
||||||
|
| 8 | 已取消 | `CANCELLED` | |
||||||
|
| 10 | 已删除 | `DELETED` | |
||||||
|
| 11 | 审核中 | `REVIEWING` | |
||||||
|
| 12 | 审核失败 | `REVIEW_FAILED` | |
||||||
|
| 其他 | — | `UNKNOWN`(不猜) | |
||||||
|
|
||||||
|
### 转运状态 `state` |
||||||
|
|
||||||
|
| 信仓码 | 含义 | core `TransferStatus` | |
||||||
|
|---|---|---| |
||||||
|
| 0 | 待审核 | `PENDING_REVIEW` | |
||||||
|
| 1 | 待处理 | `PENDING_PROCESSING` | |
||||||
|
| 2 | 待拣货 | `PENDING_PICK` | |
||||||
|
| 3 | 待贴标 | `PENDING_LABELING` | |
||||||
|
| 4 | 待打托 | `PENDING_PALLETIZING` | |
||||||
|
| 5 | 待发货 | `PENDING_OUTBOUND` | |
||||||
|
| 6 | 已发货 | `SHIPPED`(**不是** `COMPLETED`)| |
||||||
|
| 7 | 已取消 | `CANCELLED` | |
||||||
|
|
||||||
|
> **列表接口与详情接口的码表不一致**:列表写的是「0 待审核 1 待处理 2 带拣货 3 待打托 4 待发货 5 已发货 9 取消」(少「待贴标」、后续前移)。适配器以**详情码表**为准,原始值仍保存在 `rawStatus`。 |
||||||
|
|
||||||
|
### 预报状态 `state` |
||||||
|
|
||||||
|
| 信仓码 | 含义 | core `InboundStatus` | |
||||||
|
|---|---|---| |
||||||
|
| 0 | 建仓中 | `DRAFT` | |
||||||
|
| 1 | 出运中 | `IN_TRANSIT` | |
||||||
|
| 2 | 预报完成 | `PENDING_SHIPMENT` | |
||||||
|
| 3 | 在海上 | `IN_TRANSIT` | |
||||||
|
| 4 | 送仓中 | `IN_TRANSIT` | |
||||||
|
| 5 | 卸柜中 | `RECEIVING` | |
||||||
|
| 6 | 清点中 | `RECEIVING` | |
||||||
|
| 7 | 上架中 | `STORING` | |
||||||
|
| 8 | 上架完成 | `COMPLETED` | |
||||||
|
| 9 | 已驳回 | `REJECTED` | |
||||||
|
|
||||||
|
### 订单类型 `order_type` |
||||||
|
|
||||||
|
| 值 | 含义 | 对应 core | |
||||||
|
|---|---|---| |
||||||
|
| `common` | 非自供面单 | `LabelMode.WAREHOUSE_LABEL` | |
||||||
|
| `wayfair` | 自供面单 | `LabelMode.PLATFORM_LABEL`(`gzh` + `face_base64` 必填)| |
||||||
|
|
||||||
|
> 转运接口的 `order_type` 是**另一套字典**(FBA / LTL 等),与下单接口无关。 |
||||||
|
|
||||||
|
## 5. 字段口径(容易传错的) |
||||||
|
|
||||||
|
| 字段 | 要传什么 | |
||||||
|
|---|---| |
||||||
|
| 下单 `ckh` | **参考号,唯一不可重复**;适配器用 `outboundRequestNo`,重推同一单号会被拒 | |
||||||
|
| 下单 `logistics_type` | 承运商字典值(`api.get_customer_logistics` 返回的原值) | |
||||||
|
| 下单 `is_sign` | `是` / `否`;模型 `OutboundCommand.signatureRequired`,未给时兜底「否」 | |
||||||
|
| 下单 `is_split` | `1` 拆单 / `0` 打包;未给时仓方默认 `1` | |
||||||
|
| 商品 `amount` | **必填且美元**;取 `declaredValue`,缺失直接拒绝(不再兜底 0.00) | |
||||||
|
| 商品 `bar_code` | 必填且**查重**;`WarehouseProduct.barcode` 未给时退回 SKU | |
||||||
|
| 商品 `ckm` | 仓库码,取 `customItemNo` | |
||||||
|
| 转运 `po` | 必填;未给时退回 `transferRequestNo` | |
||||||
|
| 转运 `delivery_mode` / `delivery_way` | 必填,只认仓方字典原值;先调字典接口 | |
||||||
|
| 转运 `is_pallet` | 必填 `是` / `否`;模型映射 `palletRequired` | |
||||||
|
| 预报 `rfc_sku_count` | 必填;取 `referenceSkuCount`,没有退回明细行数 | |
||||||
|
| 预报 `ref_no` | 完善资料必填,**长度上限 32** | |
||||||
|
| 库存 `warehouse_code` | **必填且只能单个**;传多个显式拒绝 | |
||||||
|
| 库存 `is_show_zero` | 默认不传时只返回库存 > 0 的 SKU;模型 `includeZeroStock` | |
||||||
|
| 库龄 `bill_date` | 单值字符串 `起 - 止` | |
||||||
|
|
||||||
|
## 6. 单位与时区 |
||||||
|
|
||||||
|
| 字段 | 单位 | |
||||||
|
|---|---| |
||||||
|
| 商品 `weight_lbs` / `size_*_ln` | 磅 / 英寸(适配器从 cm、g 换算,保留 4 位) | |
||||||
|
| 商品 `amount` | 美元,2 位小数 | |
||||||
|
| 库存 `volume_cm` | 立方厘米 | |
||||||
|
| 库龄 `total_volume_cbm` | 立方米 | |
||||||
|
|
||||||
|
时间字段全部是**北京时间**,适配器解析成 UTC 后存入模型(`Instant`)。空串一律转 `null`,不猜。 |
||||||
|
|
||||||
|
## 7. 平台限制(已知且无法解决) |
||||||
|
|
||||||
|
| 接口 | 字段 | 情况 | |
||||||
|
|---|---|---| |
||||||
|
| 订单详情 `get_order` | `order_no` | 只回系统单号;业务侧单号在 `ckh` | |
||||||
|
| 订单详情 `get_order` | 面单 | 只给 `face_url`(OSS 签名链接,有时效) | |
||||||
|
| 转运详情 | `dest_warehouse` | 可能是占位 `"0"` | |
||||||
|
| 产品建档 | `state` | 新建的是**临时产品**(`state=0`),没有上架接口就下不了单 | |
||||||
|
| 预报 | 明细 | 建单时没有明细,必须先建头再补 | |
||||||
|
| 列表查询 | 订单 / 转运 / 预报 | 均无列表接口;`query(cursor)` 用单号取详情代替 | |
||||||
|
| 错误信息 | `err` | 只有一句话(如「产品参数有误」),无法细分原因 | |
||||||
|
|
||||||
|
## 8. 协议待核对(联调时必看) |
||||||
|
|
||||||
|
| 项 | 现状 | |
||||||
|
|---|---| |
||||||
|
| 生产域名 | 文档未给,常量写的是 `"待核对"` | |
||||||
|
| 限流 | 未公开,按 2 req/s | |
||||||
|
| **最优渠道 `calculate_order_v3`** | 文档标 `GET` + JSON body,**OkHttp 不支持 GET 带 body**;适配器按 **POST + JSON body** 下发 | |
||||||
|
|
||||||
|
## 9. 联调探针 |
||||||
|
|
||||||
|
三个探针,默认全部跳过: |
||||||
|
|
||||||
|
```bash |
||||||
|
# ① 登录 |
||||||
|
mvn -pl warehouse-sdk-xincang -am -DfailIfNoTests=false \ |
||||||
|
-Dxincang.probe=true \ |
||||||
|
-Dxincang.probe.appKey=<appkey> -Dxincang.probe.appSecret=<secret> \ |
||||||
|
-Dtest=XincangLoginProbeTest test |
||||||
|
|
||||||
|
# ② 只读(9 个查询接口) |
||||||
|
mvn -pl warehouse-sdk-xincang -am -DfailIfNoTests=false \ |
||||||
|
-Dxincang.probe=true \ |
||||||
|
-Dxincang.probe.appKey=<appkey> -Dxincang.probe.appSecret=<secret> \ |
||||||
|
-Dxincang.probe.sku=<有库存的SKU> -Dxincang.probe.postcode=<美国邮编> \ |
||||||
|
-Dtest=XincangReadProbeTest test |
||||||
|
|
||||||
|
# ③ 写(会留下真实数据,需二次确认) |
||||||
|
mvn -pl warehouse-sdk-xincang -am -DfailIfNoTests=false \ |
||||||
|
-Dxincang.probe=true -Dxincang.probe.write=true \ |
||||||
|
-Dxincang.probe.appKey=<appkey> -Dxincang.probe.appSecret=<secret> \ |
||||||
|
-Dxincang.probe.sku=<SKU> -Dxincang.probe.postcode=<邮编> \ |
||||||
|
-Dxincang.probe.destWarehouse=<目的仓> \ |
||||||
|
-Dtest=XincangWriteProbeTest test |
||||||
|
``` |
||||||
|
|
||||||
|
可选属性:`warehouseCode` / `carrier` / `orderNo` / `transferNo` / `forecastNo` / `qty` / |
||||||
|
`destWarehouse` / `deliveryMode` / `deliveryWay` / `orderType` / `shipmentType` / |
||||||
|
`cabinetType` / `deliveryRequirements` / `otherNeed` / `transferApprove`。 |
||||||
|
|
||||||
|
**会留下数据的探针**:商品建档(无删除接口)、预报(`delete_forecast` 未接)、 |
||||||
|
转运审核(审核后不可删,需 `-Dxincang.probe.transferApprove=true`)。 |
||||||
|
出库与转运创建可以自清理。 |
||||||
|
|
||||||
|
## 10. 未接入 |
||||||
|
|
||||||
|
| 项 | 原因 | |
||||||
|
|---|---| |
||||||
|
| 上架正式产品 | 统一模型没有「上架」语义 | |
||||||
|
| 订单 / 转运 / 预报列表 | 仓方虽提供,但统一模型暂未接列表能力 | |
||||||
|
| 文件上传 `upload.files` | 需要 multipart 文件流;商品图片与转运附件因此传不了 | |
||||||
|
| 修改订单 `api.update_order` | 文档建议停止使用 | |
||||||
|
| 费用测算 `api.calculate_order` / `_v2` | 只接了最优渠道 `_v3` | |
||||||
|
| 库龄费率以外的费用明细 | `is_need_fee_rate` 已支持,但结算账单未接 | |
||||||
@ -0,0 +1,76 @@ |
|||||||
|
package common.ecommerce.xincang.adapter; |
||||||
|
|
||||||
|
import common.ecommerce.shared.support.Money; |
||||||
|
import common.ecommerce.warehouse.capability.WarehouseProduct; |
||||||
|
import common.ecommerce.warehouse.model.InboundCommand; |
||||||
|
import common.ecommerce.warehouse.model.InboundLine; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
import java.time.LocalDate; |
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull; |
||||||
|
|
||||||
|
/** |
||||||
|
* 统一模型里「某家仓必填、其他仓不需要」的字段不再在构造期拦截。 |
||||||
|
* |
||||||
|
* <p>这些用例守护的是:信仓可以只给它认识的字段就构造出命令, |
||||||
|
* 不会因为运去哪的必填项(nameEn / packingType / 海关三项 / 入库商品行) |
||||||
|
* 被迫塞无意义的值。</p> |
||||||
|
*/ |
||||||
|
class XincangModelRelaxTest { |
||||||
|
|
||||||
|
/** 商品:不给 nameEn / packingType / 海关三项也能构造(信仓都收不到这些字段)。 */ |
||||||
|
@Test |
||||||
|
void productBuildsWithoutYqnOnlyFields() { |
||||||
|
WarehouseProduct product = WarehouseProduct.builder() |
||||||
|
.omsSku("SKU-1") |
||||||
|
.name("中文名") |
||||||
|
.lengthCm(10).widthCm(10).heightCm(10).weightGrams(100) |
||||||
|
.build(); |
||||||
|
assertNotNull(product); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 商品:信仓 amount 必填,但只需要 declaredValue,不需要 hsCode / countryOfOrigin。 |
||||||
|
* |
||||||
|
* <p>改前「海关三项必须整组给」在构造期强制,信仓调用方被迫填两个用不上的字段。</p> |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
void productCustomsValueAloneIsAccepted() { |
||||||
|
WarehouseProduct product = WarehouseProduct.builder() |
||||||
|
.omsSku("SKU-2") |
||||||
|
.name("中文名") |
||||||
|
.lengthCm(10).widthCm(10).heightCm(10).weightGrams(100) |
||||||
|
.declaredValue(Money.of("1.00", "USD")) |
||||||
|
.build(); |
||||||
|
assertNotNull(product); |
||||||
|
} |
||||||
|
|
||||||
|
/** 入库:信仓「新增预报」只建单头,可以没有商品行(明细走「完善资料」)。 */ |
||||||
|
@Test |
||||||
|
void inboundHeaderOnlyIsEnoughForForecastCreate() { |
||||||
|
InboundCommand head = InboundCommand.builder() |
||||||
|
.inboundRequestNo("FC-1") |
||||||
|
.warehouseId("NJ-2605") |
||||||
|
.shipmentType("2") |
||||||
|
.cabinetType("1") |
||||||
|
.containerNo("CAB-1") |
||||||
|
.predictionShipDate(LocalDate.now().plusDays(1)) |
||||||
|
.estimateArriveDate(LocalDate.now().plusDays(30)) |
||||||
|
.deliveryRequirements("1") |
||||||
|
.referenceSkuCount(3) |
||||||
|
.build(); |
||||||
|
assertNotNull(head); |
||||||
|
} |
||||||
|
|
||||||
|
/** 入库:完善资料阶段要明细,这时才加行,模型允许。 */ |
||||||
|
@Test |
||||||
|
void inboundWithLinesStillWorks() { |
||||||
|
InboundCommand withLines = InboundCommand.builder() |
||||||
|
.inboundRequestNo("FC-2") |
||||||
|
.warehouseId("NJ-2605") |
||||||
|
.line(InboundLine.builder().omsSku("SKU-1").quantity(1).build()) |
||||||
|
.build(); |
||||||
|
assertNotNull(withLines); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,293 @@ |
|||||||
|
package common.ecommerce.xincang.probe; |
||||||
|
|
||||||
|
import common.ecommerce.http.HttpRequest; |
||||||
|
import common.ecommerce.http.HttpResponse; |
||||||
|
import common.ecommerce.http.HttpTransport; |
||||||
|
import common.ecommerce.http.JacksonJsonCodec; |
||||||
|
import common.ecommerce.http.OkHttpTransport; |
||||||
|
import common.ecommerce.shared.spi.ChannelSecret; |
||||||
|
import common.ecommerce.shared.testkit.InMemoryLockProvider; |
||||||
|
import common.ecommerce.shared.testkit.InMemoryTokenStore; |
||||||
|
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 common.ecommerce.xincang.XincangConstants; |
||||||
|
import common.ecommerce.xincang.adapter.XincangAdapter; |
||||||
|
import org.junit.jupiter.api.Assumptions; |
||||||
|
|
||||||
|
import java.time.Clock; |
||||||
|
import java.util.List; |
||||||
|
import java.util.function.Supplier; |
||||||
|
|
||||||
|
/** |
||||||
|
* 信仓联网探针的公共基座。 |
||||||
|
* |
||||||
|
* <p><b>默认全部跳过</b>,用 {@code -Dxincang.probe=true} 显式开启;写接口还要再加 |
||||||
|
* {@code -Dxincang.probe.write=true} 二次确认。凭据与业务数据一律走系统属性, |
||||||
|
* <b>真实值不入库</b>。</p> |
||||||
|
* |
||||||
|
* <pre> |
||||||
|
* mvn -pl warehouse-sdk-xincang -am -DfailIfNoTests=false \ |
||||||
|
* -Dxincang.probe=true \ |
||||||
|
* -Dxincang.probe.appKey=你的appkey -Dxincang.probe.appSecret=你的secret \ |
||||||
|
* -Dtest=XincangReadProbeTest test |
||||||
|
* </pre> |
||||||
|
* |
||||||
|
* <p>可选属性:{@code baseUrl}、{@code warehouseCode}、{@code sku}、{@code postcode}、 |
||||||
|
* {@code qty}、{@code orderNo}、{@code transferNo}、{@code forecastNo}。</p> |
||||||
|
* |
||||||
|
* <p>设计约束:</p> |
||||||
|
* <ul> |
||||||
|
* <li>每个探针独立执行,单个失败只打印不抛出,保证一次能跑完全部接口;</li> |
||||||
|
* <li>请求 / 响应都打印(截断 + 脱敏),便于和文档逐字段对照;</li> |
||||||
|
* <li>不硬编码任何业务数据:仓代码与承运商从目录接口现取。</li> |
||||||
|
* </ul> |
||||||
|
*/ |
||||||
|
final class XincangProbeSupport { |
||||||
|
|
||||||
|
/** 通用开关。 */ |
||||||
|
static final String PROBE = "xincang.probe"; |
||||||
|
/** 写接口二次确认。 */ |
||||||
|
static final String PROBE_WRITE = "xincang.probe.write"; |
||||||
|
|
||||||
|
static final String APP_KEY = System.getProperty("xincang.probe.appKey", ""); |
||||||
|
static final String APP_SECRET = System.getProperty("xincang.probe.appSecret", ""); |
||||||
|
static final String BASE_URL = opt("xincang.probe.baseUrl", XincangConstants.TEST_BASE_URL); |
||||||
|
|
||||||
|
/** 业务输入:没有默认值,必须由调用方显式传入。 */ |
||||||
|
static final String WAREHOUSE_CODE = opt("xincang.probe.warehouseCode", ""); |
||||||
|
static final String SKU = opt("xincang.probe.sku", ""); |
||||||
|
static final String POSTCODE = opt("xincang.probe.postcode", ""); |
||||||
|
static final String ORDER_NO = opt("xincang.probe.orderNo", ""); |
||||||
|
static final String TRANSFER_NO = opt("xincang.probe.transferNo", ""); |
||||||
|
static final String FORECAST_NO = opt("xincang.probe.forecastNo", ""); |
||||||
|
|
||||||
|
private static final JacksonJsonCodec JSON = new JacksonJsonCodec(); |
||||||
|
|
||||||
|
/** 目录接口发现结果缓存,避免每个探针都列一遍。 */ |
||||||
|
private static String discoveredWarehouseCode; |
||||||
|
private static boolean warehouseDiscoveryAttempted; |
||||||
|
private static String discoveredCarrier; |
||||||
|
private static boolean carrierDiscoveryAttempted; |
||||||
|
|
||||||
|
private XincangProbeSupport() { |
||||||
|
} |
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 装配
|
||||||
|
|
||||||
|
/** 真实联网传输 + 报文打印;token 等敏感头在这里脱敏。 */ |
||||||
|
static HttpTransport transport() { |
||||||
|
return new LoggingTransport(new OkHttpTransport("common-ecommerce-xincang-probe")); |
||||||
|
} |
||||||
|
|
||||||
|
/** 装配真实适配器;令牌只存在内存里,不落盘。 */ |
||||||
|
static XincangAdapter adapter() { |
||||||
|
return new XincangAdapter(transport(), JSON, new InMemoryTokenStore(), |
||||||
|
new InMemoryLockProvider(), Clock.systemUTC()); |
||||||
|
} |
||||||
|
|
||||||
|
/** 用指定传输装配,便于需要复用连接的对象。 */ |
||||||
|
static XincangAdapter adapter(HttpTransport transport) { |
||||||
|
return new XincangAdapter(transport, JSON, new InMemoryTokenStore(), |
||||||
|
new InMemoryLockProvider(), Clock.systemUTC()); |
||||||
|
} |
||||||
|
|
||||||
|
static WarehouseContext ctx() { |
||||||
|
return ctx(WAREHOUSE_CODE.isEmpty() ? null : WAREHOUSE_CODE); |
||||||
|
} |
||||||
|
|
||||||
|
static WarehouseContext ctx(String providerWarehouseId) { |
||||||
|
return WarehouseContext.of("XC-PROBE", WarehouseProvider.XINCANG, providerWarehouseId, |
||||||
|
WarehouseConnection.of(BASE_URL, ChannelSecret.builder() |
||||||
|
.appKey(APP_KEY).appSecret(APP_SECRET).build()), |
||||||
|
"probe-" + System.currentTimeMillis(), Clock.systemUTC()); |
||||||
|
} |
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 前置检查
|
||||||
|
|
||||||
|
/** 凭据齐全才继续,否则整个探针 skip(不算失败)。 */ |
||||||
|
static void requireCredentials() { |
||||||
|
Assumptions.assumeTrue(!APP_KEY.trim().isEmpty() && !APP_SECRET.trim().isEmpty(), |
||||||
|
"未提供 -Dxincang.probe.appKey / -Dxincang.probe.appSecret,跳过探针"); |
||||||
|
} |
||||||
|
|
||||||
|
/** 需要某个业务输入时用它:缺了就跳过当前用例并说明缺哪个属性。 */ |
||||||
|
static void requireProperty(String name) { |
||||||
|
Assumptions.assumeTrue(System.getProperty(name, "").trim().length() > 0, |
||||||
|
"未提供 -D" + name + ",跳过该探针"); |
||||||
|
} |
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 执行 & 打印
|
||||||
|
|
||||||
|
/** 执行一步并打印结果;异常只打印不抛出,返回 null。 */ |
||||||
|
static <T> T step(String label, Supplier<T> action) { |
||||||
|
System.out.println(" [probe] " + label); |
||||||
|
try { |
||||||
|
T value = action.get(); |
||||||
|
System.out.println(" [ok] " + label + " → " + describe(value)); |
||||||
|
return value; |
||||||
|
} catch (RuntimeException e) { |
||||||
|
printError(e); |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static void step(String label, Runnable action) { |
||||||
|
step(label, () -> { |
||||||
|
action.run(); |
||||||
|
return Boolean.TRUE; |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
/** 异常打印:类型 + 截断消息 + 平台错误字段。 */ |
||||||
|
static void printError(RuntimeException e) { |
||||||
|
String msg = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage(); |
||||||
|
System.out.println(" [ERROR] " + e.getClass().getSimpleName() + ": " |
||||||
|
+ (msg.length() <= 400 ? msg : msg.substring(0, 400) + "…")); |
||||||
|
if (e instanceof common.ecommerce.shared.error.ChannelException) { |
||||||
|
common.ecommerce.shared.error.ChannelException ce = |
||||||
|
(common.ecommerce.shared.error.ChannelException) e; |
||||||
|
System.out.println(" operation=" + ce.operation() |
||||||
|
+ " platformCode=" + ce.platformCode() |
||||||
|
+ " platformRequestId=" + ce.platformRequestId() |
||||||
|
+ " retryable=" + ce.retryable()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static String describe(Object value) { |
||||||
|
if (value == null) { |
||||||
|
return "null"; |
||||||
|
} |
||||||
|
if (value instanceof List) { |
||||||
|
return ((List<?>) value).size() + " items"; |
||||||
|
} |
||||||
|
return String.valueOf(value); |
||||||
|
} |
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 依赖发现
|
||||||
|
|
||||||
|
/** |
||||||
|
* 仓代码:优先 {@code -Dxincang.probe.warehouseCode},否则从客户仓库接口取第一家。 |
||||||
|
* |
||||||
|
* @return 没有可用仓时返回 null,调用方打印跳过 |
||||||
|
*/ |
||||||
|
static String warehouseCode(XincangAdapter adapter) { |
||||||
|
if (!WAREHOUSE_CODE.isEmpty()) { |
||||||
|
return WAREHOUSE_CODE; |
||||||
|
} |
||||||
|
if (warehouseDiscoveryAttempted) { |
||||||
|
return discoveredWarehouseCode; |
||||||
|
} |
||||||
|
warehouseDiscoveryAttempted = true; |
||||||
|
try { |
||||||
|
List<WarehouseFacility> facilities = adapter.warehouses(ctx()); |
||||||
|
if (!facilities.isEmpty()) { |
||||||
|
discoveredWarehouseCode = facilities.get(0).warehouseCode(); |
||||||
|
System.out.println(" [discovery] 自动使用仓 " + discoveredWarehouseCode); |
||||||
|
} |
||||||
|
} catch (RuntimeException e) { |
||||||
|
printError(e); |
||||||
|
} |
||||||
|
return discoveredWarehouseCode; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 承运商 / 物流方式:优先 {@code -Dxincang.probe.carrier},否则从客户承运商接口取第一个。 |
||||||
|
*/ |
||||||
|
static String carrier(XincangAdapter adapter) { |
||||||
|
String configured = System.getProperty("xincang.probe.carrier", "").trim(); |
||||||
|
if (!configured.isEmpty()) { |
||||||
|
return configured; |
||||||
|
} |
||||||
|
if (carrierDiscoveryAttempted) { |
||||||
|
return discoveredCarrier; |
||||||
|
} |
||||||
|
carrierDiscoveryAttempted = true; |
||||||
|
try { |
||||||
|
List<String> carriers = adapter.carriers(ctx()); |
||||||
|
if (!carriers.isEmpty()) { |
||||||
|
discoveredCarrier = carriers.get(0); |
||||||
|
System.out.println(" [discovery] 自动使用承运商 " + discoveredCarrier); |
||||||
|
} |
||||||
|
} catch (RuntimeException e) { |
||||||
|
printError(e); |
||||||
|
} |
||||||
|
return discoveredCarrier; |
||||||
|
} |
||||||
|
|
||||||
|
/** 业务单号后缀:保证重跑不会撞「参考号已存在」这类唯一约束。 */ |
||||||
|
static String uniqueSuffix() { |
||||||
|
return new java.text.SimpleDateFormat("yyyyMMdd-HHmmss") |
||||||
|
.format(new java.util.Date()); |
||||||
|
} |
||||||
|
|
||||||
|
static int qty() { |
||||||
|
String raw = System.getProperty("xincang.probe.qty", "1").trim(); |
||||||
|
try { |
||||||
|
int v = Integer.parseInt(raw); |
||||||
|
return v > 0 ? v : 1; |
||||||
|
} catch (NumberFormatException e) { |
||||||
|
return 1; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static String opt(String name, String fallback) { |
||||||
|
String value = System.getProperty(name, ""); |
||||||
|
if (value == null) { |
||||||
|
return fallback; |
||||||
|
} |
||||||
|
String trimmed = value.trim(); |
||||||
|
return trimmed.isEmpty() ? fallback : trimmed; |
||||||
|
} |
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 报文打印
|
||||||
|
|
||||||
|
/** |
||||||
|
* 请求 / 响应打印。 |
||||||
|
* |
||||||
|
* <p>脱敏规则:鉴权头与 URL 里的 token / secret 一律替换成 {@code ***}; |
||||||
|
* 打印体截断到 2000 字符,避免大段 base64 或明细刷屏。</p> |
||||||
|
*/ |
||||||
|
static final class LoggingTransport implements HttpTransport { |
||||||
|
|
||||||
|
private static final int MAX_BODY = 2000; |
||||||
|
|
||||||
|
private final HttpTransport delegate; |
||||||
|
|
||||||
|
LoggingTransport(HttpTransport delegate) { |
||||||
|
this.delegate = delegate; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public HttpResponse execute(HttpRequest request) { |
||||||
|
System.out.println(" --> " + request.method() + " " + maskUrl(request.url())); |
||||||
|
System.out.println(" body " + truncate(request.body())); |
||||||
|
long start = System.nanoTime(); |
||||||
|
HttpResponse response = delegate.execute(request); |
||||||
|
long millis = (System.nanoTime() - start) / 1_000_000L; |
||||||
|
System.out.println(" <-- " + response.statusCode() + " (" + millis + "ms) " |
||||||
|
+ truncate(response.body())); |
||||||
|
return response; |
||||||
|
} |
||||||
|
|
||||||
|
/** 去掉 scheme+host,并把 query 里的敏感参数打码。 */ |
||||||
|
private static String maskUrl(String url) { |
||||||
|
if (url == null) { |
||||||
|
return "null"; |
||||||
|
} |
||||||
|
int pathStart = url.indexOf('/', url.indexOf("://") + 3); |
||||||
|
String path = pathStart < 0 ? url : url.substring(pathStart); |
||||||
|
return path.replaceAll("(?i)((?:token|secret|appkey)=)[^&]*", "$1***"); |
||||||
|
} |
||||||
|
|
||||||
|
private static String truncate(String body) { |
||||||
|
if (body == null) { |
||||||
|
return "null"; |
||||||
|
} |
||||||
|
return body.length() <= MAX_BODY |
||||||
|
? body |
||||||
|
: body.substring(0, MAX_BODY) + "...(" + body.length() + " chars)"; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,307 @@ |
|||||||
|
package common.ecommerce.xincang.probe; |
||||||
|
|
||||||
|
import common.ecommerce.warehouse.model.ChannelRecommendQuery; |
||||||
|
import common.ecommerce.warehouse.model.ChannelRecommendResult; |
||||||
|
import common.ecommerce.warehouse.model.InventoryAgeQuery; |
||||||
|
import common.ecommerce.warehouse.model.InventoryAgeRecord; |
||||||
|
import common.ecommerce.warehouse.model.InventoryQuery; |
||||||
|
import common.ecommerce.warehouse.model.InventorySnapshot; |
||||||
|
import common.ecommerce.warehouse.model.OutboundOrder; |
||||||
|
import common.ecommerce.warehouse.model.OutboundRef; |
||||||
|
import common.ecommerce.warehouse.model.TransferOrder; |
||||||
|
import common.ecommerce.warehouse.model.WarehouseFacility; |
||||||
|
import common.ecommerce.shared.support.Page; |
||||||
|
import common.ecommerce.xincang.XincangConstants; |
||||||
|
import common.ecommerce.xincang.adapter.XincangAdapter; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.junit.jupiter.api.condition.EnabledIfSystemProperty; |
||||||
|
|
||||||
|
import java.time.LocalDate; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 信仓只读接口的联网探针:核对真实出入参。 |
||||||
|
* |
||||||
|
* <p><b>默认跳过</b>,用 {@code -Dxincang.probe=true} 开启。凭据与业务数据走系统属性, |
||||||
|
* 真实值不入库;缺某个业务输入时只跳过依赖它的用例,不影响其他用例。</p> |
||||||
|
* |
||||||
|
* <pre> |
||||||
|
* mvn -pl warehouse-sdk-xincang -am -DfailIfNoTests=false \ |
||||||
|
* -Dxincang.probe=true \ |
||||||
|
* -Dxincang.probe.appKey=... -Dxincang.probe.appSecret=... \ |
||||||
|
* -Dxincang.probe.sku=... -Dxincang.probe.postcode=... \ |
||||||
|
* -Dtest=XincangReadProbeTest test |
||||||
|
* </pre> |
||||||
|
* |
||||||
|
* <p>可选属性:{@code warehouseCode} / {@code sku} / {@code postcode} / {@code orderNo} / |
||||||
|
* {@code transferNo} / {@code forecastNo} / {@code productPageSize}。</p> |
||||||
|
* |
||||||
|
* <p><b>只做查询</b>,不调用任何写接口;异常只打印不抛出,一次能跑完全部段落。</p> |
||||||
|
*/ |
||||||
|
@EnabledIfSystemProperty(named = XincangProbeSupport.PROBE, matches = "true") |
||||||
|
class XincangReadProbeTest { |
||||||
|
|
||||||
|
// ================================================================ 公共资料
|
||||||
|
|
||||||
|
/** 客户所有仓库:拿到仓代码,同时验证目录接口。 */ |
||||||
|
@Test |
||||||
|
void probeCustomerWarehouses() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
System.out.println("\n================ xincang / api.get_customer_warehouses ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
List<WarehouseFacility> warehouses = |
||||||
|
XincangProbeSupport.step("warehouses", () -> adapter.warehouses(XincangProbeSupport.ctx())); |
||||||
|
if (warehouses == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
for (WarehouseFacility w : warehouses) { |
||||||
|
System.out.println(" warehouse_code=" + w.warehouseCode() |
||||||
|
+ " id=" + w.providerWarehouseId() |
||||||
|
+ " " + w.city() + "/" + w.province() + "/" + w.country() |
||||||
|
+ " " + w.postcode()); |
||||||
|
} |
||||||
|
if (warehouses.isEmpty()) { |
||||||
|
System.out.println(" [warn] 该账户下没有任何仓库,后续依赖仓代码的探针会跳过"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** 客户所有承运商:拿到 logistics_type,用于下单与报价。 */ |
||||||
|
@Test |
||||||
|
void probeCustomerLogistics() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
System.out.println("\n================ xincang / api.get_customer_logistics ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
List<String> carriers = |
||||||
|
XincangProbeSupport.step("carriers", () -> adapter.carriers(XincangProbeSupport.ctx())); |
||||||
|
if (carriers != null) { |
||||||
|
System.out.println(" carriers=" + carriers); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// ================================================================ 库存 / 库龄
|
||||||
|
|
||||||
|
/** 实时库存:核对手上数量字段口径。 */ |
||||||
|
@Test |
||||||
|
void probeStockList() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
System.out.println("\n================ xincang / api.stocklist ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
String warehouseCode = XincangProbeSupport.warehouseCode(adapter); |
||||||
|
if (warehouseCode == null) { |
||||||
|
System.out.println(" [skip] 没有可用仓代码,跳过"); |
||||||
|
return; |
||||||
|
} |
||||||
|
InventoryQuery.Builder query = InventoryQuery.builder() |
||||||
|
.warehouseCode(warehouseCode) |
||||||
|
.pageSize(10); |
||||||
|
if (!XincangProbeSupport.SKU.isEmpty()) { |
||||||
|
query.sku(XincangProbeSupport.SKU); |
||||||
|
} |
||||||
|
Page<InventorySnapshot> page = XincangProbeSupport.step( |
||||||
|
"stocklist warehouse=" + warehouseCode, |
||||||
|
() -> adapter.query(XincangProbeSupport.ctx(warehouseCode), query.build())); |
||||||
|
if (page == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
System.out.println(" items=" + page.size() + " nextCursor=" + page.nextCursor()); |
||||||
|
for (InventorySnapshot s : page.items()) { |
||||||
|
System.out.println(" sku=" + s.providerSku() |
||||||
|
+ " onHand=" + s.onHand() |
||||||
|
+ " available=" + s.available() |
||||||
|
+ " reserved=" + s.reserved() |
||||||
|
+ " pending=" + s.pendingOutbound() |
||||||
|
+ " inTransit=" + s.inTransit() |
||||||
|
+ " alert=" + s.alertQuantity() |
||||||
|
+ " name=" + s.productName() |
||||||
|
+ " volumeCm=" + s.volumeCbm()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** 库龄列表:默认查最近 7 天,核对计费字段。 */ |
||||||
|
@Test |
||||||
|
void probeStockAgeList() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
System.out.println("\n================ xincang / api.stockagelist ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
LocalDate end = LocalDate.now(); |
||||||
|
LocalDate start = end.minusDays(7); |
||||||
|
InventoryAgeQuery query = InventoryAgeQuery.builder() |
||||||
|
.dateRange(start, end) |
||||||
|
.pageSize(10) |
||||||
|
.includeFeeRate(true) |
||||||
|
.build(); |
||||||
|
Page<InventoryAgeRecord> page = XincangProbeSupport.step( |
||||||
|
"stockagelist " + start + " ~ " + end, |
||||||
|
() -> adapter.queryAges(XincangProbeSupport.ctx(), query)); |
||||||
|
if (page == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
System.out.println(" items=" + page.size() + " nextCursor=" + page.nextCursor()); |
||||||
|
for (InventoryAgeRecord r : page.items()) { |
||||||
|
System.out.println(" sku=" + r.providerSku() |
||||||
|
+ " warehouse=" + r.warehouseCode() |
||||||
|
+ " billingDate=" + r.billingDate() |
||||||
|
+ " inStockAt=" + r.inStockAt() |
||||||
|
+ " ageDays=" + r.ageDays() |
||||||
|
+ " qty=" + r.quantity() |
||||||
|
+ " billingQty=" + r.billingQuantity() |
||||||
|
+ " feeRate=" + r.feeRate() |
||||||
|
+ " fee=" + r.fee() |
||||||
|
+ " cabinet=" + r.cabinetNo()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// ================================================================ 详情
|
||||||
|
|
||||||
|
/** 订单详情:按 -Dxincang.probe.orderNo 查。 */ |
||||||
|
@Test |
||||||
|
void probeOrderDetail() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.orderNo"); |
||||||
|
System.out.println("\n================ xincang / api.get_order ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
OutboundOrder order = XincangProbeSupport.step( |
||||||
|
"get_order " + XincangProbeSupport.ORDER_NO, |
||||||
|
() -> adapter.get(XincangProbeSupport.ctx(), |
||||||
|
OutboundRef.ofProviderOrderId(XincangProbeSupport.ORDER_NO))); |
||||||
|
if (order == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
System.out.println(" orderNo=" + order.outboundRequestNo() |
||||||
|
+ " providerOrderId=" + order.providerOrderId() |
||||||
|
+ " ref=" + order.orderRef() |
||||||
|
+ " status=" + order.status() + "(raw=" + order.rawStatus() + ")" |
||||||
|
+ " labelMode=" + order.labelMode() |
||||||
|
+ " carrier=" + order.carrierCode() |
||||||
|
+ " tracking=" + order.trackingNumber() |
||||||
|
+ " exception=" + order.exceptionCode() |
||||||
|
+ " requestedAt=" + order.requestedAt() |
||||||
|
+ " shippedAt=" + order.shippedAt() |
||||||
|
+ " fee=" + order.estimatedShippingFee()); |
||||||
|
System.out.println(" shipTo=" + order.shipTo()); |
||||||
|
for (common.ecommerce.warehouse.model.OutboundLine line : order.lines()) { |
||||||
|
System.out.println(" sku=" + line.providerSku() |
||||||
|
+ " qty=" + line.quantity() |
||||||
|
+ " name=" + line.declareName()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** 转运详情:按 -Dxincang.probe.transferNo 查。 */ |
||||||
|
@Test |
||||||
|
void probeTransferDetail() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.transferNo"); |
||||||
|
System.out.println("\n================ xincang / fba.fba_detail ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
TransferOrder order = XincangProbeSupport.step( |
||||||
|
"fba_detail " + XincangProbeSupport.TRANSFER_NO, |
||||||
|
() -> adapter.getTransfer(XincangProbeSupport.ctx(), XincangProbeSupport.TRANSFER_NO)); |
||||||
|
if (order == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
System.out.println(" transferRequestNo=" + order.transferRequestNo() |
||||||
|
+ " providerTransferNo=" + order.providerTransferNo() |
||||||
|
+ " from=" + order.fromWarehouseCode() |
||||||
|
+ " to=" + order.toWarehouseCode() |
||||||
|
+ " type=" + order.type() |
||||||
|
+ " status=" + order.status() + "(raw=" + order.rawStatus() + ")" |
||||||
|
+ " totalQty=" + order.totalQuantity() |
||||||
|
+ " estimatedOutboundAt=" + order.estimatedOutboundAt() |
||||||
|
+ " remark=" + order.remark()); |
||||||
|
} |
||||||
|
|
||||||
|
/** 预报详情:按 -Dxincang.probe.forecastNo 查。 */ |
||||||
|
@Test |
||||||
|
void probeForecastDetail() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.forecastNo"); |
||||||
|
System.out.println("\n================ xincang / forecast.forecast_detail ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
common.ecommerce.warehouse.model.InboundOrder order = XincangProbeSupport.step( |
||||||
|
"forecast_detail " + XincangProbeSupport.FORECAST_NO, |
||||||
|
() -> adapter.get(XincangProbeSupport.ctx(), XincangProbeSupport.FORECAST_NO)); |
||||||
|
if (order == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
System.out.println(" inboundRequestNo=" + order.inboundRequestNo() |
||||||
|
+ " providerInboundId=" + order.providerInboundId() |
||||||
|
+ " warehouse=" + order.warehouseCode() |
||||||
|
+ " status=" + order.status() + "(raw=" + order.rawStatus() + ")" |
||||||
|
+ " boxCount=" + order.boxCount() |
||||||
|
+ " createdAt=" + order.createdAt() |
||||||
|
+ " receivedAt=" + order.receivedAt() |
||||||
|
+ " estimatedArrivalAt=" + order.estimatedArrivalAt() |
||||||
|
+ " actualArrivalAt=" + order.actualArrivalAt() |
||||||
|
+ " remark=" + order.remark()); |
||||||
|
for (common.ecommerce.warehouse.model.InboundOrderLine line : order.lines()) { |
||||||
|
System.out.println(" sku=" + line.providerSku() |
||||||
|
+ " planned=" + line.plannedQuantity() |
||||||
|
+ " packed=" + line.packedQuantity() |
||||||
|
+ " received=" + line.receivedQuantity()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// ================================================================ 报价
|
||||||
|
|
||||||
|
/** |
||||||
|
* 最优渠道:需要 SKU 与邮编。 |
||||||
|
* |
||||||
|
* <p>协议待核对:文档写 GET + JSON body,OkHttp 不支持 GET 带 body, |
||||||
|
* 适配器按 POST + JSON body 下发。这里重点看仓方是否接受。</p> |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
void probeChannelRecommend() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.sku"); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.postcode"); |
||||||
|
System.out.println("\n================ xincang / api.calculate_order_v3 ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
ChannelRecommendQuery query = ChannelRecommendQuery.builder() |
||||||
|
.product(XincangProbeSupport.SKU, XincangProbeSupport.qty()) |
||||||
|
.postalCode(XincangProbeSupport.POSTCODE) |
||||||
|
.signatureRequired(false) |
||||||
|
.build(); |
||||||
|
ChannelRecommendResult result = XincangProbeSupport.step( |
||||||
|
"calculate_order_v3 sku=" + XincangProbeSupport.SKU |
||||||
|
+ " postcode=" + XincangProbeSupport.POSTCODE, |
||||||
|
() -> adapter.recommend(XincangProbeSupport.ctx(), query)); |
||||||
|
if (result == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
if (result.optimalPlan() == null) { |
||||||
|
System.out.println(" optimalPlan=null(该城无可用渠道,属合法结果)"); |
||||||
|
} else { |
||||||
|
System.out.println(" optimalPlan: warehouse=" + result.optimalPlan().warehouseCode() |
||||||
|
+ " service=" + result.optimalPlan().serviceCode() |
||||||
|
+ " total=" + result.optimalPlan().total()); |
||||||
|
} |
||||||
|
System.out.println(" warehouseQuotes=" + result.warehouseQuotes().size()); |
||||||
|
for (ChannelRecommendResult.WarehouseQuote q : result.warehouseQuotes()) { |
||||||
|
System.out.println(" warehouse=" + q.warehouseCode() |
||||||
|
+ " inventoryEnough=" + q.inventoryEnough() |
||||||
|
+ " insufficient=" + q.insufficientStockError()); |
||||||
|
for (ChannelRecommendResult.ServiceQuote s : q.services()) { |
||||||
|
System.out.println(" service=" + s.serviceCode() + " total=" + s.total()); |
||||||
|
for (ChannelRecommendResult.FeeItem f : s.fees()) { |
||||||
|
System.out.println(" " + f.bigFeeType() + "/" + f.feeType() |
||||||
|
+ " = " + f.fee()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// ================================================================ 商品列表
|
||||||
|
|
||||||
|
/** 产品列表:通过 createOrUpdate 的查重路径顺带验证(只读部分)。 */ |
||||||
|
@Test |
||||||
|
void probeProductLookup() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.sku"); |
||||||
|
System.out.println("\n================ xincang / api.productlist ================"); |
||||||
|
System.out.println(" [说明] 产品列表接口只在建档查重时调用,这里直接查一次核对字段:"); |
||||||
|
System.out.println(" sku=" + XincangProbeSupport.SKU |
||||||
|
+ ",请对照下方接口返回的 rst.data[].state(0 临时 / 1 正式)"); |
||||||
|
System.out.println(" [提示] 走 api.add_product 会真实建档,请用 XincangWriteProbeTest。"); |
||||||
|
System.out.println(" endpoint=" + XincangConstants.PATH_PRODUCT_LIST); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,338 @@ |
|||||||
|
package common.ecommerce.xincang.probe; |
||||||
|
|
||||||
|
import common.ecommerce.shared.model.Platform; |
||||||
|
import common.ecommerce.shared.support.Money; |
||||||
|
import common.ecommerce.warehouse.capability.WarehouseProduct; |
||||||
|
import common.ecommerce.warehouse.capability.WarehouseProductCapable; |
||||||
|
import common.ecommerce.warehouse.enums.LabelMode; |
||||||
|
import common.ecommerce.warehouse.model.InboundCommand; |
||||||
|
import common.ecommerce.warehouse.model.InboundLine; |
||||||
|
import common.ecommerce.warehouse.model.InboundOrder; |
||||||
|
import common.ecommerce.warehouse.model.InboundReceipt; |
||||||
|
import common.ecommerce.warehouse.model.OutboundCommand; |
||||||
|
import common.ecommerce.warehouse.model.OutboundLine; |
||||||
|
import common.ecommerce.warehouse.model.OutboundOrder; |
||||||
|
import common.ecommerce.warehouse.model.OutboundReceipt; |
||||||
|
import common.ecommerce.warehouse.model.OutboundRef; |
||||||
|
import common.ecommerce.warehouse.model.ShipTo; |
||||||
|
import common.ecommerce.warehouse.model.TransferCommand; |
||||||
|
import common.ecommerce.warehouse.model.TransferOrder; |
||||||
|
import common.ecommerce.warehouse.enums.TransferType; |
||||||
|
import common.ecommerce.xincang.adapter.XincangAdapter; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.junit.jupiter.api.condition.EnabledIfSystemProperty; |
||||||
|
|
||||||
|
import java.time.LocalDate; |
||||||
|
|
||||||
|
/** |
||||||
|
* 信仓写接口的联网探针:真实下单 / 建转运 / 建预报,用于核对报文。 |
||||||
|
* |
||||||
|
* <p><b>默认整类跳过</b>,需要两个开关同时打开:</p> |
||||||
|
* <pre> |
||||||
|
* -Dxincang.probe=true -Dxincang.probe.write=true |
||||||
|
* </pre> |
||||||
|
* |
||||||
|
* <p>运行示例:</p> |
||||||
|
* <pre> |
||||||
|
* mvn -pl warehouse-sdk-xincang -am -DfailIfNoTests=false \ |
||||||
|
* -Dxincang.probe=true -Dxincang.probe.write=true \ |
||||||
|
* -Dxincang.probe.appKey=... -Dxincang.probe.appSecret=... \ |
||||||
|
* -Dxincang.probe.sku=... -Dxincang.probe.postcode=... \ |
||||||
|
* -Dtest=XincangWriteProbeTest test |
||||||
|
* </pre> |
||||||
|
* |
||||||
|
* <p><b>注意:会在仓方测试环境留下真实数据。</b>能自清理的链路(订单、转运)会尽量删掉; |
||||||
|
* 商品建档与预报没有删除接口,跑完需要人工清理。所有单号都带时间戳后缀, |
||||||
|
* 重跑不会撞唯一约束。</p> |
||||||
|
*/ |
||||||
|
@EnabledIfSystemProperty(named = XincangProbeSupport.PROBE_WRITE, matches = "true") |
||||||
|
class XincangWriteProbeTest { |
||||||
|
|
||||||
|
// ================================================================ 商品
|
||||||
|
|
||||||
|
/** |
||||||
|
* 商品建档 / 更新:走 add_product 或 update_product(先查临时产品决定)。 |
||||||
|
* |
||||||
|
* <p>需要 {@code -Dxincang.probe.sku};金额按 1.00 USD 下发, |
||||||
|
* 因为信仓把 amount 列为必填且我们不再兜底 0。</p> |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
void probeProductUpsert() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.sku"); |
||||||
|
System.out.println("\n================ xincang / api.add_product | api.update_product ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
|
||||||
|
WarehouseProduct product = WarehouseProduct.builder() |
||||||
|
.omsSku(XincangProbeSupport.SKU) |
||||||
|
.name("探针商品") |
||||||
|
.nameEn("Probe Product") |
||||||
|
.barcode("PROBE-" + XincangProbeSupport.uniqueSuffix()) |
||||||
|
.packingType(0) |
||||||
|
.lengthCm(30) |
||||||
|
.widthCm(20) |
||||||
|
.heightCm(10) |
||||||
|
.weightGrams(500) |
||||||
|
.declaredValue(Money.of("1.00", "USD")) |
||||||
|
.hsCode("9403600000") |
||||||
|
.countryOfOrigin("US") |
||||||
|
.build(); |
||||||
|
|
||||||
|
WarehouseProductCapable.ProductResult result = XincangProbeSupport.step( |
||||||
|
"createOrUpdate sku=" + XincangProbeSupport.SKU, |
||||||
|
() -> adapter.createOrUpdate(XincangProbeSupport.ctx(), product)); |
||||||
|
if (result != null) { |
||||||
|
System.out.println(" providerSku=" + result.providerSku() |
||||||
|
+ " status=" + result.status() |
||||||
|
+ " rawStatus=" + result.rawStatus()); |
||||||
|
System.out.println(" [注意] 没有删除产品接口,跑完需人工清理或复用该 SKU。"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// ================================================================ 出库
|
||||||
|
|
||||||
|
/** |
||||||
|
* 出库闭环:下单 → 详情回读 → 删除。 |
||||||
|
* |
||||||
|
* <p>需要 sku + postcode;承运商从目录接口自动取(或 {@code -Dxincang.probe.carrier})。</p> |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
void probeOutboundRoundTrip() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.sku"); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.postcode"); |
||||||
|
System.out.println("\n================ xincang / api.add_order_multiple → get_order → delete_order ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
String warehouseCode = XincangProbeSupport.warehouseCode(adapter); |
||||||
|
String carrier = XincangProbeSupport.carrier(adapter); |
||||||
|
if (warehouseCode == null || carrier == null) { |
||||||
|
System.out.println(" [skip] 缺少仓代码或承运商,跳过"); |
||||||
|
return; |
||||||
|
} |
||||||
|
String requestNo = "PROBE-" + XincangProbeSupport.uniqueSuffix(); |
||||||
|
|
||||||
|
OutboundCommand command = OutboundCommand.builder() |
||||||
|
.outboundRequestNo(requestNo) |
||||||
|
.orderRef(requestNo) |
||||||
|
.labelMode(LabelMode.WAREHOUSE_LABEL) |
||||||
|
.salesPlatform(Platform.CUSTOM) |
||||||
|
.carrierCode(carrier) |
||||||
|
.warehouseId(warehouseCode) |
||||||
|
.splitOrder(true) |
||||||
|
.shipTo(ShipTo.builder() |
||||||
|
.name("Probe Receiver") |
||||||
|
.phone("5550000000") |
||||||
|
.countryCode("US") |
||||||
|
.stateOrProvince("CA") |
||||||
|
.city("Fontana") |
||||||
|
.addressLine1("1 Probe Street") |
||||||
|
.postalCode(XincangProbeSupport.POSTCODE) |
||||||
|
.build()) |
||||||
|
.line(OutboundLine.builder() |
||||||
|
.lineNo("1") |
||||||
|
.omsSku(XincangProbeSupport.SKU) |
||||||
|
.quantity(XincangProbeSupport.qty()) |
||||||
|
.declareName("Probe Item") |
||||||
|
.build()) |
||||||
|
.build(); |
||||||
|
|
||||||
|
OutboundReceipt receipt = XincangProbeSupport.step("add_order_multiple ckh=" + requestNo, |
||||||
|
() -> adapter.create(XincangProbeSupport.ctx(warehouseCode), command)); |
||||||
|
if (receipt == null || receipt.providerOrderId() == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
System.out.println(" providerOrderId=" + receipt.providerOrderId()); |
||||||
|
|
||||||
|
OutboundOrder order = XincangProbeSupport.step("get_order 回读", |
||||||
|
() -> adapter.get(XincangProbeSupport.ctx(warehouseCode), |
||||||
|
OutboundRef.ofProviderOrderId(receipt.providerOrderId()))); |
||||||
|
if (order != null) { |
||||||
|
System.out.println(" status=" + order.status() + "(raw=" + order.rawStatus() + ")" |
||||||
|
+ " ref=" + order.orderRef() |
||||||
|
+ " lines=" + order.lines().size()); |
||||||
|
System.out.println(" checkCancel=" + XincangProbeSupport.step("checkCancel", |
||||||
|
() -> adapter.checkCancel(XincangProbeSupport.ctx(warehouseCode), |
||||||
|
OutboundRef.ofProviderOrderId(receipt.providerOrderId())))); |
||||||
|
} |
||||||
|
|
||||||
|
XincangProbeSupport.step("delete_order 自清理", |
||||||
|
() -> adapter.cancel(XincangProbeSupport.ctx(warehouseCode), |
||||||
|
common.ecommerce.warehouse.model.CancelCommand.builder() |
||||||
|
.providerOrderId(receipt.providerOrderId()) |
||||||
|
.build())); |
||||||
|
} |
||||||
|
|
||||||
|
// ================================================================ 转运
|
||||||
|
|
||||||
|
/** |
||||||
|
* 转运闭环:建转运 → 详情回读 → 删除(仅待审核可删)。 |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
void probeTransferRoundTrip() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.sku"); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.destWarehouse"); |
||||||
|
System.out.println("\n================ xincang / fba.do_fba → fba_detail → fba.delete_fba ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
String warehouseCode = XincangProbeSupport.warehouseCode(adapter); |
||||||
|
if (warehouseCode == null) { |
||||||
|
System.out.println(" [skip] 缺少仓代码,跳过"); |
||||||
|
return; |
||||||
|
} |
||||||
|
String transferNo = "PROBE-" + XincangProbeSupport.uniqueSuffix(); |
||||||
|
String destWarehouse = XincangProbeSupport.opt("xincang.probe.destWarehouse", ""); |
||||||
|
|
||||||
|
TransferCommand command = TransferCommand.builder() |
||||||
|
.transferRequestNo(transferNo) |
||||||
|
.type(TransferType.OUTBOUND) |
||||||
|
.fromWarehouseCode(warehouseCode) |
||||||
|
.toWarehouseCode(destWarehouse) |
||||||
|
.po(transferNo) |
||||||
|
// 信仓只用 pre_send_time;到仓日期与收件地址它都不收,
|
||||||
|
// 这里不传,顺便验证模型已不再强制这两个字段
|
||||||
|
.estimateOutboundDate(LocalDate.now().plusDays(1)) |
||||||
|
.deliveryMode(XincangProbeSupport.opt("xincang.probe.deliveryMode", "")) |
||||||
|
.deliveryWay(XincangProbeSupport.opt("xincang.probe.deliveryWay", "")) |
||||||
|
.orderType(XincangProbeSupport.opt("xincang.probe.orderType", "")) |
||||||
|
.palletRequired(Boolean.FALSE) |
||||||
|
.line(XincangProbeSupport.SKU, XincangProbeSupport.qty()) |
||||||
|
.build(); |
||||||
|
|
||||||
|
TransferOrder created = XincangProbeSupport.step("do_fba fba_no=" + transferNo, |
||||||
|
() -> adapter.create(XincangProbeSupport.ctx(warehouseCode), command)); |
||||||
|
if (created == null || created.providerTransferNo() == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
String providerNo = created.providerTransferNo(); |
||||||
|
System.out.println(" providerTransferNo=" + providerNo + " status=" + created.status()); |
||||||
|
|
||||||
|
XincangProbeSupport.step("fba_detail 回读", |
||||||
|
() -> adapter.getTransfer(XincangProbeSupport.ctx(warehouseCode), providerNo)); |
||||||
|
|
||||||
|
XincangProbeSupport.step("fba.delete_fba 自清理", |
||||||
|
() -> adapter.deleteTransfer(XincangProbeSupport.ctx(warehouseCode), providerNo)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 转运审核:建转运 → 审核。 |
||||||
|
* |
||||||
|
* <p><b>审核之后不能删除</b>,会在测试环境留下数据,默认不跑; |
||||||
|
* 需要显式加 {@code -Dxincang.probe.transferApprove=true}。</p> |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
void probeTransferApprove() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.transferApprove"); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.sku"); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.destWarehouse"); |
||||||
|
System.out.println("\n================ xincang / fba.do_approve ================"); |
||||||
|
System.out.println(" [注意] 审核后的转运单无法删除,会留下数据。"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
String warehouseCode = XincangProbeSupport.warehouseCode(adapter); |
||||||
|
if (warehouseCode == null) { |
||||||
|
System.out.println(" [skip] 缺少仓代码,跳过"); |
||||||
|
return; |
||||||
|
} |
||||||
|
String transferNo = "PROBE-APPROVE-" + XincangProbeSupport.uniqueSuffix(); |
||||||
|
TransferCommand command = TransferCommand.builder() |
||||||
|
.transferRequestNo(transferNo) |
||||||
|
.type(TransferType.OUTBOUND) |
||||||
|
.fromWarehouseCode(warehouseCode) |
||||||
|
.toWarehouseCode(XincangProbeSupport.opt("xincang.probe.destWarehouse", "")) |
||||||
|
.po(transferNo) |
||||||
|
.estimateOutboundDate(LocalDate.now().plusDays(1)) |
||||||
|
.deliveryMode(XincangProbeSupport.opt("xincang.probe.deliveryMode", "")) |
||||||
|
.deliveryWay(XincangProbeSupport.opt("xincang.probe.deliveryWay", "")) |
||||||
|
.orderType(XincangProbeSupport.opt("xincang.probe.orderType", "")) |
||||||
|
.palletRequired(Boolean.FALSE) |
||||||
|
.line(XincangProbeSupport.SKU, XincangProbeSupport.qty()) |
||||||
|
.build(); |
||||||
|
|
||||||
|
TransferOrder created = XincangProbeSupport.step("do_fba", |
||||||
|
() -> adapter.create(XincangProbeSupport.ctx(warehouseCode), command)); |
||||||
|
if (created == null || created.providerTransferNo() == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
XincangProbeSupport.step("do_approve " + created.providerTransferNo(), |
||||||
|
() -> adapter.approve(XincangProbeSupport.ctx(warehouseCode), |
||||||
|
created.providerTransferNo())); |
||||||
|
} |
||||||
|
|
||||||
|
// ================================================================ 预报
|
||||||
|
|
||||||
|
/** |
||||||
|
* 预报闭环:新增 → 完善资料 → 提交 → 详情回读。 |
||||||
|
* |
||||||
|
* <p><b>没有删除接口</b>,跑完会在测试环境留下预报单。</p> |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
void probeForecastRoundTrip() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.sku"); |
||||||
|
System.out.println("\n================ xincang / forecast.do_forecast → improve → done → detail ================"); |
||||||
|
System.out.println(" [注意] 预报没有删除接口,会留下数据。"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
String warehouseCode = XincangProbeSupport.warehouseCode(adapter); |
||||||
|
if (warehouseCode == null) { |
||||||
|
System.out.println(" [skip] 缺少仓代码,跳过"); |
||||||
|
return; |
||||||
|
} |
||||||
|
String suffix = XincangProbeSupport.uniqueSuffix(); |
||||||
|
String requestNo = "PROBE-FC-" + suffix; |
||||||
|
|
||||||
|
InboundCommand head = InboundCommand.builder() |
||||||
|
.inboundRequestNo(requestNo) |
||||||
|
.warehouseId(warehouseCode) |
||||||
|
.shipmentType(XincangProbeSupport.opt("xincang.probe.shipmentType", "2")) |
||||||
|
.cabinetType(XincangProbeSupport.opt("xincang.probe.cabinetType", "1")) |
||||||
|
.containerNo("PROBE-CAB-" + suffix) |
||||||
|
.predictionShipDate(LocalDate.now().plusDays(1)) |
||||||
|
.estimateArriveDate(LocalDate.now().plusDays(30)) |
||||||
|
.deliveryRequirements(XincangProbeSupport.opt("xincang.probe.deliveryRequirements", "1")) |
||||||
|
.line(InboundLine.builder() |
||||||
|
.omsSku(XincangProbeSupport.SKU) |
||||||
|
.providerSku(XincangProbeSupport.SKU) |
||||||
|
.quantity(XincangProbeSupport.qty()) |
||||||
|
.build()) |
||||||
|
.build(); |
||||||
|
|
||||||
|
InboundReceipt receipt = XincangProbeSupport.step("do_forecast fba_no=" + requestNo, |
||||||
|
() -> adapter.create(XincangProbeSupport.ctx(warehouseCode), head)); |
||||||
|
if (receipt == null || receipt.providerInboundId() == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
String forecastNo = receipt.providerInboundId(); |
||||||
|
System.out.println(" forecast_no=" + forecastNo); |
||||||
|
|
||||||
|
InboundCommand improve = InboundCommand.builder() |
||||||
|
.inboundRequestNo(requestNo) |
||||||
|
.warehouseId(warehouseCode) |
||||||
|
.shipmentType(XincangProbeSupport.opt("xincang.probe.shipmentType", "2")) |
||||||
|
.cabinetType(XincangProbeSupport.opt("xincang.probe.cabinetType", "1")) |
||||||
|
.containerNo("PROBE-CAB-" + suffix) |
||||||
|
.predictionShipDate(LocalDate.now().plusDays(1)) |
||||||
|
.estimateArriveDate(LocalDate.now().plusDays(30)) |
||||||
|
.deliveryRequirements(XincangProbeSupport.opt("xincang.probe.deliveryRequirements", "1")) |
||||||
|
.referenceNo("REF-" + suffix) |
||||||
|
.otherNeed(XincangProbeSupport.opt("xincang.probe.otherNeed", "")) |
||||||
|
.line(InboundLine.builder() |
||||||
|
.omsSku(XincangProbeSupport.SKU) |
||||||
|
.providerSku(XincangProbeSupport.SKU) |
||||||
|
.quantity(XincangProbeSupport.qty()) |
||||||
|
.build()) |
||||||
|
.build(); |
||||||
|
|
||||||
|
XincangProbeSupport.step("do_improve_forecast", |
||||||
|
() -> adapter.improve(XincangProbeSupport.ctx(warehouseCode), forecastNo, improve)); |
||||||
|
XincangProbeSupport.step("done_forecast", |
||||||
|
() -> adapter.submit(XincangProbeSupport.ctx(warehouseCode), forecastNo)); |
||||||
|
|
||||||
|
InboundOrder detail = XincangProbeSupport.step("forecast_detail 回读", |
||||||
|
() -> adapter.get(XincangProbeSupport.ctx(warehouseCode), forecastNo)); |
||||||
|
if (detail != null) { |
||||||
|
System.out.println(" status=" + detail.status() + "(raw=" + detail.rawStatus() + ")" |
||||||
|
+ " boxCount=" + detail.boxCount() |
||||||
|
+ " lines=" + detail.lines().size()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue