Browse Source

feat(edayun): 对接打印箱唛(真机未启用)

POST /webApi/entryInfo/v1/newPrintCaseMarkContentType → WarehouseLabel

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

纸张码值不连续:100×100=4、100×150=2、A4=5。统一枚举 LabelSizeType 原来
只有 100×100 / 100×150 / 104×98,这次补 A4(运去哪不支持 A4,不影响它)。

统一模型的 BoxLabelCommand 没有「选哪些箱」,所以默认整单打印;
部分箱用 printCaseMarks 的 CaseSelection 重载(系统箱号 / SKU /
箱序号区间 / 客户箱号区间四选一,全空本地拒)。

madeInChina 与 separation 是易达云特有语义、统一模型没有对应概念,默认关——
猜「打」会让每箱多一行。

真机(2026-11-16):该接口在 PR 环境报「接口不存在或未启用」;
去掉 ContentType 后缀的 newPrintCaseMark 能过参数校验(缺 pageSize 报
「纸张不能为空」、缺 madeInChina 报「产地标签不能为空」),但补全后一律
「内部服务器错误」。所以映射是按文档写的,只有单测覆盖,见 TODO #68。

Co-Authored-By: Claude <noreply@anthropic.com>
master
chenchuchuan 4 days ago
parent
commit
fed2c0d4fc
  1. 64
      docs-warehouse/edayun/README.md
  2. 4
      docs-warehouse/edayun/TODO.md
  3. 6
      warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/enums/LabelSizeType.java
  4. 3
      warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/EdayunConstants.java
  5. 60
      warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunAdapter.java
  6. 127
      warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunCaseMarkMapper.java
  7. 67
      warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunCaseMarkDtos.java
  8. 61
      warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/enums/EdayunCaseMarkPaper.java
  9. 158
      warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunCaseMarkTest.java

64
docs-warehouse/edayun/README.md

@ -28,6 +28,7 @@
| 物流产品清单 | ✅ 已对接(`POST /webApi/order/listByLogisticProductHasPerm`) | | 物流产品清单 | ✅ 已对接(`POST /webApi/order/listByLogisticProductHasPerm`) |
| 物流轨迹 | ✅ 已对接(`POST /webApi/track/getTrackInfoList`) | | 物流轨迹 | ✅ 已对接(`POST /webApi/track/getTrackInfoList`) |
| 打印条码 | ✅ 已对接(`POST /webApi/skuInfo/v2/printBarcode`) | | 打印条码 | ✅ 已对接(`POST /webApi/skuInfo/v2/printBarcode`) |
| 打印箱唛 | ⚠️ 已实现(`POST /webApi/entryInfo/v1/newPrintCaseMarkContentType`),**真机未启用** |
| 其它业务接口 | ⬜ 等文档 | | 其它业务接口 | ⬜ 等文档 |
| 回调 | ⬜ 等文档 | | 回调 | ⬜ 等文档 |
| 真机验证 | ⬜ 等测试环境 | | 真机验证 | ⬜ 等测试环境 |
@ -1197,6 +1198,69 @@ POST /webApi/skuInfo/v2/printBarcode → WarehouseLabel
四种纸张尺寸都返回 `code=200`。 四种纸张尺寸都返回 `code=200`。
## 打印箱唛
```
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")));
```
四个维度全空时本地拒绝——文档写明「必须有一个不为空」。
### 两个易达云特有开关默认关
| 字段 | 默认 | 原因 |
|---|---|---|
| `madeInChina` | 0 否 | 统一模型没有「原产地标注」概念,猜「打」会让每箱多一行 |
| `separation` | false | 分隔符是易达云特有的分页提示,统一模型没有对应语义 |
### 返回同步 PDF
响应 `data` 是地址字符串,不是任务号——所以返回 `WarehouseLabel` 而不是
`LabelPrintTask`(那个是运去哪风格的异步任务语义)。
## 待确认(问易达云) ## 待确认(问易达云)
| # | 要确认 | | # | 要确认 |

4
docs-warehouse/edayun/TODO.md

@ -67,6 +67,10 @@
| 65 | 条码打印的纸张尺寸只有 4 档(7×3/10×6/6×4/A4),与入库贴标的 14 种不重叠 | 独立枚举 `BarcodePaperSize` | 宿主换标签纸时要选对枚举 | | 65 | 条码打印的纸张尺寸只有 4 档(7×3/10×6/6×4/A4),与入库贴标的 14 种不重叠 | 独立枚举 `BarcodePaperSize` | 宿主换标签纸时要选对枚举 |
| 66 | 条码文件地址的**有效期**未知(OSS 链接) | 原样返回,不缓存 | 宿主存旧链接可能 403 | | 66 | 条码文件地址的**有效期**未知(OSS 链接) | 原样返回,不缓存 | 宿主存旧链接可能 403 |
| 67 | 条码打印是否有限流 / 是否计费 | 未处理 | 大批量打印可能被限 | | 67 | 条码打印是否有限流 / 是否计费 | 未处理 | 大批量打印可能被限 |
| 68 | **箱唛接口在 PR 环境未启用**(`newPrintCaseMarkContentType` 报「接口不存在或未启用」;去掉后缀的 `newPrintCaseMark` 能过参数校验但一律「内部服务器错误」) | 按文档实现,映射只有单测 | 上线前必须真机验证 |
| 69 | 箱唛纸张码值 4/2/5 不连续 | 独立枚举 `EdayunCaseMarkPaper`,按映射表走 | 无(已规避) |
| 70 | 箱唛的 `madeInChina` / `separation` 统一模型没有语义 | 默认关 | 需要打「Made in China」时得走扩展重载 |
| 71 | 箱唛选箱条件(系统箱号 / SKU / 箱序号 / 客户箱号)统一模型没有 | 提供 `CaseSelection` 扩展重载 | 宿主想要部分箱打印必须用易达云专有 API |
|---|---|---|---| |---|---|---|---|
## 待业务确认 ## 待业务确认

6
warehouse-sdk-core/src/main/java/common/ecommerce/warehouse/enums/LabelSizeType.java

@ -13,7 +13,9 @@ public enum LabelSizeType {
/** 100mm × 150mm。 */ /** 100mm × 150mm。 */
SIZE_100_150(20, "100×150"), SIZE_100_150(20, "100×150"),
/** 104mm × 98mm(美国信纸)。 */ /** 104mm × 98mm(美国信纸)。 */
SIZE_104_98(30, "104×98(美国信纸)"); SIZE_104_98(30, "104×98(美国信纸)"),
/** A4(210mm × 297mm);易达云箱唛支持,运去哪不支持。 */
A4(40, "A4");
private final int code; private final int code;
private final String label; private final String label;
@ -45,7 +47,7 @@ public enum LabelSizeType {
/** 是否可用于每页 1 个的排版。 */ /** 是否可用于每页 1 个的排版。 */
public boolean singlePerPage() { public boolean singlePerPage() {
return this == SIZE_100_100 || this == SIZE_100_150; return this == SIZE_100_100 || this == SIZE_100_150 || this == A4;
} }
/** 是否可用于每页 6 个的排版。 */ /** 是否可用于每页 6 个的排版。 */

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

@ -103,6 +103,9 @@ public final class EdayunConstants {
/** 打印条码({@code POST /webApi/skuInfo/v2/printBarcode})。 */ /** 打印条码({@code POST /webApi/skuInfo/v2/printBarcode})。 */
public static final String PATH_BARCODE_PRINT = "/webApi/skuInfo/v2/printBarcode"; public static final String PATH_BARCODE_PRINT = "/webApi/skuInfo/v2/printBarcode";
/** 打印箱唛({@code POST /webApi/entryInfo/v1/newPrintCaseMarkContentType})。 */
public static final String PATH_CASE_MARK_PRINT = "/webApi/entryInfo/v1/newPrintCaseMarkContentType";
/** 物流增值:签收服务。 */ /** 物流增值:签收服务。 */
public static final String ADD_SERVICE_SIGNATURE = "is_signature"; public static final String ADD_SERVICE_SIGNATURE = "is_signature";

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

@ -5,6 +5,7 @@ import common.ecommerce.edayun.auth.EdayunTokenClient;
import common.ecommerce.edayun.dto.EdayunAccountFlowDtos; import common.ecommerce.edayun.dto.EdayunAccountFlowDtos;
import common.ecommerce.edayun.dto.EdayunBarcodeDtos; import common.ecommerce.edayun.dto.EdayunBarcodeDtos;
import common.ecommerce.edayun.dto.EdayunBolDtos; import common.ecommerce.edayun.dto.EdayunBolDtos;
import common.ecommerce.edayun.dto.EdayunCaseMarkDtos;
import common.ecommerce.edayun.dto.EdayunCancelDtos; import common.ecommerce.edayun.dto.EdayunCancelDtos;
import common.ecommerce.edayun.dto.EdayunCancelReturnDtos; import common.ecommerce.edayun.dto.EdayunCancelReturnDtos;
import common.ecommerce.edayun.dto.EdayunCreateOrderDtos; import common.ecommerce.edayun.dto.EdayunCreateOrderDtos;
@ -55,6 +56,7 @@ import common.ecommerce.warehouse.error.WarehouseException;
import common.ecommerce.warehouse.error.WarehouseUnsupportedCapabilityException; import common.ecommerce.warehouse.error.WarehouseUnsupportedCapabilityException;
import common.ecommerce.warehouse.model.BarcodePrintCommand; import common.ecommerce.warehouse.model.BarcodePrintCommand;
import common.ecommerce.warehouse.model.BillingDocument; import common.ecommerce.warehouse.model.BillingDocument;
import common.ecommerce.warehouse.model.BoxLabelCommand;
import common.ecommerce.warehouse.model.BolDocument; import common.ecommerce.warehouse.model.BolDocument;
import common.ecommerce.warehouse.model.CancelCommand; import common.ecommerce.warehouse.model.CancelCommand;
import common.ecommerce.warehouse.model.CancelResult; import common.ecommerce.warehouse.model.CancelResult;
@ -1008,6 +1010,64 @@ public final class EdayunAdapter implements WarehouseAdapter, WarehouseProductCa
return EdayunBarcodeMapper.toLabel(parsed.data.trim(), cmd); return EdayunBarcodeMapper.toLabel(parsed.data.trim(), cmd);
} }
// ------------------------------------------------------------------ 箱唛
/**
* 打印箱唛({@code POST /webApi/entryInfo/v1/newPrintCaseMarkContentType})。
*
* <p>与入库箱标({@code inbound().printBoxLabel})不同:那个是运去哪风格的
* 异步任务(只回任务号),易达云这个<b>同步返回 PDF 地址</b>。</p>
*
* <p>统一模型的 {@code BoxLabelCommand} 没有「选哪些箱」的字段,
* 所以默认整单打印;要打部分箱用 {@link #printCaseMarks} 的重载。</p>
*
* <p><b>真机未验证</b>:PR 环境该接口返回「接口不存在或未启用」,
* 换到 {@code /newPrintCaseMark}(无 ContentType 后缀)能过参数校验
* (缺 pageSize 报「纸张不能为空」、缺 madeInChina 报「产地标签不能为空」),
* 但补全后一律「内部服务器错误」。见 docs-warehouse/edayun/TODO.md。</p>
*/
public WarehouseLabel printCaseMarks(WarehouseContext ctx, BoxLabelCommand cmd) {
EdayunCaseMarkDtos.PrintCaseMarkRequest body = EdayunCaseMarkMapper.toRequest(cmd);
return sendCaseMark(ctx, body);
}
/**
* 打印箱唛(可选箱)。
*
* @param selection 选箱条件;四选一,全空时本地拒绝
*/
public WarehouseLabel printCaseMarks(WarehouseContext ctx, BoxLabelCommand cmd,
EdayunCaseMarkMapper.CaseSelection selection) {
EdayunCaseMarkDtos.PrintCaseMarkRequest body =
EdayunCaseMarkMapper.toRequest(cmd, selection);
return sendCaseMark(ctx, body);
}
private WarehouseLabel sendCaseMark(WarehouseContext ctx,
EdayunCaseMarkDtos.PrintCaseMarkRequest 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);
requireSuccess(ctx, parsed == null ? null : parsed.code,
parsed == null ? null : parsed.msg, resp, "warehouse.caseMark.print");
if (parsed.data == null || parsed.data.trim().isEmpty()) {
throw WarehouseException.builder()
.message("edayun printCaseMark returned no file url")
.operation("warehouse.caseMark.print")
.warehouseCode(ctx.warehouseCode())
.provider(provider().name())
.requestId(ctx.requestId())
.rawResponse(safeRelay(resp.body()))
.retryable(false)
.build();
}
return EdayunCaseMarkMapper.toLabel(parsed.data.trim());
}
// ------------------------------------------------------------------ internals // ------------------------------------------------------------------ internals
/** 发业务请求(自动取 token、算签名)。 */ /** 发业务请求(自动取 token、算签名)。 */
private HttpResponse send(WarehouseContext ctx, String path, String bodyJson, String operation) { private HttpResponse send(WarehouseContext ctx, String path, String bodyJson, String operation) {

127
warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/adapter/EdayunCaseMarkMapper.java

@ -0,0 +1,127 @@
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.WarehouseLabel;
import java.util.List;
/**
* 易达云箱唛映射({@code POST /webApi/entryInfo/v1/newPrintCaseMarkContentType})。
*
* <p><b>统一模型只能表达「整单打印」</b>:{@code BoxLabelCommand} 没有「选哪些箱」
* 的字段,所以选箱条件(系统箱号列表 / SKU / 箱序号区间 / 客户箱号区间)
* 一律不下发——仓方默认整单。要打部分箱请走 {@code printCaseMarks} 的扩展重载。</p>
*
* <p>响应 {@code data} 是 PDF 地址,同步生成;而统一模型的
* {@code LabelPrintTask} 是异步任务语义(只有任务号)。所以这里返回
* {@link WarehouseLabel},把地址放在 {@code url()}。</p>
*/
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;
private EdayunCaseMarkMapper() {
}
/**
* 统一命令 → 箱唛请求(整单打印)。
*
* @throws IllegalArgumentException 尺寸不在易达云支持的三档内
*/
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;
return req;
}
/**
* 带选箱条件的请求(易达云专有能力)。
*
* <p>选箱条件四选一,全部为空时仓方会报错,这里本地先拒。</p>
*/
public static EdayunCaseMarkDtos.PrintCaseMarkRequest toRequest(BoxLabelCommand cmd,
CaseSelection selection) {
EdayunCaseMarkDtos.PrintCaseMarkRequest req = toRequest(cmd);
if (selection == null || selection.isEmpty()) {
throw new IllegalArgumentException(
"edayun case mark 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<String> caseCodes;
private String skuCode;
private String startCaseSerialNo;
private String endCaseSerialNo;
private String startSellerCaseNo;
private String endSellerCaseNo;
public CaseSelection caseCodes(List<String> 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();
}
}
}

67
warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/dto/EdayunCaseMarkDtos.java

@ -0,0 +1,67 @@
package common.ecommerce.edayun.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.List;
/**
* 易达云报文结构:打印箱唛
* ({@code POST /webApi/entryInfo/v1/newPrintCaseMarkContentType})。
*
* <p>一个文件对应一个接口。响应 {@code data} 是<b>箱唛 PDF 地址字符串</b>,
* 同步生成,不是任务号。</p>
*
* <p><b>选箱条件四选一</b>(文档原文:箱序号 / 客户箱号 / sku 编码 / 系统箱号
* 必须有一个不为空):</p>
* <ul>
* <li>系统箱号:{@code caseCodeList}</li>
* <li>SKU:{@code skuCode}</li>
* <li>箱序号区间:{@code startCaseSerialNo} ~ {@code endCaseSerialNo}</li>
* <li>客户箱号区间:{@code startSellerCaseNo} ~ {@code endSellerCaseNo}</li>
* </ul>
*/
public final class EdayunCaseMarkDtos {
private EdayunCaseMarkDtos() {
}
/** 打印请求。 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public static final class PrintCaseMarkRequest {
/** EDA 入库单号(REV 单号)。必填。 */
public String entryCode;
/** 系统箱号列表(如 {@code B00231164777837})。 */
public List<String> 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。<b>必填</b>。 */
public Integer pageSize;
/** 是否需要 Made in China:0 否 / 1 是。<b>必填</b>。 */
public Integer madeInChina;
/** 是否打印分隔符(第一页与下一页不一致时插提示页)。<b>必填</b>。 */
public Boolean separation;
/** 每箱打印两份:0 否 / 1 是。 */
public Integer twoPrint;
}
/** 打印响应。 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public static final class PrintCaseMarkResponse {
public Integer code;
public String msg;
/** 箱唛 PDF 地址。 */
public String data;
public String traceId;
}
}

61
warehouse-sdk-edayun/src/main/java/common/ecommerce/edayun/enums/EdayunCaseMarkPaper.java

@ -0,0 +1,61 @@
package common.ecommerce.edayun.enums;
import common.ecommerce.warehouse.enums.LabelSizeType;
/**
* 易达云箱唛纸张尺寸({@code newPrintCaseMark} 的 {@code pageSize})。
*
* <p>只有三档,且码值与统一枚举 {@link LabelSizeType} 完全不同:</p>
* <table>
* <tr><th>易达云</th><th>尺寸</th><th>统一枚举</th></tr>
* <tr><td>4</td><td>100×100</td><td>{@link LabelSizeType#SIZE_100_100}</td></tr>
* <tr><td>2</td><td>100×150</td><td>{@link LabelSizeType#SIZE_100_150}</td></tr>
* <tr><td>5</td><td>A4</td><td>{@link LabelSizeType#A4}</td></tr>
* </table>
*
* <p>注意码值不连续(4 / 2 / 5),不要按顺序推。</p>
*/
public enum EdayunCaseMarkPaper {
/** 4:100×100mm。 */
SIZE_100_100(4, "100×100", LabelSizeType.SIZE_100_100),
/** 2:100×150mm。 */
SIZE_100_150(2, "100×150", LabelSizeType.SIZE_100_150),
/** 5:A4。 */
A4(5, "A4", LabelSizeType.A4);
private final int code;
private final String label;
private final LabelSizeType core;
EdayunCaseMarkPaper(int code, String label, LabelSizeType core) {
this.code = code;
this.label = label;
this.core = core;
}
public int code() {
return code;
}
public String label() {
return label;
}
/** 对应的统一尺寸。 */
public LabelSizeType core() {
return core;
}
/** 统一尺寸 → 易达云码值;不支持的尺寸显式拒绝。 */
public static EdayunCaseMarkPaper of(LabelSizeType size) {
for (EdayunCaseMarkPaper v : values()) {
if (v.core == size) {
return v;
}
}
throw new IllegalArgumentException(
"edayun case mark does not support label size: " + size
+ " (only 100x100 / 100x150 / A4)");
}
}

158
warehouse-sdk-edayun/src/test/java/common/ecommerce/edayun/adapter/EdayunCaseMarkTest.java

@ -0,0 +1,158 @@
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.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;
/**
* 箱唛打印({@code newPrintCaseMarkContentType})映射。
*
* <p>重点:码值不连续(4/2/5)、统一模型只能表达整单打印、
* Made in China 与分隔符默认关。</p>
*/
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();
}
// ------------------------------------------------------------ 纸张映射
/** 易达云码值不连续: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());
}
@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());
}
/** 统一模型的 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());
}
// ------------------------------------------------------------ 请求
@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);
}
/** 一箱一份时 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), EdayunCaseMarkMapper.toRequest(one).twoPrint);
}
/** 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);
}
// ------------------------------------------------------------ 选箱
@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);
assertEquals(java.util.Arrays.asList("B001", "B002"), req.caseCodeList);
}
@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);
}
/** 选箱条件全空时本地拒——仓方要求四选一。 */
@Test
void emptySelectionIsRejected() {
assertThrows(IllegalArgumentException.class,
() -> EdayunCaseMarkMapper.toRequest(command(LabelSizeType.SIZE_100_100),
new EdayunCaseMarkMapper.CaseSelection()));
assertThrows(IllegalArgumentException.class,
() -> EdayunCaseMarkMapper.toRequest(command(LabelSizeType.SIZE_100_100), null));
}
// ------------------------------------------------------------ 响应
/** 响应 data 是 PDF 地址,同步返回(不是任务号)。 */
@Test
void labelCarriesUrl() {
WarehouseLabel label = EdayunCaseMarkMapper.toLabel("https://oss/case.pdf");
assertEquals("https://oss/case.pdf", label.url());
assertEquals("PDF", label.format());
assertNull(label.contentBase64());
}
}
Loading…
Cancel
Save