Browse Source
补齐上一提交预留的 SKU_LABEL 能力位。 - SkuLabelCommand:仓侧单号 + 来源单号 + 导出方式 + 尺寸 + 原产地 + 四个显示开关 - SkuLabelSizeType:14 种小尺寸(40×30 … 100×100),映射为运去哪 labelSizeType 1..14。**不复用箱标的 LabelSizeType**:箱标只有 3 种尺寸 (100×100 / 100×150 / 104×98),SKU 标是 14 种,两者取值集合几乎不重叠, 合一个枚举会让「每页数量联动」那套约束套用到 SKU 标上 - YqnSkuLabelMapper 复用 YqnBoxLabelMapper 的 downloadMode 语义(1 压缩包 / 2 PDF) - InboundCapable.printSkuLabel 默认抛不支持;门面 inbound().printSkuLabel(cmd) 沿用文档给出的默认值:中文默认不显示,二维码与 ERP_SKU 默认显示。 原产地上送前统一大写,空白按「不打印」处理并省略该字段。 同样是异步任务:只返回 taskNo,label() 恒为 null。 Co-Authored-By: Claude <noreply@anthropic.com>feature/supplier-lingxing
10 changed files with 570 additions and 2 deletions
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
package common.ecommerce.warehouse.enums; |
||||
|
||||
/** |
||||
* SKU 标纸尺寸(入库计划单商品贴标)。 |
||||
* |
||||
* <p>与箱标用的 {@link LabelSizeType} 不是一套:箱标只有 3 种(100×100 / 100×150 / |
||||
* 104×98 美国信纸),SKU 标是 14 种小尺寸。两者的取值集合不重叠,合并会误导调用方。</p> |
||||
*/ |
||||
public enum SkuLabelSizeType { |
||||
|
||||
/** 40mm × 30mm。 */ |
||||
SIZE_40_30(10, "40×30"), |
||||
/** 50mm × 30mm。 */ |
||||
SIZE_50_30(20, "50×30"), |
||||
/** 50mm × 40mm。 */ |
||||
SIZE_50_40(30, "50×40"), |
||||
/** 60mm × 30mm。 */ |
||||
SIZE_60_30(40, "60×30"), |
||||
/** 60mm × 40mm。 */ |
||||
SIZE_60_40(50, "60×40"), |
||||
/** 70mm × 20mm。 */ |
||||
SIZE_70_20(60, "70×20"), |
||||
/** 70mm × 30mm。 */ |
||||
SIZE_70_30(70, "70×30"), |
||||
/** 70mm × 40mm。 */ |
||||
SIZE_70_40(80, "70×40"), |
||||
/** 70mm × 50mm。 */ |
||||
SIZE_70_50(90, "70×50"), |
||||
/** 80mm × 50mm。 */ |
||||
SIZE_80_50(100, "80×50"), |
||||
/** 80mm × 60mm。 */ |
||||
SIZE_80_60(110, "80×60"), |
||||
/** 100mm × 30mm。 */ |
||||
SIZE_100_30(120, "100×30"), |
||||
/** 100mm × 60mm。 */ |
||||
SIZE_100_60(130, "100×60"), |
||||
/** 100mm × 100mm。 */ |
||||
SIZE_100_100(140, "100×100"); |
||||
|
||||
private final int code; |
||||
private final String label; |
||||
|
||||
SkuLabelSizeType(int code, String label) { |
||||
this.code = code; |
||||
this.label = label; |
||||
} |
||||
|
||||
/** 落库用的稳定码;由 SDK 分配,永不复用、永不重排。 */ |
||||
public int code() { |
||||
return code; |
||||
} |
||||
|
||||
/** 中文显示名(即纸尺寸)。 */ |
||||
public String label() { |
||||
return label; |
||||
} |
||||
|
||||
/** 按落库码反查。 */ |
||||
public static SkuLabelSizeType ofCode(int code) { |
||||
for (SkuLabelSizeType v : values()) { |
||||
if (v.code == code) { |
||||
return v; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
@ -0,0 +1,173 @@
@@ -0,0 +1,173 @@
|
||||
package common.ecommerce.warehouse.model; |
||||
|
||||
import common.ecommerce.warehouse.enums.LabelDownloadMode; |
||||
import common.ecommerce.warehouse.enums.SkuLabelSizeType; |
||||
|
||||
/** |
||||
* 打印 SKU 标命令(入库计划单的商品贴标)。 |
||||
* |
||||
* <p>与 {@link BoxLabelCommand}(外箱标)不是一回事:箱标贴外箱、按箱排版; |
||||
* SKU 标贴单个商品,尺寸集合完全不同。</p> |
||||
* |
||||
* <p>仓方同样是<b>异步</b>生成文件:返回的 {@link LabelPrintTask} 只有任务编号, |
||||
* 下载地址要另外查任务中心。</p> |
||||
*/ |
||||
public final class SkuLabelCommand { |
||||
|
||||
/** 入库计划单号(仓方口径),必填。 */ |
||||
private final String providerInboundNo; |
||||
/** 来源单号(OMS 入库单号),必填。 */ |
||||
private final String inboundRequestNo; |
||||
private final LabelDownloadMode downloadMode; |
||||
private final SkuLabelSizeType sizeType; |
||||
/** 原产地国家,ISO 3166-1 alpha-2;null 表示不打印原产地。 */ |
||||
private final String originCountry; |
||||
/** 是否显示英文名称。 */ |
||||
private final boolean showEn; |
||||
/** 是否显示中文名称。 */ |
||||
private final boolean showCn; |
||||
/** 是否显示二维码。 */ |
||||
private final boolean showQrCode; |
||||
/** 是否显示 ERP SKU。 */ |
||||
private final boolean showErpSku; |
||||
|
||||
private SkuLabelCommand(Builder b) { |
||||
this.providerInboundNo = require(b.providerInboundNo, "providerInboundNo"); |
||||
this.inboundRequestNo = require(b.inboundRequestNo, "inboundRequestNo"); |
||||
if (b.downloadMode == null) { |
||||
throw new IllegalArgumentException("downloadMode is required"); |
||||
} |
||||
this.downloadMode = b.downloadMode; |
||||
if (b.sizeType == null) { |
||||
throw new IllegalArgumentException("sizeType is required"); |
||||
} |
||||
this.sizeType = b.sizeType; |
||||
this.originCountry = normalizeCountry(b.originCountry); |
||||
this.showEn = b.showEn; |
||||
this.showCn = b.showCn; |
||||
this.showQrCode = b.showQrCode; |
||||
this.showErpSku = b.showErpSku; |
||||
} |
||||
|
||||
public static Builder builder() { |
||||
return new Builder(); |
||||
} |
||||
|
||||
/** 入库计划单号(仓方口径)。 */ |
||||
public String providerInboundNo() { |
||||
return providerInboundNo; |
||||
} |
||||
|
||||
/** 来源单号(OMS 入库单号)。 */ |
||||
public String inboundRequestNo() { |
||||
return inboundRequestNo; |
||||
} |
||||
|
||||
public LabelDownloadMode downloadMode() { |
||||
return downloadMode; |
||||
} |
||||
|
||||
public SkuLabelSizeType sizeType() { |
||||
return sizeType; |
||||
} |
||||
|
||||
/** 原产地国家;null 表示不打印。 */ |
||||
public String originCountry() { |
||||
return originCountry; |
||||
} |
||||
|
||||
public boolean showEn() { |
||||
return showEn; |
||||
} |
||||
|
||||
public boolean showCn() { |
||||
return showCn; |
||||
} |
||||
|
||||
public boolean showQrCode() { |
||||
return showQrCode; |
||||
} |
||||
|
||||
public boolean showErpSku() { |
||||
return showErpSku; |
||||
} |
||||
|
||||
/** 国家码统一大写;空白视为未指定。 */ |
||||
private static String normalizeCountry(String v) { |
||||
if (v == null || v.trim().isEmpty()) { |
||||
return null; |
||||
} |
||||
return v.trim().toUpperCase(); |
||||
} |
||||
|
||||
private static String require(String v, String name) { |
||||
if (v == null || v.trim().isEmpty()) { |
||||
throw new IllegalArgumentException(name + " must not be blank"); |
||||
} |
||||
return v.trim(); |
||||
} |
||||
|
||||
public static final class Builder { |
||||
private String providerInboundNo; |
||||
private String inboundRequestNo; |
||||
private LabelDownloadMode downloadMode = LabelDownloadMode.PDF; |
||||
private SkuLabelSizeType sizeType; |
||||
private String originCountry; |
||||
private boolean showEn; |
||||
/** 文档默认否。 */ |
||||
private boolean showCn; |
||||
/** 文档默认是。 */ |
||||
private boolean showQrCode = true; |
||||
/** 文档默认是。 */ |
||||
private boolean showErpSku = true; |
||||
|
||||
public Builder providerInboundNo(String v) { |
||||
this.providerInboundNo = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder inboundRequestNo(String v) { |
||||
this.inboundRequestNo = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder downloadMode(LabelDownloadMode v) { |
||||
this.downloadMode = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder sizeType(SkuLabelSizeType v) { |
||||
this.sizeType = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder originCountry(String v) { |
||||
this.originCountry = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder showEn(boolean v) { |
||||
this.showEn = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder showCn(boolean v) { |
||||
this.showCn = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder showQrCode(boolean v) { |
||||
this.showQrCode = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder showErpSku(boolean v) { |
||||
this.showErpSku = v; |
||||
return this; |
||||
} |
||||
|
||||
public SkuLabelCommand build() { |
||||
return new SkuLabelCommand(this); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,100 @@
@@ -0,0 +1,100 @@
|
||||
package common.ecommerce.yqn.adapter; |
||||
|
||||
import common.ecommerce.warehouse.enums.LabelDownloadMode; |
||||
import common.ecommerce.warehouse.enums.SkuLabelSizeType; |
||||
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||
import common.ecommerce.warehouse.model.LabelPrintTask; |
||||
import common.ecommerce.warehouse.model.SkuLabelCommand; |
||||
import common.ecommerce.yqn.dto.YqnDtos; |
||||
|
||||
/** |
||||
* 运去哪入库 SKU 标报文映射(API 100)。 |
||||
*/ |
||||
public final class YqnSkuLabelMapper { |
||||
|
||||
private YqnSkuLabelMapper() { |
||||
} |
||||
|
||||
/** 统一命令 → 运去哪请求。 */ |
||||
public static YqnDtos.SkuLabelRequest toRequest(SkuLabelCommand cmd) { |
||||
YqnDtos.SkuLabelRequest req = new YqnDtos.SkuLabelRequest(); |
||||
req.orderNo = cmd.providerInboundNo(); |
||||
req.sourceNo = cmd.inboundRequestNo(); |
||||
req.downloadMode = downloadModeCode(cmd.downloadMode()); |
||||
req.labelSizeType = sizeTypeCode(cmd.sizeType()); |
||||
req.originCountry = cmd.originCountry(); |
||||
req.isShowEn = cmd.showEn(); |
||||
req.isShowCn = cmd.showCn(); |
||||
req.isShowQrCode = cmd.showQrCode(); |
||||
req.isShowErpSku = cmd.showErpSku(); |
||||
return req; |
||||
} |
||||
|
||||
/** 响应 → 任务。异步接口只回任务编号,不带文件。 */ |
||||
public static LabelPrintTask toTask(YqnDtos.BoxLabelResponse resp, SkuLabelCommand cmd) { |
||||
return LabelPrintTask.builder() |
||||
.sourceProvider(WarehouseProvider.YQN) |
||||
.taskNo(resp.taskNo) |
||||
.providerInboundNo(hasText(resp.orderNo) ? resp.orderNo : cmd.providerInboundNo()) |
||||
.inboundRequestNo(hasText(resp.sourceNo) ? resp.sourceNo : cmd.inboundRequestNo()) |
||||
.build(); |
||||
} |
||||
|
||||
/** 导出方式 → 运去哪 downloadMode:1 压缩包 / 2 单个 PDF。 */ |
||||
static Integer downloadModeCode(LabelDownloadMode mode) { |
||||
if (mode == null) { |
||||
return null; |
||||
} |
||||
switch (mode) { |
||||
case ARCHIVE: |
||||
return 1; |
||||
case PDF: |
||||
return 2; |
||||
default: |
||||
throw new IllegalArgumentException("yqn does not support downloadMode: " + mode); |
||||
} |
||||
} |
||||
|
||||
/** 尺寸 → 运去哪 labelSizeType:1..14,按文档顺序。 */ |
||||
static Integer sizeTypeCode(SkuLabelSizeType size) { |
||||
if (size == null) { |
||||
return null; |
||||
} |
||||
switch (size) { |
||||
case SIZE_40_30: |
||||
return 1; |
||||
case SIZE_50_30: |
||||
return 2; |
||||
case SIZE_50_40: |
||||
return 3; |
||||
case SIZE_60_30: |
||||
return 4; |
||||
case SIZE_60_40: |
||||
return 5; |
||||
case SIZE_70_20: |
||||
return 6; |
||||
case SIZE_70_30: |
||||
return 7; |
||||
case SIZE_70_40: |
||||
return 8; |
||||
case SIZE_70_50: |
||||
return 9; |
||||
case SIZE_80_50: |
||||
return 10; |
||||
case SIZE_80_60: |
||||
return 11; |
||||
case SIZE_100_30: |
||||
return 12; |
||||
case SIZE_100_60: |
||||
return 13; |
||||
case SIZE_100_100: |
||||
return 14; |
||||
default: |
||||
throw new IllegalArgumentException("yqn does not support sku labelSizeType: " + size); |
||||
} |
||||
} |
||||
|
||||
private static boolean hasText(String v) { |
||||
return v != null && !v.trim().isEmpty(); |
||||
} |
||||
} |
||||
@ -0,0 +1,150 @@
@@ -0,0 +1,150 @@
|
||||
package common.ecommerce.yqn.adapter; |
||||
|
||||
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.LabelDownloadMode; |
||||
import common.ecommerce.warehouse.enums.SkuLabelSizeType; |
||||
import common.ecommerce.warehouse.enums.WarehouseCapability; |
||||
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||
import common.ecommerce.warehouse.model.LabelPrintTask; |
||||
import common.ecommerce.warehouse.model.SkuLabelCommand; |
||||
import common.ecommerce.warehouse.sdk.WarehouseConnection; |
||||
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||
import common.ecommerce.yqn.YqnConstants; |
||||
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.assertFalse; |
||||
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 标(API 100)契约测试。 |
||||
*/ |
||||
class YqnSkuLabelTest { |
||||
|
||||
private static final Clock CLOCK = Clock.fixed(Instant.parse("2026-11-10T00:00:00Z"), ZoneOffset.UTC); |
||||
|
||||
private static WarehouseContext ctx() { |
||||
return WarehouseContext.of("YQN-RF_NY_US", WarehouseProvider.YQN, "RF_NY_US", |
||||
WarehouseConnection.of(YqnConstants.PR_BASE_URL, |
||||
ChannelSecret.builder().appSecret("key-1").build()), |
||||
"req-sku-label", CLOCK); |
||||
} |
||||
|
||||
private static SkuLabelCommand command() { |
||||
return SkuLabelCommand.builder() |
||||
.providerInboundNo("IP20261110001") |
||||
.inboundRequestNo("OMS-IN-001") |
||||
.downloadMode(LabelDownloadMode.PDF) |
||||
.sizeType(SkuLabelSizeType.SIZE_70_30) |
||||
.originCountry("us") |
||||
.showEn(true) |
||||
.showCn(true) |
||||
.build(); |
||||
} |
||||
|
||||
private static String okBody() { |
||||
return "{\"statusCode\":200,\"status\":0,\"code\":200,\"message\":\"ok\"," |
||||
+ "\"data\":{\"taskNo\":\"TK25082700004\",\"orderNo\":\"IP20261110001\"," |
||||
+ "\"sourceNo\":\"OMS-IN-001\"}}"; |
||||
} |
||||
|
||||
@Test |
||||
void sendsDocumentedShape() { |
||||
RecordingTransport transport = RecordingTransport.create() |
||||
.route(YqnConstants.PATH_INBOUND_SKU_LABEL, req -> Responses.ok(okBody())); |
||||
YqnAdapter adapter = new YqnAdapter(transport, new JacksonJsonCodec()); |
||||
|
||||
LabelPrintTask task = adapter.printSkuLabel(ctx(), command()); |
||||
|
||||
String body = transport.lastDataRequest().body(); |
||||
assertTrue(body.contains("\"orderNo\":\"IP20261110001\""), body); |
||||
assertTrue(body.contains("\"sourceNo\":\"OMS-IN-001\""), body); |
||||
assertTrue(body.contains("\"downloadMode\":2"), body); |
||||
// 70*30 是文档里的第 7 个
|
||||
assertTrue(body.contains("\"labelSizeType\":7"), body); |
||||
assertTrue(body.contains("\"originCountry\":\"US\""), body); |
||||
assertTrue(body.contains("\"isShowEn\":true"), body); |
||||
assertTrue(body.contains("\"isShowCn\":true"), body); |
||||
|
||||
assertEquals("TK25082700004", task.taskNo()); |
||||
assertEquals(WarehouseProvider.YQN, task.sourceProvider()); |
||||
assertNull(task.label()); |
||||
} |
||||
|
||||
/** 文档默认:二维码与 ERP SKU 都显示,中文不显示。 */ |
||||
@Test |
||||
void appliesDocumentedDefaults() { |
||||
SkuLabelCommand defaults = SkuLabelCommand.builder() |
||||
.providerInboundNo("IP1").inboundRequestNo("OMS-1") |
||||
.sizeType(SkuLabelSizeType.SIZE_40_30) |
||||
.build(); |
||||
RecordingTransport transport = RecordingTransport.create() |
||||
.route(YqnConstants.PATH_INBOUND_SKU_LABEL, req -> Responses.ok(okBody())); |
||||
new YqnAdapter(transport, new JacksonJsonCodec()).printSkuLabel(ctx(), defaults); |
||||
|
||||
String body = transport.lastDataRequest().body(); |
||||
assertTrue(body.contains("\"isShowQrCode\":true"), body); |
||||
assertTrue(body.contains("\"isShowErpSku\":true"), body); |
||||
assertTrue(body.contains("\"isShowCn\":false"), body); |
||||
// 未指定原产地就不发这个字段
|
||||
assertFalse(body.contains("originCountry"), body); |
||||
} |
||||
|
||||
@Test |
||||
void originCountryIsUpperCasedAndBlankIsDropped() { |
||||
SkuLabelCommand blank = SkuLabelCommand.builder() |
||||
.providerInboundNo("IP1").inboundRequestNo("OMS-1") |
||||
.sizeType(SkuLabelSizeType.SIZE_40_30) |
||||
.originCountry(" ") |
||||
.build(); |
||||
assertNull(blank.originCountry()); |
||||
} |
||||
|
||||
@Test |
||||
void allFourteenSizesMapInDocumentOrder() { |
||||
assertEquals(Integer.valueOf(1), YqnSkuLabelMapper.sizeTypeCode(SkuLabelSizeType.SIZE_40_30)); |
||||
assertEquals(Integer.valueOf(2), YqnSkuLabelMapper.sizeTypeCode(SkuLabelSizeType.SIZE_50_30)); |
||||
assertEquals(Integer.valueOf(3), YqnSkuLabelMapper.sizeTypeCode(SkuLabelSizeType.SIZE_50_40)); |
||||
assertEquals(Integer.valueOf(4), YqnSkuLabelMapper.sizeTypeCode(SkuLabelSizeType.SIZE_60_30)); |
||||
assertEquals(Integer.valueOf(5), YqnSkuLabelMapper.sizeTypeCode(SkuLabelSizeType.SIZE_60_40)); |
||||
assertEquals(Integer.valueOf(6), YqnSkuLabelMapper.sizeTypeCode(SkuLabelSizeType.SIZE_70_20)); |
||||
assertEquals(Integer.valueOf(7), YqnSkuLabelMapper.sizeTypeCode(SkuLabelSizeType.SIZE_70_30)); |
||||
assertEquals(Integer.valueOf(8), YqnSkuLabelMapper.sizeTypeCode(SkuLabelSizeType.SIZE_70_40)); |
||||
assertEquals(Integer.valueOf(9), YqnSkuLabelMapper.sizeTypeCode(SkuLabelSizeType.SIZE_70_50)); |
||||
assertEquals(Integer.valueOf(10), YqnSkuLabelMapper.sizeTypeCode(SkuLabelSizeType.SIZE_80_50)); |
||||
assertEquals(Integer.valueOf(11), YqnSkuLabelMapper.sizeTypeCode(SkuLabelSizeType.SIZE_80_60)); |
||||
assertEquals(Integer.valueOf(12), YqnSkuLabelMapper.sizeTypeCode(SkuLabelSizeType.SIZE_100_30)); |
||||
assertEquals(Integer.valueOf(13), YqnSkuLabelMapper.sizeTypeCode(SkuLabelSizeType.SIZE_100_60)); |
||||
assertEquals(Integer.valueOf(14), YqnSkuLabelMapper.sizeTypeCode(SkuLabelSizeType.SIZE_100_100)); |
||||
assertEquals(14, SkuLabelSizeType.values().length); |
||||
} |
||||
|
||||
@Test |
||||
void archiveModeMapsToOne() { |
||||
assertEquals(Integer.valueOf(1), YqnSkuLabelMapper.downloadModeCode(LabelDownloadMode.ARCHIVE)); |
||||
assertEquals(Integer.valueOf(2), YqnSkuLabelMapper.downloadModeCode(LabelDownloadMode.PDF)); |
||||
} |
||||
|
||||
@Test |
||||
void declaresSkuLabelCapability() { |
||||
YqnAdapter adapter = new YqnAdapter(RecordingTransport.create(), new JacksonJsonCodec()); |
||||
assertTrue(adapter.capabilities().contains(WarehouseCapability.SKU_LABEL)); |
||||
// 箱标与 SKU 标是两个独立能力位
|
||||
assertTrue(adapter.capabilities().contains(WarehouseCapability.BOX_LABEL)); |
||||
} |
||||
|
||||
@Test |
||||
void sizeTypeIsRequired() { |
||||
assertThrows(IllegalArgumentException.class, () -> SkuLabelCommand.builder() |
||||
.providerInboundNo("IP1").inboundRequestNo("OMS-1").build()); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue