Browse Source
- 路径 /inbound/inboundCreate → /v1/inbound/createInboundPlan - 响应回 data.inboundPlanOrderNo(字符串),直接作 providerInboundId 入库模型按文档重写,补齐此前缺的维度: - InboundCommand 补 inventoryType(必填) / factoryBatchNo / currency / 三个日期 / 原产地 / 发货方四项 / 集装箱号 / 装箱 / 批次 - InboundLine 的 boxNo 换成 cost(采购成本影响仓侧库存成本) - 新增 InboundCarton(箱规 + sid 归并物理箱)、InboundBatch(批次属性 开放式 key/value,各仓支持的 key 不同,不做枚举) 两条本地校验: - 集装箱号必须是 4 位大写字母 + 7 位数字,传错仓侧直接拒 - expectArriveDate 不能早于 estimateArriveDate 两个显式放弃: - logisticsType 固定 0:文档写明运去哪头程只支持 web 端,openapi 不开放 - 入库单查询未接:文档只给了创建接口,get/query 抛 UnsupportedCapability,不返回空页 Co-Authored-By: Claude <noreply@anthropic.com>feature/supplier-lingxing
8 changed files with 797 additions and 27 deletions
@ -0,0 +1,115 @@
@@ -0,0 +1,115 @@
|
||||
package common.ecommerce.warehouse.model; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 入库批次明细。 |
||||
* |
||||
* <p>批次属性是「key + value」的开放式集合,各仓支持的 key 不同 |
||||
* (运去哪用 {@code ProductionDateNumber}、{@code BatchNumber}、{@code InboundTime} 等), |
||||
* 所以这里不做枚举,交给调用方按仓方文档填。</p> |
||||
*/ |
||||
public final class InboundBatch { |
||||
|
||||
private final String providerSku; |
||||
/** 箱唛号;正式箱唛规则由仓方约束(如至少 7 位、末四位为数字)。 */ |
||||
private final String cartonNo; |
||||
private final int quantity; |
||||
private final List<BatchParam> params; |
||||
|
||||
private InboundBatch(Builder b) { |
||||
this.providerSku = require(b.providerSku, "providerSku"); |
||||
this.cartonNo = b.cartonNo; |
||||
if (b.quantity <= 0) { |
||||
throw new IllegalArgumentException("quantity must be positive"); |
||||
} |
||||
this.quantity = b.quantity; |
||||
if (b.params.isEmpty()) { |
||||
throw new IllegalArgumentException("batch params must not be empty"); |
||||
} |
||||
this.params = Collections.unmodifiableList(new ArrayList<BatchParam>(b.params)); |
||||
} |
||||
|
||||
public static Builder builder() { |
||||
return new Builder(); |
||||
} |
||||
|
||||
public String providerSku() { |
||||
return providerSku; |
||||
} |
||||
|
||||
public String cartonNo() { |
||||
return cartonNo; |
||||
} |
||||
|
||||
public int quantity() { |
||||
return quantity; |
||||
} |
||||
|
||||
public List<BatchParam> params() { |
||||
return params; |
||||
} |
||||
|
||||
private static String require(String v, String n) { |
||||
if (v == null || v.trim().isEmpty()) { |
||||
throw new IllegalArgumentException(n + " must not be blank"); |
||||
} |
||||
return v.trim(); |
||||
} |
||||
|
||||
/** 一条批次属性。 */ |
||||
public static final class BatchParam { |
||||
|
||||
private final String key; |
||||
private final String value; |
||||
|
||||
public BatchParam(String key, String value) { |
||||
if (key == null || key.trim().isEmpty()) { |
||||
throw new IllegalArgumentException("batchAttriKey must not be blank"); |
||||
} |
||||
this.key = key.trim(); |
||||
this.value = value; |
||||
} |
||||
|
||||
public String key() { |
||||
return key; |
||||
} |
||||
|
||||
public String value() { |
||||
return value; |
||||
} |
||||
} |
||||
|
||||
public static final class Builder { |
||||
private String providerSku; |
||||
private String cartonNo; |
||||
private int quantity; |
||||
private final List<BatchParam> params = new ArrayList<BatchParam>(); |
||||
|
||||
public Builder providerSku(String v) { |
||||
this.providerSku = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder cartonNo(String v) { |
||||
this.cartonNo = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder quantity(int v) { |
||||
this.quantity = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder param(String key, String value) { |
||||
this.params.add(new BatchParam(key, value)); |
||||
return this; |
||||
} |
||||
|
||||
public InboundBatch build() { |
||||
return new InboundBatch(this); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,149 @@
@@ -0,0 +1,149 @@
|
||||
package common.ecommerce.warehouse.model; |
||||
|
||||
/** |
||||
* 入库装箱信息(箱规)。 |
||||
* |
||||
* <p>{@code cartonNo} 是箱码,仓侧必填且唯一。{@code sid} 用来归并同一个物理箱: |
||||
* 一箱多 SKU 时会拆成多行,同 {@code sid} 的行属于同一箱。</p> |
||||
* |
||||
* <p>尺寸单位 cm、重量单位 g,与仓库域其它模型一致。</p> |
||||
*/ |
||||
public final class InboundCarton { |
||||
|
||||
private final String providerSku; |
||||
private final int quantity; |
||||
/** 装箱入数。 */ |
||||
private final int cartonQuantity; |
||||
/** 箱码;必填。 */ |
||||
private final String cartonNo; |
||||
/** 箱序标识;一箱多 SKU 时用来归并同一物理箱。 */ |
||||
private final String sid; |
||||
private final double weightGrams; |
||||
private final double lengthCm; |
||||
private final double widthCm; |
||||
private final double heightCm; |
||||
|
||||
private InboundCarton(Builder b) { |
||||
this.providerSku = require(b.providerSku, "providerSku"); |
||||
if (b.quantity <= 0) { |
||||
throw new IllegalArgumentException("quantity must be positive"); |
||||
} |
||||
this.quantity = b.quantity; |
||||
this.cartonQuantity = b.cartonQuantity; |
||||
this.cartonNo = require(b.cartonNo, "cartonNo"); |
||||
this.sid = b.sid; |
||||
this.weightGrams = b.weightGrams; |
||||
this.lengthCm = b.lengthCm; |
||||
this.widthCm = b.widthCm; |
||||
this.heightCm = b.heightCm; |
||||
} |
||||
|
||||
public static Builder builder() { |
||||
return new Builder(); |
||||
} |
||||
|
||||
public String providerSku() { |
||||
return providerSku; |
||||
} |
||||
|
||||
public int quantity() { |
||||
return quantity; |
||||
} |
||||
|
||||
/** 装箱入数;未指定为 0。 */ |
||||
public int cartonQuantity() { |
||||
return cartonQuantity; |
||||
} |
||||
|
||||
public String cartonNo() { |
||||
return cartonNo; |
||||
} |
||||
|
||||
public String sid() { |
||||
return sid; |
||||
} |
||||
|
||||
public double weightGrams() { |
||||
return weightGrams; |
||||
} |
||||
|
||||
public double lengthCm() { |
||||
return lengthCm; |
||||
} |
||||
|
||||
public double widthCm() { |
||||
return widthCm; |
||||
} |
||||
|
||||
public double heightCm() { |
||||
return heightCm; |
||||
} |
||||
|
||||
private static String require(String v, String n) { |
||||
if (v == null || v.trim().isEmpty()) { |
||||
throw new IllegalArgumentException(n + " must not be blank"); |
||||
} |
||||
return v.trim(); |
||||
} |
||||
|
||||
public static final class Builder { |
||||
private String providerSku; |
||||
private int quantity; |
||||
private int cartonQuantity; |
||||
private String cartonNo; |
||||
private String sid; |
||||
private double weightGrams; |
||||
private double lengthCm; |
||||
private double widthCm; |
||||
private double heightCm; |
||||
|
||||
public Builder providerSku(String v) { |
||||
this.providerSku = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder quantity(int v) { |
||||
this.quantity = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder cartonQuantity(int v) { |
||||
this.cartonQuantity = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder cartonNo(String v) { |
||||
this.cartonNo = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder sid(String v) { |
||||
this.sid = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder weightGrams(double v) { |
||||
this.weightGrams = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder lengthCm(double v) { |
||||
this.lengthCm = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder widthCm(double v) { |
||||
this.widthCm = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder heightCm(double v) { |
||||
this.heightCm = v; |
||||
return this; |
||||
} |
||||
|
||||
public InboundCarton build() { |
||||
return new InboundCarton(this); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,151 @@
@@ -0,0 +1,151 @@
|
||||
package common.ecommerce.yqn.adapter; |
||||
|
||||
import common.ecommerce.shared.support.Money; |
||||
import common.ecommerce.warehouse.model.InboundBatch; |
||||
import common.ecommerce.warehouse.model.InboundCarton; |
||||
import common.ecommerce.warehouse.model.InboundCommand; |
||||
import common.ecommerce.warehouse.model.InboundLine; |
||||
import common.ecommerce.yqn.dto.YqnDtos; |
||||
|
||||
import java.time.LocalDate; |
||||
import java.time.format.DateTimeFormatter; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 运去哪入库计划报文映射(API 97)。 |
||||
*/ |
||||
public final class YqnInboundMapper { |
||||
|
||||
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
||||
|
||||
/** 容器号:4 位大写字母 + 7 位数字。 */ |
||||
private static final java.util.regex.Pattern CONTAINER_NO = |
||||
java.util.regex.Pattern.compile("^[A-Z]{4}\\d{7}$"); |
||||
|
||||
private YqnInboundMapper() { |
||||
} |
||||
|
||||
/** 统一命令 → 运去哪创建入库计划请求。 */ |
||||
public static YqnDtos.CreateInboundPlanRequest toRequest(InboundCommand cmd, String warehouseCode) { |
||||
requireContainerNo(cmd.containerNo()); |
||||
|
||||
YqnDtos.CreateInboundPlanRequest req = new YqnDtos.CreateInboundPlanRequest(); |
||||
req.warehouseCode = warehouseCode; |
||||
req.orderNo = cmd.inboundRequestNo(); |
||||
req.inventoryType = cmd.inventoryType(); |
||||
req.batchNumber = cmd.factoryBatchNo(); |
||||
req.currency = cmd.currency(); |
||||
req.estimateArriveTime = formatDate(cmd.estimateArriveDate()); |
||||
req.expectArriveDate = formatDate(cmd.expectArriveDate()); |
||||
req.predictionShipDate = formatDate(cmd.predictionShipDate()); |
||||
req.originCountry = cmd.originCountry(); |
||||
req.shipperName = cmd.shipperName(); |
||||
req.shipperAddress = cmd.shipperAddress(); |
||||
req.shipperContact = cmd.shipperContact(); |
||||
req.shipperPhone = cmd.shipperPhone(); |
||||
req.containerNo = cmd.containerNo(); |
||||
req.remark = cmd.remark(); |
||||
// openapi 只支持自发头程;给 1 会被仓拒绝,这里前置挡掉
|
||||
req.logisticsType = 0; |
||||
|
||||
req.productItems = toProductItems(cmd.lines()); |
||||
req.cartonItems = toCartonItems(cmd.cartons()); |
||||
req.batchItems = toBatchItems(cmd.batches()); |
||||
return req; |
||||
} |
||||
|
||||
private static List<YqnDtos.CreateInboundPlanRequest.InboundProductItem> toProductItems( |
||||
List<InboundLine> lines) { |
||||
List<YqnDtos.CreateInboundPlanRequest.InboundProductItem> items = |
||||
new ArrayList<YqnDtos.CreateInboundPlanRequest.InboundProductItem>(lines.size()); |
||||
for (InboundLine line : lines) { |
||||
YqnDtos.CreateInboundPlanRequest.InboundProductItem item = |
||||
new YqnDtos.CreateInboundPlanRequest.InboundProductItem(); |
||||
item.sku = skuOf(line.providerSku(), line.omsSku()); |
||||
item.qty = line.quantity(); |
||||
Money cost = line.cost(); |
||||
item.cost = cost == null ? null : cost.amount().doubleValue(); |
||||
items.add(item); |
||||
} |
||||
return items; |
||||
} |
||||
|
||||
private static List<YqnDtos.CreateInboundPlanRequest.InboundCartonItem> toCartonItems( |
||||
List<InboundCarton> cartons) { |
||||
if (cartons == null || cartons.isEmpty()) { |
||||
return null; |
||||
} |
||||
List<YqnDtos.CreateInboundPlanRequest.InboundCartonItem> items = |
||||
new ArrayList<YqnDtos.CreateInboundPlanRequest.InboundCartonItem>(cartons.size()); |
||||
for (InboundCarton carton : cartons) { |
||||
YqnDtos.CreateInboundPlanRequest.InboundCartonItem item = |
||||
new YqnDtos.CreateInboundPlanRequest.InboundCartonItem(); |
||||
item.sku = carton.providerSku(); |
||||
item.qty = carton.quantity(); |
||||
item.cartonQty = carton.cartonQuantity() > 0 ? carton.cartonQuantity() : null; |
||||
item.cartonNo = carton.cartonNo(); |
||||
item.sid = carton.sid(); |
||||
item.cartonWeight = positiveOrNull(carton.weightGrams()); |
||||
item.cartonLength = positiveOrNull(carton.lengthCm()); |
||||
item.cartonWidth = positiveOrNull(carton.widthCm()); |
||||
item.cartonHeight = positiveOrNull(carton.heightCm()); |
||||
items.add(item); |
||||
} |
||||
return items; |
||||
} |
||||
|
||||
private static List<YqnDtos.CreateInboundPlanRequest.InboundBatchItem> toBatchItems( |
||||
List<InboundBatch> batches) { |
||||
if (batches == null || batches.isEmpty()) { |
||||
return null; |
||||
} |
||||
List<YqnDtos.CreateInboundPlanRequest.InboundBatchItem> items = |
||||
new ArrayList<YqnDtos.CreateInboundPlanRequest.InboundBatchItem>(batches.size()); |
||||
for (InboundBatch batch : batches) { |
||||
YqnDtos.CreateInboundPlanRequest.InboundBatchItem item = |
||||
new YqnDtos.CreateInboundPlanRequest.InboundBatchItem(); |
||||
item.sku = batch.providerSku(); |
||||
item.cartonNo = batch.cartonNo(); |
||||
item.qty = batch.quantity(); |
||||
List<YqnDtos.CreateInboundPlanRequest.BatchAttr> params = |
||||
new ArrayList<YqnDtos.CreateInboundPlanRequest.BatchAttr>(batch.params().size()); |
||||
for (InboundBatch.BatchParam param : batch.params()) { |
||||
YqnDtos.CreateInboundPlanRequest.BatchAttr attr = |
||||
new YqnDtos.CreateInboundPlanRequest.BatchAttr(); |
||||
attr.batchAttriKey = param.key(); |
||||
attr.batchAttriValue = param.value(); |
||||
params.add(attr); |
||||
} |
||||
item.batchParam = params; |
||||
items.add(item); |
||||
} |
||||
return items; |
||||
} |
||||
|
||||
/** 运去哪对集装箱号有格式要求,传错会被仓拒绝;本地先挡,省一个来回。 */ |
||||
static void requireContainerNo(String containerNo) { |
||||
if (containerNo == null || containerNo.trim().isEmpty()) { |
||||
return; |
||||
} |
||||
if (!CONTAINER_NO.matcher(containerNo.trim()).matches()) { |
||||
throw new IllegalArgumentException( |
||||
"yqn containerNo must be 4 uppercase letters + 7 digits, got: " + containerNo); |
||||
} |
||||
} |
||||
|
||||
static String formatDate(LocalDate date) { |
||||
return date == null ? null : DATE.format(date); |
||||
} |
||||
|
||||
static String skuOf(String providerSku, String omsSku) { |
||||
if (providerSku != null && !providerSku.trim().isEmpty()) { |
||||
return providerSku.trim(); |
||||
} |
||||
return omsSku; |
||||
} |
||||
|
||||
private static Double positiveOrNull(double v) { |
||||
return v > 0 ? v : null; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue