Browse Source
⚠ 这两个路径在测试环境真机返回 404 No handler found(2026-11-17), 文档路径及 26 个变体全试过;同环境其它接口正常响应,不是网络问题。 代码按文档实现,路径常量加了显式警告,联调时只需改一处。 - 创建:hopeDestroyData 字段名照抄(Data 不是 Date);orderNo 不传 (文档标必填但示例没有,仓方自生成);响应无 data,不回仓单号也不回状态 - 查询:请求体是裸数组;data 也是数组且查不到的单号不返回; 按来源单号查(示例里数组的值正是响应里的 sourceNo),也兼容仓方计划单号 - 新增 HengjianDestructionStatus:7 个状态值精确匹配;core 没有销毁状态 枚举,保留仓方码 + 中文名,不硬造跨仓枚举 - core DestructionCommand 补 lineName,DestructionOrder 补 lineName / hopeDestroyDate / createdAt 验证:mvn test 全量通过,恒健 329 个用例(+16)通过。 Co-Authored-By: Claude Code <noreply@anthropic.com>master
13 changed files with 874 additions and 14 deletions
@ -0,0 +1,207 @@
@@ -0,0 +1,207 @@
|
||||
package common.ecommerce.hengjian.adapter; |
||||
|
||||
import common.ecommerce.hengjian.dto.HengjianDestructionDtos; |
||||
import common.ecommerce.hengjian.enums.HengjianDestructionStatus; |
||||
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||
import common.ecommerce.warehouse.model.DestructionCommand; |
||||
import common.ecommerce.warehouse.model.DestructionOrder; |
||||
|
||||
import java.time.Instant; |
||||
import java.time.LocalDate; |
||||
import java.time.LocalDateTime; |
||||
import java.time.ZoneOffset; |
||||
import java.time.format.DateTimeFormatter; |
||||
import java.time.format.DateTimeParseException; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 恒健销毁计划映射(创建 / 查询)。 |
||||
* |
||||
* <h2>单号的口径</h2> |
||||
* <p>创建请求有两个单号字段:{@code orderNo}(销毁计划单号)与 {@code sourceNo}(来源单号)。 |
||||
* 文档的<b>请求示例里没有 {@code orderNo}</b>,而查询响应同时回 |
||||
* {@code destroyPlanOrderNo} 与 {@code sourceNo}。所以:</p> |
||||
* <ul> |
||||
* <li>我们下发的 OMS 销毁单号 → {@code sourceNo};</li> |
||||
* <li>{@code orderNo} 不传——仓方自己生成计划单号,我们不编。</li> |
||||
* </ul> |
||||
* |
||||
* <h2>查询的 {@code orderNos}</h2> |
||||
* <p>文档说传「销毁计划单单号集合」,但示例里请求数组的值 |
||||
* ({@code AAAAAAAA} / {@code XXXXXXXX})正是响应里的 {@code sourceNo}。 |
||||
* 所以按<b>来源单号</b>查——也就是我们下发的 {@code destructionNo}。</p> |
||||
* |
||||
* <h2>字段笔误</h2> |
||||
* <p>{@code hopeDestroyData}(不是 {@code Date})在创建与查询两侧都是这个拼写,照抄。</p> |
||||
*/ |
||||
public final class HengjianDestructionMapper { |
||||
|
||||
private static final DateTimeFormatter DATE_TIME = |
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
||||
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
||||
|
||||
private HengjianDestructionMapper() { |
||||
} |
||||
|
||||
// ================================================================ 创建
|
||||
|
||||
/** |
||||
* 统一命令 → 恒健创建请求。 |
||||
* |
||||
* @param warehouseCode 仓 code(命令显式指定优先,其次账户配置) |
||||
* @throws IllegalArgumentException 缺必填项 |
||||
*/ |
||||
public static HengjianDestructionDtos.CreateRequest toRequest(DestructionCommand cmd, |
||||
String warehouseCode) { |
||||
String wh = trimToNull(warehouseCode); |
||||
if (wh == null) { |
||||
throw new IllegalArgumentException( |
||||
"hengjian destruction needs an orgWarehouseCode; none given and account has none"); |
||||
} |
||||
if (cmd.lines().isEmpty()) { |
||||
throw new IllegalArgumentException( |
||||
"hengjian destruction plan requires at least one sku"); |
||||
} |
||||
if (cmd.hopeDestroyDate() == null) { |
||||
throw new IllegalArgumentException( |
||||
"hengjian destruction plan requires hopeDestroyDate"); |
||||
} |
||||
|
||||
HengjianDestructionDtos.CreateRequest req = new HengjianDestructionDtos.CreateRequest(); |
||||
req.orgWarehouseCode = wh; |
||||
// 我们下发的单号是「来源单号」;orderNo 由仓方生成,不传
|
||||
req.sourceNo = cmd.destructionNo(); |
||||
req.lineName = trimToNull(cmd.lineNameOrNull()); |
||||
req.inventoryType = cmd.inventoryType(); |
||||
req.hopeDestroyData = cmd.hopeDestroyDate().toString(); |
||||
req.remark = trimToNull(cmd.remark()); |
||||
req.destroyPlanOrderItems = toItems(cmd.lines()); |
||||
return req; |
||||
} |
||||
|
||||
private static List<HengjianDestructionDtos.CreateRequest.DestroyItem> toItems( |
||||
List<DestructionCommand.DestructionLine> lines) { |
||||
List<HengjianDestructionDtos.CreateRequest.DestroyItem> out = |
||||
new ArrayList<HengjianDestructionDtos.CreateRequest.DestroyItem>(lines.size()); |
||||
for (DestructionCommand.DestructionLine line : lines) { |
||||
HengjianDestructionDtos.CreateRequest.DestroyItem item = |
||||
new HengjianDestructionDtos.CreateRequest.DestroyItem(); |
||||
item.sku = line.providerSku(); |
||||
item.planQty = line.planQuantity(); |
||||
out.add(item); |
||||
} |
||||
return out; |
||||
} |
||||
|
||||
/** |
||||
* 创建结果 → 统一销毁单。 |
||||
* |
||||
* <p>创建响应<b>没有 data</b>,不回仓单号,也不回状态。所以 |
||||
* {@code providerDestructionId} 与 {@code status} 都留 null——不拿来源单号冒充仓单号, |
||||
* 也不把「提交成功」当「已执行」。</p> |
||||
*/ |
||||
public static DestructionOrder toCreated(DestructionCommand cmd, String warehouseCode) { |
||||
return DestructionOrder.builder() |
||||
.destructionNo(cmd.destructionNo()) |
||||
.warehouseCode(warehouseCode) |
||||
.sourceProvider(WarehouseProvider.HENGJIAN) |
||||
.build(); |
||||
} |
||||
|
||||
// ================================================================ 查询
|
||||
|
||||
/** 查询请求:裸数组(不是对象包装)。 */ |
||||
public static List<String> toFindRequest(String destructionNo) { |
||||
String no = trimToNull(destructionNo); |
||||
if (no == null) { |
||||
throw new IllegalArgumentException("hengjian destruction query requires a destructionNo"); |
||||
} |
||||
List<String> out = new ArrayList<String>(1); |
||||
out.add(no); |
||||
return out; |
||||
} |
||||
|
||||
/** 查询结果 → 统一销毁单。 */ |
||||
public static DestructionOrder toOrder(HengjianDestructionDtos.DestroyPlan plan) { |
||||
String sourceNo = trimToNull(plan.sourceNo); |
||||
String planNo = trimToNull(plan.destroyPlanOrderNo); |
||||
String requestNo = sourceNo != null ? sourceNo : planNo; |
||||
if (requestNo == null) { |
||||
throw new IllegalArgumentException( |
||||
"hengjian destruction plan has neither sourceNo nor destroyPlanOrderNo"); |
||||
} |
||||
// 状态原值保留到 rawStatus;status 是同义的中文名(core 没有销毁状态枚举)
|
||||
HengjianDestructionStatus status = HengjianDestructionStatus.of(plan.status); |
||||
return DestructionOrder.builder() |
||||
.destructionNo(requestNo) |
||||
.providerDestructionId(planNo) |
||||
.warehouseCode(trimToNull(plan.orgWarehouseCode)) |
||||
.status(status.rawName()) |
||||
.rawStatus(trimToNull(plan.status)) |
||||
.sourceProvider(WarehouseProvider.HENGJIAN) |
||||
.lineName(trimToNull(plan.lineName)) |
||||
.hopeDestroyDate(parseDate(plan.hopeDestroyData)) |
||||
.createdAt(parseTime(plan.createdAt)) |
||||
.build(); |
||||
} |
||||
|
||||
/** 从查询返回的数组里挑出与请求单号匹配的那条;没有返回 null。 */ |
||||
public static DestructionOrder find(List<HengjianDestructionDtos.DestroyPlan> plans, |
||||
String destructionNo) { |
||||
if (plans == null || plans.isEmpty()) { |
||||
return null; |
||||
} |
||||
String target = trimToNull(destructionNo); |
||||
for (HengjianDestructionDtos.DestroyPlan plan : plans) { |
||||
if (plan == null) { |
||||
continue; |
||||
} |
||||
String sourceNo = trimToNull(plan.sourceNo); |
||||
String planNo = trimToNull(plan.destroyPlanOrderNo); |
||||
// 单号既可能给来源单号,也可能给仓方计划单号——两者都比对
|
||||
if (target != null && (target.equals(sourceNo) || target.equals(planNo))) { |
||||
return toOrder(plan); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
// ================================================================ 工具
|
||||
|
||||
static Instant parseTime(String value) { |
||||
String v = trimToNull(value); |
||||
if (v == null) { |
||||
return null; |
||||
} |
||||
try { |
||||
return LocalDateTime.parse(v, DATE_TIME).toInstant(ZoneOffset.UTC); |
||||
} catch (DateTimeParseException e) { |
||||
try { |
||||
return Instant.parse(v); |
||||
} catch (DateTimeParseException ignored) { |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
|
||||
static LocalDate parseDate(String value) { |
||||
String v = trimToNull(value); |
||||
if (v == null) { |
||||
return null; |
||||
} |
||||
try { |
||||
return LocalDate.parse(v, DATE); |
||||
} catch (DateTimeParseException e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
private static String trimToNull(String v) { |
||||
if (v == null) { |
||||
return null; |
||||
} |
||||
String t = v.trim(); |
||||
return t.isEmpty() ? null : t; |
||||
} |
||||
} |
||||
@ -0,0 +1,152 @@
@@ -0,0 +1,152 @@
|
||||
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 /v2/destroyPlanOrder/create}) |
||||
* 与查询({@code POST /v2/destroyPlanOrder/find})。 |
||||
* |
||||
* <p><b>⚠ 路径未在真机确认</b>:2026-11-17 在测试环境对文档路径及 26 个变体 |
||||
* 全部返回 {@code 404 No handler found}(同环境其它接口正常响应)。 |
||||
* 代码按文档实现,<b>路径常量需在联调时核对</b>。</p> |
||||
* |
||||
* <h2>创建</h2> |
||||
* <p><b>字段名有笔误</b>:{@code hopeDestroyData}——文档里就是 {@code Data} 不是 {@code Date}, |
||||
* 照抄。</p> |
||||
* <p><b>响应无 data</b>:只有 {@code code / message},<b>不回仓单号</b>。</p> |
||||
* |
||||
* <h2>查询</h2> |
||||
* <p>请求体是<b>裸数组</b>({@code ["单号1","单号2"]}),不是对象包装。</p> |
||||
* <p>响应 {@code data} 是数组;<b>每个单号一条</b>,查不到的单号不返回(不是返回空对象)。</p> |
||||
*/ |
||||
public final class HengjianDestructionDtos { |
||||
|
||||
private HengjianDestructionDtos() { |
||||
} |
||||
|
||||
// ================================================================ 创建
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class CreateRequest { |
||||
|
||||
/** 销毁计划单号(文档标必填,但示例里没有——按选填实现,见类注释)。 */ |
||||
public String orderNo; |
||||
|
||||
/** 组织仓 code;必填。 */ |
||||
public String orgWarehouseCode; |
||||
|
||||
/** 项目名称。 */ |
||||
public String lineName; |
||||
|
||||
/** 来源单号(我们下发的销毁单号)。 */ |
||||
public String sourceNo; |
||||
|
||||
/** 库存类型:0 可售 / 1 不可售;必填。 */ |
||||
public Integer inventoryType; |
||||
|
||||
/** |
||||
* 期望销毁日期 {@code YYYY-MM-DD};必填。 |
||||
* |
||||
* <p><b>字段名是 {@code Data} 不是 {@code Date}</b>——文档原文如此,照抄。 |
||||
* 写成 {@code hopeDestroyDate} 仓方会当成没传。</p> |
||||
*/ |
||||
public String hopeDestroyData; |
||||
|
||||
public String remark; |
||||
|
||||
/** 产品信息;必填。 */ |
||||
public List<DestroyItem> destroyPlanOrderItems; |
||||
|
||||
/** 一行待销毁商品。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class DestroyItem { |
||||
|
||||
/** SKU;必填。 */ |
||||
public String sku; |
||||
|
||||
/** 计划数量;必填。 */ |
||||
public Integer planQty; |
||||
} |
||||
} |
||||
|
||||
/** 创建响应:无 data。 */ |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public static final class CreateResponse { |
||||
|
||||
@JsonProperty("code") |
||||
public Integer code; |
||||
|
||||
@JsonProperty("message") |
||||
public String message; |
||||
} |
||||
|
||||
// ================================================================ 查询
|
||||
|
||||
/** 查询响应外层。 */ |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public static final class FindResponse { |
||||
|
||||
@JsonProperty("code") |
||||
public Integer code; |
||||
|
||||
@JsonProperty("message") |
||||
public String message; |
||||
|
||||
@JsonProperty("data") |
||||
public List<DestroyPlan> data; |
||||
} |
||||
|
||||
/** 一条销毁计划。 */ |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public static final class DestroyPlan { |
||||
|
||||
/** 销毁计划单号(仓方)。 */ |
||||
@JsonProperty("destroyPlanOrderNo") |
||||
public String destroyPlanOrderNo; |
||||
|
||||
/** 来源单号(我们下发的销毁单号)。 */ |
||||
@JsonProperty("sourceNo") |
||||
public String sourceNo; |
||||
|
||||
@JsonProperty("orgWarehouseCode") |
||||
public String orgWarehouseCode; |
||||
@JsonProperty("orgWarehouseName") |
||||
public String orgWarehouseName; |
||||
@JsonProperty("orgWarehouseId") |
||||
public String orgWarehouseId; |
||||
|
||||
@JsonProperty("lineId") |
||||
public String lineId; |
||||
@JsonProperty("lineName") |
||||
public String lineName; |
||||
|
||||
/** 库存类型:0 可售 / 1 不可售。 */ |
||||
@JsonProperty("inventoryType") |
||||
public Integer inventoryType; |
||||
|
||||
/** 计划销毁日期 {@code YYYY-MM-DD};同样拼作 {@code Data}。 */ |
||||
@JsonProperty("hopeDestroyData") |
||||
public String hopeDestroyData; |
||||
|
||||
/** |
||||
* 状态码:0 草稿 / 1 提交待审核 / 2 已审核待销毁 / 3 审核不通过 / 4 销毁中 / |
||||
* 5 完成 / 10 取消。 |
||||
* |
||||
* <p>用 String 接住——文档标 INTEGER,但同站其它接口出现过数字串。</p> |
||||
*/ |
||||
@JsonProperty("status") |
||||
public String status; |
||||
|
||||
@JsonProperty("remark") |
||||
public String remark; |
||||
|
||||
@JsonProperty("createdAt") |
||||
public String createdAt; |
||||
@JsonProperty("updatedAt") |
||||
public String updatedAt; |
||||
} |
||||
} |
||||
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
package common.ecommerce.hengjian.enums; |
||||
|
||||
/** |
||||
* 恒健销毁计划单状态({@code status})。 |
||||
* |
||||
* <p>码表来自《销毁计划查询》: |
||||
* 0 草稿 / 1 提交待审核 / 2 已审核待销毁 / 3 审核不通过 / 4 销毁中 / 5 完成 / 10 取消。</p> |
||||
* |
||||
* <p><b>为什么是独立枚举而不是 {@code DestructionOrder.status()} 的字符串</b>:恒健的 |
||||
* {@code status} 是 INTEGER,运去哪创建接口不回状态、查询接口也还没接, |
||||
* 两家码表没有交集。这里保留仓方码 + 中文名,<b>不映射到 core 枚举</b>—— |
||||
* core 目前没有销毁状态的底层枚举,为一个仓硬造一套会污染其它仓。</p> |
||||
* |
||||
* <p>精确匹配,未知归 {@link #UNKNOWN} 不猜。</p> |
||||
*/ |
||||
public enum HengjianDestructionStatus { |
||||
|
||||
/** 0 草稿。 */ |
||||
DRAFT("0", "草稿"), |
||||
/** 1 提交 / 待审核。 */ |
||||
PENDING_REVIEW("1", "提交待审核"), |
||||
/** 2 已审核 / 待销毁。 */ |
||||
APPROVED("2", "已审核待销毁"), |
||||
/** 3 审核不通过 / 审核拒回。 */ |
||||
REJECTED("3", "审核不通过"), |
||||
/** 4 销毁中。 */ |
||||
DESTROYING("4", "销毁中"), |
||||
/** 5 完成。 */ |
||||
COMPLETED("5", "完成"), |
||||
/** 10 取消。 */ |
||||
CANCELLED("10", "取消"), |
||||
/** 无法识别。 */ |
||||
UNKNOWN(null, null); |
||||
|
||||
private final String rawCode; |
||||
private final String rawName; |
||||
|
||||
HengjianDestructionStatus(String rawCode, String rawName) { |
||||
this.rawCode = rawCode; |
||||
this.rawName = rawName; |
||||
} |
||||
|
||||
/** 仓方数字码;UNKNOWN 为 null。 */ |
||||
public String rawCode() { |
||||
return rawCode; |
||||
} |
||||
|
||||
/** 仓方中文名;UNKNOWN 为 null。 */ |
||||
public String rawName() { |
||||
return rawName; |
||||
} |
||||
|
||||
/** 精确匹配(忽略首尾空白);空值 / 未收录归 {@link #UNKNOWN}。 */ |
||||
public static HengjianDestructionStatus of(String raw) { |
||||
if (raw == null) { |
||||
return UNKNOWN; |
||||
} |
||||
String s = raw.trim(); |
||||
if (s.isEmpty()) { |
||||
return UNKNOWN; |
||||
} |
||||
for (HengjianDestructionStatus v : values()) { |
||||
if (v.rawCode != null && s.equals(v.rawCode)) { |
||||
return v; |
||||
} |
||||
} |
||||
return UNKNOWN; |
||||
} |
||||
} |
||||
@ -0,0 +1,263 @@
@@ -0,0 +1,263 @@
|
||||
package common.ecommerce.hengjian.adapter; |
||||
|
||||
import common.ecommerce.hengjian.HengjianConstants; |
||||
import common.ecommerce.hengjian.enums.HengjianDestructionStatus; |
||||
import common.ecommerce.http.JacksonJsonCodec; |
||||
import common.ecommerce.shared.spi.ChannelSecret; |
||||
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.DestructionCommand; |
||||
import common.ecommerce.warehouse.model.DestructionOrder; |
||||
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; |
||||
|
||||
/** |
||||
* 销毁计划创建 / 查询契约测试。 |
||||
* |
||||
* <p><b>注意</b>:这两个路径在测试环境真机返回 404(见 {@code HengjianConstants}), |
||||
* 所以本测试只能验证「按文档拼报文 + 解析响应」的行为,<b>不能</b>证明路径可用。</p> |
||||
*/ |
||||
class HengjianDestructionTest { |
||||
|
||||
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-17T00:00:00Z"), ZoneOffset.UTC)); |
||||
|
||||
private static HengjianAdapter adapter(RecordingTransport transport) { |
||||
return new HengjianAdapter(transport, new JacksonJsonCodec()); |
||||
} |
||||
|
||||
private static DestructionCommand.Builder command() { |
||||
return DestructionCommand.builder() |
||||
.destructionNo("DT-2026-0001") |
||||
.warehouseId("EFCA") |
||||
.inventoryType(1) |
||||
.hopeDestroyDate(LocalDate.parse("2026-12-01")) |
||||
.remark("过期报废") |
||||
.lineName("项目A") |
||||
.line("SKU-A", 3) |
||||
.line("SKU-B", 1); |
||||
} |
||||
|
||||
// ================================================================ 创建
|
||||
|
||||
private static RecordingTransport creating() { |
||||
return RecordingTransport.create() |
||||
.route(HengjianConstants.PATH_DESTRUCTION_CREATE, req -> Responses.ok( |
||||
"{\"statusCode\":200,\"status\":0,\"code\":200,\"message\":\"OK\"}")); |
||||
} |
||||
|
||||
@Test |
||||
void createPostsToDestroyPlanOrder() { |
||||
RecordingTransport transport = creating(); |
||||
adapter(transport).create(CTX, command().build()); |
||||
|
||||
assertEquals("POST", transport.lastDataRequest().method()); |
||||
assertEquals(HengjianConstants.TEST_BASE_URL + "/v2/destroyPlanOrder/create", |
||||
transport.lastDataRequest().url()); |
||||
} |
||||
|
||||
/** 文档字段名 {@code hopeDestroyData} 是 Data 不是 Date,照抄。 */ |
||||
@Test |
||||
void createSendsDocumentedFields() { |
||||
RecordingTransport transport = creating(); |
||||
adapter(transport).create(CTX, command().build()); |
||||
String body = transport.lastDataRequest().body(); |
||||
|
||||
assertTrue(body.contains("\"orgWarehouseCode\":\"EFCA\""), body); |
||||
assertTrue(body.contains("\"sourceNo\":\"DT-2026-0001\""), body); |
||||
assertTrue(body.contains("\"inventoryType\":1"), body); |
||||
assertTrue(body.contains("\"hopeDestroyData\":\"2026-12-01\""), body); |
||||
assertTrue(body.contains("\"lineName\":\"项目A\""), body); |
||||
assertTrue(body.contains("\"remark\":\"过期报废\""), body); |
||||
assertTrue(body.contains("\"destroyPlanOrderItems\":["), body); |
||||
assertTrue(body.contains("\"sku\":\"SKU-A\""), body); |
||||
assertTrue(body.contains("\"planQty\":3"), body); |
||||
// orderNo 由仓方生成,我们不传
|
||||
assertFalse(body.contains("\"orderNo\""), "orderNo 应由仓方生成,不传,body=" + body); |
||||
} |
||||
|
||||
/** 创建响应无 data:不拿来源单号冒充仓单号,也不编状态。 */ |
||||
@Test |
||||
void createdHasNoProviderIdOrStatus() { |
||||
DestructionOrder order = adapter(creating()).create(CTX, command().build()); |
||||
|
||||
assertEquals("DT-2026-0001", order.destructionNo()); |
||||
assertNull(order.providerDestructionId(), "响应不回仓单号"); |
||||
assertNull(order.status(), "创建只代表已提交,不能当已执行"); |
||||
assertNull(order.rawStatus()); |
||||
assertEquals("EFCA", order.warehouseCode()); |
||||
assertEquals(WarehouseProvider.HENGJIAN, order.sourceProvider()); |
||||
} |
||||
|
||||
@Test |
||||
void createRequiresLines() { |
||||
RecordingTransport transport = creating(); |
||||
assertThrows(IllegalArgumentException.class, |
||||
() -> adapter(transport).create(CTX, DestructionCommand.builder() |
||||
.destructionNo("DT-X").warehouseId("EFCA").inventoryType(0) |
||||
.hopeDestroyDate(LocalDate.parse("2026-12-01")).build())); |
||||
assertTrue(transport.dataRequests().isEmpty()); |
||||
} |
||||
|
||||
/** 命令没给仓、账户也没配仓 id 时拒绝。 */ |
||||
@Test |
||||
void createRequiresWarehouseCode() { |
||||
WarehouseContext noWarehouse = WarehouseContext.of( |
||||
"HJ-NO-WH", WarehouseProvider.HENGJIAN, null, |
||||
WarehouseConnection.of(HengjianConstants.TEST_BASE_URL, |
||||
ChannelSecret.builder().appSecret("token-1").build()), |
||||
"req-2", Clock.fixed(Instant.parse("2026-11-17T00:00:00Z"), ZoneOffset.UTC)); |
||||
RecordingTransport transport = creating(); |
||||
assertThrows(IllegalArgumentException.class, |
||||
() -> adapter(transport).create(noWarehouse, DestructionCommand.builder() |
||||
.destructionNo("DT-X").inventoryType(0) |
||||
.hopeDestroyDate(LocalDate.parse("2026-12-01")) |
||||
.line("SKU-A", 1).build())); |
||||
assertTrue(transport.dataRequests().isEmpty()); |
||||
} |
||||
|
||||
@Test |
||||
void businessErrorIsPropagated() { |
||||
RecordingTransport transport = RecordingTransport.create() |
||||
.route(HengjianConstants.PATH_DESTRUCTION_CREATE, req -> Responses.ok( |
||||
"{\"statusCode\":500,\"status\":1,\"code\":999999," |
||||
+ "\"message\":\"组织仓库不存在!\"}")); |
||||
|
||||
RuntimeException ex = assertThrows(RuntimeException.class, |
||||
() -> adapter(transport).create(CTX, command().build())); |
||||
assertTrue(ex.getMessage().contains("组织仓库不存在"), ex.getMessage()); |
||||
} |
||||
|
||||
// ================================================================ 查询
|
||||
|
||||
private static final String FIND_BODY = |
||||
"{\"status\":200,\"message\":\"OK\",\"data\":[{" |
||||
+ "\"createdAt\":\"2024-11-07 02:03:00\"," |
||||
+ "\"updatedAt\":\"2024-12-06 09:15:49\"," |
||||
+ "\"destroyPlanOrderNo\":\"DPAAAAAAA\"," |
||||
+ "\"orgWarehouseId\":12345,\"orgWarehouseCode\":\"EFCA\"," |
||||
+ "\"orgWarehouseName\":\"EF-CA\",\"lineName\":\"项目A\"," |
||||
+ "\"sourceNo\":\"DT-2026-0001\",\"inventoryType\":1," |
||||
+ "\"hopeDestroyData\":\"2026-12-01\",\"status\":1," |
||||
+ "\"remark\":\"过期报废\"}]}"; |
||||
|
||||
private static RecordingTransport finding() { |
||||
return RecordingTransport.create() |
||||
.route(HengjianConstants.PATH_DESTRUCTION_FIND, req -> Responses.ok(FIND_BODY)); |
||||
} |
||||
|
||||
/** 查询请求是裸数组,不是对象包装。 */ |
||||
@Test |
||||
void findSendsBareArray() { |
||||
RecordingTransport transport = finding(); |
||||
adapter(transport).getDestruction(CTX, "DT-2026-0001"); |
||||
|
||||
assertEquals("POST", transport.lastDataRequest().method()); |
||||
assertEquals(HengjianConstants.TEST_BASE_URL + "/v2/destroyPlanOrder/find", |
||||
transport.lastDataRequest().url()); |
||||
assertEquals("[\"DT-2026-0001\"]", transport.lastDataRequest().body()); |
||||
} |
||||
|
||||
@Test |
||||
void findMapsPlan() { |
||||
DestructionOrder order = adapter(finding()).getDestruction(CTX, "DT-2026-0001"); |
||||
|
||||
assertEquals("DT-2026-0001", order.destructionNo(), "来源单号优先"); |
||||
assertEquals("DPAAAAAAA", order.providerDestructionId()); |
||||
assertEquals("EFCA", order.warehouseCode()); |
||||
assertEquals("提交待审核", order.status(), "1 → 提交待审核"); |
||||
assertEquals("1", order.rawStatus()); |
||||
assertEquals("项目A", order.lineName()); |
||||
assertEquals(LocalDate.parse("2026-12-01"), order.hopeDestroyDate()); |
||||
assertEquals(Instant.parse("2024-11-07T02:03:00Z"), order.createdAt()); |
||||
assertEquals(WarehouseProvider.HENGJIAN, order.sourceProvider()); |
||||
} |
||||
|
||||
/** 文档里的 7 个状态值都要映射对。 */ |
||||
@Test |
||||
void allDocumentedStatusesMap() { |
||||
assertEquals("草稿", HengjianDestructionStatus.of("0").rawName()); |
||||
assertEquals("提交待审核", HengjianDestructionStatus.of("1").rawName()); |
||||
assertEquals("已审核待销毁", HengjianDestructionStatus.of("2").rawName()); |
||||
assertEquals("审核不通过", HengjianDestructionStatus.of("3").rawName()); |
||||
assertEquals("销毁中", HengjianDestructionStatus.of("4").rawName()); |
||||
assertEquals("完成", HengjianDestructionStatus.of("5").rawName()); |
||||
assertEquals("取消", HengjianDestructionStatus.of("10").rawName()); |
||||
} |
||||
|
||||
@Test |
||||
void unknownStatusIsNotGuessed() { |
||||
assertEquals(HengjianDestructionStatus.UNKNOWN, HengjianDestructionStatus.of("9")); |
||||
assertEquals(HengjianDestructionStatus.UNKNOWN, HengjianDestructionStatus.of(null)); |
||||
} |
||||
|
||||
/** 查不到的单号仓方不返回:结果里没有就是 null。 */ |
||||
@Test |
||||
void findReturnsNullWhenNotListed() { |
||||
RecordingTransport transport = RecordingTransport.create() |
||||
.route(HengjianConstants.PATH_DESTRUCTION_FIND, req -> Responses.ok( |
||||
"{\"status\":200,\"message\":\"OK\",\"data\":[]}")); |
||||
|
||||
assertNull(adapter(transport).getDestruction(CTX, "DT-NONE")); |
||||
} |
||||
|
||||
/** data 缺失也返回 null,不抛。 */ |
||||
@Test |
||||
void findReturnsNullWhenDataMissing() { |
||||
RecordingTransport transport = RecordingTransport.create() |
||||
.route(HengjianConstants.PATH_DESTRUCTION_FIND, req -> Responses.ok( |
||||
"{\"status\":200,\"message\":\"OK\"}")); |
||||
|
||||
assertNull(adapter(transport).getDestruction(CTX, "DT-NONE")); |
||||
} |
||||
|
||||
/** 按仓方计划单号查也能命中(同样回数组,逐条比对)。 */ |
||||
@Test |
||||
void findMatchesProviderPlanNo() { |
||||
DestructionOrder order = adapter(finding()).getDestruction(CTX, "DPAAAAAAA"); |
||||
|
||||
assertEquals("DT-2026-0001", order.destructionNo(), "命中后仍以来源单号作业务键"); |
||||
assertEquals("DPAAAAAAA", order.providerDestructionId()); |
||||
} |
||||
|
||||
@Test |
||||
void findRequiresNumber() { |
||||
assertThrows(IllegalArgumentException.class, |
||||
() -> adapter(RecordingTransport.create()).getDestruction(CTX, " ")); |
||||
} |
||||
|
||||
// ================================================================ 能力位
|
||||
|
||||
@Test |
||||
void declaresDestructionCapability() { |
||||
assertTrue(adapter(RecordingTransport.create()).capabilities() |
||||
.contains(WarehouseCapability.DESTRUCTION)); |
||||
} |
||||
|
||||
/** |
||||
* 路径未经真机确认:这条测试把文档路径固定下来, |
||||
* 若联调时发现不同,改常量后这里会一起失败——提醒同步文档。 |
||||
*/ |
||||
@Test |
||||
void documentedPathsArePinned() { |
||||
assertEquals("/v2/destroyPlanOrder/create", HengjianConstants.PATH_DESTRUCTION_CREATE); |
||||
assertEquals("/v2/destroyPlanOrder/find", HengjianConstants.PATH_DESTRUCTION_FIND); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue