You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.9 KiB

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