|
|
|
|
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();
|
|
|
|
|
XincangProbeSupport.requireProperty("xincang.probe.sku");
|
|
|
|
|
XincangProbeSupport.requireProperty("xincang.probe.destWarehouse");
|
|
|
|
|
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)
|
|
|
|
|
.po(transferNo)
|
|
|
|
|
// 信仓只用 pre_send_time;到仓日期与收件地址它都不收,
|
|
|
|
|
// 这里不传,顺便验证模型已不再强制这两个字段
|
|
|
|
|
.estimateOutboundDate(LocalDate.now().plusDays(1))
|
|
|
|
|
.deliveryMode(XincangProbeSupport.opt("xincang.probe.deliveryMode", ""))
|
|
|
|
|
.deliveryWay(XincangProbeSupport.opt("xincang.probe.deliveryWay", ""))
|
|
|
|
|
.orderType(XincangProbeSupport.opt("xincang.probe.orderType", ""))
|
|
|
|
|
.palletRequired(Boolean.FALSE)
|
|
|
|
|
.line(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");
|
|
|
|
|
XincangProbeSupport.requireProperty("xincang.probe.sku");
|
|
|
|
|
XincangProbeSupport.requireProperty("xincang.probe.destWarehouse");
|
|
|
|
|
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", ""))
|
|
|
|
|
.po(transferNo)
|
|
|
|
|
.estimateOutboundDate(LocalDate.now().plusDays(1))
|
|
|
|
|
.deliveryMode(XincangProbeSupport.opt("xincang.probe.deliveryMode", ""))
|
|
|
|
|
.deliveryWay(XincangProbeSupport.opt("xincang.probe.deliveryWay", ""))
|
|
|
|
|
.orderType(XincangProbeSupport.opt("xincang.probe.orderType", ""))
|
|
|
|
|
.palletRequired(Boolean.FALSE)
|
|
|
|
|
.line(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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|