Browse Source
- 新增 HengjianInboundCreateDtos + HengjianInboundMapper,实现 InboundCapable.create,声明 INBOUND - 真机确认必填 orderNo / warehouseCode / inventoryType / productItems; 文档标必填的 currency 真机不校验,按选填实现 - 响应不回仓单号(只有 code/message),providerInboundId 保持 null, 不拿来源单号顶替 - 柜型按恒健的四个独立字段映射(20GP/40GP/40HQ/45HQ + 各自箱号); 认不出的柜型直接拒绝,静默丢弃等于少报柜数 - 装箱信息映射 cartonItems(尺寸 cm / 重量 g),空则不传 - 入库查询 / 分页未接,显式抛异常而非返回 null - core InboundCommand 补 6 个恒健协议字段(documentStatus / purchaseOrderNos / actualShipDate / goodsType / shippingCompanyName / containers), 其它仓不读,行为不变 验证:mvn test 全量通过,恒健 220 个用例(+17)通过。 Co-Authored-By: Claude Code <noreply@anthropic.com>master
11 changed files with 928 additions and 15 deletions
@ -0,0 +1,210 @@ |
|||||||
|
package common.ecommerce.hengjian.adapter; |
||||||
|
|
||||||
|
import common.ecommerce.hengjian.dto.HengjianInboundCreateDtos; |
||||||
|
import common.ecommerce.shared.support.Money; |
||||||
|
import common.ecommerce.warehouse.model.InboundCarton; |
||||||
|
import common.ecommerce.warehouse.model.InboundCommand; |
||||||
|
import common.ecommerce.warehouse.model.InboundLine; |
||||||
|
|
||||||
|
import java.time.LocalDate; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Locale; |
||||||
|
|
||||||
|
/** |
||||||
|
* 恒健入库计划报文映射({@code POST /v1/inbound/createInboundPlan})。 |
||||||
|
* |
||||||
|
* <h2>真机确认的必填项</h2> |
||||||
|
* <p>{@code orderNo} / {@code warehouseCode} / {@code inventoryType} / {@code productItems}。 |
||||||
|
* 文档还标了 {@code currency},但真机校验里没有它,按选填实现。</p> |
||||||
|
* |
||||||
|
* <h2>响应不回仓单号</h2> |
||||||
|
* <p>只有 {@code code / message},所以 {@code InboundReceipt.providerInboundId} 为 null。 |
||||||
|
* 后续查详情 / 取消只能用<b>来源单号</b>({@code orderNo})。</p> |
||||||
|
* |
||||||
|
* <h2>柜型映射</h2> |
||||||
|
* <p>恒健把四种柜型拆成独立字段({@code gpQuantity20} / {@code gpQuantity40} / |
||||||
|
* {@code hqQuantity40} / {@code hqQuantity45} + 各自的箱号)。 |
||||||
|
* 统一模型的 {@code InboundCommand.Container} 用「柜型 + 数量 + 箱号」表达, |
||||||
|
* 这里按柜型名映射;认不出的柜型<b>直接拒绝</b>——静默丢弃等于少报柜数。</p> |
||||||
|
*/ |
||||||
|
public final class HengjianInboundMapper { |
||||||
|
|
||||||
|
/** 柜型的可识别写法(大小写不敏感)。 */ |
||||||
|
private static final String GP20 = "20GP"; |
||||||
|
private static final String GP40 = "40GP"; |
||||||
|
private static final String HQ40 = "40HQ"; |
||||||
|
private static final String HQ45 = "45HQ"; |
||||||
|
|
||||||
|
private HengjianInboundMapper() { |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 统一命令 → 恒健创建请求。 |
||||||
|
* |
||||||
|
* @param warehouseCode 仓 code(命令显式指定优先,其次账户配置) |
||||||
|
* @throws IllegalArgumentException 缺必填项,或柜型无法识别 |
||||||
|
*/ |
||||||
|
public static HengjianInboundCreateDtos.CreateRequest toRequest(InboundCommand cmd, |
||||||
|
String warehouseCode) { |
||||||
|
if (cmd.lines().isEmpty()) { |
||||||
|
throw new IllegalArgumentException( |
||||||
|
"hengjian inbound plan requires at least one product line"); |
||||||
|
} |
||||||
|
String orderNo = requireText(cmd.inboundRequestNo(), "inboundRequestNo"); |
||||||
|
String wh = requireText(warehouseCode, "warehouseCode"); |
||||||
|
|
||||||
|
HengjianInboundCreateDtos.CreateRequest req = new HengjianInboundCreateDtos.CreateRequest(); |
||||||
|
req.orderNo = orderNo; |
||||||
|
req.warehouseCode = wh; |
||||||
|
req.inventoryType = cmd.inventoryType(); |
||||||
|
req.status = cmd.documentStatus(); |
||||||
|
req.lineCode = trimToNull(cmd.lineName()); |
||||||
|
req.batchNumber = trimToNull(cmd.factoryBatchNo()); |
||||||
|
req.currency = trimToNull(cmd.currency()); |
||||||
|
req.shipmentId = trimToNull(cmd.shipmentId()); |
||||||
|
req.referenceId = trimToNull(cmd.referenceId()); |
||||||
|
req.estimateArriveTime = dateOf(cmd.estimateArriveDate()); |
||||||
|
req.predictionShipDate = dateOf(cmd.predictionShipDate()); |
||||||
|
req.expectArriveDate = dateOf(cmd.expectArriveDate()); |
||||||
|
req.shipperName = trimToNull(cmd.shipperName()); |
||||||
|
req.shipperAddress = trimToNull(cmd.shipperAddress()); |
||||||
|
req.shipperContact = trimToNull(cmd.shipperContact()); |
||||||
|
req.shipperPhone = trimToNull(cmd.shipperPhone()); |
||||||
|
req.remark = trimToNull(cmd.remark()); |
||||||
|
req.originCountry = trimToNull(cmd.originCountry()); |
||||||
|
req.poNos = trimToNull(cmd.purchaseOrderNos()); |
||||||
|
req.actualShipDate = dateOf(cmd.actualShipDate()); |
||||||
|
req.shippingCompany = trimToNull(cmd.shippingCompanyName()); |
||||||
|
req.goodsType = cmd.goodsType(); |
||||||
|
// tmsNo 是单值;统一模型是列表,多个时用逗号拼(文档没写分隔符,按逗号约定)
|
||||||
|
if (!cmd.transportOrderNos().isEmpty()) { |
||||||
|
req.tmsNo = join(cmd.transportOrderNos()); |
||||||
|
} |
||||||
|
|
||||||
|
req.productItems = toProductItems(cmd.lines()); |
||||||
|
req.cartonItems = toCartonItems(cmd.cartons()); |
||||||
|
applyContainers(req, cmd.containers()); |
||||||
|
return req; |
||||||
|
} |
||||||
|
|
||||||
|
private static List<HengjianInboundCreateDtos.CreateRequest.ProductItem> toProductItems( |
||||||
|
List<InboundLine> lines) { |
||||||
|
List<HengjianInboundCreateDtos.CreateRequest.ProductItem> out = |
||||||
|
new ArrayList<HengjianInboundCreateDtos.CreateRequest.ProductItem>(lines.size()); |
||||||
|
for (InboundLine line : lines) { |
||||||
|
HengjianInboundCreateDtos.CreateRequest.ProductItem item = |
||||||
|
new HengjianInboundCreateDtos.CreateRequest.ProductItem(); |
||||||
|
item.sku = skuOf(line); |
||||||
|
item.qty = line.quantity(); |
||||||
|
Money cost = line.cost(); |
||||||
|
if (cost != null) { |
||||||
|
item.cost = cost.amount().doubleValue(); |
||||||
|
} |
||||||
|
out.add(item); |
||||||
|
} |
||||||
|
return out; |
||||||
|
} |
||||||
|
|
||||||
|
private static List<HengjianInboundCreateDtos.CreateRequest.CartonItem> toCartonItems( |
||||||
|
List<InboundCarton> cartons) { |
||||||
|
if (cartons == null || cartons.isEmpty()) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
List<HengjianInboundCreateDtos.CreateRequest.CartonItem> out = |
||||||
|
new ArrayList<HengjianInboundCreateDtos.CreateRequest.CartonItem>(cartons.size()); |
||||||
|
for (InboundCarton carton : cartons) { |
||||||
|
HengjianInboundCreateDtos.CreateRequest.CartonItem item = |
||||||
|
new HengjianInboundCreateDtos.CreateRequest.CartonItem(); |
||||||
|
item.sku = trimToNull(carton.providerSku()); |
||||||
|
item.qty = carton.quantity() > 0 ? carton.quantity() : null; |
||||||
|
item.cartonQty = carton.cartonQuantity() > 0 ? carton.cartonQuantity() : null; |
||||||
|
item.cartonNo = trimToNull(carton.cartonNo()); |
||||||
|
item.cartonWeight = positiveOrNull(carton.weightGrams()); |
||||||
|
item.cartonLength = positiveOrNull(carton.lengthCm()); |
||||||
|
item.cartonWidth = positiveOrNull(carton.widthCm()); |
||||||
|
item.cartonHeight = positiveOrNull(carton.heightCm()); |
||||||
|
out.add(item); |
||||||
|
} |
||||||
|
return out; |
||||||
|
} |
||||||
|
|
||||||
|
/** 柜型 → 恒健的四个独立字段;认不出的柜型直接拒绝。 */ |
||||||
|
static void applyContainers(HengjianInboundCreateDtos.CreateRequest req, |
||||||
|
List<InboundCommand.Container> containers) { |
||||||
|
if (containers == null || containers.isEmpty()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
for (InboundCommand.Container container : containers) { |
||||||
|
String type = container.containerType().trim().toUpperCase(Locale.ROOT).replace(" ", ""); |
||||||
|
switch (type) { |
||||||
|
case GP20: |
||||||
|
req.gpQuantity20 = container.quantity(); |
||||||
|
req.gpCartonNo20 = trimToNull(container.containerNo()); |
||||||
|
break; |
||||||
|
case GP40: |
||||||
|
req.gpQuantity40 = container.quantity(); |
||||||
|
req.gpCartonNo40 = trimToNull(container.containerNo()); |
||||||
|
break; |
||||||
|
case HQ40: |
||||||
|
req.hqQuantity40 = container.quantity(); |
||||||
|
req.hqCartonNo40 = trimToNull(container.containerNo()); |
||||||
|
break; |
||||||
|
case HQ45: |
||||||
|
req.hqQuantity45 = container.quantity(); |
||||||
|
req.hqCartonNo45 = trimToNull(container.containerNo()); |
||||||
|
break; |
||||||
|
default: |
||||||
|
// 认不出就拒绝:静默丢弃等于少报柜数
|
||||||
|
throw new IllegalArgumentException( |
||||||
|
"hengjian inbound supports container types 20GP / 40GP / 40HQ / 45HQ, got " |
||||||
|
+ container.containerType()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** 仓侧 SKU 优先;没有映射时用 OMS 主 SKU。 */ |
||||||
|
static String skuOf(InboundLine line) { |
||||||
|
String provider = trimToNull(line.providerSku()); |
||||||
|
return provider != null ? provider : line.omsSku(); |
||||||
|
} |
||||||
|
|
||||||
|
private static String dateOf(LocalDate date) { |
||||||
|
return date == null ? null : date.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
private static Double positiveOrNull(double v) { |
||||||
|
return v > 0 ? v : null; |
||||||
|
} |
||||||
|
|
||||||
|
private static String join(List<String> values) { |
||||||
|
StringBuilder sb = new StringBuilder(); |
||||||
|
for (String v : values) { |
||||||
|
String t = trimToNull(v); |
||||||
|
if (t == null) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
if (sb.length() > 0) { |
||||||
|
sb.append(','); |
||||||
|
} |
||||||
|
sb.append(t); |
||||||
|
} |
||||||
|
return sb.length() == 0 ? null : sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
private static String requireText(String value, String field) { |
||||||
|
String v = trimToNull(value); |
||||||
|
if (v == null) { |
||||||
|
throw new IllegalArgumentException("hengjian inbound plan requires " + field); |
||||||
|
} |
||||||
|
return v; |
||||||
|
} |
||||||
|
|
||||||
|
private static String trimToNull(String v) { |
||||||
|
if (v == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
String t = v.trim(); |
||||||
|
return t.isEmpty() ? null : t; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,164 @@ |
|||||||
|
package common.ecommerce.hengjian.dto; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude; |
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 恒健报文结构:入库计划创建({@code POST /v1/inbound/createInboundPlan})。 |
||||||
|
* |
||||||
|
* <p><b>真机确认的必填项</b>(空 body 触发的校验信息):</p> |
||||||
|
* <pre> |
||||||
|
* orderNo(订单号必须填写) |
||||||
|
* warehouseCode(仓库必须填写) |
||||||
|
* inventoryType(库存类型必须填写) |
||||||
|
* productItems(入库产品明细必须填写) |
||||||
|
* </pre> |
||||||
|
* <p>{@code currency} 文档标必填,但<b>真机校验里没有它</b>(不传也能过校验, |
||||||
|
* 只会在鉴权处停下)——按选填实现,不传由仓方按 USD 处理。</p> |
||||||
|
* |
||||||
|
* <p><b>响应没有 data</b>:只有 {@code code / message},<b>不回仓单号</b>。 |
||||||
|
* 所以 {@code InboundReceipt.providerInboundId} 为 null——不能把来源单号当仓单号填进去。</p> |
||||||
|
*/ |
||||||
|
public final class HengjianInboundCreateDtos { |
||||||
|
|
||||||
|
private HengjianInboundCreateDtos() { |
||||||
|
} |
||||||
|
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||||
|
public static final class CreateRequest { |
||||||
|
|
||||||
|
/** |
||||||
|
* 单据状态:0 草稿 / 5 提交;不填默认 5(提交)。 |
||||||
|
* |
||||||
|
* <p>草稿状态下再调本接口是<b>更新</b>,不是新建。</p> |
||||||
|
*/ |
||||||
|
public Integer status; |
||||||
|
|
||||||
|
/** 仓库 code;必填。 */ |
||||||
|
public String warehouseCode; |
||||||
|
|
||||||
|
/** 项目名称。 */ |
||||||
|
public String lineCode; |
||||||
|
|
||||||
|
/** 库存类型:0 正常库存 / 1 不可售库存;必填。 */ |
||||||
|
public Integer inventoryType; |
||||||
|
|
||||||
|
/** 批次号。 */ |
||||||
|
public String batchNumber; |
||||||
|
|
||||||
|
/** 来源单号;必填。 */ |
||||||
|
public String orderNo; |
||||||
|
|
||||||
|
/** Amazon 订单的 ShipmentId。 */ |
||||||
|
public String shipmentId; |
||||||
|
|
||||||
|
/** Amazon 订单的 referenceId。 */ |
||||||
|
public String referenceId; |
||||||
|
|
||||||
|
/** 单据币种,默认 USD,影响库存成本计算。 */ |
||||||
|
public String currency; |
||||||
|
|
||||||
|
/** 预计入库日期 {@code yyyy-MM-dd}。 */ |
||||||
|
public String estimateArriveTime; |
||||||
|
|
||||||
|
/** 预计发运日期 {@code yyyy-MM-dd}。 */ |
||||||
|
public String predictionShipDate; |
||||||
|
|
||||||
|
/** 期望入库日期 {@code yyyy-MM-dd}。 */ |
||||||
|
public String expectArriveDate; |
||||||
|
|
||||||
|
public String shipperName; |
||||||
|
public String shipperAddress; |
||||||
|
public String shipperContact; |
||||||
|
public String shipperPhone; |
||||||
|
public String remark; |
||||||
|
public String originCountry; |
||||||
|
|
||||||
|
/** 采购单号。 */ |
||||||
|
public String poNos; |
||||||
|
|
||||||
|
/** 实际发运日期 {@code yyyy-MM-dd}(自动发运时必填)。 */ |
||||||
|
public String actualShipDate; |
||||||
|
|
||||||
|
/** 物流单号(自动发运用)。 */ |
||||||
|
public String tmsNo; |
||||||
|
|
||||||
|
/** 船运公司(自动发运用)。 */ |
||||||
|
public String shippingCompany; |
||||||
|
|
||||||
|
/** 货物类型:2 集装箱 / 4 卡车(自动发运时必填)。 */ |
||||||
|
public Integer goodsType; |
||||||
|
|
||||||
|
/** 20GP 数量 / 箱号。 */ |
||||||
|
public Integer gpQuantity20; |
||||||
|
public String gpCartonNo20; |
||||||
|
/** 40GP 数量 / 箱号。 */ |
||||||
|
public Integer gpQuantity40; |
||||||
|
public String gpCartonNo40; |
||||||
|
/** 40HQ 数量 / 箱号。 */ |
||||||
|
public Integer hqQuantity40; |
||||||
|
public String hqCartonNo40; |
||||||
|
/** 45HQ 数量 / 箱号。 */ |
||||||
|
public Integer hqQuantity45; |
||||||
|
public String hqCartonNo45; |
||||||
|
|
||||||
|
/** 产品明细;必填。 */ |
||||||
|
public List<ProductItem> productItems; |
||||||
|
|
||||||
|
/** 装箱信息。 */ |
||||||
|
public List<CartonItem> cartonItems; |
||||||
|
|
||||||
|
/** 产品明细行。 */ |
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||||
|
public static final class ProductItem { |
||||||
|
|
||||||
|
/** 入库产品 SKU;必填。 */ |
||||||
|
public String sku; |
||||||
|
|
||||||
|
/** 入库产品数量;必填。 */ |
||||||
|
public Integer qty; |
||||||
|
|
||||||
|
/** 采购成本;影响库存成本,默认 0。 */ |
||||||
|
public Double cost; |
||||||
|
} |
||||||
|
|
||||||
|
/** 装箱信息行。 */ |
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||||
|
public static final class CartonItem { |
||||||
|
|
||||||
|
/** 入库产品 SKU。 */ |
||||||
|
public String sku; |
||||||
|
|
||||||
|
/** 产品数量。 */ |
||||||
|
public Integer qty; |
||||||
|
|
||||||
|
/** 装箱入数。 */ |
||||||
|
public Integer cartonQty; |
||||||
|
|
||||||
|
/** 箱码。 */ |
||||||
|
public String cartonNo; |
||||||
|
|
||||||
|
/** 外箱重量(g)。 */ |
||||||
|
public Double cartonWeight; |
||||||
|
|
||||||
|
/** 外箱尺寸(cm)。 */ |
||||||
|
public Double cartonLength; |
||||||
|
public Double cartonWidth; |
||||||
|
public Double cartonHeight; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** 响应外层:没有 data。 */ |
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true) |
||||||
|
public static final class CreateResponse { |
||||||
|
|
||||||
|
@JsonProperty("code") |
||||||
|
public Integer code; |
||||||
|
|
||||||
|
@JsonProperty("message") |
||||||
|
public String message; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,273 @@ |
|||||||
|
package common.ecommerce.hengjian.adapter; |
||||||
|
|
||||||
|
import common.ecommerce.hengjian.HengjianConstants; |
||||||
|
import common.ecommerce.http.JacksonJsonCodec; |
||||||
|
import common.ecommerce.shared.spi.ChannelSecret; |
||||||
|
import common.ecommerce.shared.support.Money; |
||||||
|
import common.ecommerce.shared.testkit.RecordingTransport; |
||||||
|
import common.ecommerce.shared.testkit.Responses; |
||||||
|
import common.ecommerce.warehouse.enums.WarehouseCapability; |
||||||
|
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||||
|
import common.ecommerce.warehouse.model.InboundCarton; |
||||||
|
import common.ecommerce.warehouse.model.InboundCommand; |
||||||
|
import common.ecommerce.warehouse.model.InboundLine; |
||||||
|
import common.ecommerce.warehouse.model.InboundReceipt; |
||||||
|
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.LocalDate; |
||||||
|
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; |
||||||
|
|
||||||
|
/** |
||||||
|
* 入库计划创建({@code /v1/inbound/createInboundPlan})契约测试。 |
||||||
|
*/ |
||||||
|
class HengjianInboundCreateTest { |
||||||
|
|
||||||
|
private static final WarehouseContext CTX = WarehouseContext.of( |
||||||
|
"HJ-EFCA", WarehouseProvider.HENGJIAN, "EFCA", |
||||||
|
WarehouseConnection.of(HengjianConstants.TEST_BASE_URL, |
||||||
|
ChannelSecret.builder().appSecret("token-1").build()), |
||||||
|
"req-1", Clock.fixed(Instant.parse("2026-11-16T00:00:00Z"), ZoneOffset.UTC)); |
||||||
|
|
||||||
|
private static final String CREATE_BODY = |
||||||
|
"{\"statusCode\":200,\"status\":0,\"code\":200,\"message\":\"创建入库计划成功\"}"; |
||||||
|
|
||||||
|
private static HengjianAdapter adapter(RecordingTransport transport) { |
||||||
|
return new HengjianAdapter(transport, new JacksonJsonCodec()); |
||||||
|
} |
||||||
|
|
||||||
|
private static RecordingTransport creating() { |
||||||
|
return RecordingTransport.create() |
||||||
|
.route(HengjianConstants.PATH_INBOUND_CREATE, req -> Responses.ok(CREATE_BODY)); |
||||||
|
} |
||||||
|
|
||||||
|
private static InboundCommand.Builder command() { |
||||||
|
return InboundCommand.builder() |
||||||
|
.inboundRequestNo("IB-2026-0001") |
||||||
|
.warehouseId("EFCA") |
||||||
|
.inventoryType(0) |
||||||
|
.currency("USD") |
||||||
|
.line(InboundLine.builder().omsSku("SKU-A").quantity(10).build()); |
||||||
|
} |
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 请求形状
|
||||||
|
|
||||||
|
@Test |
||||||
|
void createPostsToInboundPlan() { |
||||||
|
RecordingTransport transport = creating(); |
||||||
|
adapter(transport).create(CTX, command().build()); |
||||||
|
|
||||||
|
assertEquals("POST", transport.lastDataRequest().method()); |
||||||
|
assertEquals(HengjianConstants.TEST_BASE_URL + "/v1/inbound/createInboundPlan", |
||||||
|
transport.lastDataRequest().url()); |
||||||
|
} |
||||||
|
|
||||||
|
/** 真机确认的四个必填项都要出现。 */ |
||||||
|
@Test |
||||||
|
void sendsMandatoryFields() { |
||||||
|
RecordingTransport transport = creating(); |
||||||
|
adapter(transport).create(CTX, command().build()); |
||||||
|
String body = transport.lastDataRequest().body(); |
||||||
|
|
||||||
|
String[] mandatory = {"orderNo", "warehouseCode", "inventoryType", "productItems"}; |
||||||
|
for (String field : mandatory) { |
||||||
|
assertTrue(body.contains("\"" + field + "\""), "缺少必填字段 " + field + ",body=" + body); |
||||||
|
} |
||||||
|
assertTrue(body.contains("\"orderNo\":\"IB-2026-0001\""), body); |
||||||
|
assertTrue(body.contains("\"warehouseCode\":\"EFCA\""), body); |
||||||
|
assertTrue(body.contains("\"inventoryType\":0"), body); |
||||||
|
} |
||||||
|
|
||||||
|
/** 产品明细:sku + qty,成本有就带。 */ |
||||||
|
@Test |
||||||
|
void sendsProductItems() { |
||||||
|
RecordingTransport transport = creating(); |
||||||
|
adapter(transport).create(CTX, InboundCommand.builder() |
||||||
|
.inboundRequestNo("IB-2").warehouseId("EFCA").inventoryType(0) |
||||||
|
.line(InboundLine.builder().omsSku("SKU-A").quantity(10) |
||||||
|
.cost(Money.of("2.50", "USD")).build()) |
||||||
|
.line(InboundLine.builder().providerSku("PROV-B").omsSku("OMS-B").quantity(3).build()) |
||||||
|
.build()); |
||||||
|
String body = transport.lastDataRequest().body(); |
||||||
|
|
||||||
|
assertTrue(body.contains("\"sku\":\"SKU-A\""), body); |
||||||
|
assertTrue(body.contains("\"qty\":10"), body); |
||||||
|
assertTrue(body.contains("\"cost\":2.5"), body); |
||||||
|
// 仓侧 SKU 优先
|
||||||
|
assertTrue(body.contains("\"sku\":\"PROV-B\""), body); |
||||||
|
assertFalse(body.contains("OMS-B"), "有仓侧 SKU 时不该发 OMS SKU"); |
||||||
|
} |
||||||
|
|
||||||
|
/** 文档标必填的 currency 真机校验里没有:不传也要能过。 */ |
||||||
|
@Test |
||||||
|
void currencyIsOptional() { |
||||||
|
RecordingTransport transport = creating(); |
||||||
|
adapter(transport).create(CTX, InboundCommand.builder() |
||||||
|
.inboundRequestNo("IB-3").warehouseId("EFCA").inventoryType(0) |
||||||
|
.line(InboundLine.builder().omsSku("SKU-A").quantity(1).build()).build()); |
||||||
|
|
||||||
|
assertFalse(transport.lastDataRequest().body().contains("currency")); |
||||||
|
} |
||||||
|
|
||||||
|
/** 柜型映射到恒健的四个独立字段。 */ |
||||||
|
@Test |
||||||
|
void mapsContainerTypes() { |
||||||
|
RecordingTransport transport = creating(); |
||||||
|
adapter(transport).create(CTX, command() |
||||||
|
.container(new InboundCommand.Container("20GP", 2, "TCNU1234567")) |
||||||
|
.container(new InboundCommand.Container("40HQ", 1, "OOLU7654321")) |
||||||
|
.build()); |
||||||
|
String body = transport.lastDataRequest().body(); |
||||||
|
|
||||||
|
assertTrue(body.contains("\"gpQuantity20\":2"), body); |
||||||
|
assertTrue(body.contains("\"gpCartonNo20\":\"TCNU1234567\""), body); |
||||||
|
assertTrue(body.contains("\"hqQuantity40\":1"), body); |
||||||
|
assertTrue(body.contains("\"hqCartonNo40\":\"OOLU7654321\""), body); |
||||||
|
} |
||||||
|
|
||||||
|
/** 认不出的柜型直接拒绝:静默丢弃等于少报柜数。 */ |
||||||
|
@Test |
||||||
|
void rejectsUnknownContainerType() { |
||||||
|
RecordingTransport transport = creating(); |
||||||
|
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||||
|
() -> adapter(transport).create(CTX, command() |
||||||
|
.container(new InboundCommand.Container("53FT", 1, null)).build())); |
||||||
|
|
||||||
|
assertTrue(ex.getMessage().contains("20GP"), ex.getMessage()); |
||||||
|
assertTrue(transport.dataRequests().isEmpty()); |
||||||
|
} |
||||||
|
|
||||||
|
/** 装箱信息:空不传,有则逐字段映射。 */ |
||||||
|
@Test |
||||||
|
void mapsCartonItems() { |
||||||
|
RecordingTransport transport = creating(); |
||||||
|
adapter(transport).create(CTX, command() |
||||||
|
.carton(InboundCarton.builder() |
||||||
|
.providerSku("SKU-A").quantity(10).cartonQuantity(5) |
||||||
|
.cartonNo("CTN-1") |
||||||
|
.weightGrams(1200).lengthCm(40).widthCm(30).heightCm(20) |
||||||
|
.build()) |
||||||
|
.build()); |
||||||
|
String body = transport.lastDataRequest().body(); |
||||||
|
|
||||||
|
assertTrue(body.contains("\"cartonItems\""), body); |
||||||
|
assertTrue(body.contains("\"cartonQty\":5"), body); |
||||||
|
assertTrue(body.contains("\"cartonNo\":\"CTN-1\""), body); |
||||||
|
assertTrue(body.contains("\"cartonWeight\":1200.0"), body); |
||||||
|
assertTrue(body.contains("\"cartonHeight\":20.0"), body); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void omitsCartonItemsWhenEmpty() { |
||||||
|
RecordingTransport transport = creating(); |
||||||
|
adapter(transport).create(CTX, command().build()); |
||||||
|
|
||||||
|
assertFalse(transport.lastDataRequest().body().contains("cartonItems")); |
||||||
|
} |
||||||
|
|
||||||
|
/** 日期按 yyyy-MM-dd 下发。 */ |
||||||
|
@Test |
||||||
|
void formatsDates() { |
||||||
|
RecordingTransport transport = creating(); |
||||||
|
adapter(transport).create(CTX, command() |
||||||
|
.estimateArriveDate(LocalDate.parse("2026-12-01")) |
||||||
|
.expectArriveDate(LocalDate.parse("2026-12-05")) |
||||||
|
.predictionShipDate(LocalDate.parse("2026-11-20")) |
||||||
|
.actualShipDate(LocalDate.parse("2026-11-21")) |
||||||
|
.build()); |
||||||
|
String body = transport.lastDataRequest().body(); |
||||||
|
|
||||||
|
assertTrue(body.contains("\"estimateArriveTime\":\"2026-12-01\""), body); |
||||||
|
assertTrue(body.contains("\"expectArriveDate\":\"2026-12-05\""), body); |
||||||
|
assertTrue(body.contains("\"predictionShipDate\":\"2026-11-20\""), body); |
||||||
|
assertTrue(body.contains("\"actualShipDate\":\"2026-11-21\""), body); |
||||||
|
} |
||||||
|
|
||||||
|
/** 草稿状态可传:恒健的 status=0 是草稿,再调是更新。 */ |
||||||
|
@Test |
||||||
|
void sendsDocumentStatus() { |
||||||
|
RecordingTransport transport = creating(); |
||||||
|
adapter(transport).create(CTX, command().documentStatus(0).build()); |
||||||
|
|
||||||
|
assertTrue(transport.lastDataRequest().body().contains("\"status\":0")); |
||||||
|
} |
||||||
|
|
||||||
|
/** 其它可选字段:采购单号 / 船运公司 / 货物类型。 */ |
||||||
|
@Test |
||||||
|
void sendsOptionalInboundFields() { |
||||||
|
RecordingTransport transport = creating(); |
||||||
|
adapter(transport).create(CTX, command() |
||||||
|
.purchaseOrderNos("PO-1,PO-2") |
||||||
|
.shippingCompanyName("COSCO") |
||||||
|
.goodsType(2) |
||||||
|
.build()); |
||||||
|
String body = transport.lastDataRequest().body(); |
||||||
|
|
||||||
|
assertTrue(body.contains("\"poNos\":\"PO-1,PO-2\""), body); |
||||||
|
assertTrue(body.contains("\"shippingCompany\":\"COSCO\""), body); |
||||||
|
assertTrue(body.contains("\"goodsType\":2"), body); |
||||||
|
} |
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 本地校验
|
||||||
|
|
||||||
|
@Test |
||||||
|
void rejectsEmptyLines() { |
||||||
|
RecordingTransport transport = creating(); |
||||||
|
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||||
|
() -> adapter(transport).create(CTX, InboundCommand.builder() |
||||||
|
.inboundRequestNo("IB-X").warehouseId("EFCA").inventoryType(0).build())); |
||||||
|
|
||||||
|
assertTrue(ex.getMessage().contains("product line"), ex.getMessage()); |
||||||
|
assertTrue(transport.dataRequests().isEmpty()); |
||||||
|
} |
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 响应
|
||||||
|
|
||||||
|
/** 响应不回仓单号:不能拿来源单号顶替。 */ |
||||||
|
@Test |
||||||
|
void receiptHasNoProviderId() { |
||||||
|
RecordingTransport transport = creating(); |
||||||
|
InboundReceipt receipt = adapter(transport).create(CTX, command().build()); |
||||||
|
|
||||||
|
assertEquals("IB-2026-0001", receipt.inboundRequestNo()); |
||||||
|
assertNull(receipt.providerInboundId(), "恒健不回仓单号,不能把来源单号填进去"); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void businessErrorIsPropagated() { |
||||||
|
RecordingTransport transport = RecordingTransport.create() |
||||||
|
.route(HengjianConstants.PATH_INBOUND_CREATE, req -> Responses.ok( |
||||||
|
"{\"statusCode\":500,\"status\":1,\"code\":999999," |
||||||
|
+ "\"message\":\"创建入库计划单失败SH1975454678入库订单已存在\"}")); |
||||||
|
|
||||||
|
RuntimeException ex = assertThrows(RuntimeException.class, |
||||||
|
() -> adapter(transport).create(CTX, command().build())); |
||||||
|
assertTrue(ex.getMessage().contains("入库订单已存在"), ex.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 能力位
|
||||||
|
|
||||||
|
@Test |
||||||
|
void declaresInboundCapability() { |
||||||
|
assertTrue(adapter(RecordingTransport.create()).capabilities() |
||||||
|
.contains(WarehouseCapability.INBOUND)); |
||||||
|
} |
||||||
|
|
||||||
|
/** 查询 / 分页还没接:显式拒绝,不返回 null。 */ |
||||||
|
@Test |
||||||
|
void unimplementedInboundQuery() { |
||||||
|
HengjianAdapter adapter = adapter(RecordingTransport.create()); |
||||||
|
|
||||||
|
assertThrows(RuntimeException.class, () -> adapter.get(CTX, "IB-1")); |
||||||
|
assertThrows(RuntimeException.class, () -> adapter.query(CTX, "IB-1")); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue