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.

77 lines
2.9 KiB

refactor(warehouse): 必填校验从模型下沉到各仓适配器 统一模型此前把运去哪的协议要求(packingType、两个预计日期、调拨出库必须给 shipTo)写进了构造期校验,接第二家仓时会被第一家的约束卡住:信仓既没有 packingType 字段、转运也只有发货日期并用仓库名代替地址,调用方却必须给这些 无意义的值才能构造命令。 改成按仓校验: - WarehouseProduct:packingType 不再是构造期必填(-1 表示未给) 运去哪的必填校验移到 YqnProductMapper - TransferCommand:预计到仓日期与 shipTo 不再是构造期必填 运去哪的必填校验移到 YqnTransferMapper 保留跨仓共识的一致性校验(给了两个日期才比较先后) - 信仓侧无需改动:它的必填项(deliveryMode / deliveryWay / palletRequired / 预报头字段)本来就在适配器里校验 对运去哪调用方的影响:缺少这些字段仍然报错,只是从构造期的 IllegalArgumentException 变成调用时的 IllegalArgumentException(mapper 抛出), 错误信息里带仓方字段名,更明确。 顺带修探针里因模型放宽才暴露的问题: - 写探针不再给 omsSku 硬编码 "1"、不再给转运编造 PROBE-SKU / PROBE-DEST / 假地址, 缺 sku 或 destWarehouse 时直接跳过 - 转运探针不再传 estimateInboundDate / shipTo(信仓不收,也能验证模型已放宽) - 基座里的 requireProperty 与凭据默认值恢复为「空值 + 必须由 -D 传入」 Co-Authored-By: Claude Code <noreply@anthropic.com>
1 week ago
package common.ecommerce.xincang.adapter;
import common.ecommerce.shared.support.Money;
import common.ecommerce.warehouse.capability.WarehouseProduct;
import common.ecommerce.warehouse.model.InboundCommand;
import common.ecommerce.warehouse.model.InboundLine;
import org.junit.jupiter.api.Test;
import java.time.LocalDate;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* 统一模型里「某家仓必填、其他仓不需要」的字段不再在构造期拦截。
*
* <p>这些用例守护的是:信仓可以只给它认识的字段就构造出命令,
* 不会因为运去哪的必填项(nameEn / packingType / 海关三项 / 入库商品行)
* 被迫塞无意义的值。</p>
*/
class XincangModelRelaxTest {
/** 商品:不给 nameEn / packingType / 海关三项也能构造(信仓都收不到这些字段)。 */
@Test
void productBuildsWithoutYqnOnlyFields() {
WarehouseProduct product = WarehouseProduct.builder()
.omsSku("SKU-1")
.name("中文名")
.lengthCm(10).widthCm(10).heightCm(10).weightGrams(100)
.build();
assertNotNull(product);
}
/**
* 商品:信仓 amount 必填,但只需要 declaredValue,不需要 hsCode / countryOfOrigin。
*
* <p>改前「海关三项必须整组给」在构造期强制,信仓调用方被迫填两个用不上的字段。</p>
*/
@Test
void productCustomsValueAloneIsAccepted() {
WarehouseProduct product = WarehouseProduct.builder()
.omsSku("SKU-2")
.name("中文名")
.lengthCm(10).widthCm(10).heightCm(10).weightGrams(100)
.declaredValue(Money.of("1.00", "USD"))
.build();
assertNotNull(product);
}
/** 入库:信仓「新增预报」只建单头,可以没有商品行(明细走「完善资料」)。 */
@Test
void inboundHeaderOnlyIsEnoughForForecastCreate() {
InboundCommand head = InboundCommand.builder()
.inboundRequestNo("FC-1")
.warehouseId("NJ-2605")
.shipmentType("2")
.cabinetType("1")
.containerNo("CAB-1")
.predictionShipDate(LocalDate.now().plusDays(1))
.estimateArriveDate(LocalDate.now().plusDays(30))
.deliveryRequirements("1")
.referenceSkuCount(3)
.build();
assertNotNull(head);
}
/** 入库:完善资料阶段要明细,这时才加行,模型允许。 */
@Test
void inboundWithLinesStillWorks() {
InboundCommand withLines = InboundCommand.builder()
.inboundRequestNo("FC-2")
.warehouseId("NJ-2605")
.line(InboundLine.builder().omsSku("SKU-1").quantity(1).build())
.build();
assertNotNull(withLines);
}
}