Browse Source
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
9 changed files with 548 additions and 2 deletions
@ -0,0 +1,127 @@
@@ -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(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,67 @@
@@ -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; |
||||
} |
||||
} |
||||
@ -0,0 +1,61 @@
@@ -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)"); |
||||
} |
||||
} |
||||
@ -0,0 +1,158 @@
@@ -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…
Reference in new issue