|
|
|
|
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 newPrintCaseMark})映射。
|
|
|
|
|
*
|
|
|
|
|
* <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());
|
|
|
|
|
}
|
|
|
|
|
}
|