Browse Source
仓方确认两个端点名与实际打印的东西是反的: - /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 <noreply@anthropic.com>master
21 changed files with 730 additions and 749 deletions
@ -1,37 +0,0 @@ |
|||||||
package common.ecommerce.warehouse.enums; |
|
||||||
|
|
||||||
/** |
|
||||||
* SKU 条码打印的纸张尺寸。 |
|
||||||
* |
|
||||||
* <p>易达云 {@code printBarcode} 的 {@code pageSize}:0 7×3cm / 1 10×6cm / |
|
||||||
* 2 6×4cm / 3 A4。<b>只有这 4 档</b>,与入库贴标用的 |
|
||||||
* {@link SkuLabelSizeType}(14 种小尺寸)不是一套,不能互换。</p> |
|
||||||
*/ |
|
||||||
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; |
|
||||||
} |
|
||||||
} |
|
||||||
@ -0,0 +1,47 @@ |
|||||||
|
package common.ecommerce.warehouse.enums; |
||||||
|
|
||||||
|
/** |
||||||
|
* 箱唛打印的纸张尺寸(易达云 {@code printBarcode} 的 {@code pageSize})。 |
||||||
|
* |
||||||
|
* <p><b>名称按真机实测尺寸取,不是按文档标称</b>——文档的 2 / 3 两档与实测相反。 |
||||||
|
* 实测是 PDF MediaBox 折算的毫米数(1pt = 25.4/72 mm):</p> |
||||||
|
* |
||||||
|
* <table> |
||||||
|
* <tr><th>码值</th><th>文档标称</th><th>实测</th><th>枚举</th></tr> |
||||||
|
* <tr><td>0</td><td>7×3cm</td><td>69.9 × 30.0 mm</td><td>{@link #SIZE_70_30}</td></tr> |
||||||
|
* <tr><td>1</td><td>10×6cm</td><td>100.2 × 60.0 mm</td><td>{@link #SIZE_100_60}</td></tr> |
||||||
|
* <tr><td>2</td><td>6×4cm</td><td><b>99.9 × 150.0 mm</b></td><td>{@link #SIZE_100_150}</td></tr> |
||||||
|
* <tr><td>3</td><td>A4</td><td><b>60.0 × 39.9 mm</b></td><td>{@link #SIZE_60_40}</td></tr> |
||||||
|
* </table> |
||||||
|
* |
||||||
|
* <p>与入库贴标用的 {@link SkuLabelSizeType}(14 种小尺寸)不是一套,不能互换。</p> |
||||||
|
*/ |
||||||
|
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(<b>文档标 6×4cm,实测不符</b>)。 */ |
||||||
|
SIZE_100_150(2, "100×150mm"), |
||||||
|
/** 3:约 60mm × 40mm(<b>文档标 A4,实测不符</b>)。 */ |
||||||
|
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; |
||||||
|
} |
||||||
|
} |
||||||
@ -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})。 |
|
||||||
* |
|
||||||
* <p>响应 {@code data} 是文件地址字符串——同步生成,不像入库箱标那样只有任务号。</p> |
|
||||||
*/ |
|
||||||
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<EdayunBarcodeDtos.ProductInfo> toItems( |
|
||||||
List<BarcodePrintCommand.BarcodeItem> 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<EdayunBarcodeDtos.ProductInfo> out = |
|
||||||
new ArrayList<EdayunBarcodeDtos.ProductInfo>(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; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 响应 → 面单对象。 |
|
||||||
* |
|
||||||
* <p>文件地址可能为空——仓方生成失败时仍可能回 {@code code=200}。调用方应在 |
|
||||||
* 调用前确认 {@code data} 非空,适配器已做该检查。</p> |
|
||||||
*/ |
|
||||||
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(); |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,127 +1,71 @@ |
|||||||
package common.ecommerce.edayun.adapter; |
package common.ecommerce.edayun.adapter; |
||||||
|
|
||||||
import common.ecommerce.edayun.dto.EdayunCaseMarkDtos; |
import common.ecommerce.edayun.dto.EdayunCaseMarkDtos; |
||||||
import common.ecommerce.edayun.enums.EdayunCaseMarkPaper; |
import common.ecommerce.warehouse.model.CaseMarkPrintCommand; |
||||||
import common.ecommerce.warehouse.model.BoxLabelCommand; |
|
||||||
import common.ecommerce.warehouse.model.WarehouseLabel; |
import common.ecommerce.warehouse.model.WarehouseLabel; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
||||||
/** |
/** |
||||||
* 易达云箱唛映射({@code POST /webApi/entryInfo/v1/newPrintCaseMarkContentType})。 |
* 易达云箱唛映射({@code POST /webApi/skuInfo/v2/printBarcode})。 |
||||||
* |
* |
||||||
* <p><b>统一模型只能表达「整单打印」</b>:{@code BoxLabelCommand} 没有「选哪些箱」 |
* <p>端点名叫 printBarcode,但实际打的是<b>箱唛</b>(外箱标)——已与仓方确认。 |
||||||
* 的字段,所以选箱条件(系统箱号列表 / SKU / 箱序号区间 / 客户箱号区间) |
* 响应 {@code data} 是 PDF 地址字符串,同步生成。</p> |
||||||
* 一律不下发——仓方默认整单。要打部分箱请走 {@code printCaseMarks} 的扩展重载。</p> |
|
||||||
* |
|
||||||
* <p>响应 {@code data} 是 PDF 地址,同步生成;而统一模型的 |
|
||||||
* {@code LabelPrintTask} 是异步任务语义(只有任务号)。所以这里返回 |
|
||||||
* {@link WarehouseLabel},把地址放在 {@code url()}。</p> |
|
||||||
*/ |
*/ |
||||||
public final class EdayunCaseMarkMapper { |
public final class EdayunCaseMarkMapper { |
||||||
|
|
||||||
/** 是否需要 Made in China:是。 */ |
/** 单次最多打印的 SKU 数(文档:最大 50 个)。 */ |
||||||
static final int MADE_IN_CHINA_YES = 1; |
static final int MAX_SKUS = 50; |
||||||
/** 是否需要 Made in China:否。 */ |
|
||||||
static final int MADE_IN_CHINA_NO = 0; |
|
||||||
|
|
||||||
private EdayunCaseMarkMapper() { |
private EdayunCaseMarkMapper() { |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 统一命令 → 箱唛请求(整单打印)。 |
* 统一命令 → 打印请求。 |
||||||
* |
* |
||||||
* @throws IllegalArgumentException 尺寸不在易达云支持的三档内 |
* @throws IllegalArgumentException SKU 数超限(本地先挡,省一次失败请求) |
||||||
*/ |
*/ |
||||||
public static EdayunCaseMarkDtos.PrintCaseMarkRequest toRequest(BoxLabelCommand cmd) { |
public static EdayunCaseMarkDtos.PrintCaseMarkRequest toRequest(CaseMarkPrintCommand cmd) { |
||||||
EdayunCaseMarkDtos.PrintCaseMarkRequest req = |
EdayunCaseMarkDtos.PrintCaseMarkRequest req = new EdayunCaseMarkDtos.PrintCaseMarkRequest(); |
||||||
new EdayunCaseMarkDtos.PrintCaseMarkRequest(); |
req.pageSize = cmd.paperSize().code(); |
||||||
// 统一模型里 providerInboundNo 就是仓侧 REV 单号
|
req.remark = cmd.remark(); |
||||||
req.entryCode = cmd.providerInboundNo(); |
// 只有 true 才下发:false 是仓方默认,不下发省得干扰它自己的默认值
|
||||||
|
req.isPrintSkuName = cmd.printSkuName() ? Boolean.TRUE : null; |
||||||
EdayunCaseMarkPaper paper = EdayunCaseMarkPaper.of(cmd.sizeType()); |
req.productInfos = toItems(cmd.items()); |
||||||
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; |
return req; |
||||||
} |
} |
||||||
|
|
||||||
/** |
private static List<EdayunCaseMarkDtos.ProductInfo> toItems( |
||||||
* 带选箱条件的请求(易达云专有能力)。 |
List<CaseMarkPrintCommand.CaseMarkItem> items) { |
||||||
* |
if (items.size() > MAX_SKUS) { |
||||||
* <p>选箱条件四选一,全部为空时仓方会报错,这里本地先拒。</p> |
|
||||||
*/ |
|
||||||
public static EdayunCaseMarkDtos.PrintCaseMarkRequest toRequest(BoxLabelCommand cmd, |
|
||||||
CaseSelection selection) { |
|
||||||
EdayunCaseMarkDtos.PrintCaseMarkRequest req = toRequest(cmd); |
|
||||||
if (selection == null || selection.isEmpty()) { |
|
||||||
throw new IllegalArgumentException( |
throw new IllegalArgumentException( |
||||||
"edayun case mark needs at least one box selector" |
"edayun prints at most " + MAX_SKUS + " skus at once, got " + items.size() |
||||||
+ " (case codes / sku / serial range / seller case range)"); |
+ "; split into multiple calls"); |
||||||
} |
} |
||||||
req.caseCodeList = selection.caseCodes; |
List<EdayunCaseMarkDtos.ProductInfo> out = |
||||||
req.skuCode = selection.skuCode; |
new ArrayList<EdayunCaseMarkDtos.ProductInfo>(items.size()); |
||||||
req.startCaseSerialNo = selection.startCaseSerialNo; |
for (CaseMarkPrintCommand.CaseMarkItem item : items) { |
||||||
req.endCaseSerialNo = selection.endCaseSerialNo; |
EdayunCaseMarkDtos.ProductInfo info = new EdayunCaseMarkDtos.ProductInfo(); |
||||||
req.startSellerCaseNo = selection.startSellerCaseNo; |
info.skuCode = item.providerSku(); |
||||||
req.endSellerCaseNo = selection.endSellerCaseNo; |
info.num = item.copies(); |
||||||
return req; |
out.add(info); |
||||||
|
} |
||||||
|
return out; |
||||||
} |
} |
||||||
|
|
||||||
/** 响应 → 面单对象;地址为空视为失败。 */ |
/** |
||||||
public static WarehouseLabel toLabel(String fileUrl) { |
* 响应 → 面单对象。 |
||||||
|
* |
||||||
|
* <p>文件地址可能为空——仓方生成失败时仍可能回 {@code code=200}。调用方应在 |
||||||
|
* 调用前确认 {@code data} 非空,适配器已做该检查。</p> |
||||||
|
*/ |
||||||
|
public static WarehouseLabel toLabel(String fileUrl, CaseMarkPrintCommand cmd) { |
||||||
return WarehouseLabel.builder() |
return WarehouseLabel.builder() |
||||||
// 仓方不回文件 id
|
// 仓库不返回文件 id,用 SKU 数 + 纸张尺寸拼一个可追溯的编号
|
||||||
.labelId("case-mark") |
.labelId("barcode-" + cmd.paperSize().name() + "-" + cmd.items().size()) |
||||||
.format("PDF") |
.format("PDF") |
||||||
.url(fileUrl) |
.url(fileUrl) |
||||||
.build(); |
.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,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})。 |
||||||
|
* |
||||||
|
* <p><b>统一模型只能表达「整单打印」</b>:{@code BoxLabelCommand} 没有「选哪些箱」 |
||||||
|
* 的字段,所以选箱条件(系统箱号列表 / SKU / 箱序号区间 / 客户箱号区间) |
||||||
|
* 一律不下发——仓方默认整单。要打部分箱请走 {@code printSkuLabel} 的扩展重载。</p> |
||||||
|
* |
||||||
|
* <p>响应 {@code data} 是 PDF 地址,同步生成;而统一模型的 |
||||||
|
* {@code LabelPrintTask} 是异步任务语义(只有任务号)。所以这里返回 |
||||||
|
* {@link WarehouseLabel},把地址放在 {@code url()}。</p> |
||||||
|
*/ |
||||||
|
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; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 带选箱条件的请求(易达云专有能力)。 |
||||||
|
* |
||||||
|
* <p>选箱条件四选一,全部为空时仓方会报错,这里本地先拒。</p> |
||||||
|
*/ |
||||||
|
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<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(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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})。 |
|
||||||
* |
|
||||||
* <p>一个文件对应一个接口。响应 {@code data} 是<b>文件地址字符串</b>, |
|
||||||
* 不是对象——与入库箱标那种「异步任务号」不同,这里同步给文件。</p> |
|
||||||
*/ |
|
||||||
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。<b>必填</b>。 */ |
|
||||||
public Integer pageSize; |
|
||||||
|
|
||||||
/** 产品信息,最大 50 个 SKU。<b>必填</b>。 */ |
|
||||||
public List<ProductInfo> 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; |
|
||||||
} |
|
||||||
} |
|
||||||
@ -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})。 |
||||||
|
* |
||||||
|
* <p>一个文件对应一个接口。响应 {@code data} 是<b>PDF 地址字符串</b>,同步生成。</p> |
||||||
|
* |
||||||
|
* <p><b>接口名与语义不一致</b>:端点叫 {@code newPrintCaseMark}(箱唛), |
||||||
|
* 但实际打的是 SKU 标。已与仓方确认,不要被路径名误导。</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 EdayunSkuLabelDtos { |
||||||
|
|
||||||
|
private EdayunSkuLabelDtos() { |
||||||
|
} |
||||||
|
|
||||||
|
/** 打印 SKU 标请求。 */ |
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||||
|
public static final class PrintSkuLabelRequest { |
||||||
|
|
||||||
|
/** 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 PrintSkuLabelResponse { |
||||||
|
public Integer code; |
||||||
|
public String msg; |
||||||
|
/** 箱唛 PDF 地址。 */ |
||||||
|
public String data; |
||||||
|
public String traceId; |
||||||
|
} |
||||||
|
} |
||||||
@ -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})映射。 |
|
||||||
* |
|
||||||
* <p>重点:响应 data 是文件地址、同步返回(不是任务号)、50 个 SKU 上限。</p> |
|
||||||
*/ |
|
||||||
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()); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,158 +1,166 @@ |
|||||||
package common.ecommerce.edayun.adapter; |
package common.ecommerce.edayun.adapter; |
||||||
|
|
||||||
import common.ecommerce.edayun.dto.EdayunCaseMarkDtos; |
import common.ecommerce.edayun.dto.EdayunCaseMarkDtos; |
||||||
import common.ecommerce.edayun.enums.EdayunCaseMarkPaper; |
import common.ecommerce.http.JacksonJsonCodec; |
||||||
import common.ecommerce.warehouse.enums.LabelDownloadMode; |
import common.ecommerce.shared.spi.ChannelSecret; |
||||||
import common.ecommerce.warehouse.enums.LabelSizeType; |
import common.ecommerce.shared.testkit.RecordingTransport; |
||||||
import common.ecommerce.warehouse.enums.LabelsPerPage; |
import common.ecommerce.shared.testkit.Responses; |
||||||
import common.ecommerce.warehouse.model.BoxLabelCommand; |
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.model.WarehouseLabel; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseConnection; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||||
import org.junit.jupiter.api.Test; |
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.assertEquals; |
||||||
import static org.junit.jupiter.api.Assertions.assertNull; |
import static org.junit.jupiter.api.Assertions.assertNull; |
||||||
import static org.junit.jupiter.api.Assertions.assertThrows; |
import static org.junit.jupiter.api.Assertions.assertThrows; |
||||||
import static org.junit.jupiter.api.Assertions.assertTrue; |
import static org.junit.jupiter.api.Assertions.assertTrue; |
||||||
|
|
||||||
/** |
/** |
||||||
* 箱唛打印({@code newPrintCaseMarkContentType})映射。 |
* 箱唛打印({@code /webApi/skuInfo/v2/printBarcode})映射。 |
||||||
* |
* |
||||||
* <p>重点:码值不连续(4/2/5)、统一模型只能表达整单打印、 |
* <p>重点:响应 data 是文件地址、同步返回(不是任务号)、50 个 SKU 上限。</p> |
||||||
* Made in China 与分隔符默认关。</p> |
|
||||||
*/ |
*/ |
||||||
class EdayunCaseMarkTest { |
class EdayunCaseMarkTest { |
||||||
|
|
||||||
private static BoxLabelCommand command(LabelSizeType size) { |
private static final Clock CLOCK = Clock.fixed(Instant.parse("2026-11-16T00:00:00Z"), ZoneOffset.UTC); |
||||||
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。 */ |
private static WarehouseContext ctx() { |
||||||
@Test |
return WarehouseContext.of("EDY-WH", WarehouseProvider.EDAYUN, "2", |
||||||
void paperCodesAreNotSequential() { |
WarehouseConnection.of("https://test.example/openapi", |
||||||
assertEquals(4, EdayunCaseMarkPaper.SIZE_100_100.code()); |
ChannelSecret.builder().appKey("k").appSecret("s") |
||||||
assertEquals(2, EdayunCaseMarkPaper.SIZE_100_150.code()); |
.clientId("c").clientSecret("cs").build()), |
||||||
assertEquals(5, EdayunCaseMarkPaper.A4.code()); |
"req-barcode", CLOCK); |
||||||
} |
} |
||||||
|
|
||||||
@Test |
private static RecordingTransport stub(String body) { |
||||||
void mapsCoreSizes() { |
return RecordingTransport.create() |
||||||
assertEquals(EdayunCaseMarkPaper.SIZE_100_100, |
.route(common.ecommerce.edayun.EdayunConstants.PATH_TOKEN, req -> Responses.ok( |
||||||
EdayunCaseMarkPaper.of(LabelSizeType.SIZE_100_100)); |
"{\"access_token\":\"T1\",\"token_type\":\"bearer\"}")) |
||||||
assertEquals(EdayunCaseMarkPaper.SIZE_100_150, |
.route(common.ecommerce.edayun.EdayunConstants.PATH_CASE_MARK_PRINT, |
||||||
EdayunCaseMarkPaper.of(LabelSizeType.SIZE_100_150)); |
req -> Responses.ok(body)); |
||||||
assertEquals(LabelSizeType.SIZE_100_100, |
|
||||||
EdayunCaseMarkPaper.SIZE_100_100.core()); |
|
||||||
assertEquals(LabelSizeType.A4, EdayunCaseMarkPaper.A4.core()); |
|
||||||
} |
} |
||||||
|
|
||||||
/** 统一模型的 104×98(美国信纸)易达云不支持,要显式拒绝。 */ |
private static CaseMarkPrintCommand command() { |
||||||
@Test |
return CaseMarkPrintCommand.builder() |
||||||
void unsupportedSizeIsRejected() { |
.paperSize(CaseMarkPaperSize.SIZE_70_30) |
||||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
.remark("Made in China") |
||||||
() -> EdayunCaseMarkPaper.of(LabelSizeType.SIZE_104_98)); |
.printSkuName(false) |
||||||
assertTrue(ex.getMessage().contains("only 100x100 / 100x150 / A4"), ex.getMessage()); |
.item("ybtest", 2) |
||||||
|
.build(); |
||||||
} |
} |
||||||
|
|
||||||
// ------------------------------------------------------------ 请求
|
// ------------------------------------------------------------ 请求
|
||||||
|
|
||||||
@Test |
@Test |
||||||
void mapsWholeOrderPrint() { |
void mapsRequest() { |
||||||
EdayunCaseMarkDtos.PrintCaseMarkRequest req = |
EdayunCaseMarkDtos.PrintCaseMarkRequest req = EdayunCaseMarkMapper.toRequest(command()); |
||||||
EdayunCaseMarkMapper.toRequest(command(LabelSizeType.SIZE_100_100)); |
|
||||||
|
assertEquals(Integer.valueOf(0), req.pageSize); |
||||||
assertEquals("REV0023116477", req.entryCode); |
assertEquals("Made in China", req.remark); |
||||||
assertEquals(Integer.valueOf(4), req.pageSize); |
assertEquals(1, req.productInfos.size()); |
||||||
assertEquals(Integer.valueOf(EdayunCaseMarkMapper.MADE_IN_CHINA_NO), req.madeInChina); |
assertEquals("ybtest", req.productInfos.get(0).skuCode); |
||||||
assertEquals(Boolean.FALSE, req.separation); |
assertEquals(Integer.valueOf(2), req.productInfos.get(0).num); |
||||||
assertEquals(Integer.valueOf(1), req.twoPrint); |
|
||||||
// 统一模型没有选箱字段,默认整单
|
|
||||||
assertNull(req.caseCodeList); |
|
||||||
assertNull(req.skuCode); |
|
||||||
assertNull(req.startCaseSerialNo); |
|
||||||
} |
} |
||||||
|
|
||||||
/** 一箱一份时 twoPrint=0。 */ |
/** isPrintSkuName 只在 true 时下发,false 交给仓方默认。 */ |
||||||
@Test |
@Test |
||||||
void singleCopyMapsZero() { |
void printSkuNameOnlySentWhenTrue() { |
||||||
BoxLabelCommand one = BoxLabelCommand.builder() |
assertNull(EdayunCaseMarkMapper.toRequest(command()).isPrintSkuName); |
||||||
.providerInboundNo("REV1").inboundRequestNo("IB-1") |
|
||||||
.sizeType(LabelSizeType.SIZE_100_150) |
|
||||||
.labelsPerPage(LabelsPerPage.ONE) |
|
||||||
.build(); |
|
||||||
|
|
||||||
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 |
@Test |
||||||
void madeInChinaAndSeparationDefaultOff() { |
void paperSizesMap() { |
||||||
EdayunCaseMarkDtos.PrintCaseMarkRequest req = |
assertEquals(0, CaseMarkPaperSize.SIZE_70_30.code()); |
||||||
EdayunCaseMarkMapper.toRequest(command(LabelSizeType.SIZE_100_150)); |
assertEquals(1, CaseMarkPaperSize.SIZE_100_60.code()); |
||||||
|
assertEquals(2, CaseMarkPaperSize.SIZE_100_150.code()); |
||||||
assertEquals(Integer.valueOf(0), req.madeInChina); |
assertEquals(3, CaseMarkPaperSize.SIZE_60_40.code()); |
||||||
assertEquals(Boolean.FALSE, req.separation); |
|
||||||
} |
} |
||||||
|
|
||||||
// ------------------------------------------------------------ 选箱
|
/** 超过 50 个 SKU 本地就挡,不发请求(仓方也会报「最多打印50个SKU」)。 */ |
||||||
|
|
||||||
@Test |
@Test |
||||||
void mapsCaseCodes() { |
void moreThan50SkusRejectedLocally() { |
||||||
EdayunCaseMarkMapper.CaseSelection sel = new EdayunCaseMarkMapper.CaseSelection() |
CaseMarkPrintCommand.Builder b = CaseMarkPrintCommand.builder() |
||||||
.caseCodes(java.util.Arrays.asList("B001", "B002")); |
.paperSize(CaseMarkPaperSize.SIZE_60_40); |
||||||
|
for (int i = 0; i < 51; i++) { |
||||||
EdayunCaseMarkDtos.PrintCaseMarkRequest req = EdayunCaseMarkMapper.toRequest( |
b.item("SKU-" + i, 1); |
||||||
command(LabelSizeType.SIZE_100_100), sel); |
} |
||||||
|
|
||||||
assertEquals(java.util.Arrays.asList("B001", "B002"), req.caseCodeList); |
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||||
} |
() -> EdayunCaseMarkMapper.toRequest(b.build())); |
||||||
|
|
||||||
@Test |
assertTrue(ex.getMessage().contains("at most 50"), ex.getMessage()); |
||||||
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); |
|
||||||
} |
} |
||||||
|
|
||||||
/** 选箱条件全空时本地拒——仓方要求四选一。 */ |
/** 空 SKU 列表与非法份数在命令构造期就被拒。 */ |
||||||
@Test |
@Test |
||||||
void emptySelectionIsRejected() { |
void invalidCommandRejectedAtConstruction() { |
||||||
|
assertThrows(IllegalArgumentException.class, |
||||||
|
() -> CaseMarkPrintCommand.builder().paperSize(CaseMarkPaperSize.SIZE_60_40).build()); |
||||||
assertThrows(IllegalArgumentException.class, |
assertThrows(IllegalArgumentException.class, |
||||||
() -> EdayunCaseMarkMapper.toRequest(command(LabelSizeType.SIZE_100_100), |
() -> CaseMarkPrintCommand.builder().paperSize(CaseMarkPaperSize.SIZE_60_40) |
||||||
new EdayunCaseMarkMapper.CaseSelection())); |
.item("sku", 0)); |
||||||
assertThrows(IllegalArgumentException.class, |
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 |
@Test |
||||||
void labelCarriesUrl() { |
void responseDataIsFileUrl() { |
||||||
WarehouseLabel label = EdayunCaseMarkMapper.toLabel("https://oss/case.pdf"); |
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()); |
assertEquals("PDF", label.format()); |
||||||
assertNull(label.contentBase64()); |
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()); |
||||||
|
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|||||||
@ -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})映射。 |
||||||
|
* |
||||||
|
* <p>重点:码值不连续(4/2/5)、统一模型只能表达整单打印、 |
||||||
|
* Made in China 与分隔符默认关。</p> |
||||||
|
*/ |
||||||
|
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()); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue