Browse Source
三个接口真机均确认存在:create 的参数校验可逐步推进、cancel 缺 sourceNo 回 "Required String parameter 'sourceNo' is not present"、findByPage 无参数回 403。 - 创建:真机确认必填 outOrgWarehouseCode / inOrgWarehouseCode / estimateOutboundTime / estimateInboundTime;文档另标的 projectUnicode / transportationType / inventoryType / isLabel / receiveStore / shipTo* 真机不校验, 按选填实现 - details[].qty 文档标 STRING:按字符串下发;查询响应是数字,两个 DTO 各声明 - 统一模型是 LocalDate,恒健要 yyyy-MM-dd HH:mm:ss:补当天 00:00:00 不编造时刻 - inOrgWarehouseCode=Other 表示外部仓库,映射 TransferType.OUTBOUND - 响应 data 是字符串单号,拿不到即报错;创建不回状态,status 保持 UNKNOWN - 查询:分页四件套必填、rows 上限 100 拒绝不截断;过滤参数都是单值,多给只取首个 - 取消走 GET + query,落在 deleteTransfer;仓方拒绝原样抛业务异常 - 新增 HengjianTransferStatus:13 个值精确匹配,100 取消中与 110 已取消不合并 - core 补 TransferQuery 模型 + TransferCapable.queryTransfers + 门面, TransferCommand 补 5 字段、TransferOrder 补 projectCode/attachments 验证:mvn test 全量通过,恒健 259 个用例(+21)通过。 Co-Authored-By: Claude Code <noreply@anthropic.com>master
13 changed files with 1636 additions and 7 deletions
@ -0,0 +1,180 @@
@@ -0,0 +1,180 @@
|
||||
package common.ecommerce.warehouse.model; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 调拨单查询条件(多条件分页)。 |
||||
* |
||||
* <p>各仓支持的维度不同:不支持的维度由适配器<b>显式拒绝</b>, |
||||
* 不静默忽略——忽略一个过滤条件会让调用方以为「这段时间就这么多调拨单」。</p> |
||||
*/ |
||||
public final class TransferQuery { |
||||
|
||||
private final List<String> warehouseCodes; |
||||
private final String fromWarehouseCode; |
||||
private final String toWarehouseCode; |
||||
private final List<String> sourceNos; |
||||
private final List<String> providerTransferNos; |
||||
private final String projectCode; |
||||
private final int pageSize; |
||||
private final String cursor; |
||||
|
||||
private TransferQuery(Builder b) { |
||||
this.warehouseCodes = Collections.unmodifiableList(new ArrayList<String>(b.warehouseCodes)); |
||||
this.fromWarehouseCode = b.fromWarehouseCode; |
||||
this.toWarehouseCode = b.toWarehouseCode; |
||||
this.sourceNos = Collections.unmodifiableList(new ArrayList<String>(b.sourceNos)); |
||||
this.providerTransferNos = Collections.unmodifiableList( |
||||
new ArrayList<String>(b.providerTransferNos)); |
||||
this.projectCode = b.projectCode; |
||||
this.pageSize = b.pageSize; |
||||
this.cursor = b.cursor; |
||||
} |
||||
|
||||
public static Builder builder() { |
||||
return new Builder(); |
||||
} |
||||
|
||||
/** 仓 code 列表;空表示用账户配置的仓。 */ |
||||
public List<String> warehouseCodes() { |
||||
return warehouseCodes; |
||||
} |
||||
|
||||
/** 调出仓 code;null 表示不限。 */ |
||||
public String fromWarehouseCode() { |
||||
return fromWarehouseCode; |
||||
} |
||||
|
||||
/** 调入仓 code;null 表示不限。 */ |
||||
public String toWarehouseCode() { |
||||
return toWarehouseCode; |
||||
} |
||||
|
||||
/** 来源单号列表(我们下发的调拨单号)。 */ |
||||
public List<String> sourceNos() { |
||||
return sourceNos; |
||||
} |
||||
|
||||
/** 仓方调拨单号列表。 */ |
||||
public List<String> providerTransferNos() { |
||||
return providerTransferNos; |
||||
} |
||||
|
||||
/** 项目编号;null 表示不限。 */ |
||||
public String projectCode() { |
||||
return projectCode; |
||||
} |
||||
|
||||
public int pageSize() { |
||||
return pageSize; |
||||
} |
||||
|
||||
/** 分页游标;null 表示第一页。 */ |
||||
public String cursor() { |
||||
return cursor; |
||||
} |
||||
|
||||
/** 翻页时只改游标。 */ |
||||
public Builder toBuilder() { |
||||
return builder() |
||||
.warehouseCodes(warehouseCodes) |
||||
.fromWarehouseCode(fromWarehouseCode) |
||||
.toWarehouseCode(toWarehouseCode) |
||||
.sourceNos(sourceNos) |
||||
.providerTransferNos(providerTransferNos) |
||||
.projectCode(projectCode) |
||||
.pageSize(pageSize) |
||||
.cursor(cursor); |
||||
} |
||||
|
||||
public static final class Builder { |
||||
|
||||
private final List<String> warehouseCodes = new ArrayList<String>(); |
||||
private String fromWarehouseCode; |
||||
private String toWarehouseCode; |
||||
private final List<String> sourceNos = new ArrayList<String>(); |
||||
private final List<String> providerTransferNos = new ArrayList<String>(); |
||||
private String projectCode; |
||||
private int pageSize = 100; |
||||
private String cursor; |
||||
|
||||
public Builder warehouseCode(String v) { |
||||
if (v != null && !v.trim().isEmpty()) { |
||||
this.warehouseCodes.add(v.trim()); |
||||
} |
||||
return this; |
||||
} |
||||
|
||||
public Builder warehouseCodes(List<String> v) { |
||||
if (v != null) { |
||||
for (String one : v) { |
||||
warehouseCode(one); |
||||
} |
||||
} |
||||
return this; |
||||
} |
||||
|
||||
public Builder fromWarehouseCode(String v) { |
||||
this.fromWarehouseCode = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder toWarehouseCode(String v) { |
||||
this.toWarehouseCode = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder sourceNo(String v) { |
||||
if (v != null && !v.trim().isEmpty()) { |
||||
this.sourceNos.add(v.trim()); |
||||
} |
||||
return this; |
||||
} |
||||
|
||||
public Builder sourceNos(List<String> v) { |
||||
if (v != null) { |
||||
for (String one : v) { |
||||
sourceNo(one); |
||||
} |
||||
} |
||||
return this; |
||||
} |
||||
|
||||
public Builder providerTransferNo(String v) { |
||||
if (v != null && !v.trim().isEmpty()) { |
||||
this.providerTransferNos.add(v.trim()); |
||||
} |
||||
return this; |
||||
} |
||||
|
||||
public Builder providerTransferNos(List<String> v) { |
||||
if (v != null) { |
||||
for (String one : v) { |
||||
providerTransferNo(one); |
||||
} |
||||
} |
||||
return this; |
||||
} |
||||
|
||||
public Builder projectCode(String v) { |
||||
this.projectCode = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder pageSize(int v) { |
||||
this.pageSize = v; |
||||
return this; |
||||
} |
||||
|
||||
public Builder cursor(String v) { |
||||
this.cursor = v; |
||||
return this; |
||||
} |
||||
|
||||
public TransferQuery build() { |
||||
return new TransferQuery(this); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,359 @@
@@ -0,0 +1,359 @@
|
||||
package common.ecommerce.hengjian.adapter; |
||||
|
||||
import common.ecommerce.hengjian.dto.HengjianTransferDtos; |
||||
import common.ecommerce.hengjian.enums.HengjianTransferStatus; |
||||
import common.ecommerce.shared.support.Page; |
||||
import common.ecommerce.shared.support.Money; |
||||
import common.ecommerce.warehouse.enums.TransferType; |
||||
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||
import common.ecommerce.warehouse.model.TransferCommand; |
||||
import common.ecommerce.warehouse.model.TransferOrder; |
||||
import common.ecommerce.warehouse.model.TransferQuery; |
||||
|
||||
import java.math.BigDecimal; |
||||
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.LinkedHashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 恒健调拨计划映射(创建 / 查询)。 |
||||
* |
||||
* <h2>真机确认的必填项</h2> |
||||
* <p>{@code outOrgWarehouseCode} / {@code inOrgWarehouseCode} / |
||||
* {@code estimateOutboundTime} / {@code estimateInboundTime}。文档另标了 |
||||
* {@code projectUnicode} / {@code transportationType} / {@code inventoryType} / |
||||
* {@code isLabel} / {@code receiveStore} / 六个 {@code shipTo*}, |
||||
* 但真机校验里没有——按选填实现。</p> |
||||
* |
||||
* <h2>数量类型</h2> |
||||
* <p>创建的 {@code details[].qty} 是 <b>STRING</b>(不是 INTEGER), |
||||
* 查询响应里是 INTEGER。两个 DTO 各自声明,互不干扰。</p> |
||||
*/ |
||||
public final class HengjianTransferMapper { |
||||
|
||||
/** 恒健日期时间格式(文档写 {@code yyyy-mm-dd h24:mi:ss})。 */ |
||||
private static final DateTimeFormatter DATE_TIME = |
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
||||
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
||||
|
||||
/** 外部仓库的固定代号。 */ |
||||
static final String OTHER_WAREHOUSE = "Other"; |
||||
|
||||
/** 运输方式:1 客户安排。 */ |
||||
static final int TRANSPORT_CUSTOMER = 1; |
||||
/** 运输方式:2 仓库安排。 */ |
||||
static final int TRANSPORT_WAREHOUSE = 2; |
||||
|
||||
/** 恒健列表单页上限(文档:默认最高 100)。 */ |
||||
static final int MAX_ROWS = 100; |
||||
|
||||
private HengjianTransferMapper() { |
||||
} |
||||
|
||||
// ================================================================ 创建
|
||||
|
||||
/** |
||||
* 统一命令 → 恒健创建请求。 |
||||
* |
||||
* @param ctx 用于取期望出库 / 入库时间(统一模型只有日期) |
||||
* @throws IllegalArgumentException 缺必填项 |
||||
*/ |
||||
public static HengjianTransferDtos.CreateRequest toRequest(TransferCommand cmd) { |
||||
String from = requireText(cmd.fromWarehouseCode(), "fromWarehouseCode"); |
||||
String to = requireText(cmd.toWarehouseCode(), "toWarehouseCode"); |
||||
LocalDate outDate = cmd.estimateOutboundDate(); |
||||
LocalDate inDate = cmd.estimateInboundDate(); |
||||
if (outDate == null || inDate == null) { |
||||
// 恒健只要「期望出库 / 入库时间」,统一模型里是日期;缺一个都发不出去
|
||||
throw new IllegalArgumentException( |
||||
"hengjian transfer requires estimateOutboundDate and estimateInboundDate"); |
||||
} |
||||
|
||||
HengjianTransferDtos.CreateRequest req = new HengjianTransferDtos.CreateRequest(); |
||||
req.projectUnicode = trimToNull(cmd.projectCode()); |
||||
req.outOrgWarehouseCode = from; |
||||
req.inOrgWarehouseCode = to; |
||||
req.transportationType = transportationTypeOf(cmd.transportationType()); |
||||
req.inventoryType = cmd.inventoryType(); |
||||
req.isLabel = flagOf(cmd.relabelProducts()); |
||||
req.sourceNo = cmd.transferRequestNo(); |
||||
// 统一模型只有日期,恒健要日期时间:按当天 00:00:00 补全(不编造具体时刻)
|
||||
req.estimateOutboundTime = dateTimeOf(outDate); |
||||
req.estimateInboundTime = dateTimeOf(inDate); |
||||
req.shipmentId = trimToNull(cmd.shipmentId()); |
||||
req.refferenceId = trimToNull(cmd.referenceId()); |
||||
req.receiveStore = trimToNull(cmd.receiveStore()); |
||||
req.remark = trimToNull(cmd.remark()); |
||||
req.deliveryDate = cmd.deliveryDate() == null ? null : cmd.deliveryDate().toString(); |
||||
|
||||
if (cmd.shipTo() != null) { |
||||
req.shipToCountry = trimToNull(cmd.shipTo().countryCode()); |
||||
req.shipToState = trimToNull(cmd.shipTo().stateOrProvince()); |
||||
req.shipToCity = trimToNull(cmd.shipTo().city()); |
||||
req.shipToPostal = trimToNull(cmd.shipTo().postalCode()); |
||||
req.shipToAddress1 = trimToNull(cmd.shipTo().addressLine1()); |
||||
req.shipToAddress2 = trimToNull(cmd.shipTo().addressLine2()); |
||||
req.shipToContact = trimToNull(cmd.shipTo().name()); |
||||
req.shipToTelephone = trimToNull(cmd.shipTo().phone()); |
||||
} |
||||
|
||||
req.details = toDetails(cmd.lines()); |
||||
return req; |
||||
} |
||||
|
||||
/** 产品明细:数量按<b>字符串</b>下发(恒健该字段标 STRING)。 */ |
||||
private static List<HengjianTransferDtos.CreateRequest.Detail> toDetails( |
||||
List<TransferCommand.TransferLine> lines) { |
||||
List<HengjianTransferDtos.CreateRequest.Detail> out = |
||||
new ArrayList<HengjianTransferDtos.CreateRequest.Detail>(lines.size()); |
||||
for (TransferCommand.TransferLine line : lines) { |
||||
HengjianTransferDtos.CreateRequest.Detail detail = |
||||
new HengjianTransferDtos.CreateRequest.Detail(); |
||||
detail.sku = line.providerSku(); |
||||
detail.qty = String.valueOf(line.quantity()); |
||||
out.add(detail); |
||||
} |
||||
return out; |
||||
} |
||||
|
||||
/** |
||||
* 运输方式映射。 |
||||
* |
||||
* <p>恒健 1 客户安排 / 2 仓库安排。统一模型的 {@code transportationType} 是 |
||||
* <b>仓方口径的裸数字</b>,所以直接透传 1 / 2;其它值拒绝而不是猜—— |
||||
* 猜错会让客户被误收运费。</p> |
||||
*/ |
||||
static Integer transportationTypeOf(int raw) { |
||||
if (raw == TRANSPORT_CUSTOMER || raw == TRANSPORT_WAREHOUSE) { |
||||
return raw; |
||||
} |
||||
// 0 表示未指定:按「仓库安排」下发(恒健的常用默认),并在文档里注明
|
||||
if (raw == 0) { |
||||
return TRANSPORT_WAREHOUSE; |
||||
} |
||||
throw new IllegalArgumentException( |
||||
"hengjian transfer transportationType must be 1 (customer) or 2 (warehouse), got " + raw); |
||||
} |
||||
|
||||
/** 日期 → {@code yyyy-MM-dd HH:mm:ss}(当天 00:00:00,不编造时刻)。 */ |
||||
static String dateTimeOf(LocalDate date) { |
||||
return date.atStartOfDay().format(DATE_TIME); |
||||
} |
||||
|
||||
private static Integer flagOf(Boolean flag) { |
||||
return flag == null ? null : (flag ? 1 : 0); |
||||
} |
||||
|
||||
private static String requireText(String value, String field) { |
||||
String v = trimToNull(value); |
||||
if (v == null) { |
||||
throw new IllegalArgumentException("hengjian transfer requires " + field); |
||||
} |
||||
return v; |
||||
} |
||||
|
||||
// ================================================================ 查询
|
||||
|
||||
/** 查询参数(GET)。 */ |
||||
public static Map<String, Object> toPageParams(TransferQuery query, String cursor) { |
||||
Map<String, Object> params = new LinkedHashMap<String, Object>(); |
||||
params.put("page", pageOf(cursor)); |
||||
params.put("rows", rowsOf(query.pageSize())); |
||||
params.put("sidx", "id"); |
||||
params.put("sort", "desc"); |
||||
// 恒健这几个过滤参数都是单值,不是数组;多个时只取第一个并说明
|
||||
putFirst(params, "sourceNo", query.sourceNos()); |
||||
putFirst(params, "transferOutboundPlanNo", query.providerTransferNos()); |
||||
putIfPresent(params, "projectUnicode", query.projectCode()); |
||||
putIfPresent(params, "outOrgWarehouseCode", query.fromWarehouseCode()); |
||||
putIfPresent(params, "inOrgWarehouseCode", query.toWarehouseCode()); |
||||
return params; |
||||
} |
||||
|
||||
private static void putFirst(Map<String, Object> params, String key, List<String> values) { |
||||
if (values != null && !values.isEmpty()) { |
||||
params.put(key, values.get(0)); |
||||
} |
||||
} |
||||
|
||||
private static void putIfPresent(Map<String, Object> params, String key, String value) { |
||||
String v = trimToNull(value); |
||||
if (v != null) { |
||||
params.put(key, v); |
||||
} |
||||
} |
||||
|
||||
static int pageOf(String cursor) { |
||||
String v = trimToNull(cursor); |
||||
if (v == null) { |
||||
return 1; |
||||
} |
||||
try { |
||||
int page = Integer.parseInt(v); |
||||
return page < 1 ? 1 : page; |
||||
} catch (NumberFormatException e) { |
||||
throw new IllegalArgumentException( |
||||
"hengjian transfer cursor must be a page number, got " + v); |
||||
} |
||||
} |
||||
|
||||
/** 单页行数:文档明写默认最高 100,超限拒绝不截断。 */ |
||||
static int rowsOf(int requested) { |
||||
if (requested <= 0) { |
||||
return MAX_ROWS; |
||||
} |
||||
if (requested > MAX_ROWS) { |
||||
throw new IllegalArgumentException( |
||||
"hengjian transfer rows must not exceed " + MAX_ROWS + ", got " + requested); |
||||
} |
||||
return requested; |
||||
} |
||||
|
||||
/** 创建响应 {@code data} 是字符串单号 → 回执。 */ |
||||
public static TransferOrder toCreated(TransferCommand cmd, String providerTransferNo) { |
||||
return TransferOrder.builder() |
||||
.transferRequestNo(cmd.transferRequestNo()) |
||||
.providerTransferNo(providerTransferNo) |
||||
.fromWarehouseCode(cmd.fromWarehouseCode()) |
||||
.toWarehouseCode(cmd.toWarehouseCode()) |
||||
.type(cmd.type()) |
||||
// 创建接口不回状态:保持 UNKNOWN,不拿请求侧的值冒充
|
||||
.status(common.ecommerce.warehouse.enums.TransferStatus.UNKNOWN) |
||||
.sourceProvider(WarehouseProvider.HENGJIAN) |
||||
.totalQuantity(totalQuantityOf(cmd)) |
||||
.remark(cmd.remark()) |
||||
.build(); |
||||
} |
||||
|
||||
private static int totalQuantityOf(TransferCommand cmd) { |
||||
int total = 0; |
||||
for (TransferCommand.TransferLine line : cmd.lines()) { |
||||
total += line.quantity(); |
||||
} |
||||
return total; |
||||
} |
||||
|
||||
/** 查询行 → 统一模型。 */ |
||||
public static TransferOrder toOrder(HengjianTransferDtos.TransferRow row) { |
||||
String sourceNo = trimToNull(row.sourceNo); |
||||
String planNo = trimToNull(row.transferOutboundPlanNo); |
||||
String requestNo = sourceNo != null ? sourceNo : planNo; |
||||
if (requestNo == null) { |
||||
throw new IllegalArgumentException( |
||||
"hengjian transfer row has neither sourceNo nor transferOutboundPlanNo"); |
||||
} |
||||
String from = trimToNull(row.outOrgWarehouseCode); |
||||
String to = trimToNull(row.inOrgWarehouseCode); |
||||
|
||||
TransferOrder.Builder builder = TransferOrder.builder() |
||||
.transferRequestNo(requestNo) |
||||
.providerTransferNo(planNo) |
||||
.providerId(row.id == null ? null : String.valueOf(row.id)) |
||||
.fromWarehouseCode(from == null ? OTHER_WAREHOUSE : from) |
||||
.toWarehouseCode(to == null ? OTHER_WAREHOUSE : to) |
||||
// 恒健的调拨都是仓到仓;外部仓库用 toWarehouseCode=Other 表达
|
||||
.type(OTHER_WAREHOUSE.equalsIgnoreCase(to) |
||||
? TransferType.OUTBOUND : TransferType.WAREHOUSE_TO_WAREHOUSE) |
||||
.status(HengjianTransferStatus.toCore(row.transferOutboundPlanStatus)) |
||||
.rawStatus(trimToNull(row.transferOutboundPlanStatus)) |
||||
.sourceProvider(WarehouseProvider.HENGJIAN) |
||||
.totalQuantity(totalQuantityOf(row)) |
||||
.estimatedOutboundAt(parseTime(row.estimateOutboundTime)) |
||||
.estimatedInboundAt(parseTime(row.estimateInboundTime)) |
||||
.remark(trimToNull(row.remark)) |
||||
.projectCode(trimToNull(row.projectUnicode)); |
||||
addAttachments(builder, row.attachesEntityList); |
||||
return builder.build(); |
||||
} |
||||
|
||||
private static int totalQuantityOf(HengjianTransferDtos.TransferRow row) { |
||||
int total = 0; |
||||
if (row.details != null) { |
||||
for (HengjianTransferDtos.TransferRow.Detail detail : row.details) { |
||||
if (detail != null && detail.qty != null) { |
||||
total += detail.qty; |
||||
} |
||||
} |
||||
} |
||||
return total; |
||||
} |
||||
|
||||
/** 附件:类型保留仓方原值(0/1/2/3 或 Shippinglabel 等)。 */ |
||||
private static void addAttachments(TransferOrder.Builder builder, |
||||
List<HengjianTransferDtos.TransferRow.Attachment> attachments) { |
||||
if (attachments == null) { |
||||
return; |
||||
} |
||||
for (HengjianTransferDtos.TransferRow.Attachment attachment : attachments) { |
||||
if (attachment == null) { |
||||
continue; |
||||
} |
||||
builder.attachment(common.ecommerce.warehouse.model.WarehouseAttachment.builder() |
||||
.name(trimToNull(attachment.name)) |
||||
.type(trimToNull(attachment.type)) |
||||
.url(trimToNull(attachment.url)) |
||||
.build()); |
||||
} |
||||
} |
||||
|
||||
/** 列表 → 统一 Page。 */ |
||||
public static Page<TransferOrder> toPage(HengjianTransferDtos.PageData data, |
||||
String cursor) { |
||||
if (data == null) { |
||||
return Page.last(new ArrayList<TransferOrder>()); |
||||
} |
||||
List<TransferOrder> out = new ArrayList<TransferOrder>(); |
||||
if (data.content != null) { |
||||
for (HengjianTransferDtos.TransferRow row : data.content) { |
||||
if (row != null) { |
||||
out.add(toOrder(row)); |
||||
} |
||||
} |
||||
} |
||||
boolean last = data.last != null ? data.last |
||||
: (data.numberOfElements != null && data.numberOfElements < rowsOf(0)); |
||||
if (last) { |
||||
return Page.last(out); |
||||
} |
||||
// 响应 number 是 0 基,请求 page 是 1 基:下一页 = number + 2
|
||||
int next = (data.number == null ? 0 : data.number) + 2; |
||||
return Page.of(out, String.valueOf(next)); |
||||
} |
||||
|
||||
// ================================================================ 工具
|
||||
|
||||
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 LocalDate.parse(v, DATE).atStartOfDay().toInstant(ZoneOffset.UTC); |
||||
} catch (DateTimeParseException ignored) { |
||||
try { |
||||
return Instant.parse(v); |
||||
} catch (DateTimeParseException alsoIgnored) { |
||||
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,294 @@
@@ -0,0 +1,294 @@
|
||||
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; |
||||
|
||||
/** |
||||
* 恒健报文结构:调拨计划(创建 / 查询)。 |
||||
* |
||||
* <p><b>创建接口真机确认的必填项</b>(按校验顺序):</p> |
||||
* <pre> |
||||
* outOrgWarehouseCode(调出仓库不能为空) |
||||
* inOrgWarehouseCode(调入仓库不能为空) |
||||
* estimateOutboundTime(期望出库日期不能为空) |
||||
* estimateInboundTime(期望入库日期不能为空) |
||||
* </pre> |
||||
* <p>文档还标了 {@code projectUnicode} / {@code transportationType} / {@code inventoryType} / |
||||
* {@code isLabel} / {@code receiveStore} / 六个 {@code shipTo*} 为必填,但<b>真机校验里没有它们</b> |
||||
* ——不传都能过参数校验(只停在鉴权处)。按选填实现,与 {@code currency}(入库创建) |
||||
* 是同一类情况。</p> |
||||
* |
||||
* <p><b>响应 {@code data} 是字符串</b>(调拨计划单号),不是对象。</p> |
||||
*/ |
||||
public final class HengjianTransferDtos { |
||||
|
||||
private HengjianTransferDtos() { |
||||
} |
||||
|
||||
// ================================================================ 创建
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class CreateRequest { |
||||
|
||||
/** 项目编号;文档标必填,真机不校验。 */ |
||||
public String projectUnicode; |
||||
|
||||
/** 调出仓库;必填。外部仓库填 {@code Other}。 */ |
||||
public String outOrgWarehouseCode; |
||||
|
||||
/** 调入仓库;必填。外部仓库填 {@code Other}。 */ |
||||
public String inOrgWarehouseCode; |
||||
|
||||
/** 运输方式:1 客户安排 / 2 仓库安排。 */ |
||||
public Integer transportationType; |
||||
|
||||
/** 库存类型:0 可售 / 1 不可售。 */ |
||||
public Integer inventoryType; |
||||
|
||||
/** 是否更换产品标:1 是 / 0 否。 */ |
||||
public Integer isLabel; |
||||
|
||||
/** 来源单号(参考字段);我们下发时用 transferRequestNo。 */ |
||||
public String sourceNo; |
||||
|
||||
/** 期望出库日期 {@code yyyy-MM-dd HH:mm:ss};必填。 */ |
||||
public String estimateOutboundTime; |
||||
|
||||
/** 期望入库日期 {@code yyyy-MM-dd HH:mm:ss};必填。 */ |
||||
public String estimateInboundTime; |
||||
|
||||
/** Amazon ShipmentId(参考字段)。 */ |
||||
public String shipmentId; |
||||
|
||||
/** Amazon referenceId(参考字段);<b>文档里就是三个 f</b>,照抄。 */ |
||||
public String refferenceId; |
||||
|
||||
/** 目的地址 CODE,默认等于调入仓库。 */ |
||||
public String receiveStore; |
||||
|
||||
public String shipToCountry; |
||||
public String shipToState; |
||||
public String shipToCity; |
||||
public String shipToPostal; |
||||
public String shipToAddress1; |
||||
public String shipToAddress2; |
||||
public String shipToContact; |
||||
public String shipToTelephone; |
||||
|
||||
/** 提货日期 {@code yyyy-MM-dd}。 */ |
||||
public String deliveryDate; |
||||
|
||||
public String remark; |
||||
|
||||
/** 产品明细;必填。 */ |
||||
public List<Detail> details; |
||||
|
||||
/** 产品明细行。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class Detail { |
||||
|
||||
/** 调拨产品 SKU;必填。 */ |
||||
public String sku; |
||||
|
||||
/** 数量;<b>文档标 STRING</b>(不是 INTEGER),照抄。 */ |
||||
public String qty; |
||||
} |
||||
} |
||||
|
||||
/** 创建响应:{@code data} 是调拨计划单号字符串。 */ |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public static final class CreateResponse { |
||||
|
||||
@JsonProperty("code") |
||||
public Integer code; |
||||
|
||||
@JsonProperty("message") |
||||
public String message; |
||||
|
||||
/** 调拨计划单号(字符串,不是对象)。 */ |
||||
@JsonProperty("data") |
||||
public String data; |
||||
} |
||||
|
||||
// ================================================================ 查询
|
||||
|
||||
/** 查询响应外层(分页信封)。 */ |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public static final class PageResponse { |
||||
|
||||
@JsonProperty("code") |
||||
public Integer code; |
||||
|
||||
@JsonProperty("message") |
||||
public String message; |
||||
|
||||
@JsonProperty("data") |
||||
public PageData data; |
||||
} |
||||
|
||||
/** 分页数据。 */ |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public static final class PageData { |
||||
|
||||
@JsonProperty("content") |
||||
public List<TransferRow> content; |
||||
|
||||
@JsonProperty("totalElements") |
||||
public Integer totalElements; |
||||
|
||||
@JsonProperty("totalPages") |
||||
public Integer totalPages; |
||||
|
||||
@JsonProperty("numberOfElements") |
||||
public Integer numberOfElements; |
||||
|
||||
/** 当前页码,<b>0 基</b>。 */ |
||||
@JsonProperty("number") |
||||
public Integer number; |
||||
|
||||
@JsonProperty("size") |
||||
public Integer size; |
||||
|
||||
@JsonProperty("last") |
||||
public Boolean last; |
||||
} |
||||
|
||||
/** 一行调拨计划。 */ |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public static final class TransferRow { |
||||
|
||||
/** 仓方内部 id。 */ |
||||
@JsonProperty("id") |
||||
public Long id; |
||||
|
||||
@JsonProperty("projectUnicode") |
||||
public String projectUnicode; |
||||
|
||||
/** 调拨计划单号。 */ |
||||
@JsonProperty("transferOutboundPlanNo") |
||||
public String transferOutboundPlanNo; |
||||
|
||||
/** |
||||
* 单据状态:数字(0/3/5/7/8/10/15/20/25/70/90/100/110)。 |
||||
* |
||||
* <p>用 String 接住——文档标 INTEGER,但同站的其它接口出现过数字串, |
||||
* 两种都能解析。</p> |
||||
*/ |
||||
@JsonProperty("transferOutboundPlanStatus") |
||||
public String transferOutboundPlanStatus; |
||||
|
||||
@JsonProperty("outOrgWarehouseCode") |
||||
public String outOrgWarehouseCode; |
||||
@JsonProperty("inOrgWarehouseCode") |
||||
public String inOrgWarehouseCode; |
||||
|
||||
/** 运输方式:1 客户安排 / 2 仓库安排。 */ |
||||
@JsonProperty("transportationType") |
||||
public Integer transportationType; |
||||
/** 库存类型:0 可售 / 1 不可售。 */ |
||||
@JsonProperty("inventoryType") |
||||
public Integer inventoryType; |
||||
/** 是否更换产品标:1 是 / 0 否。 */ |
||||
@JsonProperty("isLabel") |
||||
public Integer isLabel; |
||||
|
||||
@JsonProperty("sourceNo") |
||||
public String sourceNo; |
||||
|
||||
/** 期望出库 / 入库时间 {@code yyyy-MM-dd HH:mm:ss}。 */ |
||||
@JsonProperty("estimateOutboundTime") |
||||
public String estimateOutboundTime; |
||||
@JsonProperty("estimateInboundTime") |
||||
public String estimateInboundTime; |
||||
|
||||
/** 实际出库时间(示例里有,字段表没列)。 */ |
||||
@JsonProperty("actualOutboundTime") |
||||
public String actualOutboundTime; |
||||
|
||||
@JsonProperty("shipmentId") |
||||
public String shipmentId; |
||||
/** referenceId;文档拼成 {@code refferenceId},照抄。 */ |
||||
@JsonProperty("refferenceId") |
||||
public String refferenceId; |
||||
|
||||
@JsonProperty("receiveStore") |
||||
public String receiveStore; |
||||
|
||||
@JsonProperty("shipToCountry") |
||||
public String shipToCountry; |
||||
@JsonProperty("shipToState") |
||||
public String shipToState; |
||||
@JsonProperty("shipToCity") |
||||
public String shipToCity; |
||||
@JsonProperty("shipToPostal") |
||||
public String shipToPostal; |
||||
@JsonProperty("shipToAddress1") |
||||
public String shipToAddress1; |
||||
@JsonProperty("shipToAddress2") |
||||
public String shipToAddress2; |
||||
@JsonProperty("shipToContact") |
||||
public String shipToContact; |
||||
@JsonProperty("shipToTelephone") |
||||
public String shipToTelephone; |
||||
|
||||
@JsonProperty("remark") |
||||
public String remark; |
||||
|
||||
/** 产品明细。 */ |
||||
@JsonProperty("details") |
||||
public List<Detail> details; |
||||
|
||||
/** 附件。 */ |
||||
@JsonProperty("attachesEntityList") |
||||
public List<Attachment> attachesEntityList; |
||||
|
||||
/** 产品明细行(查询响应)。 */ |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public static final class Detail { |
||||
|
||||
@JsonProperty("sku") |
||||
public String sku; |
||||
@JsonProperty("sellerSku") |
||||
public String sellerSku; |
||||
@JsonProperty("parentSku") |
||||
public String parentSku; |
||||
@JsonProperty("gtin") |
||||
public String gtin; |
||||
@JsonProperty("qty") |
||||
public Integer qty; |
||||
@JsonProperty("remark") |
||||
public String remark; |
||||
/** 出库数量。 */ |
||||
@JsonProperty("qtyOutbound") |
||||
public Integer qtyOutbound; |
||||
/** 入库数量。 */ |
||||
@JsonProperty("qtyInbound") |
||||
public Integer qtyInbound; |
||||
} |
||||
|
||||
/** 附件行。 */ |
||||
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
public static final class Attachment { |
||||
|
||||
@JsonProperty("attachmentId") |
||||
public Long attachmentId; |
||||
/** 附件类型:0 Shippinglabel / 1 Packinglist / 2 BOL / 3 Other。 */ |
||||
@JsonProperty("type") |
||||
public String type; |
||||
@JsonProperty("transPlanId") |
||||
public Long transPlanId; |
||||
/** 调拨计划单号(示例里有,字段表也有)。 */ |
||||
@JsonProperty("transferOutboundPlanNo") |
||||
public String transferOutboundPlanNo; |
||||
@JsonProperty("sourceNo") |
||||
public String sourceNo; |
||||
@JsonProperty("name") |
||||
public String name; |
||||
@JsonProperty("url") |
||||
public String url; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,86 @@
@@ -0,0 +1,86 @@
|
||||
package common.ecommerce.hengjian.enums; |
||||
|
||||
import common.ecommerce.warehouse.enums.TransferStatus; |
||||
|
||||
/** |
||||
* 恒健调拨计划单状态({@code transferOutboundPlanStatus})。 |
||||
* |
||||
* <p>码表来自《调拨计划单查询接口》:0 草稿 / 3 已驳回 / 5 待审核 / 7 审核通过 / |
||||
* 8 待确认 / 10 待出库 / 15 出库中 / 20 待入库 / 25 入库中 / 70 已完成 / |
||||
* 90 已关闭 / 100 取消中 / 110 已取消。</p> |
||||
* |
||||
* <p><b>精确匹配</b>,未知归 {@link #UNKNOWN} 不猜;原值同时写进 |
||||
* {@code TransferOrder.rawStatus}。</p> |
||||
* |
||||
* <p>注意 {@code 100}(取消中)与 {@code 110}(已取消)是两个状态—— |
||||
* 合并就分不出「取消请求已发出」和「仓方已确认取消」。</p> |
||||
*/ |
||||
public enum HengjianTransferStatus { |
||||
|
||||
/** 0 草稿。 */ |
||||
DRAFT("0", TransferStatus.DRAFT), |
||||
/** 3 已驳回。 */ |
||||
REJECTED("3", TransferStatus.REJECTED), |
||||
/** 5 待审核。 */ |
||||
PENDING_REVIEW("5", TransferStatus.PENDING_REVIEW), |
||||
/** 7 审核通过。 */ |
||||
APPROVED("7", TransferStatus.APPROVED), |
||||
/** 8 待确认。 */ |
||||
PENDING_CONFIRM("8", TransferStatus.PENDING_CONFIRM), |
||||
/** 10 待出库。 */ |
||||
PENDING_OUTBOUND("10", TransferStatus.PENDING_OUTBOUND), |
||||
/** 15 出库中。 */ |
||||
OUTBOUNDING("15", TransferStatus.OUTBOUNDING), |
||||
/** 20 待入库。 */ |
||||
PENDING_INBOUND("20", TransferStatus.PENDING_INBOUND), |
||||
/** 25 入库中。 */ |
||||
INBOUNDING("25", TransferStatus.INBOUNDING), |
||||
/** 70 已完成。 */ |
||||
COMPLETED("70", TransferStatus.COMPLETED), |
||||
/** 90 已关闭。 */ |
||||
CLOSED("90", TransferStatus.CLOSED), |
||||
/** 100 取消中。 */ |
||||
CANCELLING("100", TransferStatus.CANCELLING), |
||||
/** 110 已取消。 */ |
||||
CANCELLED("110", TransferStatus.CANCELLED), |
||||
/** 无法识别。 */ |
||||
UNKNOWN(null, TransferStatus.UNKNOWN); |
||||
|
||||
private final String rawCode; |
||||
private final TransferStatus core; |
||||
|
||||
HengjianTransferStatus(String rawCode, TransferStatus core) { |
||||
this.rawCode = rawCode; |
||||
this.core = core; |
||||
} |
||||
|
||||
/** 恒健原始码;null 表示无法识别。 */ |
||||
public String rawCode() { |
||||
return rawCode; |
||||
} |
||||
|
||||
public TransferStatus toCore() { |
||||
return core; |
||||
} |
||||
|
||||
/** 精确匹配(忽略首尾空白);空值 / 未收录归 {@link #UNKNOWN}。 */ |
||||
public static HengjianTransferStatus of(String raw) { |
||||
if (raw == null) { |
||||
return UNKNOWN; |
||||
} |
||||
String s = raw.trim(); |
||||
if (s.isEmpty()) { |
||||
return UNKNOWN; |
||||
} |
||||
for (HengjianTransferStatus v : values()) { |
||||
if (v.rawCode != null && s.equals(v.rawCode)) { |
||||
return v; |
||||
} |
||||
} |
||||
return UNKNOWN; |
||||
} |
||||
|
||||
public static TransferStatus toCore(String raw) { |
||||
return of(raw).toCore(); |
||||
} |
||||
} |
||||
@ -0,0 +1,371 @@
@@ -0,0 +1,371 @@
|
||||
package common.ecommerce.hengjian.adapter; |
||||
|
||||
import common.ecommerce.hengjian.HengjianConstants; |
||||
import common.ecommerce.hengjian.enums.HengjianTransferStatus; |
||||
import common.ecommerce.http.JacksonJsonCodec; |
||||
import common.ecommerce.shared.spi.ChannelSecret; |
||||
import common.ecommerce.shared.support.Page; |
||||
import common.ecommerce.shared.testkit.RecordingTransport; |
||||
import common.ecommerce.shared.testkit.Responses; |
||||
import common.ecommerce.warehouse.enums.TransferStatus; |
||||
import common.ecommerce.warehouse.enums.TransferType; |
||||
import common.ecommerce.warehouse.enums.WarehouseCapability; |
||||
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||
import common.ecommerce.warehouse.model.OutboundRef; |
||||
import common.ecommerce.warehouse.model.ShipTo; |
||||
import common.ecommerce.warehouse.model.TransferCommand; |
||||
import common.ecommerce.warehouse.model.TransferOrder; |
||||
import common.ecommerce.warehouse.model.TransferQuery; |
||||
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 java.util.List; |
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
import static org.junit.jupiter.api.Assertions.assertFalse; |
||||
import static org.junit.jupiter.api.Assertions.assertThrows; |
||||
import static org.junit.jupiter.api.Assertions.assertTrue; |
||||
|
||||
/** |
||||
* 调拨计划创建 / 查询 / 取消契约测试。 |
||||
*/ |
||||
class HengjianTransferTest { |
||||
|
||||
private static final WarehouseContext CTX = WarehouseContext.of( |
||||
"HJ-EFGA", WarehouseProvider.HENGJIAN, "EFGA", |
||||
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 HengjianAdapter adapter(RecordingTransport transport) { |
||||
return new HengjianAdapter(transport, new JacksonJsonCodec()); |
||||
} |
||||
|
||||
private static TransferCommand.Builder command() { |
||||
return TransferCommand.builder() |
||||
.transferRequestNo("TF-2026-0001") |
||||
.type(TransferType.WAREHOUSE_TO_WAREHOUSE) |
||||
.fromWarehouseCode("EFGA") |
||||
.toWarehouseCode("EFCA") |
||||
.inventoryType(0) |
||||
.transportationType(2) |
||||
.estimateOutboundDate(LocalDate.parse("2026-12-01")) |
||||
.estimateInboundDate(LocalDate.parse("2026-12-10")) |
||||
.projectCode("P-1") |
||||
.relabelProducts(false) |
||||
.line("SKU-A", 3); |
||||
} |
||||
|
||||
// ================================================================ 创建
|
||||
|
||||
private static RecordingTransport creating() { |
||||
return RecordingTransport.create() |
||||
.route(HengjianConstants.PATH_TRANSFER_CREATE, req -> Responses.ok( |
||||
"{\"statusCode\":200,\"status\":0,\"code\":200," |
||||
+ "\"message\":\"创建调拨计划单成功\",\"data\":\"HI-TF2212089091\"}")); |
||||
} |
||||
|
||||
@Test |
||||
void createPostsToTransferPlan() { |
||||
RecordingTransport transport = creating(); |
||||
adapter(transport).create(CTX, command().build()); |
||||
|
||||
assertEquals("POST", transport.lastDataRequest().method()); |
||||
assertEquals(HengjianConstants.TEST_BASE_URL + "/v1/transferPlan/create", |
||||
transport.lastDataRequest().url()); |
||||
} |
||||
|
||||
/** 真机确认的四个必填项都要有。 */ |
||||
@Test |
||||
void createSendsMandatoryFields() { |
||||
RecordingTransport transport = creating(); |
||||
adapter(transport).create(CTX, command().build()); |
||||
String body = transport.lastDataRequest().body(); |
||||
|
||||
String[] mandatory = {"outOrgWarehouseCode", "inOrgWarehouseCode", |
||||
"estimateOutboundTime", "estimateInboundTime", "details"}; |
||||
for (String field : mandatory) { |
||||
assertTrue(body.contains("\"" + field + "\""), "缺少必填字段 " + field + ",body=" + body); |
||||
} |
||||
} |
||||
|
||||
/** 日期补成 yyyy-MM-dd HH:mm:ss(当天 00:00:00,不编造时刻)。 */ |
||||
@Test |
||||
void createFormatsDatesWithMidnight() { |
||||
RecordingTransport transport = creating(); |
||||
adapter(transport).create(CTX, command().build()); |
||||
String body = transport.lastDataRequest().body(); |
||||
|
||||
assertTrue(body.contains("\"estimateOutboundTime\":\"2026-12-01 00:00:00\""), body); |
||||
assertTrue(body.contains("\"estimateInboundTime\":\"2026-12-10 00:00:00\""), body); |
||||
} |
||||
|
||||
/** 数量按字符串下发(恒健该字段标 STRING)。 */ |
||||
@Test |
||||
void detailsQuantityIsString() { |
||||
RecordingTransport transport = creating(); |
||||
adapter(transport).create(CTX, command().build()); |
||||
String body = transport.lastDataRequest().body(); |
||||
|
||||
assertTrue(body.contains("\"qty\":\"3\""), "数量必须是字符串,body=" + body); |
||||
assertFalse(body.contains("\"qty\":3"), "不能发成数字"); |
||||
} |
||||
|
||||
/** 外部仓库用 Other;收货地址整组下发。 */ |
||||
@Test |
||||
void createSendsExternalDestination() { |
||||
RecordingTransport transport = creating(); |
||||
adapter(transport).create(CTX, command() |
||||
.toWarehouseCode("Other") |
||||
.externalDestination(true) |
||||
.shipTo(ShipTo.builder() |
||||
.name("Recv").phone("555").countryCode("US").stateOrProvince("GA") |
||||
.city("Atlanta").addressLine1("1 St").addressLine2("Suite 2") |
||||
.postalCode("30349").build()) |
||||
.build()); |
||||
String body = transport.lastDataRequest().body(); |
||||
|
||||
assertTrue(body.contains("\"inOrgWarehouseCode\":\"Other\""), body); |
||||
assertTrue(body.contains("\"shipToCity\":\"Atlanta\""), body); |
||||
assertTrue(body.contains("\"shipToContact\":\"Recv\""), body); |
||||
assertTrue(body.contains("\"shipToPostal\":\"30349\""), body); |
||||
} |
||||
|
||||
/** 未指定运输方式(0)按「仓库安排」兜底并说明;其它值拒绝。 */ |
||||
@Test |
||||
void transportationTypeMapping() { |
||||
RecordingTransport transport = creating(); |
||||
adapter(transport).create(CTX, command().transportationType(0).build()); |
||||
assertTrue(transport.lastDataRequest().body().contains("\"transportationType\":2")); |
||||
|
||||
RecordingTransport customer = creating(); |
||||
adapter(customer).create(CTX, command().transportationType(1).build()); |
||||
assertTrue(customer.lastDataRequest().body().contains("\"transportationType\":1")); |
||||
|
||||
RecordingTransport bad = creating(); |
||||
assertThrows(IllegalArgumentException.class, |
||||
() -> adapter(bad).create(CTX, command().transportationType(9).build())); |
||||
} |
||||
|
||||
/** 缺出库 / 入库日期时本地拒绝:恒健必填,发出去也会被抓。 */ |
||||
@Test |
||||
void createRequiresBothDates() { |
||||
RecordingTransport transport = creating(); |
||||
assertThrows(IllegalArgumentException.class, |
||||
() -> adapter(transport).create(CTX, TransferCommand.builder() |
||||
.transferRequestNo("TF-X").type(TransferType.WAREHOUSE_TO_WAREHOUSE) |
||||
.fromWarehouseCode("EFGA").toWarehouseCode("EFCA") |
||||
.line("SKU-A", 1) |
||||
.build())); |
||||
assertTrue(transport.dataRequests().isEmpty()); |
||||
} |
||||
|
||||
/** 拿不到单号不能当成功。 */ |
||||
@Test |
||||
void createRejectsResponseWithoutPlanNo() { |
||||
RecordingTransport transport = RecordingTransport.create() |
||||
.route(HengjianConstants.PATH_TRANSFER_CREATE, req -> Responses.ok( |
||||
"{\"code\":200,\"message\":\"OK\"}")); |
||||
|
||||
RuntimeException ex = assertThrows(RuntimeException.class, |
||||
() -> adapter(transport).create(CTX, command().build())); |
||||
assertTrue(ex.getMessage().contains("plan no"), ex.getMessage()); |
||||
} |
||||
|
||||
@Test |
||||
void createdOrderCarriesProviderNo() { |
||||
TransferOrder order = adapter(creating()).create(CTX, command().build()); |
||||
|
||||
assertEquals("TF-2026-0001", order.transferRequestNo()); |
||||
assertEquals("HI-TF2212089091", order.providerTransferNo()); |
||||
assertEquals("EFGA", order.fromWarehouseCode()); |
||||
assertEquals("EFCA", order.toWarehouseCode()); |
||||
assertEquals(3, order.totalQuantity()); |
||||
// 创建接口不回状态:保持 UNKNOWN,不拿请求侧的值冒充
|
||||
assertEquals(TransferStatus.UNKNOWN, order.status()); |
||||
assertEquals(WarehouseProvider.HENGJIAN, order.sourceProvider()); |
||||
} |
||||
|
||||
// ================================================================ 查询
|
||||
|
||||
private static final String PAGE_BODY = |
||||
"{\"statusCode\":200,\"status\":0,\"code\":200,\"message\":\"查询调拨计划单成功\",\"data\":{" |
||||
+ "\"totalElements\":1,\"totalPages\":1,\"numberOfElements\":1," |
||||
+ "\"number\":0,\"size\":10,\"last\":true,\"content\":[{" |
||||
+ "\"id\":45595,\"transferOutboundPlanNo\":\"XH-TF2604100004\"," |
||||
+ "\"projectUnicode\":\"德姆勒-分销\",\"transferOutboundPlanStatus\":70," |
||||
+ "\"outOrgWarehouseCode\":\"EFGA\",\"inOrgWarehouseCode\":\"Other\"," |
||||
+ "\"transportationType\":2,\"inventoryType\":0,\"isLabel\":0," |
||||
+ "\"sourceNo\":\"TF-2026-0001\"," |
||||
+ "\"estimateOutboundTime\":\"2026-12-01 00:00:00\"," |
||||
+ "\"estimateInboundTime\":\"2026-12-10 00:00:00\"," |
||||
+ "\"details\":[{\"sku\":\"SKU-A\",\"qty\":3,\"qtyOutbound\":3,\"qtyInbound\":0}]," |
||||
+ "\"attachesEntityList\":[{\"attachmentId\":1,\"type\":\"Other\"," |
||||
+ "\"name\":\"test.jpg\",\"url\":\"https://cdn/x.jpg\"}]}]}}"; |
||||
|
||||
private static RecordingTransport paging() { |
||||
return RecordingTransport.create() |
||||
.route(HengjianConstants.PATH_TRANSFER_PAGE, req -> Responses.ok(PAGE_BODY)); |
||||
} |
||||
|
||||
@Test |
||||
void querySendsPagingAndFilters() { |
||||
RecordingTransport transport = paging(); |
||||
adapter(transport).queryTransfers(CTX, TransferQuery.builder() |
||||
.sourceNo("TF-2026-0001") |
||||
.providerTransferNo("XH-TF2604100004") |
||||
.projectCode("P-1") |
||||
.fromWarehouseCode("EFGA") |
||||
.toWarehouseCode("Other") |
||||
.pageSize(10) |
||||
.build()); |
||||
|
||||
String url = transport.lastDataRequest().url(); |
||||
assertEquals("GET", transport.lastDataRequest().method()); |
||||
assertTrue(url.contains("page=1"), url); |
||||
assertTrue(url.contains("rows=10"), url); |
||||
assertTrue(url.contains("sidx=id"), url); |
||||
assertTrue(url.contains("sort=desc"), url); |
||||
assertTrue(url.contains("sourceNo=TF-2026-0001"), url); |
||||
assertTrue(url.contains("transferOutboundPlanNo=XH-TF2604100004"), url); |
||||
assertTrue(url.contains("outOrgWarehouseCode=EFGA"), url); |
||||
assertTrue(url.contains("inOrgWarehouseCode=Other"), url); |
||||
} |
||||
|
||||
@Test |
||||
void queryMapsOrder() { |
||||
Page<TransferOrder> page = adapter(paging()).queryTransfers(CTX, |
||||
TransferQuery.builder().pageSize(10).build()); |
||||
|
||||
assertEquals(1, page.size()); |
||||
assertFalse(page.hasMore()); |
||||
TransferOrder order = page.items().get(0); |
||||
assertEquals("TF-2026-0001", order.transferRequestNo(), "来源单号优先"); |
||||
assertEquals("XH-TF2604100004", order.providerTransferNo()); |
||||
assertEquals("45595", order.providerId()); |
||||
assertEquals(TransferStatus.COMPLETED, order.status()); |
||||
assertEquals("70", order.rawStatus()); |
||||
// 调入仓是 Other → 调拨出库
|
||||
assertEquals(TransferType.OUTBOUND, order.type()); |
||||
assertEquals("德姆勒-分销", order.projectCode()); |
||||
assertEquals(3, order.totalQuantity()); |
||||
assertEquals(Instant.parse("2026-12-01T00:00:00Z"), order.estimatedOutboundAt()); |
||||
assertEquals(1, order.attachments().size()); |
||||
assertEquals("test.jpg", order.attachments().get(0).name()); |
||||
} |
||||
|
||||
/** 页大小超 100(文档明写)拒绝,不截断。 */ |
||||
@Test |
||||
void queryRejectsRowsAboveLimit() { |
||||
RecordingTransport transport = paging(); |
||||
assertThrows(IllegalArgumentException.class, |
||||
() -> adapter(transport).queryTransfers(CTX, |
||||
TransferQuery.builder().pageSize(500).build())); |
||||
assertTrue(transport.dataRequests().isEmpty()); |
||||
} |
||||
|
||||
/** 未到末页时给出下一页游标。 */ |
||||
@Test |
||||
void queryAdvancesCursor() { |
||||
RecordingTransport transport = RecordingTransport.create() |
||||
.route(HengjianConstants.PATH_TRANSFER_PAGE, req -> Responses.ok( |
||||
"{\"code\":200,\"data\":{\"last\":false,\"number\":0,\"content\":[{" |
||||
+ "\"sourceNo\":\"TF-1\",\"transferOutboundPlanNo\":\"XH-1\"," |
||||
+ "\"transferOutboundPlanStatus\":5,\"outOrgWarehouseCode\":\"EFGA\"," |
||||
+ "\"inOrgWarehouseCode\":\"EFCA\"}]}}")); |
||||
|
||||
Page<TransferOrder> page = adapter(transport).queryTransfers(CTX, |
||||
TransferQuery.builder().pageSize(1).build()); |
||||
|
||||
assertTrue(page.hasMore()); |
||||
assertEquals("2", page.nextCursor()); |
||||
} |
||||
|
||||
/** 文档里的 13 个状态值都要映射对。 */ |
||||
@Test |
||||
void allDocumentedStatusesMap() { |
||||
assertEquals(TransferStatus.DRAFT, HengjianTransferStatus.toCore("0")); |
||||
assertEquals(TransferStatus.REJECTED, HengjianTransferStatus.toCore("3")); |
||||
assertEquals(TransferStatus.PENDING_REVIEW, HengjianTransferStatus.toCore("5")); |
||||
assertEquals(TransferStatus.APPROVED, HengjianTransferStatus.toCore("7")); |
||||
assertEquals(TransferStatus.PENDING_CONFIRM, HengjianTransferStatus.toCore("8")); |
||||
assertEquals(TransferStatus.PENDING_OUTBOUND, HengjianTransferStatus.toCore("10")); |
||||
assertEquals(TransferStatus.OUTBOUNDING, HengjianTransferStatus.toCore("15")); |
||||
assertEquals(TransferStatus.PENDING_INBOUND, HengjianTransferStatus.toCore("20")); |
||||
assertEquals(TransferStatus.INBOUNDING, HengjianTransferStatus.toCore("25")); |
||||
assertEquals(TransferStatus.COMPLETED, HengjianTransferStatus.toCore("70")); |
||||
assertEquals(TransferStatus.CLOSED, HengjianTransferStatus.toCore("90")); |
||||
assertEquals(TransferStatus.CANCELLING, HengjianTransferStatus.toCore("100")); |
||||
assertEquals(TransferStatus.CANCELLED, HengjianTransferStatus.toCore("110")); |
||||
} |
||||
|
||||
/** 100(取消中)与 110(已取消)不能合并。 */ |
||||
@Test |
||||
void cancellingIsNotCancelled() { |
||||
assertEquals(TransferStatus.CANCELLING, HengjianTransferStatus.toCore("100")); |
||||
assertEquals(TransferStatus.CANCELLED, HengjianTransferStatus.toCore("110")); |
||||
} |
||||
|
||||
@Test |
||||
void unknownStatusIsNotGuessed() { |
||||
assertEquals(TransferStatus.UNKNOWN, HengjianTransferStatus.toCore("999")); |
||||
assertEquals(TransferStatus.UNKNOWN, HengjianTransferStatus.toCore(null)); |
||||
} |
||||
|
||||
// ================================================================ 取消
|
||||
|
||||
@Test |
||||
void cancelSendsSourceNoAsQueryParam() { |
||||
RecordingTransport transport = RecordingTransport.create() |
||||
.route(HengjianConstants.PATH_TRANSFER_CANCEL, req -> Responses.ok( |
||||
"{\"statusCode\":200,\"status\":0,\"code\":200,\"message\":\"调拨计划取消成功\"}")); |
||||
|
||||
adapter(transport).deleteTransfer(CTX, "TF-2026-0001"); |
||||
|
||||
assertEquals("GET", transport.lastDataRequest().method()); |
||||
String url = transport.lastDataRequest().url(); |
||||
assertTrue(url.contains("/v1/transferPlan/cancel?"), url); |
||||
assertTrue(url.contains("sourceNo=TF-2026-0001"), url); |
||||
} |
||||
|
||||
@Test |
||||
void cancelRequiresSourceNo() { |
||||
assertThrows(IllegalArgumentException.class, |
||||
() -> adapter(RecordingTransport.create()).deleteTransfer(CTX, " ")); |
||||
} |
||||
|
||||
/** 仓方拒绝取消时原样抛业务异常(不伪装成成功)。 */ |
||||
@Test |
||||
void cancelFailureIsPropagated() { |
||||
RecordingTransport transport = RecordingTransport.create() |
||||
.route(HengjianConstants.PATH_TRANSFER_CANCEL, req -> Responses.ok( |
||||
"{\"statusCode\":500,\"status\":1,\"code\":999999," |
||||
+ "\"message\":\"调拨计划取消失败 test001:未查询到对应调拨计划数据\"}")); |
||||
|
||||
RuntimeException ex = assertThrows(RuntimeException.class, |
||||
() -> adapter(transport).deleteTransfer(CTX, "test001")); |
||||
assertTrue(ex.getMessage().contains("未查询到对应调拨计划数据"), ex.getMessage()); |
||||
} |
||||
|
||||
// ================================================================ 能力位
|
||||
|
||||
@Test |
||||
void declaresTransferCapability() { |
||||
assertTrue(adapter(RecordingTransport.create()).capabilities() |
||||
.contains(WarehouseCapability.TRANSFER)); |
||||
} |
||||
|
||||
/** 审核 / 详情接口恒健没有:默认拒绝。 */ |
||||
@Test |
||||
void approveAndGetTransferUnsupported() { |
||||
HengjianAdapter adapter = adapter(RecordingTransport.create()); |
||||
|
||||
assertThrows(RuntimeException.class, () -> adapter.approve(CTX, "TF-1")); |
||||
assertThrows(RuntimeException.class, () -> adapter.getTransfer(CTX, "TF-1")); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue