Browse Source
新增三个探针文件,默认全部跳过,凭据与业务数据全部走 -D 系统属性: - XincangProbeSupport:公共基座。装配真实 adapter、报文打印(URL 与 token 脱敏、 截断 2000 字符)、单步执行(异常只打印不抛)、仓代码 / 承运商自动发现、 带时间戳的业务单号后缀(重跑不撞唯一约束) - XincangReadProbeTest:只读接口逐个探针 仓库 / 承运商 / 实时库存 / 库龄 / 订单详情 / 转运详情 / 预报详情 / 最优渠道 - XincangWriteProbeTest:写接口探针,需 -Dxincang.probe.write=true 二次确认 商品建档、出库闭环(下单→回读→删除自清理)、 转运闭环(建→详情→删除自清理)、转运审核(审核后不可删,需单独开关)、 预报闭环(无删除接口,会留下数据) 业务输入不写默认值:SKU / 邮编 / 单号一律由 -D 传入,缺了就跳过对应用例, 不影响其他探针;仓代码与承运商从目录接口现取,换环境不用改代码。 运行方式见两个探针类的类注释。 Co-Authored-By: Claude Code <noreply@anthropic.com>feature/supplier-lingxing^2
3 changed files with 941 additions and 0 deletions
@ -0,0 +1,293 @@ |
|||||||
|
package common.ecommerce.xincang.probe; |
||||||
|
|
||||||
|
import common.ecommerce.http.HttpRequest; |
||||||
|
import common.ecommerce.http.HttpResponse; |
||||||
|
import common.ecommerce.http.HttpTransport; |
||||||
|
import common.ecommerce.http.JacksonJsonCodec; |
||||||
|
import common.ecommerce.http.OkHttpTransport; |
||||||
|
import common.ecommerce.shared.spi.ChannelSecret; |
||||||
|
import common.ecommerce.shared.testkit.InMemoryLockProvider; |
||||||
|
import common.ecommerce.shared.testkit.InMemoryTokenStore; |
||||||
|
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||||
|
import common.ecommerce.warehouse.model.WarehouseFacility; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseConnection; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||||
|
import common.ecommerce.xincang.XincangConstants; |
||||||
|
import common.ecommerce.xincang.adapter.XincangAdapter; |
||||||
|
import org.junit.jupiter.api.Assumptions; |
||||||
|
|
||||||
|
import java.time.Clock; |
||||||
|
import java.util.List; |
||||||
|
import java.util.function.Supplier; |
||||||
|
|
||||||
|
/** |
||||||
|
* 信仓联网探针的公共基座。 |
||||||
|
* |
||||||
|
* <p><b>默认全部跳过</b>,用 {@code -Dxincang.probe=true} 显式开启;写接口还要再加 |
||||||
|
* {@code -Dxincang.probe.write=true} 二次确认。凭据与业务数据一律走系统属性, |
||||||
|
* <b>真实值不入库</b>。</p> |
||||||
|
* |
||||||
|
* <pre> |
||||||
|
* mvn -pl warehouse-sdk-xincang -am -DfailIfNoTests=false \ |
||||||
|
* -Dxincang.probe=true \ |
||||||
|
* -Dxincang.probe.appKey=你的appkey -Dxincang.probe.appSecret=你的secret \ |
||||||
|
* -Dtest=XincangReadProbeTest test |
||||||
|
* </pre> |
||||||
|
* |
||||||
|
* <p>可选属性:{@code baseUrl}、{@code warehouseCode}、{@code sku}、{@code postcode}、 |
||||||
|
* {@code qty}、{@code orderNo}、{@code transferNo}、{@code forecastNo}。</p> |
||||||
|
* |
||||||
|
* <p>设计约束:</p> |
||||||
|
* <ul> |
||||||
|
* <li>每个探针独立执行,单个失败只打印不抛出,保证一次能跑完全部接口;</li> |
||||||
|
* <li>请求 / 响应都打印(截断 + 脱敏),便于和文档逐字段对照;</li> |
||||||
|
* <li>不硬编码任何业务数据:仓代码与承运商从目录接口现取。</li> |
||||||
|
* </ul> |
||||||
|
*/ |
||||||
|
final class XincangProbeSupport { |
||||||
|
|
||||||
|
/** 通用开关。 */ |
||||||
|
static final String PROBE = "xincang.probe"; |
||||||
|
/** 写接口二次确认。 */ |
||||||
|
static final String PROBE_WRITE = "xincang.probe.write"; |
||||||
|
|
||||||
|
static final String APP_KEY = System.getProperty("xincang.probe.appKey", ""); |
||||||
|
static final String APP_SECRET = System.getProperty("xincang.probe.appSecret", ""); |
||||||
|
static final String BASE_URL = opt("xincang.probe.baseUrl", XincangConstants.TEST_BASE_URL); |
||||||
|
|
||||||
|
/** 业务输入:没有默认值,必须由调用方显式传入。 */ |
||||||
|
static final String WAREHOUSE_CODE = opt("xincang.probe.warehouseCode", ""); |
||||||
|
static final String SKU = opt("xincang.probe.sku", ""); |
||||||
|
static final String POSTCODE = opt("xincang.probe.postcode", ""); |
||||||
|
static final String ORDER_NO = opt("xincang.probe.orderNo", ""); |
||||||
|
static final String TRANSFER_NO = opt("xincang.probe.transferNo", ""); |
||||||
|
static final String FORECAST_NO = opt("xincang.probe.forecastNo", ""); |
||||||
|
|
||||||
|
private static final JacksonJsonCodec JSON = new JacksonJsonCodec(); |
||||||
|
|
||||||
|
/** 目录接口发现结果缓存,避免每个探针都列一遍。 */ |
||||||
|
private static String discoveredWarehouseCode; |
||||||
|
private static boolean warehouseDiscoveryAttempted; |
||||||
|
private static String discoveredCarrier; |
||||||
|
private static boolean carrierDiscoveryAttempted; |
||||||
|
|
||||||
|
private XincangProbeSupport() { |
||||||
|
} |
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 装配
|
||||||
|
|
||||||
|
/** 真实联网传输 + 报文打印;token 等敏感头在这里脱敏。 */ |
||||||
|
static HttpTransport transport() { |
||||||
|
return new LoggingTransport(new OkHttpTransport("common-ecommerce-xincang-probe")); |
||||||
|
} |
||||||
|
|
||||||
|
/** 装配真实适配器;令牌只存在内存里,不落盘。 */ |
||||||
|
static XincangAdapter adapter() { |
||||||
|
return new XincangAdapter(transport(), JSON, new InMemoryTokenStore(), |
||||||
|
new InMemoryLockProvider(), Clock.systemUTC()); |
||||||
|
} |
||||||
|
|
||||||
|
/** 用指定传输装配,便于需要复用连接的对象。 */ |
||||||
|
static XincangAdapter adapter(HttpTransport transport) { |
||||||
|
return new XincangAdapter(transport, JSON, new InMemoryTokenStore(), |
||||||
|
new InMemoryLockProvider(), Clock.systemUTC()); |
||||||
|
} |
||||||
|
|
||||||
|
static WarehouseContext ctx() { |
||||||
|
return ctx(WAREHOUSE_CODE.isEmpty() ? null : WAREHOUSE_CODE); |
||||||
|
} |
||||||
|
|
||||||
|
static WarehouseContext ctx(String providerWarehouseId) { |
||||||
|
return WarehouseContext.of("XC-PROBE", WarehouseProvider.XINCANG, providerWarehouseId, |
||||||
|
WarehouseConnection.of(BASE_URL, ChannelSecret.builder() |
||||||
|
.appKey(APP_KEY).appSecret(APP_SECRET).build()), |
||||||
|
"probe-" + System.currentTimeMillis(), Clock.systemUTC()); |
||||||
|
} |
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 前置检查
|
||||||
|
|
||||||
|
/** 凭据齐全才继续,否则整个探针 skip(不算失败)。 */ |
||||||
|
static void requireCredentials() { |
||||||
|
Assumptions.assumeTrue(!APP_KEY.trim().isEmpty() && !APP_SECRET.trim().isEmpty(), |
||||||
|
"未提供 -Dxincang.probe.appKey / -Dxincang.probe.appSecret,跳过探针"); |
||||||
|
} |
||||||
|
|
||||||
|
/** 需要某个业务输入时用它:缺了就跳过当前用例并说明缺哪个属性。 */ |
||||||
|
static void requireProperty(String name) { |
||||||
|
Assumptions.assumeTrue(System.getProperty(name, "").trim().length() > 0, |
||||||
|
"未提供 -D" + name + ",跳过该探针"); |
||||||
|
} |
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 执行 & 打印
|
||||||
|
|
||||||
|
/** 执行一步并打印结果;异常只打印不抛出,返回 null。 */ |
||||||
|
static <T> T step(String label, Supplier<T> action) { |
||||||
|
System.out.println(" [probe] " + label); |
||||||
|
try { |
||||||
|
T value = action.get(); |
||||||
|
System.out.println(" [ok] " + label + " → " + describe(value)); |
||||||
|
return value; |
||||||
|
} catch (RuntimeException e) { |
||||||
|
printError(e); |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static void step(String label, Runnable action) { |
||||||
|
step(label, () -> { |
||||||
|
action.run(); |
||||||
|
return Boolean.TRUE; |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
/** 异常打印:类型 + 截断消息 + 平台错误字段。 */ |
||||||
|
static void printError(RuntimeException e) { |
||||||
|
String msg = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage(); |
||||||
|
System.out.println(" [ERROR] " + e.getClass().getSimpleName() + ": " |
||||||
|
+ (msg.length() <= 400 ? msg : msg.substring(0, 400) + "…")); |
||||||
|
if (e instanceof common.ecommerce.shared.error.ChannelException) { |
||||||
|
common.ecommerce.shared.error.ChannelException ce = |
||||||
|
(common.ecommerce.shared.error.ChannelException) e; |
||||||
|
System.out.println(" operation=" + ce.operation() |
||||||
|
+ " platformCode=" + ce.platformCode() |
||||||
|
+ " platformRequestId=" + ce.platformRequestId() |
||||||
|
+ " retryable=" + ce.retryable()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static String describe(Object value) { |
||||||
|
if (value == null) { |
||||||
|
return "null"; |
||||||
|
} |
||||||
|
if (value instanceof List) { |
||||||
|
return ((List<?>) value).size() + " items"; |
||||||
|
} |
||||||
|
return String.valueOf(value); |
||||||
|
} |
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 依赖发现
|
||||||
|
|
||||||
|
/** |
||||||
|
* 仓代码:优先 {@code -Dxincang.probe.warehouseCode},否则从客户仓库接口取第一家。 |
||||||
|
* |
||||||
|
* @return 没有可用仓时返回 null,调用方打印跳过 |
||||||
|
*/ |
||||||
|
static String warehouseCode(XincangAdapter adapter) { |
||||||
|
if (!WAREHOUSE_CODE.isEmpty()) { |
||||||
|
return WAREHOUSE_CODE; |
||||||
|
} |
||||||
|
if (warehouseDiscoveryAttempted) { |
||||||
|
return discoveredWarehouseCode; |
||||||
|
} |
||||||
|
warehouseDiscoveryAttempted = true; |
||||||
|
try { |
||||||
|
List<WarehouseFacility> facilities = adapter.warehouses(ctx()); |
||||||
|
if (!facilities.isEmpty()) { |
||||||
|
discoveredWarehouseCode = facilities.get(0).warehouseCode(); |
||||||
|
System.out.println(" [discovery] 自动使用仓 " + discoveredWarehouseCode); |
||||||
|
} |
||||||
|
} catch (RuntimeException e) { |
||||||
|
printError(e); |
||||||
|
} |
||||||
|
return discoveredWarehouseCode; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 承运商 / 物流方式:优先 {@code -Dxincang.probe.carrier},否则从客户承运商接口取第一个。 |
||||||
|
*/ |
||||||
|
static String carrier(XincangAdapter adapter) { |
||||||
|
String configured = System.getProperty("xincang.probe.carrier", "").trim(); |
||||||
|
if (!configured.isEmpty()) { |
||||||
|
return configured; |
||||||
|
} |
||||||
|
if (carrierDiscoveryAttempted) { |
||||||
|
return discoveredCarrier; |
||||||
|
} |
||||||
|
carrierDiscoveryAttempted = true; |
||||||
|
try { |
||||||
|
List<String> carriers = adapter.carriers(ctx()); |
||||||
|
if (!carriers.isEmpty()) { |
||||||
|
discoveredCarrier = carriers.get(0); |
||||||
|
System.out.println(" [discovery] 自动使用承运商 " + discoveredCarrier); |
||||||
|
} |
||||||
|
} catch (RuntimeException e) { |
||||||
|
printError(e); |
||||||
|
} |
||||||
|
return discoveredCarrier; |
||||||
|
} |
||||||
|
|
||||||
|
/** 业务单号后缀:保证重跑不会撞「参考号已存在」这类唯一约束。 */ |
||||||
|
static String uniqueSuffix() { |
||||||
|
return new java.text.SimpleDateFormat("yyyyMMdd-HHmmss") |
||||||
|
.format(new java.util.Date()); |
||||||
|
} |
||||||
|
|
||||||
|
static int qty() { |
||||||
|
String raw = System.getProperty("xincang.probe.qty", "1").trim(); |
||||||
|
try { |
||||||
|
int v = Integer.parseInt(raw); |
||||||
|
return v > 0 ? v : 1; |
||||||
|
} catch (NumberFormatException e) { |
||||||
|
return 1; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static String opt(String name, String fallback) { |
||||||
|
String value = System.getProperty(name, ""); |
||||||
|
if (value == null) { |
||||||
|
return fallback; |
||||||
|
} |
||||||
|
String trimmed = value.trim(); |
||||||
|
return trimmed.isEmpty() ? fallback : trimmed; |
||||||
|
} |
||||||
|
|
||||||
|
// ---------------------------------------------------------------- 报文打印
|
||||||
|
|
||||||
|
/** |
||||||
|
* 请求 / 响应打印。 |
||||||
|
* |
||||||
|
* <p>脱敏规则:鉴权头与 URL 里的 token / secret 一律替换成 {@code ***}; |
||||||
|
* 打印体截断到 2000 字符,避免大段 base64 或明细刷屏。</p> |
||||||
|
*/ |
||||||
|
static final class LoggingTransport implements HttpTransport { |
||||||
|
|
||||||
|
private static final int MAX_BODY = 2000; |
||||||
|
|
||||||
|
private final HttpTransport delegate; |
||||||
|
|
||||||
|
LoggingTransport(HttpTransport delegate) { |
||||||
|
this.delegate = delegate; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public HttpResponse execute(HttpRequest request) { |
||||||
|
System.out.println(" --> " + request.method() + " " + maskUrl(request.url())); |
||||||
|
System.out.println(" body " + truncate(request.body())); |
||||||
|
long start = System.nanoTime(); |
||||||
|
HttpResponse response = delegate.execute(request); |
||||||
|
long millis = (System.nanoTime() - start) / 1_000_000L; |
||||||
|
System.out.println(" <-- " + response.statusCode() + " (" + millis + "ms) " |
||||||
|
+ truncate(response.body())); |
||||||
|
return response; |
||||||
|
} |
||||||
|
|
||||||
|
/** 去掉 scheme+host,并把 query 里的敏感参数打码。 */ |
||||||
|
private static String maskUrl(String url) { |
||||||
|
if (url == null) { |
||||||
|
return "null"; |
||||||
|
} |
||||||
|
int pathStart = url.indexOf('/', url.indexOf("://") + 3); |
||||||
|
String path = pathStart < 0 ? url : url.substring(pathStart); |
||||||
|
return path.replaceAll("(?i)((?:token|secret|appkey)=)[^&]*", "$1***"); |
||||||
|
} |
||||||
|
|
||||||
|
private static String truncate(String body) { |
||||||
|
if (body == null) { |
||||||
|
return "null"; |
||||||
|
} |
||||||
|
return body.length() <= MAX_BODY |
||||||
|
? body |
||||||
|
: body.substring(0, MAX_BODY) + "...(" + body.length() + " chars)"; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,307 @@ |
|||||||
|
package common.ecommerce.xincang.probe; |
||||||
|
|
||||||
|
import common.ecommerce.warehouse.model.ChannelRecommendQuery; |
||||||
|
import common.ecommerce.warehouse.model.ChannelRecommendResult; |
||||||
|
import common.ecommerce.warehouse.model.InventoryAgeQuery; |
||||||
|
import common.ecommerce.warehouse.model.InventoryAgeRecord; |
||||||
|
import common.ecommerce.warehouse.model.InventoryQuery; |
||||||
|
import common.ecommerce.warehouse.model.InventorySnapshot; |
||||||
|
import common.ecommerce.warehouse.model.OutboundOrder; |
||||||
|
import common.ecommerce.warehouse.model.OutboundRef; |
||||||
|
import common.ecommerce.warehouse.model.TransferOrder; |
||||||
|
import common.ecommerce.warehouse.model.WarehouseFacility; |
||||||
|
import common.ecommerce.shared.support.Page; |
||||||
|
import common.ecommerce.xincang.XincangConstants; |
||||||
|
import common.ecommerce.xincang.adapter.XincangAdapter; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.junit.jupiter.api.condition.EnabledIfSystemProperty; |
||||||
|
|
||||||
|
import java.time.LocalDate; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 信仓只读接口的联网探针:核对真实出入参。 |
||||||
|
* |
||||||
|
* <p><b>默认跳过</b>,用 {@code -Dxincang.probe=true} 开启。凭据与业务数据走系统属性, |
||||||
|
* 真实值不入库;缺某个业务输入时只跳过依赖它的用例,不影响其他用例。</p> |
||||||
|
* |
||||||
|
* <pre> |
||||||
|
* mvn -pl warehouse-sdk-xincang -am -DfailIfNoTests=false \ |
||||||
|
* -Dxincang.probe=true \ |
||||||
|
* -Dxincang.probe.appKey=... -Dxincang.probe.appSecret=... \ |
||||||
|
* -Dxincang.probe.sku=... -Dxincang.probe.postcode=... \ |
||||||
|
* -Dtest=XincangReadProbeTest test |
||||||
|
* </pre> |
||||||
|
* |
||||||
|
* <p>可选属性:{@code warehouseCode} / {@code sku} / {@code postcode} / {@code orderNo} / |
||||||
|
* {@code transferNo} / {@code forecastNo} / {@code productPageSize}。</p> |
||||||
|
* |
||||||
|
* <p><b>只做查询</b>,不调用任何写接口;异常只打印不抛出,一次能跑完全部段落。</p> |
||||||
|
*/ |
||||||
|
@EnabledIfSystemProperty(named = XincangProbeSupport.PROBE, matches = "true") |
||||||
|
class XincangReadProbeTest { |
||||||
|
|
||||||
|
// ================================================================ 公共资料
|
||||||
|
|
||||||
|
/** 客户所有仓库:拿到仓代码,同时验证目录接口。 */ |
||||||
|
@Test |
||||||
|
void probeCustomerWarehouses() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
System.out.println("\n================ xincang / api.get_customer_warehouses ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
List<WarehouseFacility> warehouses = |
||||||
|
XincangProbeSupport.step("warehouses", () -> adapter.warehouses(XincangProbeSupport.ctx())); |
||||||
|
if (warehouses == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
for (WarehouseFacility w : warehouses) { |
||||||
|
System.out.println(" warehouse_code=" + w.warehouseCode() |
||||||
|
+ " id=" + w.providerWarehouseId() |
||||||
|
+ " " + w.city() + "/" + w.province() + "/" + w.country() |
||||||
|
+ " " + w.postcode()); |
||||||
|
} |
||||||
|
if (warehouses.isEmpty()) { |
||||||
|
System.out.println(" [warn] 该账户下没有任何仓库,后续依赖仓代码的探针会跳过"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** 客户所有承运商:拿到 logistics_type,用于下单与报价。 */ |
||||||
|
@Test |
||||||
|
void probeCustomerLogistics() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
System.out.println("\n================ xincang / api.get_customer_logistics ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
List<String> carriers = |
||||||
|
XincangProbeSupport.step("carriers", () -> adapter.carriers(XincangProbeSupport.ctx())); |
||||||
|
if (carriers != null) { |
||||||
|
System.out.println(" carriers=" + carriers); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// ================================================================ 库存 / 库龄
|
||||||
|
|
||||||
|
/** 实时库存:核对手上数量字段口径。 */ |
||||||
|
@Test |
||||||
|
void probeStockList() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
System.out.println("\n================ xincang / api.stocklist ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
String warehouseCode = XincangProbeSupport.warehouseCode(adapter); |
||||||
|
if (warehouseCode == null) { |
||||||
|
System.out.println(" [skip] 没有可用仓代码,跳过"); |
||||||
|
return; |
||||||
|
} |
||||||
|
InventoryQuery.Builder query = InventoryQuery.builder() |
||||||
|
.warehouseCode(warehouseCode) |
||||||
|
.pageSize(10); |
||||||
|
if (!XincangProbeSupport.SKU.isEmpty()) { |
||||||
|
query.sku(XincangProbeSupport.SKU); |
||||||
|
} |
||||||
|
Page<InventorySnapshot> page = XincangProbeSupport.step( |
||||||
|
"stocklist warehouse=" + warehouseCode, |
||||||
|
() -> adapter.query(XincangProbeSupport.ctx(warehouseCode), query.build())); |
||||||
|
if (page == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
System.out.println(" items=" + page.size() + " nextCursor=" + page.nextCursor()); |
||||||
|
for (InventorySnapshot s : page.items()) { |
||||||
|
System.out.println(" sku=" + s.providerSku() |
||||||
|
+ " onHand=" + s.onHand() |
||||||
|
+ " available=" + s.available() |
||||||
|
+ " reserved=" + s.reserved() |
||||||
|
+ " pending=" + s.pendingOutbound() |
||||||
|
+ " inTransit=" + s.inTransit() |
||||||
|
+ " alert=" + s.alertQuantity() |
||||||
|
+ " name=" + s.productName() |
||||||
|
+ " volumeCm=" + s.volumeCbm()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** 库龄列表:默认查最近 7 天,核对计费字段。 */ |
||||||
|
@Test |
||||||
|
void probeStockAgeList() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
System.out.println("\n================ xincang / api.stockagelist ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
LocalDate end = LocalDate.now(); |
||||||
|
LocalDate start = end.minusDays(7); |
||||||
|
InventoryAgeQuery query = InventoryAgeQuery.builder() |
||||||
|
.dateRange(start, end) |
||||||
|
.pageSize(10) |
||||||
|
.includeFeeRate(true) |
||||||
|
.build(); |
||||||
|
Page<InventoryAgeRecord> page = XincangProbeSupport.step( |
||||||
|
"stockagelist " + start + " ~ " + end, |
||||||
|
() -> adapter.queryAges(XincangProbeSupport.ctx(), query)); |
||||||
|
if (page == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
System.out.println(" items=" + page.size() + " nextCursor=" + page.nextCursor()); |
||||||
|
for (InventoryAgeRecord r : page.items()) { |
||||||
|
System.out.println(" sku=" + r.providerSku() |
||||||
|
+ " warehouse=" + r.warehouseCode() |
||||||
|
+ " billingDate=" + r.billingDate() |
||||||
|
+ " inStockAt=" + r.inStockAt() |
||||||
|
+ " ageDays=" + r.ageDays() |
||||||
|
+ " qty=" + r.quantity() |
||||||
|
+ " billingQty=" + r.billingQuantity() |
||||||
|
+ " feeRate=" + r.feeRate() |
||||||
|
+ " fee=" + r.fee() |
||||||
|
+ " cabinet=" + r.cabinetNo()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// ================================================================ 详情
|
||||||
|
|
||||||
|
/** 订单详情:按 -Dxincang.probe.orderNo 查。 */ |
||||||
|
@Test |
||||||
|
void probeOrderDetail() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.orderNo"); |
||||||
|
System.out.println("\n================ xincang / api.get_order ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
OutboundOrder order = XincangProbeSupport.step( |
||||||
|
"get_order " + XincangProbeSupport.ORDER_NO, |
||||||
|
() -> adapter.get(XincangProbeSupport.ctx(), |
||||||
|
OutboundRef.ofProviderOrderId(XincangProbeSupport.ORDER_NO))); |
||||||
|
if (order == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
System.out.println(" orderNo=" + order.outboundRequestNo() |
||||||
|
+ " providerOrderId=" + order.providerOrderId() |
||||||
|
+ " ref=" + order.orderRef() |
||||||
|
+ " status=" + order.status() + "(raw=" + order.rawStatus() + ")" |
||||||
|
+ " labelMode=" + order.labelMode() |
||||||
|
+ " carrier=" + order.carrierCode() |
||||||
|
+ " tracking=" + order.trackingNumber() |
||||||
|
+ " exception=" + order.exceptionCode() |
||||||
|
+ " requestedAt=" + order.requestedAt() |
||||||
|
+ " shippedAt=" + order.shippedAt() |
||||||
|
+ " fee=" + order.estimatedShippingFee()); |
||||||
|
System.out.println(" shipTo=" + order.shipTo()); |
||||||
|
for (common.ecommerce.warehouse.model.OutboundLine line : order.lines()) { |
||||||
|
System.out.println(" sku=" + line.providerSku() |
||||||
|
+ " qty=" + line.quantity() |
||||||
|
+ " name=" + line.declareName()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** 转运详情:按 -Dxincang.probe.transferNo 查。 */ |
||||||
|
@Test |
||||||
|
void probeTransferDetail() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.transferNo"); |
||||||
|
System.out.println("\n================ xincang / fba.fba_detail ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
TransferOrder order = XincangProbeSupport.step( |
||||||
|
"fba_detail " + XincangProbeSupport.TRANSFER_NO, |
||||||
|
() -> adapter.getTransfer(XincangProbeSupport.ctx(), XincangProbeSupport.TRANSFER_NO)); |
||||||
|
if (order == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
System.out.println(" transferRequestNo=" + order.transferRequestNo() |
||||||
|
+ " providerTransferNo=" + order.providerTransferNo() |
||||||
|
+ " from=" + order.fromWarehouseCode() |
||||||
|
+ " to=" + order.toWarehouseCode() |
||||||
|
+ " type=" + order.type() |
||||||
|
+ " status=" + order.status() + "(raw=" + order.rawStatus() + ")" |
||||||
|
+ " totalQty=" + order.totalQuantity() |
||||||
|
+ " estimatedOutboundAt=" + order.estimatedOutboundAt() |
||||||
|
+ " remark=" + order.remark()); |
||||||
|
} |
||||||
|
|
||||||
|
/** 预报详情:按 -Dxincang.probe.forecastNo 查。 */ |
||||||
|
@Test |
||||||
|
void probeForecastDetail() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.forecastNo"); |
||||||
|
System.out.println("\n================ xincang / forecast.forecast_detail ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
common.ecommerce.warehouse.model.InboundOrder order = XincangProbeSupport.step( |
||||||
|
"forecast_detail " + XincangProbeSupport.FORECAST_NO, |
||||||
|
() -> adapter.get(XincangProbeSupport.ctx(), XincangProbeSupport.FORECAST_NO)); |
||||||
|
if (order == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
System.out.println(" inboundRequestNo=" + order.inboundRequestNo() |
||||||
|
+ " providerInboundId=" + order.providerInboundId() |
||||||
|
+ " warehouse=" + order.warehouseCode() |
||||||
|
+ " status=" + order.status() + "(raw=" + order.rawStatus() + ")" |
||||||
|
+ " boxCount=" + order.boxCount() |
||||||
|
+ " createdAt=" + order.createdAt() |
||||||
|
+ " receivedAt=" + order.receivedAt() |
||||||
|
+ " estimatedArrivalAt=" + order.estimatedArrivalAt() |
||||||
|
+ " actualArrivalAt=" + order.actualArrivalAt() |
||||||
|
+ " remark=" + order.remark()); |
||||||
|
for (common.ecommerce.warehouse.model.InboundOrderLine line : order.lines()) { |
||||||
|
System.out.println(" sku=" + line.providerSku() |
||||||
|
+ " planned=" + line.plannedQuantity() |
||||||
|
+ " packed=" + line.packedQuantity() |
||||||
|
+ " received=" + line.receivedQuantity()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// ================================================================ 报价
|
||||||
|
|
||||||
|
/** |
||||||
|
* 最优渠道:需要 SKU 与邮编。 |
||||||
|
* |
||||||
|
* <p>协议待核对:文档写 GET + JSON body,OkHttp 不支持 GET 带 body, |
||||||
|
* 适配器按 POST + JSON body 下发。这里重点看仓方是否接受。</p> |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
void probeChannelRecommend() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.sku"); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.postcode"); |
||||||
|
System.out.println("\n================ xincang / api.calculate_order_v3 ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
ChannelRecommendQuery query = ChannelRecommendQuery.builder() |
||||||
|
.product(XincangProbeSupport.SKU, XincangProbeSupport.qty()) |
||||||
|
.postalCode(XincangProbeSupport.POSTCODE) |
||||||
|
.signatureRequired(false) |
||||||
|
.build(); |
||||||
|
ChannelRecommendResult result = XincangProbeSupport.step( |
||||||
|
"calculate_order_v3 sku=" + XincangProbeSupport.SKU |
||||||
|
+ " postcode=" + XincangProbeSupport.POSTCODE, |
||||||
|
() -> adapter.recommend(XincangProbeSupport.ctx(), query)); |
||||||
|
if (result == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
if (result.optimalPlan() == null) { |
||||||
|
System.out.println(" optimalPlan=null(该城无可用渠道,属合法结果)"); |
||||||
|
} else { |
||||||
|
System.out.println(" optimalPlan: warehouse=" + result.optimalPlan().warehouseCode() |
||||||
|
+ " service=" + result.optimalPlan().serviceCode() |
||||||
|
+ " total=" + result.optimalPlan().total()); |
||||||
|
} |
||||||
|
System.out.println(" warehouseQuotes=" + result.warehouseQuotes().size()); |
||||||
|
for (ChannelRecommendResult.WarehouseQuote q : result.warehouseQuotes()) { |
||||||
|
System.out.println(" warehouse=" + q.warehouseCode() |
||||||
|
+ " inventoryEnough=" + q.inventoryEnough() |
||||||
|
+ " insufficient=" + q.insufficientStockError()); |
||||||
|
for (ChannelRecommendResult.ServiceQuote s : q.services()) { |
||||||
|
System.out.println(" service=" + s.serviceCode() + " total=" + s.total()); |
||||||
|
for (ChannelRecommendResult.FeeItem f : s.fees()) { |
||||||
|
System.out.println(" " + f.bigFeeType() + "/" + f.feeType() |
||||||
|
+ " = " + f.fee()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// ================================================================ 商品列表
|
||||||
|
|
||||||
|
/** 产品列表:通过 createOrUpdate 的查重路径顺带验证(只读部分)。 */ |
||||||
|
@Test |
||||||
|
void probeProductLookup() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.sku"); |
||||||
|
System.out.println("\n================ xincang / api.productlist ================"); |
||||||
|
System.out.println(" [说明] 产品列表接口只在建档查重时调用,这里直接查一次核对字段:"); |
||||||
|
System.out.println(" sku=" + XincangProbeSupport.SKU |
||||||
|
+ ",请对照下方接口返回的 rst.data[].state(0 临时 / 1 正式)"); |
||||||
|
System.out.println(" [提示] 走 api.add_product 会真实建档,请用 XincangWriteProbeTest。"); |
||||||
|
System.out.println(" endpoint=" + XincangConstants.PATH_PRODUCT_LIST); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,341 @@ |
|||||||
|
package common.ecommerce.xincang.probe; |
||||||
|
|
||||||
|
import common.ecommerce.shared.model.Platform; |
||||||
|
import common.ecommerce.shared.support.Money; |
||||||
|
import common.ecommerce.warehouse.capability.WarehouseProduct; |
||||||
|
import common.ecommerce.warehouse.capability.WarehouseProductCapable; |
||||||
|
import common.ecommerce.warehouse.enums.LabelMode; |
||||||
|
import common.ecommerce.warehouse.model.InboundCommand; |
||||||
|
import common.ecommerce.warehouse.model.InboundLine; |
||||||
|
import common.ecommerce.warehouse.model.InboundOrder; |
||||||
|
import common.ecommerce.warehouse.model.InboundReceipt; |
||||||
|
import common.ecommerce.warehouse.model.OutboundCommand; |
||||||
|
import common.ecommerce.warehouse.model.OutboundLine; |
||||||
|
import common.ecommerce.warehouse.model.OutboundOrder; |
||||||
|
import common.ecommerce.warehouse.model.OutboundReceipt; |
||||||
|
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.enums.TransferType; |
||||||
|
import common.ecommerce.xincang.adapter.XincangAdapter; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.junit.jupiter.api.condition.EnabledIfSystemProperty; |
||||||
|
|
||||||
|
import java.time.LocalDate; |
||||||
|
|
||||||
|
/** |
||||||
|
* 信仓写接口的联网探针:真实下单 / 建转运 / 建预报,用于核对报文。 |
||||||
|
* |
||||||
|
* <p><b>默认整类跳过</b>,需要两个开关同时打开:</p> |
||||||
|
* <pre> |
||||||
|
* -Dxincang.probe=true -Dxincang.probe.write=true |
||||||
|
* </pre> |
||||||
|
* |
||||||
|
* <p>运行示例:</p> |
||||||
|
* <pre> |
||||||
|
* mvn -pl warehouse-sdk-xincang -am -DfailIfNoTests=false \ |
||||||
|
* -Dxincang.probe=true -Dxincang.probe.write=true \ |
||||||
|
* -Dxincang.probe.appKey=... -Dxincang.probe.appSecret=... \ |
||||||
|
* -Dxincang.probe.sku=... -Dxincang.probe.postcode=... \ |
||||||
|
* -Dtest=XincangWriteProbeTest test |
||||||
|
* </pre> |
||||||
|
* |
||||||
|
* <p><b>注意:会在仓方测试环境留下真实数据。</b>能自清理的链路(订单、转运)会尽量删掉; |
||||||
|
* 商品建档与预报没有删除接口,跑完需要人工清理。所有单号都带时间戳后缀, |
||||||
|
* 重跑不会撞唯一约束。</p> |
||||||
|
*/ |
||||||
|
@EnabledIfSystemProperty(named = XincangProbeSupport.PROBE_WRITE, matches = "true") |
||||||
|
class XincangWriteProbeTest { |
||||||
|
|
||||||
|
// ================================================================ 商品
|
||||||
|
|
||||||
|
/** |
||||||
|
* 商品建档 / 更新:走 add_product 或 update_product(先查临时产品决定)。 |
||||||
|
* |
||||||
|
* <p>需要 {@code -Dxincang.probe.sku};金额按 1.00 USD 下发, |
||||||
|
* 因为信仓把 amount 列为必填且我们不再兜底 0。</p> |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
void probeProductUpsert() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.sku"); |
||||||
|
System.out.println("\n================ xincang / api.add_product | api.update_product ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
|
||||||
|
WarehouseProduct product = WarehouseProduct.builder() |
||||||
|
.omsSku(XincangProbeSupport.SKU) |
||||||
|
.name("探针商品") |
||||||
|
.nameEn("Probe Product") |
||||||
|
.barcode("PROBE-" + XincangProbeSupport.uniqueSuffix()) |
||||||
|
.packingType(0) |
||||||
|
.lengthCm(30) |
||||||
|
.widthCm(20) |
||||||
|
.heightCm(10) |
||||||
|
.weightGrams(500) |
||||||
|
.declaredValue(Money.of("1.00", "USD")) |
||||||
|
.hsCode("9403600000") |
||||||
|
.countryOfOrigin("US") |
||||||
|
.build(); |
||||||
|
|
||||||
|
WarehouseProductCapable.ProductResult result = XincangProbeSupport.step( |
||||||
|
"createOrUpdate sku=" + XincangProbeSupport.SKU, |
||||||
|
() -> adapter.createOrUpdate(XincangProbeSupport.ctx(), product)); |
||||||
|
if (result != null) { |
||||||
|
System.out.println(" providerSku=" + result.providerSku() |
||||||
|
+ " status=" + result.status() |
||||||
|
+ " rawStatus=" + result.rawStatus()); |
||||||
|
System.out.println(" [注意] 没有删除产品接口,跑完需人工清理或复用该 SKU。"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// ================================================================ 出库
|
||||||
|
|
||||||
|
/** |
||||||
|
* 出库闭环:下单 → 详情回读 → 删除。 |
||||||
|
* |
||||||
|
* <p>需要 sku + postcode;承运商从目录接口自动取(或 {@code -Dxincang.probe.carrier})。</p> |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
void probeOutboundRoundTrip() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.sku"); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.postcode"); |
||||||
|
System.out.println("\n================ xincang / api.add_order_multiple → get_order → delete_order ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
String warehouseCode = XincangProbeSupport.warehouseCode(adapter); |
||||||
|
String carrier = XincangProbeSupport.carrier(adapter); |
||||||
|
if (warehouseCode == null || carrier == null) { |
||||||
|
System.out.println(" [skip] 缺少仓代码或承运商,跳过"); |
||||||
|
return; |
||||||
|
} |
||||||
|
String requestNo = "PROBE-" + XincangProbeSupport.uniqueSuffix(); |
||||||
|
|
||||||
|
OutboundCommand command = OutboundCommand.builder() |
||||||
|
.outboundRequestNo(requestNo) |
||||||
|
.orderRef(requestNo) |
||||||
|
.labelMode(LabelMode.WAREHOUSE_LABEL) |
||||||
|
.salesPlatform(Platform.CUSTOM) |
||||||
|
.carrierCode(carrier) |
||||||
|
.warehouseId(warehouseCode) |
||||||
|
.splitOrder(true) |
||||||
|
.shipTo(ShipTo.builder() |
||||||
|
.name("Probe Receiver") |
||||||
|
.phone("5550000000") |
||||||
|
.countryCode("US") |
||||||
|
.stateOrProvince("CA") |
||||||
|
.city("Fontana") |
||||||
|
.addressLine1("1 Probe Street") |
||||||
|
.postalCode(XincangProbeSupport.POSTCODE) |
||||||
|
.build()) |
||||||
|
.line(OutboundLine.builder() |
||||||
|
.lineNo("1") |
||||||
|
.omsSku(XincangProbeSupport.SKU) |
||||||
|
.quantity(XincangProbeSupport.qty()) |
||||||
|
.declareName("Probe Item") |
||||||
|
.build()) |
||||||
|
.build(); |
||||||
|
|
||||||
|
OutboundReceipt receipt = XincangProbeSupport.step("add_order_multiple ckh=" + requestNo, |
||||||
|
() -> adapter.create(XincangProbeSupport.ctx(warehouseCode), command)); |
||||||
|
if (receipt == null || receipt.providerOrderId() == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
System.out.println(" providerOrderId=" + receipt.providerOrderId()); |
||||||
|
|
||||||
|
OutboundOrder order = XincangProbeSupport.step("get_order 回读", |
||||||
|
() -> adapter.get(XincangProbeSupport.ctx(warehouseCode), |
||||||
|
OutboundRef.ofProviderOrderId(receipt.providerOrderId()))); |
||||||
|
if (order != null) { |
||||||
|
System.out.println(" status=" + order.status() + "(raw=" + order.rawStatus() + ")" |
||||||
|
+ " ref=" + order.orderRef() |
||||||
|
+ " lines=" + order.lines().size()); |
||||||
|
System.out.println(" checkCancel=" + XincangProbeSupport.step("checkCancel", |
||||||
|
() -> adapter.checkCancel(XincangProbeSupport.ctx(warehouseCode), |
||||||
|
OutboundRef.ofProviderOrderId(receipt.providerOrderId())))); |
||||||
|
} |
||||||
|
|
||||||
|
XincangProbeSupport.step("delete_order 自清理", |
||||||
|
() -> adapter.cancel(XincangProbeSupport.ctx(warehouseCode), |
||||||
|
common.ecommerce.warehouse.model.CancelCommand.builder() |
||||||
|
.providerOrderId(receipt.providerOrderId()) |
||||||
|
.build())); |
||||||
|
} |
||||||
|
|
||||||
|
// ================================================================ 转运
|
||||||
|
|
||||||
|
/** |
||||||
|
* 转运闭环:建转运 → 详情回读 → 删除(仅待审核可删)。 |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
void probeTransferRoundTrip() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
System.out.println("\n================ xincang / fba.do_fba → fba_detail → fba.delete_fba ================"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
String warehouseCode = XincangProbeSupport.warehouseCode(adapter); |
||||||
|
if (warehouseCode == null) { |
||||||
|
System.out.println(" [skip] 缺少仓代码,跳过"); |
||||||
|
return; |
||||||
|
} |
||||||
|
String transferNo = "PROBE-" + XincangProbeSupport.uniqueSuffix(); |
||||||
|
String destWarehouse = XincangProbeSupport.opt("xincang.probe.destWarehouse", ""); |
||||||
|
|
||||||
|
TransferCommand command = TransferCommand.builder() |
||||||
|
.transferRequestNo(transferNo) |
||||||
|
.type(TransferType.OUTBOUND) |
||||||
|
.fromWarehouseCode(warehouseCode) |
||||||
|
.toWarehouseCode(destWarehouse.isEmpty() ? "PROBE-DEST" : destWarehouse) |
||||||
|
.po(transferNo) |
||||||
|
// 信仓 fba.do_fba 只用 pre_send_time,不用到仓日期;给同一天仅为满足模型约束
|
||||||
|
.estimateOutboundDate(LocalDate.now().plusDays(1)) |
||||||
|
.estimateInboundDate(LocalDate.now().plusDays(1)) |
||||||
|
.shipTo(ShipTo.builder().name("Probe").countryCode("US").stateOrProvince("CA") |
||||||
|
.city("Fontana").addressLine1("1 Probe St").postalCode("91752").build()) |
||||||
|
.deliveryMode(XincangProbeSupport.opt("xincang.probe.deliveryMode", "")) |
||||||
|
.deliveryWay(XincangProbeSupport.opt("xincang.probe.deliveryWay", "")) |
||||||
|
.orderType(XincangProbeSupport.opt("xincang.probe.orderType", "")) |
||||||
|
.palletRequired(Boolean.FALSE) |
||||||
|
.line(XincangProbeSupport.SKU.isEmpty() ? "PROBE-SKU" : XincangProbeSupport.SKU, |
||||||
|
XincangProbeSupport.qty()) |
||||||
|
.build(); |
||||||
|
|
||||||
|
TransferOrder created = XincangProbeSupport.step("do_fba fba_no=" + transferNo, |
||||||
|
() -> adapter.create(XincangProbeSupport.ctx(warehouseCode), command)); |
||||||
|
if (created == null || created.providerTransferNo() == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
String providerNo = created.providerTransferNo(); |
||||||
|
System.out.println(" providerTransferNo=" + providerNo + " status=" + created.status()); |
||||||
|
|
||||||
|
XincangProbeSupport.step("fba_detail 回读", |
||||||
|
() -> adapter.getTransfer(XincangProbeSupport.ctx(warehouseCode), providerNo)); |
||||||
|
|
||||||
|
XincangProbeSupport.step("fba.delete_fba 自清理", |
||||||
|
() -> adapter.deleteTransfer(XincangProbeSupport.ctx(warehouseCode), providerNo)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 转运审核:建转运 → 审核。 |
||||||
|
* |
||||||
|
* <p><b>审核之后不能删除</b>,会在测试环境留下数据,默认不跑; |
||||||
|
* 需要显式加 {@code -Dxincang.probe.transferApprove=true}。</p> |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
void probeTransferApprove() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.transferApprove"); |
||||||
|
System.out.println("\n================ xincang / fba.do_approve ================"); |
||||||
|
System.out.println(" [注意] 审核后的转运单无法删除,会留下数据。"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
String warehouseCode = XincangProbeSupport.warehouseCode(adapter); |
||||||
|
if (warehouseCode == null) { |
||||||
|
System.out.println(" [skip] 缺少仓代码,跳过"); |
||||||
|
return; |
||||||
|
} |
||||||
|
String transferNo = "PROBE-APPROVE-" + XincangProbeSupport.uniqueSuffix(); |
||||||
|
TransferCommand command = TransferCommand.builder() |
||||||
|
.transferRequestNo(transferNo) |
||||||
|
.type(TransferType.OUTBOUND) |
||||||
|
.fromWarehouseCode(warehouseCode) |
||||||
|
.toWarehouseCode(XincangProbeSupport.opt("xincang.probe.destWarehouse", "PROBE-DEST")) |
||||||
|
.po(transferNo) |
||||||
|
.estimateOutboundDate(LocalDate.now().plusDays(1)) |
||||||
|
.estimateInboundDate(LocalDate.now().plusDays(1)) |
||||||
|
.shipTo(ShipTo.builder().name("Probe").countryCode("US").stateOrProvince("CA") |
||||||
|
.city("Fontana").addressLine1("1 Probe St").postalCode("91752").build()) |
||||||
|
.deliveryMode(XincangProbeSupport.opt("xincang.probe.deliveryMode", "")) |
||||||
|
.deliveryWay(XincangProbeSupport.opt("xincang.probe.deliveryWay", "")) |
||||||
|
.orderType(XincangProbeSupport.opt("xincang.probe.orderType", "")) |
||||||
|
.palletRequired(Boolean.FALSE) |
||||||
|
.line(XincangProbeSupport.SKU.isEmpty() ? "PROBE-SKU" : XincangProbeSupport.SKU, |
||||||
|
XincangProbeSupport.qty()) |
||||||
|
.build(); |
||||||
|
|
||||||
|
TransferOrder created = XincangProbeSupport.step("do_fba", |
||||||
|
() -> adapter.create(XincangProbeSupport.ctx(warehouseCode), command)); |
||||||
|
if (created == null || created.providerTransferNo() == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
XincangProbeSupport.step("do_approve " + created.providerTransferNo(), |
||||||
|
() -> adapter.approve(XincangProbeSupport.ctx(warehouseCode), |
||||||
|
created.providerTransferNo())); |
||||||
|
} |
||||||
|
|
||||||
|
// ================================================================ 预报
|
||||||
|
|
||||||
|
/** |
||||||
|
* 预报闭环:新增 → 完善资料 → 提交 → 详情回读。 |
||||||
|
* |
||||||
|
* <p><b>没有删除接口</b>,跑完会在测试环境留下预报单。</p> |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
void probeForecastRoundTrip() { |
||||||
|
XincangProbeSupport.requireCredentials(); |
||||||
|
XincangProbeSupport.requireProperty("xincang.probe.sku"); |
||||||
|
System.out.println("\n================ xincang / forecast.do_forecast → improve → done → detail ================"); |
||||||
|
System.out.println(" [注意] 预报没有删除接口,会留下数据。"); |
||||||
|
XincangAdapter adapter = XincangProbeSupport.adapter(); |
||||||
|
String warehouseCode = XincangProbeSupport.warehouseCode(adapter); |
||||||
|
if (warehouseCode == null) { |
||||||
|
System.out.println(" [skip] 缺少仓代码,跳过"); |
||||||
|
return; |
||||||
|
} |
||||||
|
String suffix = XincangProbeSupport.uniqueSuffix(); |
||||||
|
String requestNo = "PROBE-FC-" + suffix; |
||||||
|
|
||||||
|
InboundCommand head = InboundCommand.builder() |
||||||
|
.inboundRequestNo(requestNo) |
||||||
|
.warehouseId(warehouseCode) |
||||||
|
.shipmentType(XincangProbeSupport.opt("xincang.probe.shipmentType", "2")) |
||||||
|
.cabinetType(XincangProbeSupport.opt("xincang.probe.cabinetType", "1")) |
||||||
|
.containerNo("PROBE-CAB-" + suffix) |
||||||
|
.predictionShipDate(LocalDate.now().plusDays(1)) |
||||||
|
.estimateArriveDate(LocalDate.now().plusDays(30)) |
||||||
|
.deliveryRequirements(XincangProbeSupport.opt("xincang.probe.deliveryRequirements", "1")) |
||||||
|
.line(InboundLine.builder() |
||||||
|
.omsSku(XincangProbeSupport.SKU) |
||||||
|
.providerSku(XincangProbeSupport.SKU) |
||||||
|
.quantity(XincangProbeSupport.qty()) |
||||||
|
.build()) |
||||||
|
.build(); |
||||||
|
|
||||||
|
InboundReceipt receipt = XincangProbeSupport.step("do_forecast fba_no=" + requestNo, |
||||||
|
() -> adapter.create(XincangProbeSupport.ctx(warehouseCode), head)); |
||||||
|
if (receipt == null || receipt.providerInboundId() == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
String forecastNo = receipt.providerInboundId(); |
||||||
|
System.out.println(" forecast_no=" + forecastNo); |
||||||
|
|
||||||
|
InboundCommand improve = InboundCommand.builder() |
||||||
|
.inboundRequestNo(requestNo) |
||||||
|
.warehouseId(warehouseCode) |
||||||
|
.shipmentType(XincangProbeSupport.opt("xincang.probe.shipmentType", "2")) |
||||||
|
.cabinetType(XincangProbeSupport.opt("xincang.probe.cabinetType", "1")) |
||||||
|
.containerNo("PROBE-CAB-" + suffix) |
||||||
|
.predictionShipDate(LocalDate.now().plusDays(1)) |
||||||
|
.estimateArriveDate(LocalDate.now().plusDays(30)) |
||||||
|
.deliveryRequirements(XincangProbeSupport.opt("xincang.probe.deliveryRequirements", "1")) |
||||||
|
.referenceNo("REF-" + suffix) |
||||||
|
.otherNeed(XincangProbeSupport.opt("xincang.probe.otherNeed", "")) |
||||||
|
.line(InboundLine.builder() |
||||||
|
.omsSku(XincangProbeSupport.SKU) |
||||||
|
.providerSku(XincangProbeSupport.SKU) |
||||||
|
.quantity(XincangProbeSupport.qty()) |
||||||
|
.build()) |
||||||
|
.build(); |
||||||
|
|
||||||
|
XincangProbeSupport.step("do_improve_forecast", |
||||||
|
() -> adapter.improve(XincangProbeSupport.ctx(warehouseCode), forecastNo, improve)); |
||||||
|
XincangProbeSupport.step("done_forecast", |
||||||
|
() -> adapter.submit(XincangProbeSupport.ctx(warehouseCode), forecastNo)); |
||||||
|
|
||||||
|
InboundOrder detail = XincangProbeSupport.step("forecast_detail 回读", |
||||||
|
() -> adapter.get(XincangProbeSupport.ctx(warehouseCode), forecastNo)); |
||||||
|
if (detail != null) { |
||||||
|
System.out.println(" status=" + detail.status() + "(raw=" + detail.rawStatus() + ")" |
||||||
|
+ " boxCount=" + detail.boxCount() |
||||||
|
+ " lines=" + detail.lines().size()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue