From b675dd67e0f2bda11a8562881bd3285085592857 Mon Sep 17 00:00:00 2001 From: chenchuchuan <13554600537@163.com> Date: Mon, 16 Nov 2026 17:25:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor(edayun):=20=E4=BF=AE=E6=AD=A3=20printB?= =?UTF-8?q?arcode=20/=20newPrintCaseMark=20=E7=9A=84=E8=AF=AD=E4=B9=89?= =?UTF-8?q?=E5=BD=92=E5=B1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 仓方确认两个端点名与实际打印的东西是反的: - /webApi/skuInfo/v2/printBarcode → 实际是箱唛(外箱标) - /webApi/entryInfo/v1/newPrintCaseMark* → 实际是 SKU 标 代码按实际语义命名(端点不变): - printCaseMarks(...) + CaseMarkPrintCommand / CaseMarkPaperSize / CASE_MARK_PRINT - printSkuLabel(...) + EdayunSkuLabelDtos / EdayunSkuLabelMapper / EdayunSkuLabelPaper 纸张尺寸真机实测(MediaBox)发现文档标称有错: pageSize=2 文档说 6×4cm,实测 100×150mm pageSize=3 文档说 A4, 实测 60×40mm 枚举按实测尺寸命名,码值原样保留。 其余三个尺寸与文档一致:0→70×30、1→100×60。 Co-Authored-By: Claude --- docs-warehouse/edayun/README.md | 137 ++++--------- docs-warehouse/edayun/TODO.md | 4 +- ...PrintCapable.java => CaseMarkPrintCapable.java} | 8 +- .../warehouse/enums/BarcodePaperSize.java | 37 ---- .../warehouse/enums/CaseMarkPaperSize.java | 47 +++++ .../warehouse/enums/WarehouseCapability.java | 4 +- ...PrintCommand.java => CaseMarkPrintCommand.java} | 34 ++-- .../warehouse/sdk/WarehouseOperations.java | 18 +- .../common/ecommerce/edayun/EdayunConstants.java | 17 +- .../ecommerce/edayun/adapter/EdayunAdapter.java | 91 +++++---- .../edayun/adapter/EdayunBarcodeMapper.java | 70 ------- .../edayun/adapter/EdayunCaseMarkMapper.java | 134 ++++--------- .../edayun/adapter/EdayunSkuLabelMapper.java | 127 ++++++++++++ .../ecommerce/edayun/dto/EdayunBarcodeDtos.java | 52 ----- .../ecommerce/edayun/dto/EdayunCaseMarkDtos.java | 56 +++--- .../ecommerce/edayun/dto/EdayunSkuLabelDtos.java | 69 +++++++ ...CaseMarkPaper.java => EdayunSkuLabelPaper.java} | 10 +- .../edayun/adapter/EdayunBarcodeTest.java | 166 ---------------- .../edayun/adapter/EdayunCaseMarkTest.java | 218 +++++++++++---------- .../edayun/adapter/EdayunSkuLabelTest.java | 158 +++++++++++++++ ...ProbeTest.java => EdayunCaseMarkProbeTest.java} | 22 +-- 21 files changed, 730 insertions(+), 749 deletions(-) rename warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/capability/{BarcodePrintCapable.java => CaseMarkPrintCapable.java} (76%) delete mode 100644 warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/enums/BarcodePaperSize.java create mode 100644 warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/enums/CaseMarkPaperSize.java rename warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/{BarcodePrintCommand.java => CaseMarkPrintCommand.java} (77%) delete mode 100644 warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunBarcodeMapper.java create mode 100644 warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunSkuLabelMapper.java delete mode 100644 warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunBarcodeDtos.java create mode 100644 warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunSkuLabelDtos.java rename warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/enums/{EdayunCaseMarkPaper.java => EdayunSkuLabelPaper.java} (84%) delete mode 100644 warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunBarcodeTest.java create mode 100644 warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunSkuLabelTest.java rename warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/probe/{EdayunBarcodeProbeTest.java => EdayunCaseMarkProbeTest.java} (86%) diff --git a/docs-warehouse/edayun/README.md b/docs-warehouse/edayun/README.md index 18961ae..e88b358 100644 --- a/docs-warehouse/edayun/README.md +++ b/docs-warehouse/edayun/README.md @@ -27,8 +27,8 @@ | BOL 查询(平台仓订单) | ✅ 已对接(`POST /webApi/fbaOrder/v1/getOrderBolList`) | | 物流产品清单 | ✅ 已对接(`POST /webApi/order/listByLogisticProductHasPerm`) | | 物流轨迹 | ✅ 已对接(`POST /webApi/track/getTrackInfoList`) | -| 打印条码 | ✅ 已对接(`POST /webApi/skuInfo/v2/printBarcode`) | -| 打印箱唛 | ⚠️ 已实现(`POST /webApi/entryInfo/v1/newPrintCaseMarkContentType`),**真机未启用** | +| 打印箱唛 | ✅ 已对接(`POST /webApi/skuInfo/v2/printBarcode`) | +| 打印 SKU 标 | ⚠️ 已实现(`POST /webApi/entryInfo/v1/newPrintCaseMarkContentType`),**真机未启用** | | 其它业务接口 | ⬜ 等文档 | | 回调 | ⬜ 等文档 | | 真机验证 | ⬜ 等测试环境 | @@ -1143,123 +1143,72 @@ POST /webApi/track/getTrackInfoList → List / TrackingInfo **PR 环境没有任何可查到的轨迹**,映射只被单测覆盖。 -## 打印条码 +## 打印箱唛 / SKU 标 -``` -POST /webApi/skuInfo/v2/printBarcode → WarehouseLabel -``` +### 两个端点名与实际语义是反的 -### 与入库 SKU 贴标不是一回事 +已与仓方确认: -| | `inbound().printSkuLabel()` | `printBarcodes()` | -|---|---|---| -| 对象 | 入库计划单 | **任意 SKU** | -| 绑定 | 必填入库单号 | 不绑单据 | -| 纸张 | 14 种小尺寸 | **4 档** | -| 返回 | 异步任务号 | **同步 PDF 地址** | +| 端点 | 实际打印 | 我们的方法 | 能力位 | +|---|---|---|---| +| `/webApi/skuInfo/v2/printBarcode` | **箱唛**(外箱标) | `printCaseMarks(...)` | `CASE_MARK_PRINT` | +| `/webApi/entryInfo/v1/newPrintCaseMarkContentType` | **SKU 标** | `printSkuLabel(...)` | 走入库 `SKU_LABEL` 语义 | -因为纸张集合完全不同,新增了独立枚举 `BarcodePaperSize`(7×3cm / 10×6cm / 6×4cm / A4), -没有复用 `SkuLabelSizeType`——那可是 14 个取值,混用会误导调用方。 +**不要被路径名误导**。代码里两个方法的 javadoc 都写了这条提醒。 -### 响应 `data` 是文件地址字符串 +### 箱唛(printBarcode) -```json -{"code":200,"msg":"操作成功","data":"https://.../barcode123.pdf","traceId":null} +``` +POST /webApi/skuInfo/v2/printBarcode → WarehouseLabel ``` -不是对象、也不是任务号——仓方同步生成 PDF。映射到 `WarehouseLabel.url()`。 +请求体按 SKU 列表打,服务端把每个 SKU 的条码排版成箱唛 PDF。 -### 本地提前挡住的两条 +**四种纸张尺寸实测(MediaBox,单位 pt):** -| 约束 | 仓方提示 | 我们 | -|---|---|---| -| SKU 数 > 50 | `最多打印50个SKU` | `BarcodePrintCommand` 构造期就拒 | -| 份数 ≤ 0 | `内部服务器错误` | 同上 | +| `pageSize` | 文档标称 | 实测 MediaBox | 折算 | +|---|---|---|---| +| 0 | 7×3cm | `198 × 85` | 69.9 × 30.0 mm | +| 1 | 10×6cm | `284 × 170` | 100.2 × 60.0 mm | +| 2 | 6×4cm | `283 × 425` | **99.9 × 150.0 mm** | +| 3 | A4 | `170 × 113` | **60.0 × 39.9 mm** | -仓方对非法 `num` 回的是「内部服务器错误」,看不出原因,所以本地先挡。 +**`pageSize=2` 和 `pageSize=3` 的文档标称与实际相反**:文档说 2 是「6×4cm」、 +3 是「A4」,实际 2 打出来是 100×150mm、3 打出来是 60×40mm。 +枚举按**实测尺寸**命名(`SIZE_60_40` / `SIZE_100_150`),码值原样保留。 -### 其它实测校验 +**本地提前挡的两条**(仓方都回「内部服务器错误」,看不出原因): -| 场景 | 仓方返回 | +| 约束 | 本地行为 | |---|---| -| 缺 `productInfos` / 空数组 | `产品信息不能为空` | -| 缺 `pageSize` | `纸张尺寸不能为空` | -| `pageSize=9`(非法) | `内部服务器错误` | -| SKU 不存在 | `sku=NO-SUCH-SKU信息不存在` | - -### `isPrintSkuName` 只在 true 时下发 - -`false` 是仓方默认值,不下发,省得干扰它自己的默认。 +| SKU 数 > 50 | 构造期拒绝(仓方提示「最多打印50个SKU」) | +| 份数 ≤ 0 | 构造期拒绝 | -### 真机验证(2026-11-16) - -`ybtest` + A4 + `isPrintSkuName=true` → 拿到真实 PDF: -`https://oss.edayun.com/test/2026/11/16/02/.../barcode7640824581948387426.pdf` +`isPrintSkuName` 只在 `true` 时下发,`false` 交给仓方默认。 -四种纸张尺寸都返回 `code=200`。 +**真机(2026-11-16)**:`ybtest` 拿到真实 PDF,四种纸张都 `code=200`。 +仓方其它校验:缺 `productInfos` →「产品信息不能为空」、缺 `pageSize` → +「纸张尺寸不能为空」、SKU 不存在 →「sku=XXX信息不存在」。 -## 打印箱唛 +### SKU 标(newPrintCaseMarkContentType) ``` POST /webApi/entryInfo/v1/newPrintCaseMarkContentType → WarehouseLabel ``` -### 真机:接口不存在或未启用 - -PR 环境实测(2026-11-16): - -| 路径 | 结果 | -|---|---| -| `entryInfo/v1/newPrintCaseMarkContentType` | `code=500`「接口不存在或未启用!」 | -| `entryInfo/v1/printCaseMarkContentType` / `printCaseMark` / `v2/...` | 同上 | -| `entryInfo/v1/newPrintCaseMark`(无后缀) | **能过参数校验** | - -`newPrintCaseMark` 的校验提示确认了必填项:缺 `pageSize` →「纸张不能为空」, -缺 `madeInChina` →「产地标签不能为空」。但**补全后一律「内部服务器错误」**, -试过 skuCode、箱序号区间、`twoPrint`、`separation`、四种纸张,都没过。 - -所以本接口的实现是**按文档写的**,没有真机返回可对照——映射只有单测覆盖。 - -### 纸张码值不连续 - -| 易达云 | 尺寸 | 统一枚举 | -|---|---|---| -| 4 | 100×100 | `LabelSizeType.SIZE_100_100` | -| 2 | 100×150 | `LabelSizeType.SIZE_100_150` | -| 5 | A4 | `LabelSizeType.A4`(本次新增) | - -**码值是 4 / 2 / 5,不是 1/2/3**,不能按顺序推。统一枚举原来只有三种 -(100×100 / 100×150 / 104×98),A4 是这次为箱唛新增的。 - -104×98(美国信纸)易达云不支持,`EdayunCaseMarkPaper.of()` 会显式拒绝。 - -### 统一模型只能表达「整单打印」 - -`BoxLabelCommand` 没有「选哪些箱」的字段,所以选箱条件 -(`caseCodeList` / `skuCode` / 箱序号区间 / 客户箱号区间)默认不下发, -由仓方整单打印。 - -要打部分箱用扩展重载: - -```java -edaunAdapter.printCaseMarks(ctx, cmd, - new EdayunCaseMarkMapper.CaseSelection() - .caseCodes(Arrays.asList("B001", "B002"))); -``` - -四个维度全空时本地拒绝——文档写明「必须有一个不为空」。 +**真机未启用**:PR 环境该路径报「接口不存在或未启用」,去掉 +`ContentType` 后缀的 `newPrintCaseMark` 能过参数校验(缺 `pageSize` 报 +「纸张不能为空」、缺 `madeInChina` 报「产地标签不能为空」),但补全后一律 +「内部服务器错误」。所以本接口实现是**按文档写的**,映射只有单测覆盖。 -### 两个易达云特有开关默认关 - -| 字段 | 默认 | 原因 | -|---|---|---| -| `madeInChina` | 0 否 | 统一模型没有「原产地标注」概念,猜「打」会让每箱多一行 | -| `separation` | false | 分隔符是易达云特有的分页提示,统一模型没有对应语义 | +纸张码值不连续:`100×100=4` / `100×150=2` / `A4=5`。统一枚举 +`LabelSizeType` 为此补了 `A4`。 -### 返回同步 PDF +统一模型的 `BoxLabelCommand` 没有「选哪些箱」,默认整单打印;部分箱用 +`printSkuLabel(ctx, cmd, CaseSelection)` 重载(系统箱号 / SKU / 箱序号区间 / +客户箱号区间四选一,全空本地拒)。 -响应 `data` 是地址字符串,不是任务号——所以返回 `WarehouseLabel` 而不是 -`LabelPrintTask`(那个是运去哪风格的异步任务语义)。 +`madeInChina` 与 `separation` 是易达云特有语义,统一模型没有对应概念 → 默认关。 ## 待确认(问易达云) diff --git a/docs-warehouse/edayun/TODO.md b/docs-warehouse/edayun/TODO.md index 1c2985c..62e89c4 100644 --- a/docs-warehouse/edayun/TODO.md +++ b/docs-warehouse/edayun/TODO.md @@ -68,7 +68,9 @@ | 66 | 条码文件地址的**有效期**未知(OSS 链接) | 原样返回,不缓存 | 宿主存旧链接可能 403 | | 67 | 条码打印是否有限流 / 是否计费 | 未处理 | 大批量打印可能被限 | | 68 | **箱唛接口在 PR 环境未启用**(`newPrintCaseMarkContentType` 报「接口不存在或未启用」;去掉后缀的 `newPrintCaseMark` 能过参数校验但一律「内部服务器错误」) | 按文档实现,映射只有单测 | 上线前必须真机验证 | -| 69 | 箱唛纸张码值 4/2/5 不连续 | 独立枚举 `EdayunCaseMarkPaper`,按映射表走 | 无(已规避) | +| 69 | SKU 标纸张码值 4/2/5 不连续 | 独立枚举 `EdayunSkuLabelPaper`,按映射表走 | 无(已规避) | +| 72 | **`printBarcode` 的 pageSize=2 / pageSize=3 文档标称与实际相反**(文档 2=6×4cm、3=A4;实测 2=100×150mm、3=60×40mm) | 枚举按实测尺寸命名,码值不变 | 按文档标称选纸会打错 | +| 73 | 两个端点名与实际语义相反(printBarcode=箱唛、newPrintCaseMark=SKU 标) | 代码按实际语义命名并在 javadoc 标注 | 无(已规避) | | 70 | 箱唛的 `madeInChina` / `separation` 统一模型没有语义 | 默认关 | 需要打「Made in China」时得走扩展重载 | | 71 | 箱唛选箱条件(系统箱号 / SKU / 箱序号 / 客户箱号)统一模型没有 | 提供 `CaseSelection` 扩展重载 | 宿主想要部分箱打印必须用易达云专有 API | |---|---|---|---| diff --git a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/capability/BarcodePrintCapable.java b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/capability/CaseMarkPrintCapable.java similarity index 76% rename from warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/capability/BarcodePrintCapable.java rename to warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/capability/CaseMarkPrintCapable.java index dd9c006..7f8211f 100644 --- a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/capability/BarcodePrintCapable.java +++ b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/capability/CaseMarkPrintCapable.java @@ -1,12 +1,12 @@ package common.ecommerce.warehouse.capability; -import common.ecommerce.warehouse.model.BarcodePrintCommand; +import common.ecommerce.warehouse.model.CaseMarkPrintCommand; import common.ecommerce.warehouse.model.WarehouseLabel; import common.ecommerce.warehouse.sdk.WarehouseAdapter; import common.ecommerce.warehouse.sdk.WarehouseContext; /** - * 商品条码打印能力:按 SKU 打条码贴纸,不依赖任何单据。 + * 箱唛打印能力:按 SKU 打外箱标(箱唛)。 * *

与 {@link InboundCapable#printSkuLabel} 不是一回事:那个是入库计划单的贴标 * (绑定入库单号、有 14 种小纸尺寸、仓方异步生成);这个是按 SKU 打条码, @@ -14,7 +14,7 @@ import common.ecommerce.warehouse.sdk.WarehouseContext; * *

只读语义(不改业务状态),但会生成文件;重复调用只是再生成一份。

*/ -public interface BarcodePrintCapable extends WarehouseAdapter { +public interface CaseMarkPrintCapable extends WarehouseAdapter { /** * 打印 SKU 条码。 @@ -23,5 +23,5 @@ public interface BarcodePrintCapable extends WarehouseAdapter { * @throws common.ecommerce.warehouse.error.WarehouseUnsupportedCapabilityException * 该仓不声明 {@code BARCODE_PRINT} */ - WarehouseLabel printBarcodes(WarehouseContext ctx, BarcodePrintCommand cmd); + WarehouseLabel printCaseMarks(WarehouseContext ctx, CaseMarkPrintCommand cmd); } diff --git a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/enums/BarcodePaperSize.java b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/enums/BarcodePaperSize.java deleted file mode 100644 index 261d8cc..0000000 --- a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/enums/BarcodePaperSize.java +++ /dev/null @@ -1,37 +0,0 @@ -package common.ecommerce.warehouse.enums; - -/** - * SKU 条码打印的纸张尺寸。 - * - *

易达云 {@code printBarcode} 的 {@code pageSize}:0 7×3cm / 1 10×6cm / - * 2 6×4cm / 3 A4。只有这 4 档,与入库贴标用的 - * {@link SkuLabelSizeType}(14 种小尺寸)不是一套,不能互换。

- */ -public enum BarcodePaperSize { - - /** 0:70mm × 30mm。 */ - SIZE_70_30(0, "7×3cm"), - /** 1:100mm × 60mm。 */ - SIZE_100_60(1, "10×6cm"), - /** 2:60mm × 40mm。 */ - SIZE_60_40(2, "6×4cm"), - /** 3:A4。 */ - A4(3, "A4"); - - private final int code; - private final String label; - - BarcodePaperSize(int code, String label) { - this.code = code; - this.label = label; - } - - /** 仓方码值。 */ - public int code() { - return code; - } - - public String label() { - return label; - } -} diff --git a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/enums/CaseMarkPaperSize.java b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/enums/CaseMarkPaperSize.java new file mode 100644 index 0000000..5c96ccb --- /dev/null +++ b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/enums/CaseMarkPaperSize.java @@ -0,0 +1,47 @@ +package common.ecommerce.warehouse.enums; + +/** + * 箱唛打印的纸张尺寸(易达云 {@code printBarcode} 的 {@code pageSize})。 + * + *

名称按真机实测尺寸取,不是按文档标称——文档的 2 / 3 两档与实测相反。 + * 实测是 PDF MediaBox 折算的毫米数(1pt = 25.4/72 mm):

+ * + * + * + * + * + * + * + *
码值文档标称实测枚举
07×3cm69.9 × 30.0 mm{@link #SIZE_70_30}
110×6cm100.2 × 60.0 mm{@link #SIZE_100_60}
26×4cm99.9 × 150.0 mm{@link #SIZE_100_150}
3A460.0 × 39.9 mm{@link #SIZE_60_40}
+ * + *

与入库贴标用的 {@link SkuLabelSizeType}(14 种小尺寸)不是一套,不能互换。

+ */ +public enum CaseMarkPaperSize { + + /** 0:约 70mm × 30mm(文档 7×3cm,实测一致)。 */ + SIZE_70_30(0, "70×30mm"), + /** 1:约 100mm × 60mm(文档 10×6cm,实测一致)。 */ + SIZE_100_60(1, "100×60mm"), + /** 2:约 100mm × 150mm(文档标 6×4cm,实测不符)。 */ + SIZE_100_150(2, "100×150mm"), + /** 3:约 60mm × 40mm(文档标 A4,实测不符)。 */ + SIZE_60_40(3, "60×40mm"); + + private final int code; + private final String label; + + CaseMarkPaperSize(int code, String label) { + this.code = code; + this.label = label; + } + + /** 仓方码值。 */ + public int code() { + return code; + } + + /** 实测尺寸的显示名。 */ + public String label() { + return label; + } +} diff --git a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/enums/WarehouseCapability.java b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/enums/WarehouseCapability.java index 078e7e7..2e1f9f9 100644 --- a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/enums/WarehouseCapability.java +++ b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/enums/WarehouseCapability.java @@ -58,8 +58,8 @@ public enum WarehouseCapability { CHANNEL_RECOMMEND(240, "最优渠道推荐"), /** 物流异动单:召回 / 换址 / 在途异常(对已交运的运单发起处理) */ TRACKING_CHANGE(250, "物流异动单"), - /** 商品条码打印(不依赖单据,按 SKU 打条码) */ - BARCODE_PRINT(260, "商品条码打印"); + /** 箱唛打印(不依赖单据,按 SKU 打外箱标) */ + CASE_MARK_PRINT(260, "箱唛打印"); private final int code; private final String label; diff --git a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/BarcodePrintCommand.java b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/CaseMarkPrintCommand.java similarity index 77% rename from warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/BarcodePrintCommand.java rename to warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/CaseMarkPrintCommand.java index 8b40386..0e8c147 100644 --- a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/BarcodePrintCommand.java +++ b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/model/CaseMarkPrintCommand.java @@ -1,13 +1,13 @@ package common.ecommerce.warehouse.model; -import common.ecommerce.warehouse.enums.BarcodePaperSize; +import common.ecommerce.warehouse.enums.CaseMarkPaperSize; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** - * SKU 条码打印命令(打商品条码,不是入库单的 SKU 贴标)。 + * 箱唛打印命令(打外箱标,不是入库单的 SKU 贴标)。 * *

与 {@link SkuLabelCommand} 的区别:那个是入库计划单的贴标(绑定 * 入库单号、14 种小纸尺寸);这个是按 SKU 打条码,不依赖任何单据, @@ -16,19 +16,19 @@ import java.util.List; *

仓方同步返回文件地址(不是异步任务),所以返回的是 * {@link WarehouseLabel} 而不是 {@link LabelPrintTask}。

*/ -public final class BarcodePrintCommand { +public final class CaseMarkPrintCommand { /** 一次最多打多少种 SKU。 */ public static final int MAX_SKUS = 50; - private final BarcodePaperSize paperSize; + private final CaseMarkPaperSize paperSize; /** 备注,如 {@code Made in China}。 */ private final String remark; /** 是否打印 SKU 名称。 */ private final boolean printSkuName; - private final List items; + private final List items; - private BarcodePrintCommand(Builder b) { + private CaseMarkPrintCommand(Builder b) { if (b.paperSize == null) { throw new IllegalArgumentException("paperSize is required"); } @@ -42,14 +42,14 @@ public final class BarcodePrintCommand { throw new IllegalArgumentException( "at most " + MAX_SKUS + " skus per print, got " + b.items.size()); } - this.items = Collections.unmodifiableList(new ArrayList(b.items)); + this.items = Collections.unmodifiableList(new ArrayList(b.items)); } public static Builder builder() { return new Builder(); } - public BarcodePaperSize paperSize() { + public CaseMarkPaperSize paperSize() { return paperSize; } @@ -63,17 +63,17 @@ public final class BarcodePrintCommand { return printSkuName; } - public List items() { + public List items() { return items; } /** 一个 SKU 及其打印份数。 */ - public static final class BarcodeItem { + public static final class CaseMarkItem { private final String providerSku; private final int copies; - public BarcodeItem(String providerSku, int copies) { + public CaseMarkItem(String providerSku, int copies) { if (providerSku == null || providerSku.trim().isEmpty()) { throw new IllegalArgumentException("providerSku must not be blank"); } @@ -94,12 +94,12 @@ public final class BarcodePrintCommand { } public static final class Builder { - private BarcodePaperSize paperSize; + private CaseMarkPaperSize paperSize; private String remark; private boolean printSkuName; - private final List items = new ArrayList(); + private final List items = new ArrayList(); - public Builder paperSize(BarcodePaperSize v) { + public Builder paperSize(CaseMarkPaperSize v) { this.paperSize = v; return this; } @@ -115,12 +115,12 @@ public final class BarcodePrintCommand { } public Builder item(String providerSku, int copies) { - this.items.add(new BarcodeItem(providerSku, copies)); + this.items.add(new CaseMarkItem(providerSku, copies)); return this; } - public BarcodePrintCommand build() { - return new BarcodePrintCommand(this); + public CaseMarkPrintCommand build() { + return new CaseMarkPrintCommand(this); } } } diff --git a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/sdk/WarehouseOperations.java b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/sdk/WarehouseOperations.java index e3534eb..958b7f9 100644 --- a/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/sdk/WarehouseOperations.java +++ b/warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/sdk/WarehouseOperations.java @@ -4,7 +4,7 @@ import common.ecommerce.shared.audit.CallObserver; import common.ecommerce.shared.audit.CallSupport; import common.ecommerce.shared.idempotency.IdempotencyGuard; import common.ecommerce.shared.support.Page; -import common.ecommerce.warehouse.capability.BarcodePrintCapable; +import common.ecommerce.warehouse.capability.CaseMarkPrintCapable; import common.ecommerce.warehouse.capability.BolCapable; import common.ecommerce.warehouse.capability.DestructionCapable; import common.ecommerce.warehouse.capability.InboundCapable; @@ -25,7 +25,7 @@ import common.ecommerce.warehouse.enums.InventorySyncStrategy; import common.ecommerce.warehouse.enums.WarehouseCapability; import common.ecommerce.warehouse.enums.WarehouseProvider; import common.ecommerce.warehouse.error.WarehouseUnsupportedCapabilityException; -import common.ecommerce.warehouse.model.BarcodePrintCommand; +import common.ecommerce.warehouse.model.CaseMarkPrintCommand; import common.ecommerce.warehouse.model.BillingDocument; import common.ecommerce.warehouse.model.BoxLabelCommand; import common.ecommerce.warehouse.model.ChannelRecommendQuery; @@ -344,19 +344,19 @@ public final class WarehouseOperations { } /** - * 打印 SKU 条码(不依赖单据)。 + * 打印箱唛(外箱标,不依赖入库单)。 * - *

与 {@code inbound().printSkuLabel()} 不同:那个绑定入库计划单, - * 这个只按 SKU 打。仓方同步返回文件地址,所以不走幂等守卫—— + *

与 {@code inbound().printSkuLabel()} 不同:那个是入库计划单的 SKU 贴标, + * 这个只按 SKU 打外箱标。仓方同步返回文件地址,所以不走幂等守卫—— * 重复调用只是再生成一份,不改业务状态。

*/ - public WarehouseLabel printBarcodes(BarcodePrintCommand cmd) { - require(WarehouseCapability.BARCODE_PRINT, BarcodePrintCapable.class); - return CallSupport.observe(observer, ctx, "warehouse.barcode.print", + public WarehouseLabel printCaseMarks(CaseMarkPrintCommand cmd) { + require(WarehouseCapability.CASE_MARK_PRINT, CaseMarkPrintCapable.class); + return CallSupport.observe(observer, ctx, "warehouse.caseMark.print", CallSupport.params("paperSize", cmd.paperSize(), "skuCount", cmd.items().size()), r -> CallSupport.NO_COUNT, - () -> ((BarcodePrintCapable) adapter).printBarcodes(ctx, cmd)); + () -> ((CaseMarkPrintCapable) adapter).printCaseMarks(ctx, cmd)); } /** 费用视图。 */ diff --git a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/EdayunConstants.java b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/EdayunConstants.java index eab9992..9bf95e4 100644 --- a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/EdayunConstants.java +++ b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/EdayunConstants.java @@ -100,11 +100,20 @@ public final class EdayunConstants { /** 查询订单物流轨迹({@code POST /webApi/track/getTrackInfoList})。 */ public static final String PATH_TRACK = "/webApi/track/getTrackInfoList"; - /** 打印条码({@code POST /webApi/skuInfo/v2/printBarcode})。 */ - public static final String PATH_BARCODE_PRINT = "/webApi/skuInfo/v2/printBarcode"; + /** + * 打印箱唛({@code POST /webApi/skuInfo/v2/printBarcode})。 + * + *

端点名是 printBarcode,实际打的是箱唛——已与仓方确认。

+ */ + public static final String PATH_CASE_MARK_PRINT = "/webApi/skuInfo/v2/printBarcode"; - /** 打印箱唛({@code POST /webApi/entryInfo/v1/newPrintCaseMarkContentType})。 */ - public static final String PATH_CASE_MARK_PRINT = "/webApi/entryInfo/v1/newPrintCaseMarkContentType"; + /** + * 打印 SKU 标({@code POST /webApi/entryInfo/v1/newPrintCaseMarkContentType})。 + * + *

端点名是 newPrintCaseMark,实际打的是 SKU 标——已与仓方确认。

+ */ + public static final String PATH_SKU_LABEL_PRINT = + "/webApi/entryInfo/v1/newPrintCaseMarkContentType"; /** 物流增值:签收服务。 */ public static final String ADD_SERVICE_SIGNATURE = "is_signature"; diff --git a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunAdapter.java b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunAdapter.java index 79fa8be..9e4d51d 100644 --- a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunAdapter.java +++ b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunAdapter.java @@ -3,11 +3,10 @@ package common.ecommerce.edayun.adapter; import common.ecommerce.edayun.EdayunConstants; import common.ecommerce.edayun.auth.EdayunTokenClient; import common.ecommerce.edayun.dto.EdayunAccountFlowDtos; -import common.ecommerce.edayun.dto.EdayunBarcodeDtos; import common.ecommerce.edayun.dto.EdayunBolDtos; -import common.ecommerce.edayun.dto.EdayunCaseMarkDtos; import common.ecommerce.edayun.dto.EdayunCancelDtos; import common.ecommerce.edayun.dto.EdayunCancelReturnDtos; +import common.ecommerce.edayun.dto.EdayunCaseMarkDtos; import common.ecommerce.edayun.dto.EdayunCreateOrderDtos; import common.ecommerce.edayun.dto.EdayunCreateProductDtos; import common.ecommerce.edayun.dto.EdayunFeeEstimateDtos; @@ -22,6 +21,7 @@ import common.ecommerce.edayun.dto.EdayunRentDetailDtos; import common.ecommerce.edayun.dto.EdayunReturnDetailDtos; import common.ecommerce.edayun.dto.EdayunReturnDtos; import common.ecommerce.edayun.dto.EdayunRmaListDtos; +import common.ecommerce.edayun.dto.EdayunSkuLabelDtos; import common.ecommerce.edayun.dto.EdayunTrackDtos; import common.ecommerce.edayun.enums.EdayunCancelStatus; import common.ecommerce.edayun.http.EdayunRequestFactory; @@ -35,8 +35,8 @@ import common.ecommerce.shared.spi.ChannelSecret; import common.ecommerce.shared.spi.LockProvider; import common.ecommerce.shared.spi.TokenStore; import common.ecommerce.shared.support.Page; -import common.ecommerce.warehouse.capability.BarcodePrintCapable; import common.ecommerce.warehouse.capability.BolCapable; +import common.ecommerce.warehouse.capability.CaseMarkPrintCapable; import common.ecommerce.warehouse.capability.InboundCapable; import common.ecommerce.warehouse.capability.InventoryCapable; import common.ecommerce.warehouse.capability.LogisticsProductCapable; @@ -54,12 +54,12 @@ import common.ecommerce.warehouse.enums.WarehouseCapability; import common.ecommerce.warehouse.enums.WarehouseProvider; import common.ecommerce.warehouse.error.WarehouseException; import common.ecommerce.warehouse.error.WarehouseUnsupportedCapabilityException; -import common.ecommerce.warehouse.model.BarcodePrintCommand; import common.ecommerce.warehouse.model.BillingDocument; -import common.ecommerce.warehouse.model.BoxLabelCommand; import common.ecommerce.warehouse.model.BolDocument; +import common.ecommerce.warehouse.model.BoxLabelCommand; import common.ecommerce.warehouse.model.CancelCommand; import common.ecommerce.warehouse.model.CancelResult; +import common.ecommerce.warehouse.model.CaseMarkPrintCommand; import common.ecommerce.warehouse.model.FeeEstimateQuery; import common.ecommerce.warehouse.model.FeeEstimateResult; import common.ecommerce.warehouse.model.FeeQuery; @@ -102,7 +102,7 @@ import java.util.List; public final class EdayunAdapter implements WarehouseAdapter, WarehouseProductCapable, OutboundCapable, WarehouseFeeCapable, WarehouseFeeEstimateCapable, InventoryCapable, InboundCapable, WarehouseReturnCapable, BolCapable, LogisticsProductCapable, - TrackingCapable, BarcodePrintCapable { + TrackingCapable, CaseMarkPrintCapable { /** 物流产品查询的适用业务:1 店铺订单(默认口径)。 */ private static final int APPLICABLE_BUSINESS_STORE_ORDER = 1; @@ -160,7 +160,7 @@ public final class EdayunAdapter implements WarehouseAdapter, WarehouseProductCa WarehouseCapability.INVENTORY_QUERY, WarehouseCapability.INBOUND, WarehouseCapability.RETURN, WarehouseCapability.BOL, WarehouseCapability.LOGISTICS_PRODUCT, WarehouseCapability.TRACKING, - WarehouseCapability.BARCODE_PRINT); + WarehouseCapability.CASE_MARK_PRINT); } /** @@ -973,11 +973,16 @@ public final class EdayunAdapter implements WarehouseAdapter, WarehouseProductCa // ------------------------------------------------------------------ 条码打印 + // ------------------------------------------------------------------ 箱唛 + /** - * 打印 SKU 条码({@code POST /webApi/skuInfo/v2/printBarcode})。 + * 打印箱唛({@code POST /webApi/skuInfo/v2/printBarcode})。 * - *

与入库贴标({@code inbound().printSkuLabel})不同:这个只按 SKU 打, - * 不绑单据,且仓方同步返回 PDF 地址。

+ *

端点名叫 printBarcode,但实际打的是箱唛(外箱标)——已与仓方确认。 + * 真正的 SKU 标走 {@code printSkuLabel}(端点 {@code newPrintCaseMark})。

+ * + *

与入库箱标({@code inbound().printBoxLabel})不同:那个是运去哪风格的 + * 异步任务(只回任务号),易达云这个同步返回 PDF 地址。

* *

真机实测的仓方校验:{@code productInfos} 为空报「产品信息不能为空」, * 缺 {@code pageSize} 报「纸张尺寸不能为空」,{@code pageSize} 非 0~3 报 @@ -985,21 +990,21 @@ public final class EdayunAdapter implements WarehouseAdapter, WarehouseProductCa * 报「最多打印50个SKU」。本地已提前挡住后两者。

*/ @Override - public WarehouseLabel printBarcodes(WarehouseContext ctx, BarcodePrintCommand cmd) { - EdayunBarcodeDtos.PrintBarcodeRequest body = EdayunBarcodeMapper.toRequest(cmd); + public WarehouseLabel printCaseMarks(WarehouseContext ctx, CaseMarkPrintCommand cmd) { + EdayunCaseMarkDtos.PrintCaseMarkRequest body = EdayunCaseMarkMapper.toRequest(cmd); String bodyJson = json.toJson(body); - HttpResponse resp = send(ctx, EdayunConstants.PATH_BARCODE_PRINT, bodyJson, - "warehouse.barcode.print"); - EdayunBarcodeDtos.PrintBarcodeResponse parsed = - json.fromJson(resp.body(), EdayunBarcodeDtos.PrintBarcodeResponse.class); + HttpResponse resp = send(ctx, EdayunConstants.PATH_CASE_MARK_PRINT, bodyJson, + "warehouse.caseMark.print"); + EdayunCaseMarkDtos.PrintCaseMarkResponse parsed = + json.fromJson(resp.body(), EdayunCaseMarkDtos.PrintCaseMarkResponse.class); requireSuccess(ctx, parsed == null ? null : parsed.code, - parsed == null ? null : parsed.msg, resp, "warehouse.barcode.print"); + parsed == null ? null : parsed.msg, resp, "warehouse.caseMark.print"); if (parsed.data == null || parsed.data.trim().isEmpty()) { throw WarehouseException.builder() .message("edayun printBarcode returned no file url") - .operation("warehouse.barcode.print") + .operation("warehouse.caseMark.print") .warehouseCode(ctx.warehouseCode()) .provider(provider().name()) .requestId(ctx.requestId()) @@ -1007,57 +1012,57 @@ public final class EdayunAdapter implements WarehouseAdapter, WarehouseProductCa .retryable(false) .build(); } - return EdayunBarcodeMapper.toLabel(parsed.data.trim(), cmd); + return EdayunCaseMarkMapper.toLabel(parsed.data.trim(), cmd); } - // ------------------------------------------------------------------ 箱唛 + // ------------------------------------------------------------------ SKU 标 /** - * 打印箱唛({@code POST /webApi/entryInfo/v1/newPrintCaseMarkContentType})。 + * 打印 SKU 标({@code POST /webApi/entryInfo/v1/newPrintCaseMarkContentType})。 * - *

与入库箱标({@code inbound().printBoxLabel})不同:那个是运去哪风格的 - * 异步任务(只回任务号),易达云这个同步返回 PDF 地址。

+ *

端点名叫 newPrintCaseMark,但实际打的是 SKU 标——已与仓方确认。 + * 箱唛走 {@code printCaseMarks}(端点 {@code printBarcode})。

* *

统一模型的 {@code BoxLabelCommand} 没有「选哪些箱」的字段, - * 所以默认整单打印;要打部分箱用 {@link #printCaseMarks} 的重载。

+ * 所以默认整单打印;要打部分箱用重载。

* *

真机未验证:PR 环境该接口返回「接口不存在或未启用」, * 换到 {@code /newPrintCaseMark}(无 ContentType 后缀)能过参数校验 * (缺 pageSize 报「纸张不能为空」、缺 madeInChina 报「产地标签不能为空」), * 但补全后一律「内部服务器错误」。见 docs-warehouse/edayun/TODO.md。

*/ - public WarehouseLabel printCaseMarks(WarehouseContext ctx, BoxLabelCommand cmd) { - EdayunCaseMarkDtos.PrintCaseMarkRequest body = EdayunCaseMarkMapper.toRequest(cmd); - return sendCaseMark(ctx, body); + public WarehouseLabel printSkuLabel(WarehouseContext ctx, BoxLabelCommand cmd) { + EdayunSkuLabelDtos.PrintSkuLabelRequest body = EdayunSkuLabelMapper.toRequest(cmd); + return sendSkuLabel(ctx, body); } /** - * 打印箱唛(可选箱)。 + * 打印 SKU 标(可选箱)。 * * @param selection 选箱条件;四选一,全空时本地拒绝 */ - public WarehouseLabel printCaseMarks(WarehouseContext ctx, BoxLabelCommand cmd, - EdayunCaseMarkMapper.CaseSelection selection) { - EdayunCaseMarkDtos.PrintCaseMarkRequest body = - EdayunCaseMarkMapper.toRequest(cmd, selection); - return sendCaseMark(ctx, body); + public WarehouseLabel printSkuLabel(WarehouseContext ctx, BoxLabelCommand cmd, + EdayunSkuLabelMapper.CaseSelection selection) { + EdayunSkuLabelDtos.PrintSkuLabelRequest body = + EdayunSkuLabelMapper.toRequest(cmd, selection); + return sendSkuLabel(ctx, body); } - private WarehouseLabel sendCaseMark(WarehouseContext ctx, - EdayunCaseMarkDtos.PrintCaseMarkRequest body) { + private WarehouseLabel sendSkuLabel(WarehouseContext ctx, + EdayunSkuLabelDtos.PrintSkuLabelRequest body) { String bodyJson = json.toJson(body); - HttpResponse resp = send(ctx, EdayunConstants.PATH_CASE_MARK_PRINT, bodyJson, - "warehouse.caseMark.print"); - EdayunCaseMarkDtos.PrintCaseMarkResponse parsed = - json.fromJson(resp.body(), EdayunCaseMarkDtos.PrintCaseMarkResponse.class); + HttpResponse resp = send(ctx, EdayunConstants.PATH_SKU_LABEL_PRINT, bodyJson, + "warehouse.skuLabel.print"); + EdayunSkuLabelDtos.PrintSkuLabelResponse parsed = + json.fromJson(resp.body(), EdayunSkuLabelDtos.PrintSkuLabelResponse.class); requireSuccess(ctx, parsed == null ? null : parsed.code, - parsed == null ? null : parsed.msg, resp, "warehouse.caseMark.print"); + parsed == null ? null : parsed.msg, resp, "warehouse.skuLabel.print"); if (parsed.data == null || parsed.data.trim().isEmpty()) { throw WarehouseException.builder() - .message("edayun printCaseMark returned no file url") - .operation("warehouse.caseMark.print") + .message("edayun newPrintCaseMark returned no file url") + .operation("warehouse.skuLabel.print") .warehouseCode(ctx.warehouseCode()) .provider(provider().name()) .requestId(ctx.requestId()) @@ -1065,7 +1070,7 @@ public final class EdayunAdapter implements WarehouseAdapter, WarehouseProductCa .retryable(false) .build(); } - return EdayunCaseMarkMapper.toLabel(parsed.data.trim()); + return EdayunSkuLabelMapper.toLabel(parsed.data.trim()); } // ------------------------------------------------------------------ internals diff --git a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunBarcodeMapper.java b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunBarcodeMapper.java deleted file mode 100644 index 6d395ab..0000000 --- a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunBarcodeMapper.java +++ /dev/null @@ -1,70 +0,0 @@ -package common.ecommerce.edayun.adapter; - -import common.ecommerce.edayun.dto.EdayunBarcodeDtos; -import common.ecommerce.warehouse.model.BarcodePrintCommand; -import common.ecommerce.warehouse.model.WarehouseLabel; - -import java.util.ArrayList; -import java.util.List; - -/** - * 易达云条码打印映射({@code POST /webApi/skuInfo/v2/printBarcode})。 - * - *

响应 {@code data} 是文件地址字符串——同步生成,不像入库箱标那样只有任务号。

- */ -public final class EdayunBarcodeMapper { - - /** 单次最多打印的 SKU 数(文档:最大 50 个)。 */ - static final int MAX_SKUS = 50; - - private EdayunBarcodeMapper() { - } - - /** - * 统一命令 → 打印请求。 - * - * @throws IllegalArgumentException SKU 数超限(本地先挡,省一次失败请求) - */ - public static EdayunBarcodeDtos.PrintBarcodeRequest toRequest(BarcodePrintCommand cmd) { - EdayunBarcodeDtos.PrintBarcodeRequest req = new EdayunBarcodeDtos.PrintBarcodeRequest(); - req.pageSize = cmd.paperSize().code(); - req.remark = cmd.remark(); - // 只有 true 才下发:false 是仓方默认,不下发省得干扰它自己的默认值 - req.isPrintSkuName = cmd.printSkuName() ? Boolean.TRUE : null; - req.productInfos = toItems(cmd.items()); - return req; - } - - private static List toItems( - List items) { - if (items.size() > MAX_SKUS) { - throw new IllegalArgumentException( - "edayun prints at most " + MAX_SKUS + " skus at once, got " + items.size() - + "; split into multiple calls"); - } - List out = - new ArrayList(items.size()); - for (BarcodePrintCommand.BarcodeItem item : items) { - EdayunBarcodeDtos.ProductInfo info = new EdayunBarcodeDtos.ProductInfo(); - info.skuCode = item.providerSku(); - info.num = item.copies(); - out.add(info); - } - return out; - } - - /** - * 响应 → 面单对象。 - * - *

文件地址可能为空——仓方生成失败时仍可能回 {@code code=200}。调用方应在 - * 调用前确认 {@code data} 非空,适配器已做该检查。

- */ - public static WarehouseLabel toLabel(String fileUrl, BarcodePrintCommand cmd) { - return WarehouseLabel.builder() - // 仓库不返回文件 id,用 SKU 数 + 纸张尺寸拼一个可追溯的编号 - .labelId("barcode-" + cmd.paperSize().name() + "-" + cmd.items().size()) - .format("PDF") - .url(fileUrl) - .build(); - } -} diff --git a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunCaseMarkMapper.java b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunCaseMarkMapper.java index b0c6cf7..3aeadab 100644 --- a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunCaseMarkMapper.java +++ b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunCaseMarkMapper.java @@ -1,127 +1,71 @@ package common.ecommerce.edayun.adapter; import common.ecommerce.edayun.dto.EdayunCaseMarkDtos; -import common.ecommerce.edayun.enums.EdayunCaseMarkPaper; -import common.ecommerce.warehouse.model.BoxLabelCommand; +import common.ecommerce.warehouse.model.CaseMarkPrintCommand; import common.ecommerce.warehouse.model.WarehouseLabel; +import java.util.ArrayList; import java.util.List; /** - * 易达云箱唛映射({@code POST /webApi/entryInfo/v1/newPrintCaseMarkContentType})。 + * 易达云箱唛映射({@code POST /webApi/skuInfo/v2/printBarcode})。 * - *

统一模型只能表达「整单打印」:{@code BoxLabelCommand} 没有「选哪些箱」 - * 的字段,所以选箱条件(系统箱号列表 / SKU / 箱序号区间 / 客户箱号区间) - * 一律不下发——仓方默认整单。要打部分箱请走 {@code printCaseMarks} 的扩展重载。

- * - *

响应 {@code data} 是 PDF 地址,同步生成;而统一模型的 - * {@code LabelPrintTask} 是异步任务语义(只有任务号)。所以这里返回 - * {@link WarehouseLabel},把地址放在 {@code url()}。

+ *

端点名叫 printBarcode,但实际打的是箱唛(外箱标)——已与仓方确认。 + * 响应 {@code data} 是 PDF 地址字符串,同步生成。

*/ public final class EdayunCaseMarkMapper { - /** 是否需要 Made in China:是。 */ - static final int MADE_IN_CHINA_YES = 1; - /** 是否需要 Made in China:否。 */ - static final int MADE_IN_CHINA_NO = 0; + /** 单次最多打印的 SKU 数(文档:最大 50 个)。 */ + static final int MAX_SKUS = 50; private EdayunCaseMarkMapper() { } /** - * 统一命令 → 箱唛请求(整单打印)。 + * 统一命令 → 打印请求。 * - * @throws IllegalArgumentException 尺寸不在易达云支持的三档内 + * @throws IllegalArgumentException SKU 数超限(本地先挡,省一次失败请求) */ - public static EdayunCaseMarkDtos.PrintCaseMarkRequest toRequest(BoxLabelCommand cmd) { - EdayunCaseMarkDtos.PrintCaseMarkRequest req = - new EdayunCaseMarkDtos.PrintCaseMarkRequest(); - // 统一模型里 providerInboundNo 就是仓侧 REV 单号 - req.entryCode = cmd.providerInboundNo(); - - EdayunCaseMarkPaper paper = EdayunCaseMarkPaper.of(cmd.sizeType()); - req.pageSize = paper.code(); - - // 统一模型没有「原产地标注」,默认不打 Made in China——猜「打」会让每箱多一行 - req.madeInChina = MADE_IN_CHINA_NO; - // 分隔符是易达云特有的分页提示,统一模型没有对应语义,默认关 - req.separation = Boolean.FALSE; - req.twoPrint = cmd.twoCopies() ? 1 : 0; + public static EdayunCaseMarkDtos.PrintCaseMarkRequest toRequest(CaseMarkPrintCommand cmd) { + EdayunCaseMarkDtos.PrintCaseMarkRequest req = new EdayunCaseMarkDtos.PrintCaseMarkRequest(); + req.pageSize = cmd.paperSize().code(); + req.remark = cmd.remark(); + // 只有 true 才下发:false 是仓方默认,不下发省得干扰它自己的默认值 + req.isPrintSkuName = cmd.printSkuName() ? Boolean.TRUE : null; + req.productInfos = toItems(cmd.items()); return req; } - /** - * 带选箱条件的请求(易达云专有能力)。 - * - *

选箱条件四选一,全部为空时仓方会报错,这里本地先拒。

- */ - public static EdayunCaseMarkDtos.PrintCaseMarkRequest toRequest(BoxLabelCommand cmd, - CaseSelection selection) { - EdayunCaseMarkDtos.PrintCaseMarkRequest req = toRequest(cmd); - if (selection == null || selection.isEmpty()) { + private static List toItems( + List items) { + if (items.size() > MAX_SKUS) { throw new IllegalArgumentException( - "edayun case mark needs at least one box selector" - + " (case codes / sku / serial range / seller case range)"); + "edayun prints at most " + MAX_SKUS + " skus at once, got " + items.size() + + "; split into multiple calls"); } - req.caseCodeList = selection.caseCodes; - req.skuCode = selection.skuCode; - req.startCaseSerialNo = selection.startCaseSerialNo; - req.endCaseSerialNo = selection.endCaseSerialNo; - req.startSellerCaseNo = selection.startSellerCaseNo; - req.endSellerCaseNo = selection.endSellerCaseNo; - return req; + List out = + new ArrayList(items.size()); + for (CaseMarkPrintCommand.CaseMarkItem item : items) { + EdayunCaseMarkDtos.ProductInfo info = new EdayunCaseMarkDtos.ProductInfo(); + info.skuCode = item.providerSku(); + info.num = item.copies(); + out.add(info); + } + return out; } - /** 响应 → 面单对象;地址为空视为失败。 */ - public static WarehouseLabel toLabel(String fileUrl) { + /** + * 响应 → 面单对象。 + * + *

文件地址可能为空——仓方生成失败时仍可能回 {@code code=200}。调用方应在 + * 调用前确认 {@code data} 非空,适配器已做该检查。

+ */ + public static WarehouseLabel toLabel(String fileUrl, CaseMarkPrintCommand cmd) { return WarehouseLabel.builder() - // 仓方不回文件 id - .labelId("case-mark") + // 仓库不返回文件 id,用 SKU 数 + 纸张尺寸拼一个可追溯的编号 + .labelId("barcode-" + cmd.paperSize().name() + "-" + cmd.items().size()) .format("PDF") .url(fileUrl) .build(); } - - /** 选箱条件:四个维度都是「有就用」。 */ - public static final class CaseSelection { - private List caseCodes; - private String skuCode; - private String startCaseSerialNo; - private String endCaseSerialNo; - private String startSellerCaseNo; - private String endSellerCaseNo; - - public CaseSelection caseCodes(List v) { - this.caseCodes = v; - return this; - } - - public CaseSelection skuCode(String v) { - this.skuCode = v; - return this; - } - - public CaseSelection caseSerialRange(String start, String end) { - this.startCaseSerialNo = start; - this.endCaseSerialNo = end; - return this; - } - - public CaseSelection sellerCaseRange(String start, String end) { - this.startSellerCaseNo = start; - this.endSellerCaseNo = end; - return this; - } - - boolean isEmpty() { - return (caseCodes == null || caseCodes.isEmpty()) - && isBlank(skuCode) - && isBlank(startCaseSerialNo) && isBlank(endCaseSerialNo) - && isBlank(startSellerCaseNo) && isBlank(endSellerCaseNo); - } - - private static boolean isBlank(String v) { - return v == null || v.trim().isEmpty(); - } - } } diff --git a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunSkuLabelMapper.java b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunSkuLabelMapper.java new file mode 100644 index 0000000..23631ad --- /dev/null +++ b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunSkuLabelMapper.java @@ -0,0 +1,127 @@ +package common.ecommerce.edayun.adapter; + +import common.ecommerce.edayun.dto.EdayunSkuLabelDtos; +import common.ecommerce.edayun.enums.EdayunSkuLabelPaper; +import common.ecommerce.warehouse.model.BoxLabelCommand; +import common.ecommerce.warehouse.model.WarehouseLabel; + +import java.util.List; + +/** + * 易达云 SKU 标映射({@code POST /webApi/entryInfo/v1/newPrintCaseMarkContentType})。 + * + *

统一模型只能表达「整单打印」:{@code BoxLabelCommand} 没有「选哪些箱」 + * 的字段,所以选箱条件(系统箱号列表 / SKU / 箱序号区间 / 客户箱号区间) + * 一律不下发——仓方默认整单。要打部分箱请走 {@code printSkuLabel} 的扩展重载。

+ * + *

响应 {@code data} 是 PDF 地址,同步生成;而统一模型的 + * {@code LabelPrintTask} 是异步任务语义(只有任务号)。所以这里返回 + * {@link WarehouseLabel},把地址放在 {@code url()}。

+ */ +public final class EdayunSkuLabelMapper { + + /** 是否需要 Made in China:是。 */ + static final int MADE_IN_CHINA_YES = 1; + /** 是否需要 Made in China:否。 */ + static final int MADE_IN_CHINA_NO = 0; + + private EdayunSkuLabelMapper() { + } + + /** + * 统一命令 → SKU 标请求(整单打印)。 + * + * @throws IllegalArgumentException 尺寸不在易达云支持的三档内 + */ + public static EdayunSkuLabelDtos.PrintSkuLabelRequest toRequest(BoxLabelCommand cmd) { + EdayunSkuLabelDtos.PrintSkuLabelRequest req = + new EdayunSkuLabelDtos.PrintSkuLabelRequest(); + // 统一模型里 providerInboundNo 就是仓侧 REV 单号 + req.entryCode = cmd.providerInboundNo(); + + EdayunSkuLabelPaper paper = EdayunSkuLabelPaper.of(cmd.sizeType()); + req.pageSize = paper.code(); + + // 统一模型没有「原产地标注」,默认不打 Made in China——猜「打」会让每箱多一行 + req.madeInChina = MADE_IN_CHINA_NO; + // 分隔符是易达云特有的分页提示,统一模型没有对应语义,默认关 + req.separation = Boolean.FALSE; + req.twoPrint = cmd.twoCopies() ? 1 : 0; + return req; + } + + /** + * 带选箱条件的请求(易达云专有能力)。 + * + *

选箱条件四选一,全部为空时仓方会报错,这里本地先拒。

+ */ + public static EdayunSkuLabelDtos.PrintSkuLabelRequest toRequest(BoxLabelCommand cmd, + CaseSelection selection) { + EdayunSkuLabelDtos.PrintSkuLabelRequest req = toRequest(cmd); + if (selection == null || selection.isEmpty()) { + throw new IllegalArgumentException( + "edayun sku label needs at least one box selector" + + " (case codes / sku / serial range / seller case range)"); + } + req.caseCodeList = selection.caseCodes; + req.skuCode = selection.skuCode; + req.startCaseSerialNo = selection.startCaseSerialNo; + req.endCaseSerialNo = selection.endCaseSerialNo; + req.startSellerCaseNo = selection.startSellerCaseNo; + req.endSellerCaseNo = selection.endSellerCaseNo; + return req; + } + + /** 响应 → 面单对象;地址为空视为失败。 */ + public static WarehouseLabel toLabel(String fileUrl) { + return WarehouseLabel.builder() + // 仓方不回文件 id + .labelId("case-mark") + .format("PDF") + .url(fileUrl) + .build(); + } + + /** 选箱条件:四个维度都是「有就用」。 */ + public static final class CaseSelection { + private List caseCodes; + private String skuCode; + private String startCaseSerialNo; + private String endCaseSerialNo; + private String startSellerCaseNo; + private String endSellerCaseNo; + + public CaseSelection caseCodes(List v) { + this.caseCodes = v; + return this; + } + + public CaseSelection skuCode(String v) { + this.skuCode = v; + return this; + } + + public CaseSelection caseSerialRange(String start, String end) { + this.startCaseSerialNo = start; + this.endCaseSerialNo = end; + return this; + } + + public CaseSelection sellerCaseRange(String start, String end) { + this.startSellerCaseNo = start; + this.endSellerCaseNo = end; + return this; + } + + boolean isEmpty() { + return (caseCodes == null || caseCodes.isEmpty()) + && isBlank(skuCode) + && isBlank(startCaseSerialNo) && isBlank(endCaseSerialNo) + && isBlank(startSellerCaseNo) && isBlank(endSellerCaseNo); + } + + private static boolean isBlank(String v) { + return v == null || v.trim().isEmpty(); + } + } +} diff --git a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunBarcodeDtos.java b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunBarcodeDtos.java deleted file mode 100644 index ea7ab16..0000000 --- a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunBarcodeDtos.java +++ /dev/null @@ -1,52 +0,0 @@ -package common.ecommerce.edayun.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; - -import java.util.List; - -/** - * 易达云报文结构:打印条码({@code POST /webApi/skuInfo/v2/printBarcode})。 - * - *

一个文件对应一个接口。响应 {@code data} 是文件地址字符串, - * 不是对象——与入库箱标那种「异步任务号」不同,这里同步给文件。

- */ -public final class EdayunBarcodeDtos { - - private EdayunBarcodeDtos() { - } - - /** 打印请求。 */ - @JsonInclude(JsonInclude.Include.NON_NULL) - public static final class PrintBarcodeRequest { - - /** 备注,如 {@code Made in China};≤64。 */ - public String remark; - /** 是否打印 SKU 名称。 */ - public Boolean isPrintSkuName; - - /** 纸张尺寸:0 7×3cm / 1 10×6cm / 2 6×4cm / 3 A4。必填。 */ - public Integer pageSize; - - /** 产品信息,最大 50 个 SKU。必填。 */ - public List productInfos; - } - - /** 一个 SKU。 */ - @JsonInclude(JsonInclude.Include.NON_NULL) - public static final class ProductInfo { - public String skuCode; - /** 打印份数;必须 > 0。 */ - public Integer num; - } - - /** 打印响应。 */ - @JsonInclude(JsonInclude.Include.NON_NULL) - public static final class PrintBarcodeResponse { - public Integer code; - public String msg; - /** 条码文件地址(PDF)。 */ - public String data; - /** 文档标为 object,实际是字符串 {@code "null"};保留 Object 避免解析失败。 */ - public Object traceId; - } -} diff --git a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunCaseMarkDtos.java b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunCaseMarkDtos.java index a6b2dc8..53a176a 100644 --- a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunCaseMarkDtos.java +++ b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunCaseMarkDtos.java @@ -5,20 +5,13 @@ import com.fasterxml.jackson.annotation.JsonInclude; import java.util.List; /** - * 易达云报文结构:打印箱唛 - * ({@code POST /webApi/entryInfo/v1/newPrintCaseMarkContentType})。 + * 易达云报文结构:打印箱唛({@code POST /webApi/skuInfo/v2/printBarcode})。 * *

一个文件对应一个接口。响应 {@code data} 是箱唛 PDF 地址字符串, * 同步生成,不是任务号。

* - *

选箱条件四选一(文档原文:箱序号 / 客户箱号 / sku 编码 / 系统箱号 - * 必须有一个不为空):

- *
    - *
  • 系统箱号:{@code caseCodeList}
  • - *
  • SKU:{@code skuCode}
  • - *
  • 箱序号区间:{@code startCaseSerialNo} ~ {@code endCaseSerialNo}
  • - *
  • 客户箱号区间:{@code startSellerCaseNo} ~ {@code endSellerCaseNo}
  • - *
+ *

接口名与语义不一致:端点叫 {@code printBarcode},但实际打的是 + * 箱唛(外箱标)。已与仓方确认,不要被路径名误导。

*/ public final class EdayunCaseMarkDtos { @@ -29,30 +22,24 @@ public final class EdayunCaseMarkDtos { @JsonInclude(JsonInclude.Include.NON_NULL) public static final class PrintCaseMarkRequest { - /** EDA 入库单号(REV 单号)。必填。 */ - public String entryCode; + /** 备注,如 {@code Made in China};≤64。 */ + public String remark; + /** 是否打印 SKU 名称。 */ + public Boolean isPrintSkuName; - /** 系统箱号列表(如 {@code B00231164777837})。 */ - public List caseCodeList; - /** SKU 编码。 */ - public String skuCode; - /** 箱序号开始。 */ - public String startCaseSerialNo; - /** 箱序号结束。 */ - public String endCaseSerialNo; - /** 开始打印的客户箱号。 */ - public String startSellerCaseNo; - /** 结束打印的客户箱号。 */ - public String endSellerCaseNo; - - /** 纸张尺寸:2 100×150 / 4 100×100 / 5 A4。必填。 */ + /** 纸张尺寸:0 7×3cm / 1 10×6cm / 2 6×4cm / 3 A4。必填。 */ public Integer pageSize; - /** 是否需要 Made in China:0 否 / 1 是。必填。 */ - public Integer madeInChina; - /** 是否打印分隔符(第一页与下一页不一致时插提示页)。必填。 */ - public Boolean separation; - /** 每箱打印两份:0 否 / 1 是。 */ - public Integer twoPrint; + + /** 产品信息,最大 50 个 SKU。必填。 */ + public List productInfos; + } + + /** 一个 SKU。 */ + @JsonInclude(JsonInclude.Include.NON_NULL) + public static final class ProductInfo { + public String skuCode; + /** 打印份数;必须 > 0。 */ + public Integer num; } /** 打印响应。 */ @@ -60,8 +47,9 @@ public final class EdayunCaseMarkDtos { public static final class PrintCaseMarkResponse { public Integer code; public String msg; - /** 箱唛 PDF 地址。 */ + /** 条码文件地址(PDF)。 */ public String data; - public String traceId; + /** 文档标为 object,实际是字符串 {@code "null"};保留 Object 避免解析失败。 */ + public Object traceId; } } diff --git a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunSkuLabelDtos.java b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunSkuLabelDtos.java new file mode 100644 index 0000000..64ffb89 --- /dev/null +++ b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunSkuLabelDtos.java @@ -0,0 +1,69 @@ +package common.ecommerce.edayun.dto; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import java.util.List; + +/** + * 易达云报文结构:打印 SKU 标 + * ({@code POST /webApi/entryInfo/v1/newPrintCaseMarkContentType})。 + * + *

一个文件对应一个接口。响应 {@code data} 是PDF 地址字符串,同步生成。

+ * + *

接口名与语义不一致:端点叫 {@code newPrintCaseMark}(箱唛), + * 但实际打的是 SKU 标。已与仓方确认,不要被路径名误导。

+ * + *

选箱条件四选一(文档原文:箱序号 / 客户箱号 / sku 编码 / 系统箱号 + * 必须有一个不为空):

+ *
    + *
  • 系统箱号:{@code caseCodeList}
  • + *
  • SKU:{@code skuCode}
  • + *
  • 箱序号区间:{@code startCaseSerialNo} ~ {@code endCaseSerialNo}
  • + *
  • 客户箱号区间:{@code startSellerCaseNo} ~ {@code endSellerCaseNo}
  • + *
+ */ +public final class EdayunSkuLabelDtos { + + private EdayunSkuLabelDtos() { + } + + /** 打印 SKU 标请求。 */ + @JsonInclude(JsonInclude.Include.NON_NULL) + public static final class PrintSkuLabelRequest { + + /** EDA 入库单号(REV 单号)。必填。 */ + public String entryCode; + + /** 系统箱号列表(如 {@code B00231164777837})。 */ + public List caseCodeList; + /** SKU 编码。 */ + public String skuCode; + /** 箱序号开始。 */ + public String startCaseSerialNo; + /** 箱序号结束。 */ + public String endCaseSerialNo; + /** 开始打印的客户箱号。 */ + public String startSellerCaseNo; + /** 结束打印的客户箱号。 */ + public String endSellerCaseNo; + + /** 纸张尺寸:2 100×150 / 4 100×100 / 5 A4。必填。 */ + public Integer pageSize; + /** 是否需要 Made in China:0 否 / 1 是。必填。 */ + public Integer madeInChina; + /** 是否打印分隔符(第一页与下一页不一致时插提示页)。必填。 */ + public Boolean separation; + /** 每箱打印两份:0 否 / 1 是。 */ + public Integer twoPrint; + } + + /** 打印响应。 */ + @JsonInclude(JsonInclude.Include.NON_NULL) + public static final class PrintSkuLabelResponse { + public Integer code; + public String msg; + /** 箱唛 PDF 地址。 */ + public String data; + public String traceId; + } +} diff --git a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/enums/EdayunCaseMarkPaper.java b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/enums/EdayunSkuLabelPaper.java similarity index 84% rename from warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/enums/EdayunCaseMarkPaper.java rename to warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/enums/EdayunSkuLabelPaper.java index 1f0fdd8..1708e60 100644 --- a/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/enums/EdayunCaseMarkPaper.java +++ b/warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/enums/EdayunSkuLabelPaper.java @@ -3,7 +3,7 @@ package common.ecommerce.edayun.enums; import common.ecommerce.warehouse.enums.LabelSizeType; /** - * 易达云箱唛纸张尺寸({@code newPrintCaseMark} 的 {@code pageSize})。 + * 易达云 SKU 标纸张尺寸({@code newPrintCaseMark} 的 {@code pageSize})。 * *

只有三档,且码值与统一枚举 {@link LabelSizeType} 完全不同:

* @@ -15,7 +15,7 @@ import common.ecommerce.warehouse.enums.LabelSizeType; * *

注意码值不连续(4 / 2 / 5),不要按顺序推。

*/ -public enum EdayunCaseMarkPaper { +public enum EdayunSkuLabelPaper { /** 4:100×100mm。 */ SIZE_100_100(4, "100×100", LabelSizeType.SIZE_100_100), @@ -28,7 +28,7 @@ public enum EdayunCaseMarkPaper { private final String label; private final LabelSizeType core; - EdayunCaseMarkPaper(int code, String label, LabelSizeType core) { + EdayunSkuLabelPaper(int code, String label, LabelSizeType core) { this.code = code; this.label = label; this.core = core; @@ -48,8 +48,8 @@ public enum EdayunCaseMarkPaper { } /** 统一尺寸 → 易达云码值;不支持的尺寸显式拒绝。 */ - public static EdayunCaseMarkPaper of(LabelSizeType size) { - for (EdayunCaseMarkPaper v : values()) { + public static EdayunSkuLabelPaper of(LabelSizeType size) { + for (EdayunSkuLabelPaper v : values()) { if (v.core == size) { return v; } diff --git a/warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunBarcodeTest.java b/warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunBarcodeTest.java deleted file mode 100644 index 4eea93a..0000000 --- a/warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunBarcodeTest.java +++ /dev/null @@ -1,166 +0,0 @@ -package common.ecommerce.edayun.adapter; - -import common.ecommerce.edayun.dto.EdayunBarcodeDtos; -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.BarcodePaperSize; -import common.ecommerce.warehouse.enums.WarehouseProvider; -import common.ecommerce.warehouse.model.BarcodePrintCommand; -import common.ecommerce.warehouse.model.WarehouseLabel; -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * 打印条码({@code /webApi/skuInfo/v2/printBarcode})映射。 - * - *

重点:响应 data 是文件地址、同步返回(不是任务号)、50 个 SKU 上限。

- */ -class EdayunBarcodeTest { - - 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-barcode", CLOCK); - } - - private static RecordingTransport stub(String body) { - return RecordingTransport.create() - .route(common.ecommerce.edayun.EdayunConstants.PATH_TOKEN, req -> Responses.ok( - "{\"access_token\":\"T1\",\"token_type\":\"bearer\"}")) - .route(common.ecommerce.edayun.EdayunConstants.PATH_BARCODE_PRINT, - req -> Responses.ok(body)); - } - - private static BarcodePrintCommand command() { - return BarcodePrintCommand.builder() - .paperSize(BarcodePaperSize.SIZE_70_30) - .remark("Made in China") - .printSkuName(false) - .item("ybtest", 2) - .build(); - } - - // ------------------------------------------------------------ 请求 - - @Test - void mapsRequest() { - EdayunBarcodeDtos.PrintBarcodeRequest req = EdayunBarcodeMapper.toRequest(command()); - - assertEquals(Integer.valueOf(0), req.pageSize); - assertEquals("Made in China", req.remark); - assertEquals(1, req.productInfos.size()); - assertEquals("ybtest", req.productInfos.get(0).skuCode); - assertEquals(Integer.valueOf(2), req.productInfos.get(0).num); - } - - /** isPrintSkuName 只在 true 时下发,false 交给仓方默认。 */ - @Test - void printSkuNameOnlySentWhenTrue() { - assertNull(EdayunBarcodeMapper.toRequest(command()).isPrintSkuName); - - BarcodePrintCommand withName = BarcodePrintCommand.builder() - .paperSize(BarcodePaperSize.A4) - .printSkuName(true) - .item("sku", 1) - .build(); - assertEquals(Boolean.TRUE, EdayunBarcodeMapper.toRequest(withName).isPrintSkuName); - } - - @Test - void paperSizesMap() { - assertEquals(0, BarcodePaperSize.SIZE_70_30.code()); - assertEquals(1, BarcodePaperSize.SIZE_100_60.code()); - assertEquals(2, BarcodePaperSize.SIZE_60_40.code()); - assertEquals(3, BarcodePaperSize.A4.code()); - } - - /** 超过 50 个 SKU 本地就挡,不发请求(仓方也会报「最多打印50个SKU」)。 */ - @Test - void moreThan50SkusRejectedLocally() { - BarcodePrintCommand.Builder b = BarcodePrintCommand.builder() - .paperSize(BarcodePaperSize.A4); - for (int i = 0; i < 51; i++) { - b.item("SKU-" + i, 1); - } - - IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> EdayunBarcodeMapper.toRequest(b.build())); - - assertTrue(ex.getMessage().contains("at most 50"), ex.getMessage()); - } - - /** 空 SKU 列表与非法份数在命令构造期就被拒。 */ - @Test - void invalidCommandRejectedAtConstruction() { - assertThrows(IllegalArgumentException.class, - () -> BarcodePrintCommand.builder().paperSize(BarcodePaperSize.A4).build()); - assertThrows(IllegalArgumentException.class, - () -> BarcodePrintCommand.builder().paperSize(BarcodePaperSize.A4) - .item("sku", 0)); - assertThrows(IllegalArgumentException.class, - () -> BarcodePrintCommand.builder().paperSize(BarcodePaperSize.A4) - .item(" ", 1)); - // 缺纸张尺寸 - assertThrows(IllegalArgumentException.class, - () -> BarcodePrintCommand.builder().item("sku", 1).build()); - } - - // ------------------------------------------------------------ 响应 - - /** data 是文件地址字符串,直接落 WarehouseLabel.url。 */ - @Test - void responseDataIsFileUrl() { - RecordingTransport transport = stub("{\"code\":200,\"msg\":\"操作成功\"," - + "\"data\":\"https://oss.edayun.com/barcode1.pdf\",\"traceId\":null}"); - - WarehouseLabel label = new EdayunAdapter(transport, new JacksonJsonCodec()) - .printBarcodes(ctx(), command()); - - assertEquals("https://oss.edayun.com/barcode1.pdf", label.url()); - assertEquals("PDF", label.format()); - assertNull(label.contentBase64()); - assertTrue(transport.lastDataRequest().body().contains("\"skuCode\":\"ybtest\"")); - } - - /** code=200 但 data 为空 → 抛异常,不能返回没有文件的对象。 */ - @Test - void blankDataFails() { - RecordingTransport transport = stub( - "{\"code\":200,\"msg\":\"操作成功\",\"data\":\" \"}"); - - assertThrows(RuntimeException.class, - () -> new EdayunAdapter(transport, new JacksonJsonCodec()) - .printBarcodes(ctx(), command())); - } - - /** 仓方业务错误(如 SKU 不存在)要抛异常并带出原因。 */ - @Test - void businessErrorFails() { - RecordingTransport transport = stub( - "{\"code\":500,\"msg\":\"sku=NO-SUCH信息不存在\",\"data\":null}"); - - try { - new EdayunAdapter(transport, new JacksonJsonCodec()) - .printBarcodes(ctx(), command()); - org.junit.jupiter.api.Assertions.fail("should have thrown"); - } catch (RuntimeException e) { - assertTrue(e.getMessage().contains("SKU") || e.getMessage().contains("sku"), e.getMessage()); - } - } -} diff --git a/warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunCaseMarkTest.java b/warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunCaseMarkTest.java index 7a89362..dbae2a7 100644 --- a/warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunCaseMarkTest.java +++ b/warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunCaseMarkTest.java @@ -1,158 +1,166 @@ package common.ecommerce.edayun.adapter; import common.ecommerce.edayun.dto.EdayunCaseMarkDtos; -import common.ecommerce.edayun.enums.EdayunCaseMarkPaper; -import common.ecommerce.warehouse.enums.LabelDownloadMode; -import common.ecommerce.warehouse.enums.LabelSizeType; -import common.ecommerce.warehouse.enums.LabelsPerPage; -import common.ecommerce.warehouse.model.BoxLabelCommand; +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.CaseMarkPaperSize; +import common.ecommerce.warehouse.enums.WarehouseProvider; +import common.ecommerce.warehouse.model.CaseMarkPrintCommand; import common.ecommerce.warehouse.model.WarehouseLabel; +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 static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; /** - * 箱唛打印({@code newPrintCaseMarkContentType})映射。 + * 箱唛打印({@code /webApi/skuInfo/v2/printBarcode})映射。 * - *

重点:码值不连续(4/2/5)、统一模型只能表达整单打印、 - * Made in China 与分隔符默认关。

+ *

重点:响应 data 是文件地址、同步返回(不是任务号)、50 个 SKU 上限。

*/ class EdayunCaseMarkTest { - private static BoxLabelCommand command(LabelSizeType size) { - return BoxLabelCommand.builder() - .providerInboundNo("REV0023116477") - .inboundRequestNo("IB-001") - .sizeType(size) - .labelsPerPage(LabelsPerPage.ONE) - .downloadMode(LabelDownloadMode.PDF) - .twoCopies(true) - .build(); - } - - // ------------------------------------------------------------ 纸张映射 + private static final Clock CLOCK = Clock.fixed(Instant.parse("2026-11-16T00:00:00Z"), ZoneOffset.UTC); - /** 易达云码值不连续:100×100=4、100×150=2、A4=5。 */ - @Test - void paperCodesAreNotSequential() { - assertEquals(4, EdayunCaseMarkPaper.SIZE_100_100.code()); - assertEquals(2, EdayunCaseMarkPaper.SIZE_100_150.code()); - assertEquals(5, EdayunCaseMarkPaper.A4.code()); + 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-barcode", CLOCK); } - @Test - void mapsCoreSizes() { - assertEquals(EdayunCaseMarkPaper.SIZE_100_100, - EdayunCaseMarkPaper.of(LabelSizeType.SIZE_100_100)); - assertEquals(EdayunCaseMarkPaper.SIZE_100_150, - EdayunCaseMarkPaper.of(LabelSizeType.SIZE_100_150)); - assertEquals(LabelSizeType.SIZE_100_100, - EdayunCaseMarkPaper.SIZE_100_100.core()); - assertEquals(LabelSizeType.A4, EdayunCaseMarkPaper.A4.core()); + private static RecordingTransport stub(String body) { + return RecordingTransport.create() + .route(common.ecommerce.edayun.EdayunConstants.PATH_TOKEN, req -> Responses.ok( + "{\"access_token\":\"T1\",\"token_type\":\"bearer\"}")) + .route(common.ecommerce.edayun.EdayunConstants.PATH_CASE_MARK_PRINT, + req -> Responses.ok(body)); } - /** 统一模型的 104×98(美国信纸)易达云不支持,要显式拒绝。 */ - @Test - void unsupportedSizeIsRejected() { - IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> EdayunCaseMarkPaper.of(LabelSizeType.SIZE_104_98)); - assertTrue(ex.getMessage().contains("only 100x100 / 100x150 / A4"), ex.getMessage()); + private static CaseMarkPrintCommand command() { + return CaseMarkPrintCommand.builder() + .paperSize(CaseMarkPaperSize.SIZE_70_30) + .remark("Made in China") + .printSkuName(false) + .item("ybtest", 2) + .build(); } // ------------------------------------------------------------ 请求 @Test - void mapsWholeOrderPrint() { - EdayunCaseMarkDtos.PrintCaseMarkRequest req = - EdayunCaseMarkMapper.toRequest(command(LabelSizeType.SIZE_100_100)); - - assertEquals("REV0023116477", req.entryCode); - assertEquals(Integer.valueOf(4), req.pageSize); - assertEquals(Integer.valueOf(EdayunCaseMarkMapper.MADE_IN_CHINA_NO), req.madeInChina); - assertEquals(Boolean.FALSE, req.separation); - assertEquals(Integer.valueOf(1), req.twoPrint); - // 统一模型没有选箱字段,默认整单 - assertNull(req.caseCodeList); - assertNull(req.skuCode); - assertNull(req.startCaseSerialNo); + void mapsRequest() { + EdayunCaseMarkDtos.PrintCaseMarkRequest req = EdayunCaseMarkMapper.toRequest(command()); + + assertEquals(Integer.valueOf(0), req.pageSize); + assertEquals("Made in China", req.remark); + assertEquals(1, req.productInfos.size()); + assertEquals("ybtest", req.productInfos.get(0).skuCode); + assertEquals(Integer.valueOf(2), req.productInfos.get(0).num); } - /** 一箱一份时 twoPrint=0。 */ + /** isPrintSkuName 只在 true 时下发,false 交给仓方默认。 */ @Test - void singleCopyMapsZero() { - BoxLabelCommand one = BoxLabelCommand.builder() - .providerInboundNo("REV1").inboundRequestNo("IB-1") - .sizeType(LabelSizeType.SIZE_100_150) - .labelsPerPage(LabelsPerPage.ONE) - .build(); + void printSkuNameOnlySentWhenTrue() { + assertNull(EdayunCaseMarkMapper.toRequest(command()).isPrintSkuName); - assertEquals(Integer.valueOf(0), EdayunCaseMarkMapper.toRequest(one).twoPrint); + CaseMarkPrintCommand withName = CaseMarkPrintCommand.builder() + .paperSize(CaseMarkPaperSize.SIZE_60_40) + .printSkuName(true) + .item("sku", 1) + .build(); + assertEquals(Boolean.TRUE, EdayunCaseMarkMapper.toRequest(withName).isPrintSkuName); } - /** Made in China 与分隔符是易达云特有语义,统一模型没有 → 默认关。 */ @Test - void madeInChinaAndSeparationDefaultOff() { - EdayunCaseMarkDtos.PrintCaseMarkRequest req = - EdayunCaseMarkMapper.toRequest(command(LabelSizeType.SIZE_100_150)); - - assertEquals(Integer.valueOf(0), req.madeInChina); - assertEquals(Boolean.FALSE, req.separation); + void paperSizesMap() { + assertEquals(0, CaseMarkPaperSize.SIZE_70_30.code()); + assertEquals(1, CaseMarkPaperSize.SIZE_100_60.code()); + assertEquals(2, CaseMarkPaperSize.SIZE_100_150.code()); + assertEquals(3, CaseMarkPaperSize.SIZE_60_40.code()); } - // ------------------------------------------------------------ 选箱 - + /** 超过 50 个 SKU 本地就挡,不发请求(仓方也会报「最多打印50个SKU」)。 */ @Test - void mapsCaseCodes() { - EdayunCaseMarkMapper.CaseSelection sel = new EdayunCaseMarkMapper.CaseSelection() - .caseCodes(java.util.Arrays.asList("B001", "B002")); - - EdayunCaseMarkDtos.PrintCaseMarkRequest req = EdayunCaseMarkMapper.toRequest( - command(LabelSizeType.SIZE_100_100), sel); + void moreThan50SkusRejectedLocally() { + CaseMarkPrintCommand.Builder b = CaseMarkPrintCommand.builder() + .paperSize(CaseMarkPaperSize.SIZE_60_40); + for (int i = 0; i < 51; i++) { + b.item("SKU-" + i, 1); + } - assertEquals(java.util.Arrays.asList("B001", "B002"), req.caseCodeList); - } + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, + () -> EdayunCaseMarkMapper.toRequest(b.build())); - @Test - void mapsRangesAndSku() { - EdayunCaseMarkMapper.CaseSelection sel = new EdayunCaseMarkMapper.CaseSelection() - .skuCode("SKU-1") - .caseSerialRange("1", "2") - .sellerCaseRange("S1", "S2"); - - EdayunCaseMarkDtos.PrintCaseMarkRequest req = EdayunCaseMarkMapper.toRequest( - command(LabelSizeType.A4), sel); - - assertEquals("SKU-1", req.skuCode); - assertEquals("1", req.startCaseSerialNo); - assertEquals("2", req.endCaseSerialNo); - assertEquals("S1", req.startSellerCaseNo); - assertEquals("S2", req.endSellerCaseNo); - // A4 码值是 5 - assertEquals(Integer.valueOf(5), req.pageSize); + assertTrue(ex.getMessage().contains("at most 50"), ex.getMessage()); } - /** 选箱条件全空时本地拒——仓方要求四选一。 */ + /** 空 SKU 列表与非法份数在命令构造期就被拒。 */ @Test - void emptySelectionIsRejected() { + void invalidCommandRejectedAtConstruction() { + assertThrows(IllegalArgumentException.class, + () -> CaseMarkPrintCommand.builder().paperSize(CaseMarkPaperSize.SIZE_60_40).build()); assertThrows(IllegalArgumentException.class, - () -> EdayunCaseMarkMapper.toRequest(command(LabelSizeType.SIZE_100_100), - new EdayunCaseMarkMapper.CaseSelection())); + () -> CaseMarkPrintCommand.builder().paperSize(CaseMarkPaperSize.SIZE_60_40) + .item("sku", 0)); assertThrows(IllegalArgumentException.class, - () -> EdayunCaseMarkMapper.toRequest(command(LabelSizeType.SIZE_100_100), null)); + () -> CaseMarkPrintCommand.builder().paperSize(CaseMarkPaperSize.SIZE_60_40) + .item(" ", 1)); + // 缺纸张尺寸 + assertThrows(IllegalArgumentException.class, + () -> CaseMarkPrintCommand.builder().item("sku", 1).build()); } // ------------------------------------------------------------ 响应 - /** 响应 data 是 PDF 地址,同步返回(不是任务号)。 */ + /** data 是文件地址字符串,直接落 WarehouseLabel.url。 */ @Test - void labelCarriesUrl() { - WarehouseLabel label = EdayunCaseMarkMapper.toLabel("https://oss/case.pdf"); + void responseDataIsFileUrl() { + RecordingTransport transport = stub("{\"code\":200,\"msg\":\"操作成功\"," + + "\"data\":\"https://oss.edayun.com/barcode1.pdf\",\"traceId\":null}"); + + WarehouseLabel label = new EdayunAdapter(transport, new JacksonJsonCodec()) + .printCaseMarks(ctx(), command()); - assertEquals("https://oss/case.pdf", label.url()); + assertEquals("https://oss.edayun.com/barcode1.pdf", label.url()); assertEquals("PDF", label.format()); assertNull(label.contentBase64()); + assertTrue(transport.lastDataRequest().body().contains("\"skuCode\":\"ybtest\"")); + } + + /** code=200 但 data 为空 → 抛异常,不能返回没有文件的对象。 */ + @Test + void blankDataFails() { + RecordingTransport transport = stub( + "{\"code\":200,\"msg\":\"操作成功\",\"data\":\" \"}"); + + assertThrows(RuntimeException.class, + () -> new EdayunAdapter(transport, new JacksonJsonCodec()) + .printCaseMarks(ctx(), command())); + } + + /** 仓方业务错误(如 SKU 不存在)要抛异常并带出原因。 */ + @Test + void businessErrorFails() { + RecordingTransport transport = stub( + "{\"code\":500,\"msg\":\"sku=NO-SUCH信息不存在\",\"data\":null}"); + + try { + new EdayunAdapter(transport, new JacksonJsonCodec()) + .printCaseMarks(ctx(), command()); + org.junit.jupiter.api.Assertions.fail("should have thrown"); + } catch (RuntimeException e) { + assertTrue(e.getMessage().contains("SKU") || e.getMessage().contains("sku"), e.getMessage()); + } } } diff --git a/warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunSkuLabelTest.java b/warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunSkuLabelTest.java new file mode 100644 index 0000000..845a4e7 --- /dev/null +++ b/warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunSkuLabelTest.java @@ -0,0 +1,158 @@ +package common.ecommerce.edayun.adapter; + +import common.ecommerce.edayun.dto.EdayunSkuLabelDtos; +import common.ecommerce.edayun.enums.EdayunSkuLabelPaper; +import common.ecommerce.warehouse.enums.LabelDownloadMode; +import common.ecommerce.warehouse.enums.LabelSizeType; +import common.ecommerce.warehouse.enums.LabelsPerPage; +import common.ecommerce.warehouse.model.BoxLabelCommand; +import common.ecommerce.warehouse.model.WarehouseLabel; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * SKU 标打印({@code newPrintCaseMarkContentType})映射。 + * + *

重点:码值不连续(4/2/5)、统一模型只能表达整单打印、 + * Made in China 与分隔符默认关。

+ */ +class EdayunSkuLabelTest { + + private static BoxLabelCommand command(LabelSizeType size) { + return BoxLabelCommand.builder() + .providerInboundNo("REV0023116477") + .inboundRequestNo("IB-001") + .sizeType(size) + .labelsPerPage(LabelsPerPage.ONE) + .downloadMode(LabelDownloadMode.PDF) + .twoCopies(true) + .build(); + } + + // ------------------------------------------------------------ 纸张映射 + + /** 易达云码值不连续:100×100=4、100×150=2、A4=5。 */ + @Test + void paperCodesAreNotSequential() { + assertEquals(4, EdayunSkuLabelPaper.SIZE_100_100.code()); + assertEquals(2, EdayunSkuLabelPaper.SIZE_100_150.code()); + assertEquals(5, EdayunSkuLabelPaper.A4.code()); + } + + @Test + void mapsCoreSizes() { + assertEquals(EdayunSkuLabelPaper.SIZE_100_100, + EdayunSkuLabelPaper.of(LabelSizeType.SIZE_100_100)); + assertEquals(EdayunSkuLabelPaper.SIZE_100_150, + EdayunSkuLabelPaper.of(LabelSizeType.SIZE_100_150)); + assertEquals(LabelSizeType.SIZE_100_100, + EdayunSkuLabelPaper.SIZE_100_100.core()); + assertEquals(LabelSizeType.A4, EdayunSkuLabelPaper.A4.core()); + } + + /** 统一模型的 104×98(美国信纸)易达云不支持,要显式拒绝。 */ + @Test + void unsupportedSizeIsRejected() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, + () -> EdayunSkuLabelPaper.of(LabelSizeType.SIZE_104_98)); + assertTrue(ex.getMessage().contains("only 100x100 / 100x150 / A4"), ex.getMessage()); + } + + // ------------------------------------------------------------ 请求 + + @Test + void mapsWholeOrderPrint() { + EdayunSkuLabelDtos.PrintSkuLabelRequest req = + EdayunSkuLabelMapper.toRequest(command(LabelSizeType.SIZE_100_100)); + + assertEquals("REV0023116477", req.entryCode); + assertEquals(Integer.valueOf(4), req.pageSize); + assertEquals(Integer.valueOf(EdayunSkuLabelMapper.MADE_IN_CHINA_NO), req.madeInChina); + assertEquals(Boolean.FALSE, req.separation); + assertEquals(Integer.valueOf(1), req.twoPrint); + // 统一模型没有选箱字段,默认整单 + assertNull(req.caseCodeList); + assertNull(req.skuCode); + assertNull(req.startCaseSerialNo); + } + + /** 一箱一份时 twoPrint=0。 */ + @Test + void singleCopyMapsZero() { + BoxLabelCommand one = BoxLabelCommand.builder() + .providerInboundNo("REV1").inboundRequestNo("IB-1") + .sizeType(LabelSizeType.SIZE_100_150) + .labelsPerPage(LabelsPerPage.ONE) + .build(); + + assertEquals(Integer.valueOf(0), EdayunSkuLabelMapper.toRequest(one).twoPrint); + } + + /** Made in China 与分隔符是易达云特有语义,统一模型没有 → 默认关。 */ + @Test + void madeInChinaAndSeparationDefaultOff() { + EdayunSkuLabelDtos.PrintSkuLabelRequest req = + EdayunSkuLabelMapper.toRequest(command(LabelSizeType.SIZE_100_150)); + + assertEquals(Integer.valueOf(0), req.madeInChina); + assertEquals(Boolean.FALSE, req.separation); + } + + // ------------------------------------------------------------ 选箱 + + @Test + void mapsCaseCodes() { + EdayunSkuLabelMapper.CaseSelection sel = new EdayunSkuLabelMapper.CaseSelection() + .caseCodes(java.util.Arrays.asList("B001", "B002")); + + EdayunSkuLabelDtos.PrintSkuLabelRequest req = EdayunSkuLabelMapper.toRequest( + command(LabelSizeType.SIZE_100_100), sel); + + assertEquals(java.util.Arrays.asList("B001", "B002"), req.caseCodeList); + } + + @Test + void mapsRangesAndSku() { + EdayunSkuLabelMapper.CaseSelection sel = new EdayunSkuLabelMapper.CaseSelection() + .skuCode("SKU-1") + .caseSerialRange("1", "2") + .sellerCaseRange("S1", "S2"); + + EdayunSkuLabelDtos.PrintSkuLabelRequest req = EdayunSkuLabelMapper.toRequest( + command(LabelSizeType.A4), sel); + + assertEquals("SKU-1", req.skuCode); + assertEquals("1", req.startCaseSerialNo); + assertEquals("2", req.endCaseSerialNo); + assertEquals("S1", req.startSellerCaseNo); + assertEquals("S2", req.endSellerCaseNo); + // A4 码值是 5 + assertEquals(Integer.valueOf(5), req.pageSize); + } + + /** 选箱条件全空时本地拒——仓方要求四选一。 */ + @Test + void emptySelectionIsRejected() { + assertThrows(IllegalArgumentException.class, + () -> EdayunSkuLabelMapper.toRequest(command(LabelSizeType.SIZE_100_100), + new EdayunSkuLabelMapper.CaseSelection())); + assertThrows(IllegalArgumentException.class, + () -> EdayunSkuLabelMapper.toRequest(command(LabelSizeType.SIZE_100_100), null)); + } + + // ------------------------------------------------------------ 响应 + + /** 响应 data 是 PDF 地址,同步返回(不是任务号)。 */ + @Test + void labelCarriesUrl() { + WarehouseLabel label = EdayunSkuLabelMapper.toLabel("https://oss/case.pdf"); + + assertEquals("https://oss/case.pdf", label.url()); + assertEquals("PDF", label.format()); + assertNull(label.contentBase64()); + } +} diff --git a/warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/probe/EdayunBarcodeProbeTest.java b/warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/probe/EdayunCaseMarkProbeTest.java similarity index 86% rename from warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/probe/EdayunBarcodeProbeTest.java rename to warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/probe/EdayunCaseMarkProbeTest.java index 9434e35..94af220 100644 --- a/warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/probe/EdayunBarcodeProbeTest.java +++ b/warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/probe/EdayunCaseMarkProbeTest.java @@ -2,15 +2,15 @@ package common.ecommerce.edayun.probe; import common.ecommerce.edayun.EdayunConstants; import common.ecommerce.edayun.adapter.EdayunAdapter; -import common.ecommerce.edayun.adapter.EdayunBarcodeMapper; -import common.ecommerce.edayun.dto.EdayunBarcodeDtos; +import common.ecommerce.edayun.adapter.EdayunCaseMarkMapper; +import common.ecommerce.edayun.dto.EdayunCaseMarkDtos; 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.BarcodePaperSize; +import common.ecommerce.warehouse.enums.CaseMarkPaperSize; import common.ecommerce.warehouse.enums.WarehouseProvider; -import common.ecommerce.warehouse.model.BarcodePrintCommand; +import common.ecommerce.warehouse.model.CaseMarkPrintCommand; import common.ecommerce.warehouse.model.WarehouseLabel; import common.ecommerce.warehouse.sdk.WarehouseConnection; import common.ecommerce.warehouse.sdk.WarehouseContext; @@ -22,7 +22,7 @@ import java.time.Clock; import java.util.UUID; /** - * 打印条码联调探针:只读(生成 PDF,不改仓侧业务数据)。 + * 箱唛打印联调探针:只读(生成 PDF,不改仓侧业务数据)。 * *
  * # 只看报文(不联网)
@@ -37,7 +37,7 @@ import java.util.UUID;
  * 
*/ @EnabledIfSystemProperty(named = "edayun.probe.barcode", matches = "true") -class EdayunBarcodeProbeTest { +class EdayunCaseMarkProbeTest { 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", ""); @@ -49,18 +49,18 @@ class EdayunBarcodeProbeTest { @Test void probePrintBarcode() { - BarcodePrintCommand cmd = BarcodePrintCommand.builder() - .paperSize(BarcodePaperSize.A4) + CaseMarkPrintCommand cmd = CaseMarkPrintCommand.builder() + .paperSize(CaseMarkPaperSize.SIZE_60_40) .remark("PROBE") .printSkuName(true) .item(SKU, 1) .build(); - EdayunBarcodeDtos.PrintBarcodeRequest req = EdayunBarcodeMapper.toRequest(cmd); + EdayunCaseMarkDtos.PrintCaseMarkRequest req = EdayunCaseMarkMapper.toRequest(cmd); String bodyJson = new JacksonJsonCodec().toJson(req); System.out.println("\n================ edayun / POST " - + EdayunConstants.PATH_BARCODE_PRINT + " ================"); + + EdayunConstants.PATH_CASE_MARK_PRINT + " ================"); System.out.println("[probe] baseUrl=" + BASE_URL + " sku=" + SKU); System.out.println("[request] " + bodyJson); @@ -81,7 +81,7 @@ class EdayunBarcodeProbeTest { new OkHttpTransport("common-ecommerce/1.0.0 (edayun-probe)", 10_000, 60_000), new JacksonJsonCodec()); - WarehouseLabel label = adapter.printBarcodes(ctx, cmd); + WarehouseLabel label = adapter.printCaseMarks(ctx, cmd); System.out.println("[OK] labelId=" + label.labelId() + " format=" + label.format() + " url=" + label.url()); } catch (RuntimeException e) {