32 changed files with 4241 additions and 21 deletions
@ -0,0 +1,186 @@
@@ -0,0 +1,186 @@
|
||||
package common.ecommerce.edayun.adapter; |
||||
|
||||
import common.ecommerce.edayun.dto.EdayunFeeEstimateDtos; |
||||
import common.ecommerce.shared.support.Money; |
||||
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||
import common.ecommerce.warehouse.model.FeeEstimateQuery; |
||||
import common.ecommerce.warehouse.model.FeeEstimateResult; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 易达云费用试算映射({@code POST /webApi/estimate/v1/trial})。 |
||||
* |
||||
* <p>统一模型只有「按包裹」这一种口径,对应易达云的 |
||||
* {@code manualInputSwitch = true} + {@code packageDetails}。</p> |
||||
* |
||||
* <p><b>三处本地定值</b>(标准模型没有对应字段,见 docs-warehouse/edayun/TODO.md):</p> |
||||
* <ul> |
||||
* <li>{@code estimatedGoodsType} 固定 {@code GENERAL_CARGO}——真机实测缺了会报 |
||||
* 「手动输入时,货物类型[estimatedGoodsType]不能为空!」</li> |
||||
* <li>{@code manualInputSwitch} 固定 true——按 SKU 预估需要 SKU 清单,标准模型没有</li> |
||||
* <li>虚拟包裹、{@code logisticsProductIds} 之外的过滤条件不下发</li> |
||||
* </ul> |
||||
*/ |
||||
public final class EdayunFeeEstimateMapper { |
||||
|
||||
/** 货物类型:普通货物(不带电)。标准模型无此字段。 */ |
||||
static final String DEFAULT_GOODS_TYPE = "GENERAL_CARGO"; |
||||
|
||||
/** 币种兜底;实测都会返回 currencyCode。 */ |
||||
private static final String DEFAULT_CURRENCY = "USD"; |
||||
|
||||
private EdayunFeeEstimateMapper() { |
||||
} |
||||
|
||||
/** |
||||
* 统一试算条件 → 易达云请求。 |
||||
* |
||||
* @param providerWarehouseId 仓方仓 id;数字进 {@code warehouseId},非数字进 |
||||
* {@code warehouseCode}(文档说两者必填一个) |
||||
* @throws IllegalArgumentException 既没有仓 id 也没有仓编码,或没有包裹尺寸 |
||||
*/ |
||||
public static EdayunFeeEstimateDtos.TrialRequest toRequest(FeeEstimateQuery query, |
||||
String providerWarehouseId) { |
||||
EdayunFeeEstimateDtos.TrialRequest req = new EdayunFeeEstimateDtos.TrialRequest(); |
||||
applyWarehouse(req, providerWarehouseId, query.warehouseCodes()); |
||||
|
||||
req.endCountryCode = query.receiveCountry(); |
||||
req.city = query.receiveCity(); |
||||
// 必填;FeeEstimateQuery 构造期已校验非空
|
||||
req.endZipcode = query.receivePostal(); |
||||
|
||||
req.manualInputSwitch = Boolean.TRUE; |
||||
req.estimatedGoodsType = DEFAULT_GOODS_TYPE; |
||||
|
||||
EdayunFeeEstimateDtos.PackageItem pkg = new EdayunFeeEstimateDtos.PackageItem(); |
||||
pkg.length = toDouble(query.lengthCm()); |
||||
pkg.width = toDouble(query.widthCm()); |
||||
pkg.height = toDouble(query.heightCm()); |
||||
// 我们的模型是克,易达云请求体也是克(响应才是 kg)
|
||||
pkg.weight = toDouble(query.weightGrams()); |
||||
req.packageDetails = Collections.singletonList(pkg); |
||||
|
||||
Long productId = logisticsProductIdOf(query); |
||||
req.logisticsProductIds = productId == null ? null |
||||
: Collections.singletonList(productId); |
||||
return req; |
||||
} |
||||
|
||||
/** |
||||
* 仓:{@code warehouseId} 与 {@code warehouseCode} 必填一个。 |
||||
* |
||||
* <p>取 {@code providerWarehouseId};缺省时退回调用方给的 {@code warehouseCodes} 首个。</p> |
||||
*/ |
||||
private static void applyWarehouse(EdayunFeeEstimateDtos.TrialRequest req, |
||||
String providerWarehouseId, List<String> warehouseCodes) { |
||||
String raw = hasText(providerWarehouseId) ? providerWarehouseId.trim() |
||||
: firstOf(warehouseCodes); |
||||
if (!hasText(raw)) { |
||||
throw new IllegalArgumentException( |
||||
"edayun fee estimate requires a warehouse: pass providerWarehouseId" |
||||
+ " (numeric warehouse id or warehouse code)"); |
||||
} |
||||
Long id = numericOrNull(raw); |
||||
if (id != null) { |
||||
req.warehouseId = id; |
||||
} else { |
||||
req.warehouseCode = raw; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 指定物流产品 id。 |
||||
* |
||||
* <p>统一模型的 {@code logisticsServiceCode} / {@code logisticsProductCode} 是仓方口径的字符串; |
||||
* 易达云要的是数字 id。非数字视为「不指定渠道」,让仓方返回全部报价—— |
||||
* 传一个非数字进去只会让仓方静默查不到。</p> |
||||
*/ |
||||
static Long logisticsProductIdOf(FeeEstimateQuery query) { |
||||
Long id = numericOrNull(query.logisticsProductCode()); |
||||
return id != null ? id : numericOrNull(query.logisticsServiceCode()); |
||||
} |
||||
|
||||
/** |
||||
* 试算结果 → 统一结果。 |
||||
* |
||||
* <p>只取 {@code successItems}:{@code failItems} 是「不支持派送」这类无报价渠道, |
||||
* 塞进 {@link FeeEstimateResult.CarrierQuote} 只会得到一堆空金额的假渠道。 |
||||
* 全部失败时返回 {@code carriers()} 为空的仓结果——按能力接口约定, |
||||
* 这表示「该仓无法承运该包裹」,具体原因({@code errorInfo})只在原报文里。</p> |
||||
*/ |
||||
public static FeeEstimateResult toResult(EdayunFeeEstimateDtos.TrialResponse response, |
||||
String warehouseCode) { |
||||
FeeEstimateResult.Builder builder = FeeEstimateResult.builder() |
||||
.sourceProvider(WarehouseProvider.EDAYUN) |
||||
.shipOrgWarehouseCode(warehouseCode); |
||||
EdayunFeeEstimateDtos.TrialData data = response == null ? null : response.data; |
||||
if (data != null && data.successItems != null) { |
||||
for (EdayunFeeEstimateDtos.EstimateItem item : data.successItems) { |
||||
if (item != null) { |
||||
builder.carrier(toQuote(item)); |
||||
} |
||||
} |
||||
} |
||||
return builder.build(); |
||||
} |
||||
|
||||
private static FeeEstimateResult.CarrierQuote toQuote(EdayunFeeEstimateDtos.EstimateItem item) { |
||||
String currency = hasText(item.currencyCode) ? item.currencyCode.trim() : DEFAULT_CURRENCY; |
||||
FeeEstimateResult.CarrierQuote.Builder quote = FeeEstimateResult.CarrierQuote.builder() |
||||
// 易达云只给物流产品(渠道)名称,没有独立的承运商字段
|
||||
.carrier(item.logisticProductName) |
||||
.logisticsServiceCode(item.logisticProductId) |
||||
.totalRate(item.estimatedPrice == null ? null |
||||
: Money.of(BigDecimal.valueOf(item.estimatedPrice), currency)); |
||||
if (item.detailList != null) { |
||||
for (EdayunFeeEstimateDtos.DetailItem detail : item.detailList) { |
||||
if (detail == null) { |
||||
continue; |
||||
} |
||||
quote.costItem(FeeEstimateResult.CarrierQuote.CostItem.builder() |
||||
.costName(detail.billingItemName) |
||||
.estimatedCost(detail.estimatedPrice == null ? null |
||||
: Money.of(BigDecimal.valueOf(detail.estimatedPrice), |
||||
hasText(detail.currencyCode) ? detail.currencyCode.trim() |
||||
: currency)) |
||||
.build()); |
||||
} |
||||
} |
||||
return quote.build(); |
||||
} |
||||
|
||||
private static Double toDouble(BigDecimal v) { |
||||
return v == null ? null : v.doubleValue(); |
||||
} |
||||
|
||||
private static Long numericOrNull(String v) { |
||||
if (!hasText(v)) { |
||||
return null; |
||||
} |
||||
try { |
||||
return Long.valueOf(v.trim()); |
||||
} catch (NumberFormatException e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
private static String firstOf(List<String> values) { |
||||
if (values == null || values.isEmpty()) { |
||||
return null; |
||||
} |
||||
for (String v : values) { |
||||
if (hasText(v)) { |
||||
return v.trim(); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
private static boolean hasText(String v) { |
||||
return v != null && !v.trim().isEmpty(); |
||||
} |
||||
} |
||||
@ -0,0 +1,201 @@
@@ -0,0 +1,201 @@
|
||||
package common.ecommerce.edayun.adapter; |
||||
|
||||
import common.ecommerce.edayun.dto.EdayunInboundDtos; |
||||
import common.ecommerce.warehouse.model.InboundCarton; |
||||
import common.ecommerce.warehouse.model.InboundCommand; |
||||
|
||||
import java.time.LocalDate; |
||||
import java.time.ZoneOffset; |
||||
import java.util.ArrayList; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 易达云自发入库单映射 |
||||
* ({@code POST /webApi/entryInfo/v1/saveEntrySpontaneousOrder})。 |
||||
* |
||||
* <p>一个接口吃下新增 / 更新 / 发布,靠 {@code saveType} 区分:</p> |
||||
* <ul> |
||||
* <li>创建 → {@link #SAVE_PUBLISH}(2,保存并发布)</li> |
||||
* <li>编辑 → {@link #SAVE_UPDATE}(1,更新),需要 {@code entryCode}</li> |
||||
* </ul> |
||||
* |
||||
* <p><b>只下发统一模型有的三组</b>:{@code basicInfo} / {@code logisticsInfo} / |
||||
* {@code cargoInfos}。头程拖车、报关、清关、海外拖车在标准模型里没有对应字段, |
||||
* 不下发——这些服务范围本来就由仓方按物流产品判定,缺字段时仓方会报错。</p> |
||||
*/ |
||||
public final class EdayunInboundMapper { |
||||
|
||||
/** 保存类型:新增。 */ |
||||
static final int SAVE_NEW = 0; |
||||
/** 保存类型:更新。 */ |
||||
static final int SAVE_UPDATE = 1; |
||||
/** 保存类型:保存并发布。 */ |
||||
static final int SAVE_PUBLISH = 2; |
||||
|
||||
/** 客户单号长度上限。 */ |
||||
static final int MAX_CUSTOMER_ORDER_NO = 30; |
||||
|
||||
private static final double GRAMS_PER_KG = 1000.0; |
||||
|
||||
private EdayunInboundMapper() { |
||||
} |
||||
|
||||
/** |
||||
* 统一命令 → 保存入库单请求。 |
||||
* |
||||
* @param saveType {@link #SAVE_PUBLISH} / {@link #SAVE_UPDATE} |
||||
* @param entryCode 仓侧入库单号;仅更新时必填 |
||||
* @param warehouseId 仓方仓标识;数字进 {@code shelfWarehouseId},非数字进 |
||||
* {@code shelfWarehouseCode} |
||||
*/ |
||||
public static EdayunInboundDtos.SaveEntryRequest toRequest(InboundCommand cmd, int saveType, |
||||
String entryCode, String warehouseId) { |
||||
EdayunInboundDtos.SaveEntryRequest req = new EdayunInboundDtos.SaveEntryRequest(); |
||||
req.saveType = saveType; |
||||
|
||||
String customerOrderNo = cmd.inboundRequestNo(); |
||||
if (customerOrderNo.length() > MAX_CUSTOMER_ORDER_NO) { |
||||
throw new IllegalArgumentException( |
||||
"edayun customerOrderNo must not exceed " + MAX_CUSTOMER_ORDER_NO |
||||
+ " chars, got " + customerOrderNo.length() + ": " + customerOrderNo); |
||||
} |
||||
req.customerOrderNo = customerOrderNo; |
||||
|
||||
if (saveType == SAVE_UPDATE) { |
||||
if (!hasText(entryCode)) { |
||||
throw new IllegalArgumentException( |
||||
"edayun updating an inbound order requires entryCode (provider entry no)"); |
||||
} |
||||
req.entryCode = entryCode.trim(); |
||||
} |
||||
|
||||
req.basicInfo = toBasicInfo(cmd, warehouseId); |
||||
req.logisticsInfo = toLogisticsInfo(cmd); |
||||
req.cargoInfos = toCargoInfos(cmd.cartons()); |
||||
return req; |
||||
} |
||||
|
||||
/** |
||||
* 基础信息:仓 id 或编码二选一。 |
||||
* |
||||
* <p>易达云的 {@code shelfWarehouseId} 是数字、{@code shelfWarehouseCode} 是编码(如 |
||||
* {@code USLA})。配成 {@code EDY-WH-1} 这类 OMS 编码时走 code 分支。</p> |
||||
*/ |
||||
private static EdayunInboundDtos.BasicInfo toBasicInfo(InboundCommand cmd, String warehouseId) { |
||||
EdayunInboundDtos.BasicInfo info = new EdayunInboundDtos.BasicInfo(); |
||||
String raw = hasText(cmd.warehouseId()) ? cmd.warehouseId().trim() |
||||
: (hasText(warehouseId) ? warehouseId.trim() : null); |
||||
Long id = numericOrNull(raw); |
||||
if (id != null) { |
||||
info.shelfWarehouseId = id; |
||||
} else if (raw != null) { |
||||
info.shelfWarehouseCode = raw; |
||||
} |
||||
|
||||
info.intShippingMethod = cmd.transportType(); |
||||
info.cabinetType = intOrNull(cmd.cabinetType()); |
||||
// shippingProductId 是「查询入库物流产品」接口给的 id,标准模型没有对应字段
|
||||
return info; |
||||
} |
||||
|
||||
/** |
||||
* 物流信息:只填标准模型有的。 |
||||
* |
||||
* <p>{@code waybill}(快递单号)与 {@code shipCompany}(承运商名)标准模型没有, |
||||
* <b>不下发</b>——快递类发布时仓方会报缺字段,由宿主补。不要把柜号之类的 |
||||
* {@code transportOrderNos} 塞进 {@code waybill},那是另一回事。</p> |
||||
*/ |
||||
private static EdayunInboundDtos.LogisticsInfo toLogisticsInfo(InboundCommand cmd) { |
||||
EdayunInboundDtos.LogisticsInfo info = new EdayunInboundDtos.LogisticsInfo(); |
||||
info.cabinetCode = blankToNull(cmd.containerNo()); |
||||
// 预计离港 ≈ 预计发运日期;预计到港 ≈ 预计到仓日期(口径待仓方确认)
|
||||
info.estimatedDepartureTime = millisOf(cmd.predictionShipDate()); |
||||
info.estimatedArrivalDate = millisOf(cmd.estimateArriveDate()); |
||||
return info; |
||||
} |
||||
|
||||
/** |
||||
* 装箱 → 箱货信息。 |
||||
* |
||||
* <p>统一模型一行是「一个 SKU 在一箱里的数量」,一箱多 SKU 时同一 {@code sid} |
||||
* 会拆成多行。这里按 {@code sid}(缺失时用箱码)归并成「一箱 = 一个 cargoInfo + |
||||
* 多条 boxSkuInfoList」,与文档结构对齐。</p> |
||||
* |
||||
* <p>{@code cargoInfos} 是必填的,而箱规只有 {@code InboundCarton} 才有—— |
||||
* 调用方只给了 SKU 明细时<b>本地拒绝</b>,不凭空编一个箱子。</p> |
||||
*/ |
||||
static List<EdayunInboundDtos.CargoInfo> toCargoInfos(List<InboundCarton> cartons) { |
||||
if (cartons == null || cartons.isEmpty()) { |
||||
throw new IllegalArgumentException( |
||||
"edayun spontaneous entry requires carton info (cartonNo + box size/weight);" |
||||
+ " product lines alone cannot fill cargoInfos"); |
||||
} |
||||
Map<String, EdayunInboundDtos.CargoInfo> byBox = |
||||
new LinkedHashMap<String, EdayunInboundDtos.CargoInfo>(); |
||||
for (InboundCarton carton : cartons) { |
||||
if (carton == null) { |
||||
continue; |
||||
} |
||||
String key = hasText(carton.sid()) ? carton.sid().trim() : carton.cartonNo(); |
||||
EdayunInboundDtos.CargoInfo box = byBox.get(key); |
||||
if (box == null) { |
||||
box = new EdayunInboundDtos.CargoInfo(); |
||||
box.outsideBoxCode = carton.cartonNo(); |
||||
box.boxLength = positiveOrNull(carton.lengthCm()); |
||||
box.boxWidth = positiveOrNull(carton.widthCm()); |
||||
box.boxHeight = positiveOrNull(carton.heightCm()); |
||||
// 我们的模型是克,易达云这组字段按 kg(与创建产品口径一致)
|
||||
box.weight = positiveOrNull(carton.weightGrams() / GRAMS_PER_KG); |
||||
box.boxSkuInfoList = new ArrayList<EdayunInboundDtos.BoxSku>(); |
||||
byBox.put(key, box); |
||||
} |
||||
EdayunInboundDtos.BoxSku sku = new EdayunInboundDtos.BoxSku(); |
||||
sku.skuCode = carton.providerSku(); |
||||
sku.skuForecastQuantity = carton.quantity(); |
||||
box.boxSkuInfoList.add(sku); |
||||
} |
||||
return new ArrayList<EdayunInboundDtos.CargoInfo>(byBox.values()); |
||||
} |
||||
|
||||
/** 本地日期 → 毫秒时间戳(按 UTC 起算,易达云时间戳不带时区)。 */ |
||||
static Long millisOf(LocalDate date) { |
||||
return date == null ? null : date.atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli(); |
||||
} |
||||
|
||||
static Long numericOrNull(String v) { |
||||
if (!hasText(v)) { |
||||
return null; |
||||
} |
||||
try { |
||||
return Long.valueOf(v.trim()); |
||||
} catch (NumberFormatException e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** 字符串码 → 数字;非数字视为未给。 */ |
||||
static Integer intOrNull(String v) { |
||||
if (!hasText(v)) { |
||||
return null; |
||||
} |
||||
try { |
||||
return Integer.valueOf(v.trim()); |
||||
} catch (NumberFormatException e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
private static Double positiveOrNull(double v) { |
||||
return v > 0 ? v : null; |
||||
} |
||||
|
||||
private static String blankToNull(String v) { |
||||
return hasText(v) ? v.trim() : null; |
||||
} |
||||
|
||||
private static boolean hasText(String v) { |
||||
return v != null && !v.trim().isEmpty(); |
||||
} |
||||
} |
||||
@ -0,0 +1,170 @@
@@ -0,0 +1,170 @@
|
||||
package common.ecommerce.edayun.adapter; |
||||
|
||||
import common.ecommerce.edayun.dto.EdayunInboundQueryDtos; |
||||
import common.ecommerce.edayun.enums.EdayunInboundSkuStatus; |
||||
import common.ecommerce.shared.support.Page; |
||||
import common.ecommerce.warehouse.enums.InboundStatus; |
||||
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||
import common.ecommerce.warehouse.model.InboundOrder; |
||||
import common.ecommerce.warehouse.model.InboundOrderLine; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 易达云入库明细查询映射 |
||||
* ({@code POST /webApi/entryInfo/v1/selectEntrySkuGoodsDetail})。 |
||||
* |
||||
* <p>一行 = 一个 SKU 的预报 / 清点 / 上架数量。这是目前唯一能拿到入库进度的接口。</p> |
||||
* |
||||
* <p><b>这个接口只回 SKU 级数据</b>:没有仓、没有时间、没有箱明细、没有单头状态。 |
||||
* 所以 {@link InboundOrder} 里这些字段是空的,单头状态由 SKU 状态<b>汇总</b>得到。</p> |
||||
*/ |
||||
public final class EdayunInboundQueryMapper { |
||||
|
||||
/** 单页上限。 */ |
||||
static final int MAX_PAGE_SIZE = 1000; |
||||
/** 默认页大小(文档写「默认 200 条」)。 */ |
||||
static final int DEFAULT_PAGE_SIZE = 200; |
||||
|
||||
private EdayunInboundQueryMapper() { |
||||
} |
||||
|
||||
/** 查询请求。 */ |
||||
public static EdayunInboundQueryDtos.SelectEntrySkuRequest toRequest(String entryCode, int pageNum) { |
||||
if (!hasText(entryCode)) { |
||||
throw new IllegalArgumentException( |
||||
"edayun inbound query requires entryCode (provider REV no);" |
||||
+ " the endpoint cannot look up by customerOrderNo"); |
||||
} |
||||
EdayunInboundQueryDtos.SelectEntrySkuRequest req = |
||||
new EdayunInboundQueryDtos.SelectEntrySkuRequest(); |
||||
req.entryCode = entryCode.trim(); |
||||
req.pageNum = pageNum; |
||||
req.pageSize = DEFAULT_PAGE_SIZE; |
||||
return req; |
||||
} |
||||
|
||||
/** |
||||
* 一页 SKU 明细 → 入库单。 |
||||
* |
||||
* <p>仓库编码用 OMS 配置的仓(接口不回仓);状态取<b>最靠前</b>的那条—— |
||||
* 还有 SKU 没上架,整单就不算完成。</p> |
||||
* |
||||
* @param allRows 已翻页合并的全部行 |
||||
*/ |
||||
public static InboundOrder toOrder(String entryCode, List<EdayunInboundQueryDtos.EntrySkuRow> allRows, |
||||
String warehouseCode) { |
||||
InboundOrder.Builder builder = InboundOrder.builder() |
||||
.inboundRequestNo(entryCode) |
||||
.providerInboundId(entryCode) |
||||
.warehouseCode(warehouseCode) |
||||
.sourceProvider(WarehouseProvider.EDAYUN) |
||||
.status(headStatusOf(allRows)) |
||||
.rawStatus(rawStatusOf(allRows)) |
||||
.inventoryType(0); |
||||
|
||||
int planned = 0; |
||||
int received = 0; |
||||
List<InboundOrderLine> lines = new ArrayList<InboundOrderLine>(); |
||||
int boxes = 0; |
||||
for (EdayunInboundQueryDtos.EntrySkuRow row : allRows) { |
||||
if (row == null) { |
||||
continue; |
||||
} |
||||
int forecast = intOf(row.forecastQuantity); |
||||
int shelves = intOf(row.shelvesQuantity); |
||||
planned += forecast; |
||||
received += shelves; |
||||
boxes += 1; |
||||
// 没有 SKU 的行无法落库,跳过比整单失败合适
|
||||
if (!hasText(row.skuCode)) { |
||||
continue; |
||||
} |
||||
lines.add(InboundOrderLine.builder() |
||||
.providerSku(row.skuCode.trim()) |
||||
.plannedQuantity(forecast) |
||||
.packedQuantity(intOf(row.actualCheckedQuantity)) |
||||
.receivedQuantity(shelves) |
||||
.productName(blankToNull(row.skuName)) |
||||
.build()); |
||||
} |
||||
builder.plannedQuantity(planned) |
||||
.receivedQuantity(received) |
||||
.boxCount(boxes) |
||||
.lines(lines); |
||||
return builder.build(); |
||||
} |
||||
|
||||
/** |
||||
* 单头状态:任意一个 SKU 未完成 → 整单未完成。 |
||||
* |
||||
* <p>取「最靠前」的状态而不是第一条:顺序按 {@link InboundStatus#code()}, |
||||
* 数值小的更靠前。UNKNOWN(0) 会污染结果,所以有可识别状态时忽略它。</p> |
||||
*/ |
||||
static InboundStatus headStatusOf(List<EdayunInboundQueryDtos.EntrySkuRow> rows) { |
||||
InboundStatus earliest = null; |
||||
for (EdayunInboundQueryDtos.EntrySkuRow row : rows) { |
||||
if (row == null) { |
||||
continue; |
||||
} |
||||
InboundStatus s = EdayunInboundSkuStatus.toCore(row.status, row.statusName); |
||||
if (s == InboundStatus.UNKNOWN) { |
||||
continue; |
||||
} |
||||
if (earliest == null || s.code() < earliest.code()) { |
||||
earliest = s; |
||||
} |
||||
} |
||||
return earliest == null ? InboundStatus.UNKNOWN : earliest; |
||||
} |
||||
|
||||
/** 仓方原始状态;用于诊断(如「已上架」)。 */ |
||||
public static String rawStatusOf(List<EdayunInboundQueryDtos.EntrySkuRow> rows) { |
||||
for (EdayunInboundQueryDtos.EntrySkuRow row : rows) { |
||||
if (row != null && hasText(row.statusName)) { |
||||
return row.statusName.trim(); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** 一页结果 → 分页;游标是页码字符串,按是否满页判断有没有下一页。 */ |
||||
public static Page<InboundOrder> toPage(String entryCode, |
||||
List<EdayunInboundQueryDtos.EntrySkuRow> rows, |
||||
String warehouseCode, int pageNum, int pageSize) { |
||||
if (rows == null || rows.isEmpty()) { |
||||
return Page.empty(); |
||||
} |
||||
InboundOrder order = toOrder(entryCode, rows, warehouseCode); |
||||
boolean more = rows.size() >= pageSize; |
||||
return Page.of(Collections.singletonList(order), |
||||
more ? String.valueOf(pageNum + 1) : null); |
||||
} |
||||
|
||||
/** 游标是字符串化的页码。 */ |
||||
static int pageNumber(String cursor) { |
||||
if (!hasText(cursor)) { |
||||
return 1; |
||||
} |
||||
try { |
||||
int v = Integer.parseInt(cursor.trim()); |
||||
return v > 0 ? v : 1; |
||||
} catch (NumberFormatException e) { |
||||
return 1; |
||||
} |
||||
} |
||||
|
||||
private static int intOf(Integer v) { |
||||
return v == null ? 0 : v; |
||||
} |
||||
|
||||
private static String blankToNull(String v) { |
||||
return hasText(v) ? v.trim() : null; |
||||
} |
||||
|
||||
private static boolean hasText(String v) { |
||||
return v != null && !v.trim().isEmpty(); |
||||
} |
||||
} |
||||
@ -0,0 +1,158 @@
@@ -0,0 +1,158 @@
|
||||
package common.ecommerce.edayun.adapter; |
||||
|
||||
import common.ecommerce.edayun.dto.EdayunInventoryDtos; |
||||
import common.ecommerce.shared.support.Page; |
||||
import common.ecommerce.warehouse.model.InventoryQuery; |
||||
import common.ecommerce.warehouse.model.InventorySnapshot; |
||||
|
||||
import java.time.Instant; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 易达云库存查询映射({@code POST /webApi/userSkuStock/v1/queryInventory})。 |
||||
* |
||||
* <p>语义:一行 = 一个 SKU 在一个仓的库存汇总。默认只返回总库存大于 0 的数据。</p> |
||||
*/ |
||||
public final class EdayunInventoryMapper { |
||||
|
||||
/** 单页上限。 */ |
||||
static final int MAX_PAGE_SIZE = 500; |
||||
|
||||
/** SKU 过滤上限。 */ |
||||
static final int MAX_SKUS = 100; |
||||
|
||||
private EdayunInventoryMapper() { |
||||
} |
||||
|
||||
/** |
||||
* 统一查询条件 → 库存查询请求。 |
||||
* |
||||
* @param providerWarehouseId 仓方数字仓 id;为空时不下发 {@code warehouseIdList} |
||||
* (仓方按账号下全部仓返回) |
||||
*/ |
||||
public static EdayunInventoryDtos.QueryInventoryRequest toRequest( |
||||
InventoryQuery query, String providerWarehouseId, int pageNum) { |
||||
EdayunInventoryDtos.QueryInventoryRequest req = |
||||
new EdayunInventoryDtos.QueryInventoryRequest(); |
||||
req.pageNum = pageNum; |
||||
req.pageSize = pageSize(query.pageSize()); |
||||
|
||||
if (!query.providerSkus().isEmpty()) { |
||||
if (query.providerSkus().size() > MAX_SKUS) { |
||||
throw new IllegalArgumentException( |
||||
"edayun inventory query accepts at most " + MAX_SKUS + " sku codes, got " |
||||
+ query.providerSkus().size()); |
||||
} |
||||
req.skuCodeList = new ArrayList<String>(query.providerSkus()); |
||||
} |
||||
|
||||
Long warehouseId = warehouseIdOf(providerWarehouseId); |
||||
req.warehouseIdList = warehouseId == null ? null |
||||
: Collections.singletonList(warehouseId); |
||||
|
||||
// 统一模型是「包含零库存」,仓方是「只查大于 0」,方向相反
|
||||
if (query.includeZeroStock() != null) { |
||||
req.totalStockGreaterThanZero = !query.includeZeroStock(); |
||||
} |
||||
return req; |
||||
} |
||||
|
||||
/** 库存响应 → 快照分页。 */ |
||||
public static Page<InventorySnapshot> toPage( |
||||
EdayunInventoryDtos.QueryInventoryResponse response, String fallbackWarehouseCode, |
||||
Instant asOf, int currentPage, int pageSize) { |
||||
if (response == null || response.rows == null || response.rows.isEmpty()) { |
||||
return Page.empty(); |
||||
} |
||||
List<InventorySnapshot> out = new ArrayList<InventorySnapshot>(response.rows.size()); |
||||
for (EdayunInventoryDtos.InventoryRow row : response.rows) { |
||||
if (row == null || !hasText(row.skuCode)) { |
||||
// 没有 SKU 的库存行无法落库,跳过比整页失败合适
|
||||
continue; |
||||
} |
||||
out.add(InventorySnapshot.builder() |
||||
.warehouseCode(firstNonBlank(row.warehouseCode, fallbackWarehouseCode)) |
||||
.providerSku(row.skuCode.trim()) |
||||
.available(intOf(row.stock)) |
||||
.onHand(intOf(row.totalStock)) |
||||
.inTransit(intOf(row.inTransitStock)) |
||||
.reserved(intOf(row.frozenStock)) |
||||
.inventoryType(0) |
||||
.asOfUtc(asOf) |
||||
.productName(blankToNull(row.skuName)) |
||||
.pendingOutbound(intOf(row.toDeliverStock)) |
||||
.alertQuantity(intOf(row.safeStock)) |
||||
.build()); |
||||
} |
||||
return Page.of(out, nextCursor(response.total, currentPage, pageSize, out.size())); |
||||
} |
||||
|
||||
/** |
||||
* 有下一页时返回下一页页码。 |
||||
* |
||||
* <p>文档写明 {@code total} 是响应数据总数(行数),优先用它判断; |
||||
* 缺失时退回「本页是否满页」。</p> |
||||
*/ |
||||
static String nextCursor(Long total, int currentPage, int pageSize, int fetched) { |
||||
boolean more = total != null |
||||
? (long) currentPage * pageSize < total |
||||
: fetched >= pageSize; |
||||
return more ? String.valueOf(currentPage + 1) : null; |
||||
} |
||||
|
||||
/** 游标是字符串化的页码。 */ |
||||
static int pageNumber(String cursor) { |
||||
if (!hasText(cursor)) { |
||||
return 1; |
||||
} |
||||
try { |
||||
int v = Integer.parseInt(cursor.trim()); |
||||
return v > 0 ? v : 1; |
||||
} catch (NumberFormatException e) { |
||||
return 1; |
||||
} |
||||
} |
||||
|
||||
/** 每页条数:默认 100,上限 500。 */ |
||||
static int pageSize(int requested) { |
||||
if (requested <= 0) { |
||||
return 100; |
||||
} |
||||
return Math.min(requested, MAX_PAGE_SIZE); |
||||
} |
||||
|
||||
/** 仓方仓 id 是数字;非数字直接拒绝,避免仓侧静默查不到。 */ |
||||
static Long warehouseIdOf(String providerWarehouseId) { |
||||
if (!hasText(providerWarehouseId)) { |
||||
return null; |
||||
} |
||||
try { |
||||
return Long.valueOf(providerWarehouseId.trim()); |
||||
} catch (NumberFormatException e) { |
||||
throw new IllegalArgumentException( |
||||
"edayun warehouseIdList must be numeric, got: " + providerWarehouseId |
||||
+ " (configure the provider warehouse id as edayun's numeric warehouse id)"); |
||||
} |
||||
} |
||||
|
||||
private static int intOf(Integer v) { |
||||
return v == null ? 0 : v; |
||||
} |
||||
|
||||
private static String firstNonBlank(String a, String b) { |
||||
if (hasText(a)) { |
||||
return a.trim(); |
||||
} |
||||
return hasText(b) ? b.trim() : null; |
||||
} |
||||
|
||||
private static String blankToNull(String v) { |
||||
return hasText(v) ? v.trim() : null; |
||||
} |
||||
|
||||
private static boolean hasText(String v) { |
||||
return v != null && !v.trim().isEmpty(); |
||||
} |
||||
} |
||||
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
package common.ecommerce.edayun.adapter; |
||||
|
||||
import java.time.Instant; |
||||
import java.time.ZoneOffset; |
||||
import java.time.ZonedDateTime; |
||||
|
||||
/** |
||||
* 易达云费用类查询的时间窗约束。 |
||||
* |
||||
* <p>易达云各费用接口都限制「最大查询 3 个月」。本地<b>只挡明显超限</b>, |
||||
* 精确阈值交给仓方判定——真机实测(2026-11-13,PR 环境)边界不是自然月也不是 |
||||
* 固定天数:</p> |
||||
* |
||||
* <pre> |
||||
* 6/1 ~ 10/1 通过 6/2 ~ 10/2 拒绝 |
||||
* 7/2 ~ 10/31 通过 7/1 ~ 10/31 拒绝 |
||||
* 6/1 ~ 11/1 拒绝「计费时间范围不能超过3个月」 |
||||
* </pre> |
||||
* |
||||
* <p>按「自然月加 N」严格算会把上面<b>通过</b>的那些合法窗口挡在本地, |
||||
* 所以这里放宽到 {@code months + 1} 个月:既拦住「一次拉一年」这类明显错误, |
||||
* 又不会误伤 3~4 个月之间的窗口。真正超限时仓方返回 |
||||
* {@code code=500, msg=计费时间范围不能超过3个月},由适配器原样抛出。</p> |
||||
*/ |
||||
final class EdayunQueryWindows { |
||||
|
||||
/** |
||||
* 本地允许的余量(月)。3 个月 + 1 个月 = 4 个月。 |
||||
* |
||||
* <p>实测存在 3~4 个月之间被仓方接受的窗口,余量不能少于 1 个月。</p> |
||||
*/ |
||||
private static final int LOCAL_SLACK_MONTHS = 1; |
||||
|
||||
/** 支持的月数上限;超出说明调用方传错了常量。 */ |
||||
private static final int MAX_GUARD_MONTHS = 12; |
||||
|
||||
private EdayunQueryWindows() { |
||||
} |
||||
|
||||
/** |
||||
* 校验时间窗没有明显超过 {@code months} 个月。 |
||||
* |
||||
* <p>时间点按 UTC 换算成日期比较——仓方按自己的时区解释毫秒时间戳, |
||||
* 这里只做保守的日期级判断。</p> |
||||
* |
||||
* @param what 用于报错的业务名,如 {@code "order cost"} / {@code "rent detail"} |
||||
* @throws IllegalArgumentException 明显超出上限 |
||||
*/ |
||||
static void requireWithinMonths(Instant start, Instant end, int months, String what) { |
||||
if (months <= 0 || months > MAX_GUARD_MONTHS) { |
||||
throw new IllegalArgumentException( |
||||
"edayun " + what + " window guard configured with unsupported months: " + months); |
||||
} |
||||
ZonedDateTime from = start.atZone(ZoneOffset.UTC); |
||||
ZonedDateTime to = end.atZone(ZoneOffset.UTC); |
||||
if (from.plusMonths(months + LOCAL_SLACK_MONTHS).isBefore(to)) { |
||||
throw new IllegalArgumentException( |
||||
"edayun " + what + " query range must not exceed " + months + " months, got " |
||||
+ from.toLocalDate() + " ~ " + to.toLocalDate() |
||||
+ "; split the window and query again"); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,192 @@
@@ -0,0 +1,192 @@
|
||||
package common.ecommerce.edayun.adapter; |
||||
|
||||
import common.ecommerce.edayun.dto.EdayunRentDetailDtos; |
||||
import common.ecommerce.shared.support.Money; |
||||
import common.ecommerce.warehouse.enums.WarehouseFeeType; |
||||
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||
import common.ecommerce.warehouse.model.BillingDocument; |
||||
import common.ecommerce.warehouse.model.FeeQuery; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.time.Instant; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 易达云仓租费用明细映射 |
||||
* ({@code POST /webApi/order/cost/v1/selectUserRentDetailList})。 |
||||
* |
||||
* <p>与另外两个费用接口的区别:</p> |
||||
* <ul> |
||||
* <li>{@code accountFlow/list} = 账户流水(充值 / 扣费 / 退费 + 余额)</li> |
||||
* <li>{@code selectOrderCostInfoList} = 按<b>订单</b>拆的尾程 / 操作费</li> |
||||
* <li>本接口 = <b>仓租</b>:按 SKU + 计费日逐条,带租期天数、库存件数、计费体积与单价</li> |
||||
* </ul> |
||||
* |
||||
* <p>金额口径:{@code rentPrice} 是原价减折扣后的实收;缺失时用 |
||||
* {@code originalPrice - discountPrice} 兜底,两者都没有才记 0。</p> |
||||
*/ |
||||
public final class EdayunRentDetailMapper { |
||||
|
||||
/** 计费时间窗上限 3 个月。 */ |
||||
static final int MAX_RANGE_MONTHS = 3; |
||||
|
||||
/** 单页上限。 */ |
||||
static final int MAX_PAGE_SIZE = 200; |
||||
|
||||
/** |
||||
* 翻页上限:{@value #MAX_PAGES} 页 × {@value #MAX_PAGE_SIZE} 条。 |
||||
* |
||||
* <p>仓租按 SKU + 天出账,3 个月窗口下条数可能上万;这里设上限防止一次拉爆, |
||||
* 超出时适配器<b>显式失败</b>而不是截断——见 docs-warehouse/edayun/TODO.md。</p> |
||||
*/ |
||||
static final int MAX_PAGES = 20; |
||||
|
||||
/** 一次拉取的最大行数;超过即失败。 */ |
||||
static final int MAX_ROWS = MAX_PAGES * MAX_PAGE_SIZE; |
||||
|
||||
private EdayunRentDetailMapper() { |
||||
} |
||||
|
||||
/** |
||||
* 统一查询条件 → 仓租明细查询请求。 |
||||
* |
||||
* <p>文档里 {@code billDateBegin} / {@code billDateEnd} 都是必填,所以没有 |
||||
* 时间窗时<b>本地直接拒绝</b>——仓租没有按单号单独查的口径。</p> |
||||
* |
||||
* @param providerWarehouseId 仓方仓 id;非空时作为 {@code warehouseIds} 唯一元素 |
||||
*/ |
||||
public static EdayunRentDetailDtos.SelectRentDetailRequest toRequest( |
||||
FeeQuery query, String providerWarehouseId) { |
||||
if (!query.hasSettledRange()) { |
||||
throw new IllegalArgumentException( |
||||
"edayun rent detail query requires a billing time range (billDateBegin/End);" |
||||
+ " refusing to pull all rents"); |
||||
} |
||||
requireStorageOnly(query); |
||||
|
||||
EdayunRentDetailDtos.SelectRentDetailRequest req = |
||||
new EdayunRentDetailDtos.SelectRentDetailRequest(); |
||||
req.pageNum = 1; |
||||
req.pageSize = MAX_PAGE_SIZE; |
||||
|
||||
EdayunQueryWindows.requireWithinMonths(query.settledAfter(), query.settledBefore(), |
||||
MAX_RANGE_MONTHS, "rent detail"); |
||||
req.billDateBegin = query.settledAfter().toEpochMilli(); |
||||
req.billDateEnd = query.settledBefore().toEpochMilli(); |
||||
|
||||
Long warehouseId = warehouseIdOf(providerWarehouseId); |
||||
req.warehouseIds = warehouseId == null ? null |
||||
: Collections.singletonList(warehouseId); |
||||
|
||||
String businessNum = firstNonBlank(query.externalOrderNo(), query.saleOrderNo()); |
||||
req.businessNums = businessNum == null ? null |
||||
: Collections.singletonList(businessNum); |
||||
|
||||
// 仓租是 SKU 维度;只给条码时用条码查,别把条码当 SKU 传
|
||||
req.skuCodes = hasText(query.providerSku()) |
||||
? Collections.singletonList(query.providerSku().trim()) : null; |
||||
|
||||
return req; |
||||
} |
||||
|
||||
/** |
||||
* 本接口只出仓租。 |
||||
* |
||||
* <p>宿主若明确要求别的费用类型,说明用错了接口——显式拒绝而不是返回空集合, |
||||
* 否则调用方会误以为「该期间没有作业费」。</p> |
||||
*/ |
||||
private static void requireStorageOnly(FeeQuery query) { |
||||
if (query.costType() != null && query.costType() != WarehouseFeeType.STORAGE) { |
||||
throw new IllegalArgumentException( |
||||
"edayun rent detail query only returns STORAGE cost, got " + query.costType() |
||||
+ "; use settlements() or orderCosts() for other fee types"); |
||||
} |
||||
if (query.hasDateRange()) { |
||||
throw new IllegalArgumentException( |
||||
"edayun rent detail query uses settledAfter/settledBefore (billDateBegin/End)," |
||||
+ " not snapshot date range"); |
||||
} |
||||
} |
||||
|
||||
/** 仓方仓 id 是数字;非数字直接拒绝,避免仓侧静默查不到。 */ |
||||
static Long warehouseIdOf(String providerWarehouseId) { |
||||
if (!hasText(providerWarehouseId)) { |
||||
return null; |
||||
} |
||||
try { |
||||
return Long.valueOf(providerWarehouseId.trim()); |
||||
} catch (NumberFormatException e) { |
||||
throw new IllegalArgumentException( |
||||
"edayun warehouseIds must be numeric, got: " + providerWarehouseId |
||||
+ " (configure the provider warehouse id as edayun's numeric warehouse id)"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 一行仓租明细 → 一条 {@link BillingDocument}。 |
||||
* |
||||
* <p>仓租天然就是仓储费,费用类型固定 {@link WarehouseFeeType#STORAGE}, |
||||
* 不按 {@code billingName} 关键字猜。</p> |
||||
*/ |
||||
public static BillingDocument toDocument(EdayunRentDetailDtos.RentDetailRow row, |
||||
String warehouseCode) { |
||||
String currency = hasText(row.currencyCode) ? row.currencyCode.trim() : "USD"; |
||||
return BillingDocument.builder() |
||||
.warehouseCode(firstNonBlank(row.warehouseName, warehouseCode)) |
||||
.sourceProvider(WarehouseProvider.EDAYUN) |
||||
.documentNo(firstNonBlank(row.businessNum, row.orderNo)) |
||||
// billingId 是计费明细唯一标识,可作为重复拉取的去重键
|
||||
.serialNumber(row.billingId == null ? null : String.valueOf(row.billingId)) |
||||
.feeName(firstNonBlank(row.billingName, "仓租")) |
||||
.feeType(WarehouseFeeType.STORAGE) |
||||
.estimated(false) |
||||
.settledAt(row.billingDate == null ? null : Instant.ofEpochMilli(row.billingDate)) |
||||
.amount(moneyOf(row, currency)) |
||||
.saleOrderNo(row.orderNo) |
||||
.providerSku(row.skuCode) |
||||
.build(); |
||||
} |
||||
|
||||
/** 批量映射,跳过 null 行。 */ |
||||
public static List<BillingDocument> toDocuments(List<EdayunRentDetailDtos.RentDetailRow> rows, |
||||
String warehouseCode) { |
||||
if (rows == null || rows.isEmpty()) { |
||||
return Collections.emptyList(); |
||||
} |
||||
List<BillingDocument> out = new ArrayList<BillingDocument>(rows.size()); |
||||
for (EdayunRentDetailDtos.RentDetailRow row : rows) { |
||||
if (row != null) { |
||||
out.add(toDocument(row, warehouseCode)); |
||||
} |
||||
} |
||||
return out; |
||||
} |
||||
|
||||
/** 实收金额:{@code rentPrice} 优先,缺失时原价减折扣。 */ |
||||
static Money moneyOf(EdayunRentDetailDtos.RentDetailRow row, String currency) { |
||||
BigDecimal amount = null; |
||||
if (row.rentPrice != null) { |
||||
amount = BigDecimal.valueOf(row.rentPrice); |
||||
} else if (row.originalPrice != null) { |
||||
BigDecimal discount = row.discountPrice == null |
||||
? BigDecimal.ZERO : BigDecimal.valueOf(row.discountPrice); |
||||
amount = BigDecimal.valueOf(row.originalPrice).subtract(discount); |
||||
} |
||||
return amount == null ? Money.zero(currency) : Money.of(amount, currency); |
||||
} |
||||
|
||||
private static String firstNonBlank(String... values) { |
||||
for (String v : values) { |
||||
if (hasText(v)) { |
||||
return v.trim(); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
private static boolean hasText(String v) { |
||||
return v != null && !v.trim().isEmpty(); |
||||
} |
||||
} |
||||
@ -0,0 +1,171 @@
@@ -0,0 +1,171 @@
|
||||
package common.ecommerce.edayun.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 易达云报文结构:费用试算 / 预估({@code POST /webApi/estimate/v1/trial})。 |
||||
* |
||||
* <p>一个文件对应一个接口,只放该接口的请求 / 响应与内嵌子结构。</p> |
||||
* |
||||
* <p>三种预估方式(优先级从高到低):</p> |
||||
* <ol> |
||||
* <li>虚拟包裹:{@code hasOutboundFeeInputSkuSwitch = true} + {@code virtualPackageDetails}</li> |
||||
* <li>按包裹:{@code manualInputSwitch = true} + {@code packageDetails}</li> |
||||
* <li>按 SKU:{@code manualInputSwitch = false} + {@code skuInfoDetails}</li> |
||||
* </ol> |
||||
* |
||||
* <p>响应把渠道分成 {@code successItems}(有报价)与 {@code failItems}(不支持派送), |
||||
* 每个失败项也带 {@code errorMessage}。</p> |
||||
*/ |
||||
public final class EdayunFeeEstimateDtos { |
||||
|
||||
private EdayunFeeEstimateDtos() { |
||||
} |
||||
|
||||
/** 试算请求。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class TrialRequest { |
||||
|
||||
/** 出货仓库 id;与 {@link #warehouseCode} 必填一个。 */ |
||||
public Long warehouseId; |
||||
/** 出货仓库编码;与 {@link #warehouseId} 必填一个。 */ |
||||
public String warehouseCode; |
||||
/** 目的国二字码;缺省用仓库所在国。 */ |
||||
public String endCountryCode; |
||||
/** 城市;部分物流(如澳洲 Allied)必须给城市才能报价。 */ |
||||
public String city; |
||||
/** 目的地邮编。<b>必填</b>。 */ |
||||
public String endZipcode; |
||||
|
||||
/** true 按包裹预估 / false 按 SKU 预估。<b>必填</b>。 */ |
||||
public Boolean manualInputSwitch; |
||||
/** 货物类型;按包裹预估时必填。 */ |
||||
public String estimatedGoodsType; |
||||
|
||||
/** 按 SKU 预估时的商品集合。 */ |
||||
public List<SkuItem> skuInfoDetails; |
||||
/** 按包裹预估时的包裹集合(文档:目前仅支持单包裹)。 */ |
||||
public List<PackageItem> packageDetails; |
||||
/** 指定物流产品 id 列表;不给则返回全部渠道的报价。 */ |
||||
public List<Long> logisticsProductIds; |
||||
|
||||
/** true 时走虚拟包裹预估,优先级高于前两种。 */ |
||||
public Boolean hasOutboundFeeInputSkuSwitch; |
||||
/** 虚拟包裹。 */ |
||||
public List<VirtualPackage> virtualPackageDetails; |
||||
} |
||||
|
||||
/** 按 SKU 预估的一个商品。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class SkuItem { |
||||
public String skuCode; |
||||
public Integer quantity; |
||||
} |
||||
|
||||
/** 包裹尺寸重量;长度单位 cm,重量单位 g。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class PackageItem { |
||||
public Double length; |
||||
public Double width; |
||||
public Double height; |
||||
/** 克。 */ |
||||
public Double weight; |
||||
} |
||||
|
||||
/** 虚拟包裹:自己给装箱明细,不查仓内 SKU 资料。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class VirtualPackage { |
||||
public Double length; |
||||
public Double width; |
||||
public Double height; |
||||
/** 克。 */ |
||||
public Double weight; |
||||
/** 货物类型;虚拟包裹必填。 */ |
||||
public String electricType; |
||||
/** 包裹内的产品(只给尺寸重量与数量,不需要 skuCode)。 */ |
||||
public List<VirtualSkuItem> skuInfoDetails; |
||||
} |
||||
|
||||
/** 虚拟包裹内的一个产品。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class VirtualSkuItem { |
||||
public Double length; |
||||
public Double width; |
||||
public Double height; |
||||
/** 克。 */ |
||||
public Double weight; |
||||
public Integer quantity; |
||||
} |
||||
|
||||
/** 试算响应。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class TrialResponse { |
||||
public Integer code; |
||||
public String msg; |
||||
public TrialData data; |
||||
public Object traceId; |
||||
} |
||||
|
||||
/** 试算结果数据。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class TrialData { |
||||
/** 有报价的渠道。 */ |
||||
public List<EstimateItem> successItems; |
||||
/** 无报价的渠道(如「不支持派送」)。 */ |
||||
public List<EstimateItem> failItems; |
||||
/** 是否展示错误提示。 */ |
||||
public Boolean showError; |
||||
/** 整体错误提示,如「没有物流产品符合预估!」。 */ |
||||
public String errorInfo; |
||||
} |
||||
|
||||
/** 一个渠道的试算结果。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class EstimateItem { |
||||
|
||||
/** 物流产品 id。 */ |
||||
public String logisticProductId; |
||||
/** 物流产品名称,如「美国经济派送」。 */ |
||||
public String logisticProductName; |
||||
/** 时效描述,如 {@code 2-8 工作日}。 */ |
||||
public String timeLimit; |
||||
|
||||
/** 计费尺寸(cm)。 */ |
||||
public List<Lwh> lwhs; |
||||
/** 计费重量;实测单位是 <b>kg</b>(请求 1000g → 响应 1.000)。 */ |
||||
public Double weight; |
||||
public String currencyCode; |
||||
/** 预估总价。 */ |
||||
public Double estimatedPrice; |
||||
|
||||
/** 费用明细。 */ |
||||
public List<DetailItem> detailList; |
||||
|
||||
public String errorCode; |
||||
public String errorMessage; |
||||
} |
||||
|
||||
/** 计费尺寸。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class Lwh { |
||||
public Double length; |
||||
public Double width; |
||||
public Double height; |
||||
} |
||||
|
||||
/** 一条费用明细。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class DetailItem { |
||||
/** 计费项 id。 */ |
||||
public String billingId; |
||||
/** 计费项名称,如「尾程配送费」。 */ |
||||
public String billingItemName; |
||||
/** 预估金额。 */ |
||||
public Double estimatedPrice; |
||||
/** 优惠后预估金额;实测有 {@code 0.000},语义未确认。 */ |
||||
public Double preferentialEstimatedPrice; |
||||
public String currencyCode; |
||||
} |
||||
} |
||||
@ -0,0 +1,129 @@
@@ -0,0 +1,129 @@
|
||||
package common.ecommerce.edayun.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 易达云报文结构:创建 / 编辑自发入库单 |
||||
* ({@code POST /webApi/entryInfo/v1/saveEntrySpontaneousOrder})。 |
||||
* |
||||
* <p>自发入库单 = 卖家自己备货、自己找代理送到 EDA 海外仓,物流信息由卖家维护。 |
||||
* 一个接口承担新增 / 更新 / 保存并发布,靠 {@code saveType} 区分。</p> |
||||
* |
||||
* <p>只映射统一模型能提供的部分:{@code basicInfo} / {@code logisticsInfo} / {@code cargoInfos}。 |
||||
* 头程拖车、报关、清关、海外拖车四组({@code domesticTrailerInfo} 等)在统一模型里 |
||||
* 没有对应字段,<b>不下发</b>——需要时由仓方报错,由宿主走人工。</p> |
||||
*/ |
||||
public final class EdayunInboundDtos { |
||||
|
||||
private EdayunInboundDtos() { |
||||
} |
||||
|
||||
/** 保存入库单请求。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class SaveEntryRequest { |
||||
|
||||
/** 保存类型:0 新增 / 1 更新 / 2 保存并发布。默认新增。 */ |
||||
public Integer saveType; |
||||
/** 入库单号;{@code saveType=1} 更新时必填。 */ |
||||
public String entryCode; |
||||
/** 客户单号,≤30。必填。 */ |
||||
public String customerOrderNo; |
||||
|
||||
public BasicInfo basicInfo; |
||||
public LogisticsInfo logisticsInfo; |
||||
public List<CargoInfo> cargoInfos; |
||||
} |
||||
|
||||
/** 基础信息。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class BasicInfo { |
||||
|
||||
/** 上架仓编码,如 {@code USLA}。 */ |
||||
public String shelfWarehouseCode; |
||||
/** 上架仓 id(数字)。 */ |
||||
public Long shelfWarehouseId; |
||||
|
||||
/** 头程运输方式,取值由仓方字典定义。 */ |
||||
public Integer intShippingMethod; |
||||
/** 柜型,取值由仓方字典定义。 */ |
||||
public Integer cabinetType; |
||||
/** 入库物流产品 id(来自「查询入库物流产品」接口)。 */ |
||||
public Long shippingProductId; |
||||
} |
||||
|
||||
/** 物流信息。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class LogisticsInfo { |
||||
|
||||
/** 柜号。 */ |
||||
public String cabinetCode; |
||||
/** 承运商名称(快递类发布时必填)。 */ |
||||
public String shipCompany; |
||||
/** 预计离港时间(毫秒);卡车类发布时必填。 */ |
||||
public Long estimatedDepartureTime; |
||||
/** 实际离港时间(毫秒)。 */ |
||||
public Long departureTime; |
||||
/** 预计到港时间(毫秒)。 */ |
||||
public Long estimatedArrivalDate; |
||||
/** 快递单号 / 跟踪单号(快递类发布时必填)。 */ |
||||
public String waybill; |
||||
/** 车牌号。 */ |
||||
public String carNumber; |
||||
/** 起运港编码(字典值)。 */ |
||||
public String startLocationCode; |
||||
/** 卸货港编码(字典值)。 */ |
||||
public String dischargeLocationCode; |
||||
/** 物流类型,取值由仓方字典定义。 */ |
||||
public Integer logisticsType; |
||||
/** 最终目的港编码(字典值)。 */ |
||||
public String endLocationCode; |
||||
} |
||||
|
||||
/** 箱货信息。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class CargoInfo { |
||||
|
||||
/** 外箱编号,如 {@code 1-10}。 */ |
||||
public String outsideBoxCode; |
||||
/** 箱长(cm)。 */ |
||||
public Double boxLength; |
||||
/** 箱宽(cm)。 */ |
||||
public Double boxWidth; |
||||
/** 箱高(cm)。 */ |
||||
public Double boxHeight; |
||||
/** 箱重(kg)。 */ |
||||
public Double weight; |
||||
|
||||
public List<BoxSku> boxSkuInfoList; |
||||
} |
||||
|
||||
/** 箱内 SKU。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class BoxSku { |
||||
|
||||
public String skuCode; |
||||
/** 预报数量。 */ |
||||
public Integer skuForecastQuantity; |
||||
} |
||||
|
||||
/** 保存入库单响应。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class SaveEntryResponse { |
||||
public Integer code; |
||||
public String msg; |
||||
public SaveEntryData data; |
||||
/** 文档标为 object,实际可能是字符串;保留 Object 避免解析失败。 */ |
||||
public Object traceId; |
||||
} |
||||
|
||||
/** 响应数据。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class SaveEntryData { |
||||
/** 仓侧入库单号,如 {@code REV25052032239}。 */ |
||||
public String entryCode; |
||||
/** 回显的客户单号。 */ |
||||
public String customerOrderNo; |
||||
} |
||||
} |
||||
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
package common.ecommerce.edayun.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 易达云报文结构:按 SKU 查询入库单货箱信息 / 预报上架信息 |
||||
* ({@code POST /webApi/entryInfo/v1/selectEntrySkuGoodsDetail})。 |
||||
* |
||||
* <p>一行 = 一个 SKU 在入库单里的预报 / 清点 / 上架数量与状态。 |
||||
* 这是目前唯一能拿到入库进度的接口——创建接口只回 {@code entryCode},不带状态。</p> |
||||
*/ |
||||
public final class EdayunInboundQueryDtos { |
||||
|
||||
private EdayunInboundQueryDtos() { |
||||
} |
||||
|
||||
/** 查询请求。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class SelectEntrySkuRequest { |
||||
|
||||
/** 入库单号(仓侧 REV 单号)。必填。 */ |
||||
public String entryCode; |
||||
/** 每页条数,默认 200,最大 1000。必填。 */ |
||||
public Integer pageSize; |
||||
/** 页码,从 1 开始。必填。 */ |
||||
public Integer pageNum; |
||||
} |
||||
|
||||
/** 查询响应。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class SelectEntrySkuResponse { |
||||
/** 总行数。 */ |
||||
public Long total; |
||||
public Integer code; |
||||
public String msg; |
||||
public String traceId; |
||||
public List<EntrySkuRow> rows; |
||||
} |
||||
|
||||
/** 一条 SKU 的入库明细。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class EntrySkuRow { |
||||
|
||||
public String barcode; |
||||
public String skuCode; |
||||
public String skuName; |
||||
public String extraBarcode; |
||||
|
||||
/** 预报是否带电:0 是 / 1 否(同其它接口的反向标志)。 */ |
||||
public Integer forecastElectrified; |
||||
/** 复核是否带电。 */ |
||||
public Integer verifyElectrified; |
||||
/** 是否带电:0 带电 / 1 不带电。 */ |
||||
public Integer electricFlag; |
||||
/** 电池包装。 */ |
||||
public Integer electricPackage; |
||||
|
||||
/** 预报箱规,形如 {@code 115.3*79.8*36}(cm)。 */ |
||||
public String forecastCargoSize; |
||||
/** 头程箱规。 */ |
||||
public String firstCargoSize; |
||||
/** 实际箱规。 */ |
||||
public String cargoSize; |
||||
|
||||
/** 预报重量,量级像克(示例 {@code 12100})。 */ |
||||
public Double forecastWeight; |
||||
/** 头程重量,量级像千克(示例 {@code 12.1})。 */ |
||||
public Double firstWeight; |
||||
/** 实际重量,量级像克。 */ |
||||
public Double weight; |
||||
|
||||
/** 预报数量。 */ |
||||
public Integer forecastQuantity; |
||||
/** 实际清点数量。 */ |
||||
public Integer actualCheckedQuantity; |
||||
/** 上架数量。 */ |
||||
public Integer shelvesQuantity; |
||||
/** 头程数量。 */ |
||||
public Integer firstripQuantity; |
||||
|
||||
public String entryCode; |
||||
/** SKU 级状态码;示例 {@code 4}。 */ |
||||
public Integer status; |
||||
/** 状态名;示例「已上架」。 */ |
||||
public String statusName; |
||||
|
||||
/** 序列号列表(逗号分隔)。 */ |
||||
public String snCodeList; |
||||
} |
||||
} |
||||
@ -0,0 +1,85 @@
@@ -0,0 +1,85 @@
|
||||
package common.ecommerce.edayun.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 易达云报文结构:库存查询 |
||||
* ({@code POST /webApi/userSkuStock/v1/queryInventory})。 |
||||
* |
||||
* <p>一行 = 一个 SKU 在一个仓的库存汇总。默认只返回总库存大于 0 的数据, |
||||
* 单页最多 500 条。</p> |
||||
*/ |
||||
public final class EdayunInventoryDtos { |
||||
|
||||
private EdayunInventoryDtos() { |
||||
} |
||||
|
||||
/** 查询请求。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class QueryInventoryRequest { |
||||
|
||||
/** 页码,从 1 开始。必填。 */ |
||||
public Integer pageNum; |
||||
/** 每页条数,最大 500。必填。 */ |
||||
public Integer pageSize; |
||||
|
||||
/** SKU 编码列表,最多 100 个。 */ |
||||
public List<String> skuCodeList; |
||||
/** 仓库 id 列表(数字)。 */ |
||||
public List<Long> warehouseIdList; |
||||
|
||||
/** |
||||
* 是否只查总库存大于 0 的数据。 |
||||
* |
||||
* <p>不传时仓方默认 {@code true};要零库存数据时显式传 {@code false}。</p> |
||||
*/ |
||||
public Boolean totalStockGreaterThanZero; |
||||
} |
||||
|
||||
/** 查询响应。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class QueryInventoryResponse { |
||||
/** 响应数据总数(行数)。 */ |
||||
public Long total; |
||||
public List<InventoryRow> rows; |
||||
public Integer code; |
||||
public String msg; |
||||
/** 文档标为 object,实际可能是字符串;保留 Object 避免解析失败。 */ |
||||
public Object traceId; |
||||
} |
||||
|
||||
/** 一条库存记录。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class InventoryRow { |
||||
|
||||
public String skuCode; |
||||
public String barcode; |
||||
public String skuName; |
||||
|
||||
/** 总库存。 */ |
||||
public Integer totalStock; |
||||
/** 可用库存。 */ |
||||
public Integer stock; |
||||
/** 冻结库存。 */ |
||||
public Integer frozenStock; |
||||
/** 待出库库存。 */ |
||||
public Integer toDeliverStock; |
||||
/** 安全库存(预警数量)。 */ |
||||
public Integer safeStock; |
||||
/** 不可售库存。 */ |
||||
public Integer nonSaleStock; |
||||
/** 在途库存。 */ |
||||
public Integer inTransitStock; |
||||
|
||||
public String countryName; |
||||
public String warehouseName; |
||||
public Long warehouseId; |
||||
public String warehouseCode; |
||||
|
||||
public String goodsType; |
||||
/** 序列号入库数量。 */ |
||||
public Integer snInStock; |
||||
} |
||||
} |
||||
@ -0,0 +1,117 @@
@@ -0,0 +1,117 @@
|
||||
package common.ecommerce.edayun.dto; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 易达云报文结构:查询仓租费用明细 |
||||
* ({@code POST /webApi/order/cost/v1/selectUserRentDetailList})。 |
||||
* |
||||
* <p>一个文件对应一个接口,只放该接口的请求 / 响应与内嵌子结构。</p> |
||||
* |
||||
* <p>与「订单费用明细」({@code selectOrderCostInfoList})的区别:那个按<b>订单</b> |
||||
* 拆尾程 / 操作费等费用;这个是<b>仓租</b>——按 SKU + 计费日逐日累计, |
||||
* 带租期天数、库存件数、计费体积与单价。</p> |
||||
*/ |
||||
public final class EdayunRentDetailDtos { |
||||
|
||||
private EdayunRentDetailDtos() { |
||||
} |
||||
|
||||
/** 查询请求。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class SelectRentDetailRequest { |
||||
|
||||
/** 页码,从 1 开始。必填。 */ |
||||
public Integer pageNum; |
||||
/** 每页条数,最大 200。必填。 */ |
||||
public Integer pageSize; |
||||
|
||||
/** 计费时间开始(毫秒)。<b>必填</b>,最大查询 3 个月。 */ |
||||
public Long billDateBegin; |
||||
/** 计费时间结束(毫秒)。<b>必填</b>。 */ |
||||
public Long billDateEnd; |
||||
|
||||
/** 仓库 id 列表,最大 20 个。 */ |
||||
public List<Long> warehouseIds; |
||||
/** 业务单号列表,最大 20 个。 */ |
||||
public List<String> businessNums; |
||||
/** SKU 编码列表,最大 100 个。 */ |
||||
public List<String> skuCodes; |
||||
/** 条码列表,最大 100 个。 */ |
||||
public List<String> barCodes; |
||||
/** 外部条码列表,最大 100 个。 */ |
||||
public List<String> extraBarcodes; |
||||
} |
||||
|
||||
/** 查询响应。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class SelectRentDetailResponse { |
||||
public Long total; |
||||
public List<RentDetailRow> rows; |
||||
public Integer code; |
||||
public String msg; |
||||
/** 文档标为 object,实际是字符串(如 {@code "null"});保留 Object 避免解析失败。 */ |
||||
public Object traceId; |
||||
} |
||||
|
||||
/** 一条仓租明细。 */ |
||||
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||
public static final class RentDetailRow { |
||||
|
||||
/** 业务单号,形如 {@code 98-N9490-20260928}(仓 id - 批次 - 日期)。 */ |
||||
public String businessNum; |
||||
/** 计费日期(毫秒)。 */ |
||||
public Long billingDate; |
||||
|
||||
public String warehouseId; |
||||
public String warehouseName; |
||||
|
||||
public String skuCode; |
||||
public String barcode; |
||||
/** 仓侧订单号。 */ |
||||
public String orderNo; |
||||
/** 来源单据类型:5 增值单等。 */ |
||||
public Integer orderType; |
||||
public String orderTypeName; |
||||
|
||||
/** 累计租期天数。 */ |
||||
public Integer rentDays; |
||||
/** 计费时库存件数。 */ |
||||
public Integer totalStock; |
||||
|
||||
/** 单件尺寸(cm)。 */ |
||||
public Double length; |
||||
public Double width; |
||||
public Double height; |
||||
/** 单件重量;文档示例 {@code 60000},量级像克。 */ |
||||
public Double weight; |
||||
/** 货物类型,如 {@code TM}。 */ |
||||
public String goodsType; |
||||
|
||||
/** SKU 总体积。 */ |
||||
public Double skuTotalVol; |
||||
public String totalVolUnit; |
||||
/** 计费体积。 */ |
||||
public Double billingVol; |
||||
/** 计费体积单位,如 {@code CBFT}。 */ |
||||
public String billingVolUnit; |
||||
|
||||
/** 计费项 id;同一计费明细的唯一标识,可作去重键。 */ |
||||
public Long billingId; |
||||
/** 计费项名称,如「仓租」。 */ |
||||
public String billingName; |
||||
|
||||
/** 单价。 */ |
||||
public Double unitPrice; |
||||
/** 原价。 */ |
||||
public Double originalPrice; |
||||
/** 折扣金额。 */ |
||||
public Double discountPrice; |
||||
/** 币种,如 {@code CAD}。 */ |
||||
public String currencyCode; |
||||
/** 仓租金额(原价 - 折扣)。 */ |
||||
public Double rentPrice; |
||||
} |
||||
} |
||||
@ -0,0 +1,86 @@
@@ -0,0 +1,86 @@
|
||||
package common.ecommerce.edayun.enums; |
||||
|
||||
import common.ecommerce.warehouse.enums.InboundStatus; |
||||
|
||||
/** |
||||
* 易达云入库 SKU 状态({@code selectEntrySkuGoodsDetail} 的 {@code status})。 |
||||
* |
||||
* <p><b>只有一个是实测确认的</b>:{@code 4 = 已上架}(文档响应示例)。 |
||||
* 完整码表易达云还没给,所以其余先按 {@code statusName} 中文名兜底推断 |
||||
* (与费用类型一样的关键字推断思路),<b>认不出归 {@link InboundStatus#UNKNOWN} |
||||
* 并保留原文</b>,不猜。</p> |
||||
* |
||||
* <p>拿到码表后请把关键字兜底换成精确码值——中文名可能随语言 / 配置变化。</p> |
||||
*/ |
||||
public enum EdayunInboundSkuStatus { |
||||
|
||||
/** 4 已上架(文档示例)。 */ |
||||
STORED(4, InboundStatus.COMPLETED), |
||||
/** 无法识别。 */ |
||||
UNKNOWN(null, InboundStatus.UNKNOWN); |
||||
|
||||
private final Integer rawCode; |
||||
private final InboundStatus core; |
||||
|
||||
EdayunInboundSkuStatus(Integer rawCode, InboundStatus core) { |
||||
this.rawCode = rawCode; |
||||
this.core = core; |
||||
} |
||||
|
||||
/** 仓方状态码;null 表示无法识别。 */ |
||||
public Integer rawCode() { |
||||
return rawCode; |
||||
} |
||||
|
||||
public InboundStatus toCore() { |
||||
return core; |
||||
} |
||||
|
||||
/** |
||||
* 状态码 + 中文名 → 底层状态。 |
||||
* |
||||
* <p>码值优先;认不出码时按中文名兜底;两者都认不出返回 {@code UNKNOWN}。</p> |
||||
*/ |
||||
public static InboundStatus toCore(Integer status, String statusName) { |
||||
if (status != null) { |
||||
for (EdayunInboundSkuStatus v : values()) { |
||||
if (status.equals(v.rawCode)) { |
||||
return v.core; |
||||
} |
||||
} |
||||
} |
||||
return byName(statusName); |
||||
} |
||||
|
||||
/** |
||||
* 按中文名兜底。 |
||||
* |
||||
* <p>顺序有意义:「已取消」要在「已」之前判,避免被当成完成。</p> |
||||
*/ |
||||
static InboundStatus byName(String statusName) { |
||||
if (statusName == null || statusName.trim().isEmpty()) { |
||||
return InboundStatus.UNKNOWN; |
||||
} |
||||
String n = statusName.trim(); |
||||
if (n.contains("取消") || n.contains("作废") || n.contains("驳回")) { |
||||
return InboundStatus.CANCELLED; |
||||
} |
||||
if (n.contains("上架中")) { |
||||
return InboundStatus.STORING; |
||||
} |
||||
if (n.contains("已上架") || n.contains("完成")) { |
||||
return InboundStatus.COMPLETED; |
||||
} |
||||
if (n.contains("清点") || n.contains("收货") || n.contains("卸柜") || n.contains("签收")) { |
||||
return InboundStatus.RECEIVING; |
||||
} |
||||
if (n.contains("在途") || n.contains("运输") || n.contains("离港") |
||||
|| n.contains("到港") || n.contains("发出")) { |
||||
return InboundStatus.IN_TRANSIT; |
||||
} |
||||
if (n.contains("待") || n.contains("预报") || n.contains("草稿")) { |
||||
return InboundStatus.PENDING_SHIPMENT; |
||||
} |
||||
return InboundStatus.UNKNOWN; |
||||
} |
||||
} |
||||
@ -0,0 +1,248 @@
@@ -0,0 +1,248 @@
|
||||
package common.ecommerce.edayun.adapter; |
||||
|
||||
import common.ecommerce.edayun.dto.EdayunFeeEstimateDtos; |
||||
import common.ecommerce.shared.support.Money; |
||||
import common.ecommerce.warehouse.enums.WarehouseCapability; |
||||
import common.ecommerce.warehouse.model.FeeEstimateQuery; |
||||
import common.ecommerce.warehouse.model.FeeEstimateResult; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.List; |
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
import static org.junit.jupiter.api.Assertions.assertNull; |
||||
import static org.junit.jupiter.api.Assertions.assertThrows; |
||||
import static org.junit.jupiter.api.Assertions.assertTrue; |
||||
|
||||
/** |
||||
* 费用试算({@code /webApi/estimate/v1/trial})映射。 |
||||
* |
||||
* <p>重点:仓 id/编码二选一、包裹模式固定下发、只映射 successItems、 |
||||
* 响应重量是 kg 而请求是 g。</p> |
||||
*/ |
||||
class EdayunFeeEstimateTest { |
||||
|
||||
private static FeeEstimateQuery query() { |
||||
return FeeEstimateQuery.builder() |
||||
.lengthCm(new BigDecimal("22")) |
||||
.widthCm(new BigDecimal("22")) |
||||
.heightCm(new BigDecimal("22")) |
||||
.weightGrams(new BigDecimal("1000")) |
||||
.receiveCountry("US") |
||||
.receivePostal("91761") |
||||
.logisticsServiceCode("80") |
||||
.build(); |
||||
} |
||||
|
||||
// ------------------------------------------------------------ 请求
|
||||
|
||||
@Test |
||||
void numericWarehouseIdGoesToWarehouseId() { |
||||
EdayunFeeEstimateDtos.TrialRequest req = |
||||
EdayunFeeEstimateMapper.toRequest(query(), "2"); |
||||
|
||||
assertEquals(Long.valueOf(2L), req.warehouseId); |
||||
assertNull(req.warehouseCode); |
||||
assertEquals("91761", req.endZipcode); |
||||
assertEquals("US", req.endCountryCode); |
||||
assertEquals(Boolean.TRUE, req.manualInputSwitch); |
||||
assertEquals("GENERAL_CARGO", req.estimatedGoodsType); |
||||
} |
||||
|
||||
/** 非数字仓 id 走 warehouseCode(文档说两者必填一个)。 */ |
||||
@Test |
||||
void nonNumericWarehouseGoesToWarehouseCode() { |
||||
EdayunFeeEstimateDtos.TrialRequest req = |
||||
EdayunFeeEstimateMapper.toRequest(query(), "USLA"); |
||||
|
||||
assertEquals("USLA", req.warehouseCode); |
||||
assertNull(req.warehouseId); |
||||
} |
||||
|
||||
/** providerWarehouseId 缺省时退回调用方给的 warehouseCode。 */ |
||||
@Test |
||||
void fallsBackToQueryWarehouseCode() { |
||||
FeeEstimateQuery q = FeeEstimateQuery.builder() |
||||
.warehouseCode("USLA") |
||||
.lengthCm(BigDecimal.ONE).widthCm(BigDecimal.ONE).heightCm(BigDecimal.ONE) |
||||
.weightGrams(BigDecimal.ONE) |
||||
.receiveCountry("US").receivePostal("91761") |
||||
.logisticsServiceCode("80") |
||||
.build(); |
||||
|
||||
EdayunFeeEstimateDtos.TrialRequest req = EdayunFeeEstimateMapper.toRequest(q, null); |
||||
|
||||
assertEquals("USLA", req.warehouseCode); |
||||
} |
||||
|
||||
@Test |
||||
void withoutAnyWarehouseIsRejected() { |
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||
() -> EdayunFeeEstimateMapper.toRequest(query(), null)); |
||||
|
||||
assertTrue(ex.getMessage().contains("requires a warehouse"), ex.getMessage()); |
||||
} |
||||
|
||||
/** 请求里的重量是克(实测 1000g → 响应 weight 1.000kg)。 */ |
||||
@Test |
||||
void packageUsesCentimetersAndGrams() { |
||||
EdayunFeeEstimateDtos.TrialRequest req = |
||||
EdayunFeeEstimateMapper.toRequest(query(), "2"); |
||||
|
||||
assertEquals(1, req.packageDetails.size()); |
||||
EdayunFeeEstimateDtos.PackageItem pkg = req.packageDetails.get(0); |
||||
assertEquals(Double.valueOf(22.0), pkg.length); |
||||
assertEquals(Double.valueOf(1000.0), pkg.weight); |
||||
} |
||||
|
||||
/** 物流产品 id 只认数字;非数字当作「不指定渠道」。 */ |
||||
@Test |
||||
void logisticsProductIdOnlyAcceptsNumeric() { |
||||
assertEquals(Long.valueOf(80L), EdayunFeeEstimateMapper.logisticsProductIdOf(query())); |
||||
|
||||
FeeEstimateQuery nonNumeric = FeeEstimateQuery.builder() |
||||
.lengthCm(BigDecimal.ONE).widthCm(BigDecimal.ONE).heightCm(BigDecimal.ONE) |
||||
.weightGrams(BigDecimal.ONE) |
||||
.receiveCountry("US").receivePostal("91761") |
||||
.logisticsServiceCode("US_ECONOMY") |
||||
.build(); |
||||
assertNull(EdayunFeeEstimateMapper.logisticsProductIdOf(nonNumeric)); |
||||
} |
||||
|
||||
@Test |
||||
void returnsEmptyListWhenNothingChosen() { |
||||
EdayunFeeEstimateDtos.TrialRequest req = |
||||
EdayunFeeEstimateMapper.toRequest(query(), "2"); |
||||
assertEquals(java.util.Collections.singletonList(80L), req.logisticsProductIds); |
||||
} |
||||
|
||||
/** 没指定渠道时不下发 logisticsProductIds,让仓方返回全部报价。 */ |
||||
@Test |
||||
void omitsLogisticsProductIdsWhenNotNumeric() { |
||||
FeeEstimateQuery q = FeeEstimateQuery.builder() |
||||
.lengthCm(BigDecimal.ONE).widthCm(BigDecimal.ONE).heightCm(BigDecimal.ONE) |
||||
.weightGrams(BigDecimal.ONE) |
||||
.receiveCountry("US").receivePostal("91761") |
||||
.logisticsServiceCode("US_ECONOMY") |
||||
.build(); |
||||
|
||||
assertNull(EdayunFeeEstimateMapper.toRequest(q, "2").logisticsProductIds); |
||||
} |
||||
|
||||
// ------------------------------------------------------------ 响应
|
||||
|
||||
private static EdayunFeeEstimateDtos.TrialResponse response() { |
||||
EdayunFeeEstimateDtos.DetailItem freight = new EdayunFeeEstimateDtos.DetailItem(); |
||||
freight.billingId = "1604101111532494888"; |
||||
freight.billingItemName = "尾程配送费"; |
||||
freight.estimatedPrice = 3.315; |
||||
freight.preferentialEstimatedPrice = 0.0; |
||||
freight.currencyCode = "USD"; |
||||
|
||||
EdayunFeeEstimateDtos.DetailItem check = new EdayunFeeEstimateDtos.DetailItem(); |
||||
check.billingId = "1697455503566127105"; |
||||
check.billingItemName = "安全检查费"; |
||||
check.estimatedPrice = 2.0; |
||||
check.currencyCode = "USD"; |
||||
|
||||
EdayunFeeEstimateDtos.EstimateItem ok = new EdayunFeeEstimateDtos.EstimateItem(); |
||||
ok.logisticProductId = "80"; |
||||
ok.logisticProductName = "美国经济派送"; |
||||
ok.timeLimit = "2-8 工作日"; |
||||
ok.weight = 1.0; |
||||
ok.currencyCode = "USD"; |
||||
ok.estimatedPrice = 5.315; |
||||
ok.detailList = java.util.Arrays.asList(freight, check); |
||||
ok.errorCode = "SUCCESS"; |
||||
|
||||
EdayunFeeEstimateDtos.EstimateItem fail = new EdayunFeeEstimateDtos.EstimateItem(); |
||||
fail.logisticProductId = "82"; |
||||
fail.logisticProductName = "美国标准派送"; |
||||
fail.errorMessage = "不支持派送"; |
||||
|
||||
EdayunFeeEstimateDtos.TrialData data = new EdayunFeeEstimateDtos.TrialData(); |
||||
data.successItems = java.util.Collections.singletonList(ok); |
||||
data.failItems = java.util.Collections.singletonList(fail); |
||||
data.showError = Boolean.FALSE; |
||||
|
||||
EdayunFeeEstimateDtos.TrialResponse resp = new EdayunFeeEstimateDtos.TrialResponse(); |
||||
resp.code = 200; |
||||
resp.msg = "操作成功"; |
||||
resp.data = data; |
||||
return resp; |
||||
} |
||||
|
||||
@Test |
||||
void mapsSuccessItemsToQuotes() { |
||||
FeeEstimateResult result = EdayunFeeEstimateMapper.toResult(response(), "EDY-WH"); |
||||
|
||||
assertEquals(1, result.carriers().size()); |
||||
FeeEstimateResult.CarrierQuote quote = result.carriers().get(0); |
||||
assertEquals("美国经济派送", quote.carrier()); |
||||
assertEquals("80", quote.logisticsServiceCode()); |
||||
assertEquals(new BigDecimal("5.315"), quote.totalRate().amount()); |
||||
assertEquals("USD", quote.totalRate().currencyCode()); |
||||
assertEquals(2, quote.costItems().size()); |
||||
assertEquals("尾程配送费", quote.costItems().get(0).costName()); |
||||
assertEquals(new BigDecimal("3.315"), quote.costItems().get(0).estimatedCost().amount()); |
||||
} |
||||
|
||||
/** 失败渠道不进结果——它们没有任何金额,混进去就是假渠道。 */ |
||||
@Test |
||||
void failItemsAreDropped() { |
||||
FeeEstimateResult result = EdayunFeeEstimateMapper.toResult(response(), "W"); |
||||
|
||||
assertEquals(1, result.carriers().size()); |
||||
for (FeeEstimateResult.CarrierQuote q : result.carriers()) { |
||||
assertTrue(!"美国标准派送".equals(q.carrier())); |
||||
} |
||||
} |
||||
|
||||
/** 全部失败时返回空渠道列表,不抛异常(能力接口约定:表示该仓无法承运)。 */ |
||||
@Test |
||||
void allFailedYieldsEmptyCarriers() { |
||||
EdayunFeeEstimateDtos.TrialResponse resp = response(); |
||||
resp.data.successItems = java.util.Collections.emptyList(); |
||||
resp.data.showError = Boolean.TRUE; |
||||
resp.data.errorInfo = "没有物流产品符合预估!"; |
||||
|
||||
FeeEstimateResult result = EdayunFeeEstimateMapper.toResult(resp, "W"); |
||||
|
||||
assertTrue(result.carriers().isEmpty()); |
||||
assertEquals("W", result.shipOrgWarehouseCode()); |
||||
} |
||||
|
||||
@Test |
||||
void handlesNullData() { |
||||
EdayunFeeEstimateDtos.TrialResponse resp = new EdayunFeeEstimateDtos.TrialResponse(); |
||||
|
||||
List<FeeEstimateResult.CarrierQuote> carriers = |
||||
EdayunFeeEstimateMapper.toResult(resp, "W").carriers(); |
||||
|
||||
assertTrue(carriers.isEmpty()); |
||||
} |
||||
|
||||
/** 币种缺失时回退 USD;明细自己的币种优先。 */ |
||||
@Test |
||||
void currencyFallsBackPerLevel() { |
||||
EdayunFeeEstimateDtos.TrialResponse resp = response(); |
||||
resp.data.successItems.get(0).currencyCode = null; |
||||
resp.data.successItems.get(0).detailList.get(0).currencyCode = "GBP"; |
||||
|
||||
FeeEstimateResult.CarrierQuote quote = |
||||
EdayunFeeEstimateMapper.toResult(resp, "W").carriers().get(0); |
||||
|
||||
assertEquals("USD", quote.totalRate().currencyCode()); |
||||
assertEquals("GBP", quote.costItems().get(0).estimatedCost().currencyCode()); |
||||
} |
||||
|
||||
/** 能力位要声明 FEE_ESTIMATE,否则门面直接拒绝。 */ |
||||
@Test |
||||
void estimateCapabilityDeclared() { |
||||
assertTrue(new common.ecommerce.edayun.adapter.EdayunAdapter( |
||||
common.ecommerce.shared.testkit.RecordingTransport.create(), |
||||
new common.ecommerce.http.JacksonJsonCodec()) |
||||
.capabilities().contains(WarehouseCapability.FEE_ESTIMATE)); |
||||
} |
||||
} |
||||
@ -0,0 +1,173 @@
@@ -0,0 +1,173 @@
|
||||
package common.ecommerce.edayun.adapter; |
||||
|
||||
import common.ecommerce.edayun.dto.EdayunInboundQueryDtos; |
||||
import common.ecommerce.edayun.enums.EdayunInboundSkuStatus; |
||||
import common.ecommerce.shared.support.Page; |
||||
import common.ecommerce.warehouse.enums.InboundStatus; |
||||
import common.ecommerce.warehouse.model.InboundOrder; |
||||
import common.ecommerce.warehouse.model.InboundOrderLine; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.Collections; |
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
import static org.junit.jupiter.api.Assertions.assertNull; |
||||
import static org.junit.jupiter.api.Assertions.assertThrows; |
||||
import static org.junit.jupiter.api.Assertions.assertTrue; |
||||
|
||||
/** |
||||
* 入库明细查询({@code selectEntrySkuGoodsDetail})映射。 |
||||
* |
||||
* <p>重点:只认 entryCode、单头状态由 SKU 状态汇总、状态码表未确认时的中文名兜底。</p> |
||||
*/ |
||||
class EdayunInboundQueryTest { |
||||
|
||||
private static EdayunInboundQueryDtos.EntrySkuRow row(String sku, int forecast, |
||||
int checked, int shelves, |
||||
Integer status, String statusName) { |
||||
EdayunInboundQueryDtos.EntrySkuRow row = new EdayunInboundQueryDtos.EntrySkuRow(); |
||||
row.skuCode = sku; |
||||
row.skuName = "候杰测试" + sku; |
||||
row.forecastQuantity = forecast; |
||||
row.actualCheckedQuantity = checked; |
||||
row.shelvesQuantity = shelves; |
||||
row.status = status; |
||||
row.statusName = statusName; |
||||
row.entryCode = "REV24050738176"; |
||||
row.forecastWeight = 12100.0; |
||||
row.firstWeight = 12.1; |
||||
row.forecastCargoSize = "115.3*79.8*36"; |
||||
return row; |
||||
} |
||||
|
||||
// ------------------------------------------------------------ 请求
|
||||
|
||||
@Test |
||||
void mapsEntryCodeAndPaging() { |
||||
EdayunInboundQueryDtos.SelectEntrySkuRequest req = |
||||
EdayunInboundQueryMapper.toRequest("REV24050738176", 1); |
||||
|
||||
assertEquals("REV24050738176", req.entryCode); |
||||
assertEquals(Integer.valueOf(1), req.pageNum); |
||||
assertEquals(Integer.valueOf(200), req.pageSize); |
||||
} |
||||
|
||||
/** 接口只能按仓侧 entryCode 查,没有单号就别发。 */ |
||||
@Test |
||||
void blankEntryCodeIsRejected() { |
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||
() -> EdayunInboundQueryMapper.toRequest(" ", 1)); |
||||
|
||||
assertTrue(ex.getMessage().contains("entryCode"), ex.getMessage()); |
||||
} |
||||
|
||||
// ------------------------------------------------------------ 状态
|
||||
|
||||
/** 码 4 = 已上架(文档示例)。 */ |
||||
@Test |
||||
void code4IsCompleted() { |
||||
assertEquals(InboundStatus.COMPLETED, |
||||
EdayunInboundSkuStatus.toCore(4, "已上架")); |
||||
} |
||||
|
||||
/** 码表未给的部分按中文名兜底。 */ |
||||
@Test |
||||
void unknownCodeFallsBackToChineseName() { |
||||
assertEquals(InboundStatus.RECEIVING, EdayunInboundSkuStatus.toCore(99, "清点中")); |
||||
assertEquals(InboundStatus.IN_TRANSIT, EdayunInboundSkuStatus.toCore(99, "在途")); |
||||
assertEquals(InboundStatus.STORING, EdayunInboundSkuStatus.toCore(99, "上架中")); |
||||
assertEquals(InboundStatus.CANCELLED, EdayunInboundSkuStatus.toCore(99, "已取消")); |
||||
} |
||||
|
||||
/** 认不出就是 UNKNOWN,不猜。 */ |
||||
@Test |
||||
void unrecognizedStatusIsUnknown() { |
||||
assertEquals(InboundStatus.UNKNOWN, EdayunInboundSkuStatus.toCore(77, null)); |
||||
assertEquals(InboundStatus.UNKNOWN, EdayunInboundSkuStatus.toCore(null, "莫名其妙")); |
||||
assertNull(EdayunInboundSkuStatus.UNKNOWN.rawCode()); |
||||
} |
||||
|
||||
// ------------------------------------------------------------ 汇总
|
||||
|
||||
/** 还有 SKU 没上架,整单不算完成。 */ |
||||
@Test |
||||
void headStatusTakesLeastAdvancedSku() { |
||||
InboundOrder order = EdayunInboundQueryMapper.toOrder("REV1", Arrays.asList( |
||||
row("SKU-A", 10, 10, 10, 4, "已上架"), |
||||
row("SKU-B", 5, 5, 0, 99, "清点中")), "EDY-WH"); |
||||
|
||||
assertEquals(InboundStatus.RECEIVING, order.status()); |
||||
assertEquals("已上架", order.rawStatus()); |
||||
} |
||||
|
||||
/** 全部认不出 → UNKNOWN,不能当成完成。 */ |
||||
@Test |
||||
void allUnknownStatusStaysUnknown() { |
||||
InboundOrder order = EdayunInboundQueryMapper.toOrder("REV1", |
||||
Collections.singletonList(row("SKU-A", 1, 1, 1, 77, null)), "EDY-WH"); |
||||
|
||||
assertEquals(InboundStatus.UNKNOWN, order.status()); |
||||
} |
||||
|
||||
// ------------------------------------------------------------ 映射
|
||||
|
||||
@Test |
||||
void mapsQuantitiesAndLines() { |
||||
InboundOrder order = EdayunInboundQueryMapper.toOrder("REV1", Arrays.asList( |
||||
row("SKU-A", 10, 9, 8, 4, "已上架"), |
||||
row("SKU-B", 5, 5, 5, 4, "已上架")), "EDY-WH"); |
||||
|
||||
assertEquals("REV1", order.inboundRequestNo()); |
||||
assertEquals("REV1", order.providerInboundId()); |
||||
assertEquals("EDY-WH", order.warehouseCode()); |
||||
assertEquals(15, order.plannedQuantity()); |
||||
assertEquals(13, order.receivedQuantity()); |
||||
assertEquals(2, order.boxCount()); |
||||
assertEquals(2, order.lines().size()); |
||||
|
||||
InboundOrderLine line = order.lines().get(0); |
||||
assertEquals("SKU-A", line.providerSku()); |
||||
assertEquals(10, line.plannedQuantity()); |
||||
assertEquals(9, line.packedQuantity()); |
||||
assertEquals(8, line.receivedQuantity()); |
||||
assertTrue(!line.quantityMatchesPlan()); |
||||
assertEquals("候杰测试SKU-A", line.productName()); |
||||
} |
||||
|
||||
/** 没有 SKU 的行不计入明细,但数量照算——否则总数会悄悄变少。 */ |
||||
@Test |
||||
void rowsWithoutSkuAreSkippedButCounted() { |
||||
InboundOrder order = EdayunInboundQueryMapper.toOrder("REV1", Arrays.asList( |
||||
row(null, 3, 3, 3, 4, "已上架"), |
||||
row("SKU-B", 5, 5, 5, 4, "已上架")), "EDY-WH"); |
||||
|
||||
assertEquals(1, order.lines().size()); |
||||
assertEquals(8, order.plannedQuantity()); |
||||
} |
||||
|
||||
// ------------------------------------------------------------ 分页
|
||||
|
||||
@Test |
||||
void pageCarriesNextCursorWhenFull() { |
||||
Page<InboundOrder> page = EdayunInboundQueryMapper.toPage("REV1", |
||||
java.util.Collections.nCopies(200, row("SKU", 1, 1, 1, 4, "已上架")), |
||||
"EDY-WH", 1, 200); |
||||
|
||||
assertEquals(1, page.size()); |
||||
assertEquals("2", page.nextCursor()); |
||||
assertTrue(page.hasMore()); |
||||
} |
||||
|
||||
@Test |
||||
void emptyRowsYieldEmptyPage() { |
||||
assertTrue(EdayunInboundQueryMapper.toPage("REV1", null, "EDY-WH", 1, 200).items().isEmpty()); |
||||
} |
||||
|
||||
@Test |
||||
void cursorParsing() { |
||||
assertEquals(1, EdayunInboundQueryMapper.pageNumber(null)); |
||||
assertEquals(1, EdayunInboundQueryMapper.pageNumber("abc")); |
||||
assertEquals(3, EdayunInboundQueryMapper.pageNumber("3")); |
||||
} |
||||
} |
||||
@ -0,0 +1,168 @@
@@ -0,0 +1,168 @@
|
||||
package common.ecommerce.edayun.adapter; |
||||
|
||||
import common.ecommerce.edayun.dto.EdayunInboundDtos; |
||||
import common.ecommerce.warehouse.model.InboundCarton; |
||||
import common.ecommerce.warehouse.model.InboundCommand; |
||||
import common.ecommerce.warehouse.model.InboundLine; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.time.LocalDate; |
||||
import java.util.List; |
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
import static org.junit.jupiter.api.Assertions.assertNull; |
||||
import static org.junit.jupiter.api.Assertions.assertThrows; |
||||
import static org.junit.jupiter.api.Assertions.assertTrue; |
||||
|
||||
/** |
||||
* 自发入库单({@code saveEntrySpontaneousOrder})映射。 |
||||
* |
||||
* <p>重点:saveType 语义、一箱多 SKU 按 sid 归并、重量 g→kg、缺箱规本地拒绝。</p> |
||||
*/ |
||||
class EdayunInboundTest { |
||||
|
||||
private static InboundCommand.Builder cmd() { |
||||
return InboundCommand.builder() |
||||
.inboundRequestNo("PO-2026-001") |
||||
.warehouseId("2") |
||||
.predictionShipDate(LocalDate.of(2026, 12, 1)) |
||||
.estimateArriveDate(LocalDate.of(2026, 12, 20)) |
||||
.line(InboundLine.builder().omsSku("SKU-A").quantity(10).build()); |
||||
} |
||||
|
||||
private static InboundCarton carton(String sku, int qty, String sid) { |
||||
return InboundCarton.builder() |
||||
.providerSku(sku).quantity(qty).cartonNo("BOX-" + sid) |
||||
.sid(sid) |
||||
.lengthCm(50).widthCm(40).heightCm(30) |
||||
.weightGrams(12000) |
||||
.build(); |
||||
} |
||||
|
||||
// ------------------------------------------------------------ 请求
|
||||
|
||||
@Test |
||||
void createSendsPublishAndCustomerOrderNo() { |
||||
EdayunInboundDtos.SaveEntryRequest req = EdayunInboundMapper.toRequest( |
||||
cmd().carton(carton("SKU-A", 10, "1")).build(), |
||||
EdayunInboundMapper.SAVE_PUBLISH, null, null); |
||||
|
||||
assertEquals(Integer.valueOf(2), req.saveType); |
||||
assertEquals("PO-2026-001", req.customerOrderNo); |
||||
// 新建不带 entryCode
|
||||
assertNull(req.entryCode); |
||||
} |
||||
|
||||
/** 更新必须带仓侧 entryCode,否则会变成「新建」把单子建重复。 */ |
||||
@Test |
||||
void updateRequiresEntryCode() { |
||||
InboundCommand command = cmd().carton(carton("SKU-A", 10, "1")).build(); |
||||
|
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||
() -> EdayunInboundMapper.toRequest(command, |
||||
EdayunInboundMapper.SAVE_UPDATE, null, null)); |
||||
assertTrue(ex.getMessage().contains("entryCode"), ex.getMessage()); |
||||
|
||||
EdayunInboundDtos.SaveEntryRequest req = EdayunInboundMapper.toRequest( |
||||
command, EdayunInboundMapper.SAVE_UPDATE, "REV25052032239", null); |
||||
assertEquals("REV25052032239", req.entryCode); |
||||
} |
||||
|
||||
/** 客户单号上限 30,超了本地拒绝而不是让仓方截断。 */ |
||||
@Test |
||||
void tooLongCustomerOrderNoIsRejected() { |
||||
StringBuilder tooLong = new StringBuilder(); |
||||
for (int i = 0; i < 31; i++) { |
||||
tooLong.append('X'); |
||||
} |
||||
InboundCommand command = InboundCommand.builder() |
||||
.inboundRequestNo(tooLong.toString()) |
||||
.carton(carton("SKU-A", 1, "1")) |
||||
.build(); |
||||
|
||||
assertThrows(IllegalArgumentException.class, |
||||
() -> EdayunInboundMapper.toRequest(command, EdayunInboundMapper.SAVE_PUBLISH, null, null)); |
||||
} |
||||
|
||||
/** 数字仓 → shelfWarehouseId,非数字 → shelfWarehouseCode。 */ |
||||
@Test |
||||
void warehouseGoesToIdOrCode() { |
||||
EdayunInboundDtos.SaveEntryRequest numeric = EdayunInboundMapper.toRequest( |
||||
cmd().carton(carton("SKU-A", 1, "1")).build(), 2, null, null); |
||||
assertEquals(Long.valueOf(2L), numeric.basicInfo.shelfWarehouseId); |
||||
assertNull(numeric.basicInfo.shelfWarehouseCode); |
||||
|
||||
InboundCommand coded = cmd().warehouseId("USLA").carton(carton("SKU-A", 1, "1")).build(); |
||||
EdayunInboundDtos.SaveEntryRequest code = EdayunInboundMapper.toRequest(coded, 2, null, "USLA"); |
||||
assertEquals("USLA", code.basicInfo.shelfWarehouseCode); |
||||
assertNull(code.basicInfo.shelfWarehouseId); |
||||
} |
||||
|
||||
/** 预计离港 / 到港是毫秒时间戳。 */ |
||||
@Test |
||||
void datesBecomeMillis() { |
||||
EdayunInboundDtos.SaveEntryRequest req = EdayunInboundMapper.toRequest( |
||||
cmd().carton(carton("SKU-A", 1, "1")).build(), 2, null, null); |
||||
|
||||
assertEquals(Long.valueOf(LocalDate.of(2026, 12, 1).atStartOfDay(java.time.ZoneOffset.UTC) |
||||
.toInstant().toEpochMilli()), req.logisticsInfo.estimatedDepartureTime); |
||||
assertEquals(Long.valueOf(LocalDate.of(2026, 12, 20).atStartOfDay(java.time.ZoneOffset.UTC) |
||||
.toInstant().toEpochMilli()), req.logisticsInfo.estimatedArrivalDate); |
||||
} |
||||
|
||||
/** 箱规是 cargoInfos 的唯一来源;没有箱规就拒绝,别编一个箱子。 */ |
||||
@Test |
||||
void missingCartonsAreRejected() { |
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||
() -> EdayunInboundMapper.toRequest(cmd().build(), 2, null, null)); |
||||
|
||||
assertTrue(ex.getMessage().contains("carton"), ex.getMessage()); |
||||
} |
||||
|
||||
// ------------------------------------------------------------ 箱货
|
||||
|
||||
/** 一箱多 SKU:同一 sid 的行归并成一个 cargoInfo,含多条 boxSkuInfoList。 */ |
||||
@Test |
||||
void sameSidBecomesOneBoxWithMultipleSkus() { |
||||
List<EdayunInboundDtos.CargoInfo> cargoInfos = EdayunInboundMapper.toCargoInfos( |
||||
java.util.Arrays.asList(carton("SKU-A", 5, "1"), carton("SKU-B", 3, "1"))); |
||||
|
||||
assertEquals(1, cargoInfos.size()); |
||||
EdayunInboundDtos.CargoInfo box = cargoInfos.get(0); |
||||
assertEquals(2, box.boxSkuInfoList.size()); |
||||
assertEquals("SKU-A", box.boxSkuInfoList.get(0).skuCode); |
||||
assertEquals(Integer.valueOf(3), box.boxSkuInfoList.get(1).skuForecastQuantity); |
||||
} |
||||
|
||||
@Test |
||||
void differentSidsBecomeDifferentBoxes() { |
||||
List<EdayunInboundDtos.CargoInfo> cargoInfos = EdayunInboundMapper.toCargoInfos( |
||||
java.util.Arrays.asList(carton("SKU-A", 5, "1"), carton("SKU-A", 5, "2"))); |
||||
|
||||
assertEquals(2, cargoInfos.size()); |
||||
} |
||||
|
||||
/** 统一模型是克,易达云的箱重按 kg(与创建产品一致)。 */ |
||||
@Test |
||||
void weightIsConvertedToKg() { |
||||
EdayunInboundDtos.CargoInfo box = EdayunInboundMapper.toCargoInfos( |
||||
java.util.Collections.singletonList(carton("SKU-A", 1, "1"))).get(0); |
||||
|
||||
assertEquals(12.0, box.weight, 1e-9); |
||||
assertEquals(50.0, box.boxLength, 1e-9); |
||||
} |
||||
|
||||
/** 尺寸 / 重量为 0 视为未填,不下发(0 会被仓方当成真实尺寸)。 */ |
||||
@Test |
||||
void zeroDimensionsAreOmitted() { |
||||
InboundCarton bare = InboundCarton.builder() |
||||
.providerSku("SKU-A").quantity(1).cartonNo("BOX-1").build(); |
||||
|
||||
EdayunInboundDtos.CargoInfo box = EdayunInboundMapper.toCargoInfos( |
||||
java.util.Collections.singletonList(bare)).get(0); |
||||
|
||||
assertNull(box.boxLength); |
||||
assertNull(box.weight); |
||||
assertEquals("BOX-1", box.outsideBoxCode); |
||||
} |
||||
} |
||||
@ -0,0 +1,198 @@
@@ -0,0 +1,198 @@
|
||||
package common.ecommerce.edayun.adapter; |
||||
|
||||
import common.ecommerce.edayun.dto.EdayunInventoryDtos; |
||||
import common.ecommerce.shared.support.Page; |
||||
import common.ecommerce.warehouse.model.InventoryQuery; |
||||
import common.ecommerce.warehouse.model.InventorySnapshot; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.time.Instant; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.Collections; |
||||
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.assertNull; |
||||
import static org.junit.jupiter.api.Assertions.assertThrows; |
||||
import static org.junit.jupiter.api.Assertions.assertTrue; |
||||
|
||||
/** |
||||
* 库存查询({@code queryInventory})映射。 |
||||
* |
||||
* <p>重点:零库存开关方向相反、仓 id 必须是数字、分页用 total 判断。</p> |
||||
*/ |
||||
class EdayunInventoryTest { |
||||
|
||||
private static final Instant AS_OF = Instant.parse("2026-11-13T00:00:00Z"); |
||||
|
||||
// ------------------------------------------------------------ 请求
|
||||
|
||||
@Test |
||||
void mapsPagingSkuAndWarehouse() { |
||||
EdayunInventoryDtos.QueryInventoryRequest req = EdayunInventoryMapper.toRequest( |
||||
InventoryQuery.builder().sku("ybtest").pageSize(1000).build(), "2", 1); |
||||
|
||||
assertEquals(Integer.valueOf(1), req.pageNum); |
||||
// 上限 500
|
||||
assertEquals(Integer.valueOf(500), req.pageSize); |
||||
assertEquals(Collections.singletonList("ybtest"), req.skuCodeList); |
||||
assertEquals(Collections.singletonList(2L), req.warehouseIdList); |
||||
// 没传零库存开关时不加限制,由仓方默认(只查总库存 > 0)
|
||||
assertNull(req.totalStockGreaterThanZero); |
||||
} |
||||
|
||||
/** 统一模型是「包含零库存」,仓方是「只查大于 0」,方向相反。 */ |
||||
@Test |
||||
void includeZeroStockIsInverted() { |
||||
EdayunInventoryDtos.QueryInventoryRequest yes = EdayunInventoryMapper.toRequest( |
||||
InventoryQuery.builder().includeZeroStock(true).build(), null, 1); |
||||
EdayunInventoryDtos.QueryInventoryRequest no = EdayunInventoryMapper.toRequest( |
||||
InventoryQuery.builder().includeZeroStock(false).build(), null, 1); |
||||
|
||||
assertEquals(Boolean.FALSE, yes.totalStockGreaterThanZero); |
||||
assertEquals(Boolean.TRUE, no.totalStockGreaterThanZero); |
||||
} |
||||
|
||||
/** 每页默认 100。 */ |
||||
@Test |
||||
void pageSizeDefaultsTo100() { |
||||
assertEquals(Integer.valueOf(100), EdayunInventoryMapper.toRequest( |
||||
InventoryQuery.builder().build(), null, 1).pageSize); |
||||
} |
||||
|
||||
@Test |
||||
void moreThan100SkusIsRejected() { |
||||
List<String> skus = new ArrayList<String>(); |
||||
for (int i = 0; i < 101; i++) { |
||||
skus.add("SKU-" + i); |
||||
} |
||||
|
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||
() -> EdayunInventoryMapper.toRequest( |
||||
InventoryQuery.builder().skus(skus).build(), null, 1)); |
||||
|
||||
assertTrue(ex.getMessage().contains("at most 100"), ex.getMessage()); |
||||
} |
||||
|
||||
/** 仓 id 非数字直接拒绝,避免仓侧静默查不到。 */ |
||||
@Test |
||||
void nonNumericWarehouseIdIsRejected() { |
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||
() -> EdayunInventoryMapper.toRequest( |
||||
InventoryQuery.builder().build(), "EDY-WH-1", 1)); |
||||
|
||||
assertTrue(ex.getMessage().contains("must be numeric"), ex.getMessage()); |
||||
} |
||||
|
||||
// ------------------------------------------------------------ 响应
|
||||
|
||||
private static EdayunInventoryDtos.InventoryRow row() { |
||||
EdayunInventoryDtos.InventoryRow row = new EdayunInventoryDtos.InventoryRow(); |
||||
row.skuCode = "ybtest"; |
||||
row.barcode = "N94900194952"; |
||||
row.skuName = "苹果15"; |
||||
row.totalStock = 10; |
||||
row.stock = 4; |
||||
row.frozenStock = 1; |
||||
row.toDeliverStock = 2; |
||||
row.safeStock = 5; |
||||
row.nonSaleStock = 3; |
||||
row.inTransitStock = 20; |
||||
row.warehouseId = 2L; |
||||
row.warehouseCode = "USLA"; |
||||
return row; |
||||
} |
||||
|
||||
private static EdayunInventoryDtos.QueryInventoryResponse response( |
||||
Long total, EdayunInventoryDtos.InventoryRow... rows) { |
||||
EdayunInventoryDtos.QueryInventoryResponse r = |
||||
new EdayunInventoryDtos.QueryInventoryResponse(); |
||||
r.total = total; |
||||
r.rows = Arrays.asList(rows); |
||||
return r; |
||||
} |
||||
|
||||
@Test |
||||
void mapsRowToSnapshot() { |
||||
Page<InventorySnapshot> page = EdayunInventoryMapper.toPage( |
||||
response(1L, row()), "EDY-WH", AS_OF, 1, 100); |
||||
|
||||
assertEquals(1, page.size()); |
||||
InventorySnapshot s = page.items().get(0); |
||||
assertEquals("USLA", s.warehouseCode()); |
||||
assertEquals("ybtest", s.providerSku()); |
||||
assertEquals(4, s.available()); |
||||
assertEquals(10, s.onHand()); |
||||
assertEquals(20, s.inTransit()); |
||||
assertEquals(1, s.reserved()); |
||||
assertEquals(2, s.pendingOutbound()); |
||||
assertEquals(5, s.alertQuantity()); |
||||
assertEquals("苹果15", s.productName()); |
||||
assertEquals(AS_OF, s.asOfUtc()); |
||||
// 该接口不区分可售 / 不可售库位,统一按可售
|
||||
assertEquals(0, s.inventoryType()); |
||||
assertTrue(s.sellable()); |
||||
} |
||||
|
||||
/** 仓编码缺失时回退 OMS 仓编码,快照必须有 warehouseCode。 */ |
||||
@Test |
||||
void warehouseCodeFallsBack() { |
||||
EdayunInventoryDtos.InventoryRow r = row(); |
||||
r.warehouseCode = null; |
||||
|
||||
assertEquals("EDY-WH", EdayunInventoryMapper.toPage( |
||||
response(1L, r), "EDY-WH", AS_OF, 1, 100) |
||||
.items().get(0).warehouseCode()); |
||||
} |
||||
|
||||
/** 没有 SKU 的行跳过,不应让整页失败。 */ |
||||
@Test |
||||
void rowsWithoutSkuAreSkipped() { |
||||
EdayunInventoryDtos.InventoryRow dirty = row(); |
||||
dirty.skuCode = " "; |
||||
|
||||
Page<InventorySnapshot> page = EdayunInventoryMapper.toPage( |
||||
response(2L, dirty, row()), "EDY-WH", AS_OF, 1, 100); |
||||
|
||||
assertEquals(1, page.size()); |
||||
} |
||||
|
||||
@Test |
||||
void emptyRowsYieldEmptyPage() { |
||||
assertTrue(EdayunInventoryMapper.toPage(null, "EDY-WH", AS_OF, 1, 100).items().isEmpty()); |
||||
assertTrue(EdayunInventoryMapper.toPage( |
||||
response(0L), "EDY-WH", AS_OF, 1, 100).items().isEmpty()); |
||||
} |
||||
|
||||
// ------------------------------------------------------------ 分页
|
||||
|
||||
@Test |
||||
void nextCursorUsesTotal() { |
||||
assertEquals("2", EdayunInventoryMapper.nextCursor(200L, 1, 100, 100)); |
||||
assertNull(EdayunInventoryMapper.nextCursor(200L, 2, 100, 100)); |
||||
} |
||||
|
||||
/** total 缺失时按本页是否满页判断。 */ |
||||
@Test |
||||
void nextCursorFallsBackToFullPage() { |
||||
assertEquals("2", EdayunInventoryMapper.nextCursor(null, 1, 100, 100)); |
||||
assertNull(EdayunInventoryMapper.nextCursor(null, 1, 100, 99)); |
||||
} |
||||
|
||||
@Test |
||||
void cursorParsing() { |
||||
assertEquals(1, EdayunInventoryMapper.pageNumber(null)); |
||||
assertEquals(1, EdayunInventoryMapper.pageNumber("abc")); |
||||
assertEquals(3, EdayunInventoryMapper.pageNumber("3")); |
||||
} |
||||
|
||||
@Test |
||||
void hasMoreMatchesCursor() { |
||||
assertTrue(EdayunInventoryMapper.toPage( |
||||
response(200L, row()), "W", AS_OF, 1, 1).hasMore()); |
||||
assertFalse(EdayunInventoryMapper.toPage( |
||||
response(1L, row()), "W", AS_OF, 1, 100).hasMore()); |
||||
} |
||||
} |
||||
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
package common.ecommerce.edayun.adapter; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.time.Instant; |
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows; |
||||
import static org.junit.jupiter.api.Assertions.assertTrue; |
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
||||
|
||||
/** |
||||
* 时间窗守卫。 |
||||
* |
||||
* <p>边界取自 PR 环境真机实测(2026-11-13):6/1~10/1 仓方接受、 |
||||
* 6/1~11/1 仓方拒绝。本地只挡明显超限,不误伤仓方接受的窗口。</p> |
||||
*/ |
||||
class EdayunQueryWindowsTest { |
||||
|
||||
private static final int MONTHS = 3; |
||||
|
||||
private static void check(String start, String end) { |
||||
EdayunQueryWindows.requireWithinMonths(Instant.parse(start), Instant.parse(end), |
||||
MONTHS, "rent detail"); |
||||
} |
||||
|
||||
/** 恰好 3 个自然月。 */ |
||||
@Test |
||||
void exactlyThreeMonthsIsAccepted() { |
||||
assertDoesNotThrow(() -> check("2026-06-01T00:00:00Z", "2026-09-01T00:00:00Z")); |
||||
} |
||||
|
||||
/** 真机实测仓方接受的 4 个月窗口不能被本地挡住。 */ |
||||
@Test |
||||
void windowProviderAcceptsIsNotBlocked() { |
||||
assertDoesNotThrow(() -> check("2026-06-01T00:00:00Z", "2026-10-01T00:00:00Z")); |
||||
assertDoesNotThrow(() -> check("2026-07-02T00:00:00Z", "2026-10-31T00:00:00Z")); |
||||
} |
||||
|
||||
/** 真机实测仓方拒绝的窗口,本地也挡。 */ |
||||
@Test |
||||
void obviouslyTooLongIsRejected() { |
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||
() -> check("2026-06-01T00:00:00Z", "2026-11-01T00:00:00Z")); |
||||
assertTrue(ex.getMessage().contains("3 months"), ex.getMessage()); |
||||
assertTrue(ex.getMessage().contains("2026-06-01"), ex.getMessage()); |
||||
} |
||||
|
||||
/** 拉一年这种明显错误必须本地挡掉,不发请求。 */ |
||||
@Test |
||||
void oneYearIsRejected() { |
||||
assertThrows(IllegalArgumentException.class, |
||||
() -> check("2026-01-01T00:00:00Z", "2027-01-01T00:00:00Z")); |
||||
} |
||||
|
||||
/** 时间窗由 FeeQuery 保证 start <= end,这里再兜一层不抛意外异常。 */ |
||||
@Test |
||||
void sameInstantIsAccepted() { |
||||
assertDoesNotThrow(() -> check("2026-06-01T00:00:00Z", "2026-06-01T00:00:00Z")); |
||||
} |
||||
} |
||||
@ -0,0 +1,235 @@
@@ -0,0 +1,235 @@
|
||||
package common.ecommerce.edayun.adapter; |
||||
|
||||
import common.ecommerce.edayun.dto.EdayunRentDetailDtos; |
||||
import common.ecommerce.warehouse.enums.WarehouseFeeType; |
||||
import common.ecommerce.warehouse.model.BillingDocument; |
||||
import common.ecommerce.warehouse.model.FeeQuery; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.time.Instant; |
||||
import java.util.List; |
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
import static org.junit.jupiter.api.Assertions.assertNull; |
||||
import static org.junit.jupiter.api.Assertions.assertThrows; |
||||
import static org.junit.jupiter.api.Assertions.assertTrue; |
||||
|
||||
/** |
||||
* 仓租费用明细({@code selectUserRentDetailList})映射。 |
||||
* |
||||
* <p>重点:时间窗必填且 ≤3 个月、仓 id 必须是数字、金额取 rentPrice、 |
||||
* 费用类型固定 STORAGE。</p> |
||||
*/ |
||||
class EdayunRentDetailTest { |
||||
|
||||
private static final Instant JAN_1 = Instant.parse("2026-01-01T00:00:00Z"); |
||||
private static final Instant FEB_15 = Instant.parse("2026-02-15T00:00:00Z"); |
||||
|
||||
private static FeeQuery.Builder range() { |
||||
return FeeQuery.builder().settledAfter(JAN_1).settledBefore(FEB_15); |
||||
} |
||||
|
||||
// ------------------------------------------------------------ 请求
|
||||
|
||||
@Test |
||||
void mapsTimeWindowAndWarehouseId() { |
||||
EdayunRentDetailDtos.SelectRentDetailRequest req = |
||||
EdayunRentDetailMapper.toRequest(range().build(), "98"); |
||||
|
||||
assertEquals(Long.valueOf(JAN_1.toEpochMilli()), req.billDateBegin); |
||||
assertEquals(Long.valueOf(FEB_15.toEpochMilli()), req.billDateEnd); |
||||
assertEquals(1, req.warehouseIds.size()); |
||||
assertEquals(Long.valueOf(98L), req.warehouseIds.get(0)); |
||||
assertEquals(Integer.valueOf(1), req.pageNum); |
||||
assertEquals(Integer.valueOf(200), req.pageSize); |
||||
} |
||||
|
||||
/** 仓租没有按单号单独查的口径:没时间窗直接拒绝。 */ |
||||
@Test |
||||
void withoutTimeRangeIsRejected() { |
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||
() -> EdayunRentDetailMapper.toRequest( |
||||
FeeQuery.builder().externalOrderNo("98-N9490-20260928").build(), "98")); |
||||
|
||||
assertTrue(ex.getMessage().contains("billing time range"), ex.getMessage()); |
||||
} |
||||
|
||||
/** 文档写明最大查询 3 个月。 */ |
||||
@Test |
||||
void rangeOver3MonthsIsRejected() { |
||||
FeeQuery tooLong = FeeQuery.builder() |
||||
.settledAfter(JAN_1) |
||||
.settledBefore(Instant.parse("2026-06-01T00:00:00Z")) |
||||
.build(); |
||||
|
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||
() -> EdayunRentDetailMapper.toRequest(tooLong, "98")); |
||||
|
||||
assertTrue(ex.getMessage().contains("3 months"), ex.getMessage()); |
||||
} |
||||
|
||||
/** 本接口只出仓租,明确要别的费用类型说明用错了接口。 */ |
||||
@Test |
||||
void nonStorageCostTypeIsRejected() { |
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||
() -> EdayunRentDetailMapper.toRequest( |
||||
range().costType(WarehouseFeeType.LAST_MILE).build(), "98")); |
||||
|
||||
assertTrue(ex.getMessage().contains("only returns STORAGE"), ex.getMessage()); |
||||
} |
||||
|
||||
/** 快照日期是运去哪的口径,易达云按计费时间窗查。 */ |
||||
@Test |
||||
void snapshotDateRangeIsRejected() { |
||||
FeeQuery q = FeeQuery.builder() |
||||
.snapshotDateRange(java.time.LocalDate.of(2026, 1, 1), |
||||
java.time.LocalDate.of(2026, 1, 31)) |
||||
.settledAfter(JAN_1).settledBefore(FEB_15) |
||||
.build(); |
||||
|
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||
() -> EdayunRentDetailMapper.toRequest(q, "98")); |
||||
|
||||
assertTrue(ex.getMessage().contains("settledAfter"), ex.getMessage()); |
||||
} |
||||
|
||||
@Test |
||||
void filtersMapToSingletonLists() { |
||||
EdayunRentDetailDtos.SelectRentDetailRequest req = EdayunRentDetailMapper.toRequest( |
||||
range().externalOrderNo("98-N9490-20260928").providerSku("CANADA-TEST").build(), null); |
||||
|
||||
assertEquals(java.util.Collections.singletonList("98-N9490-20260928"), req.businessNums); |
||||
assertEquals(java.util.Collections.singletonList("CANADA-TEST"), req.skuCodes); |
||||
// 仓 id 未知时不下发,避免空数组被仓方当成「查所有仓」
|
||||
assertNull(req.warehouseIds); |
||||
} |
||||
|
||||
/** 仓 id 非数字直接拒绝,避免仓侧静默查不到。 */ |
||||
@Test |
||||
void nonNumericWarehouseIdIsRejected() { |
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
||||
() -> EdayunRentDetailMapper.toRequest(range().build(), "EDY-WH-1")); |
||||
|
||||
assertTrue(ex.getMessage().contains("must be numeric"), ex.getMessage()); |
||||
} |
||||
|
||||
// ------------------------------------------------------------ 响应
|
||||
|
||||
private static EdayunRentDetailDtos.RentDetailRow row() { |
||||
EdayunRentDetailDtos.RentDetailRow row = new EdayunRentDetailDtos.RentDetailRow(); |
||||
row.businessNum = "98-N9490-20260928"; |
||||
row.billingDate = 1790568000000L; |
||||
row.warehouseId = "98"; |
||||
row.warehouseName = "加西3仓"; |
||||
row.skuCode = "CANADA-TEST"; |
||||
row.orderNo = "RLB0011790104"; |
||||
row.rentDays = 1021; |
||||
row.totalStock = 7; |
||||
row.billingVol = 6.7; |
||||
row.billingVolUnit = "CBFT"; |
||||
row.billingId = 1679667136799649000L; |
||||
row.billingName = "仓租"; |
||||
row.unitPrice = 0.34; |
||||
row.originalPrice = 2.278; |
||||
row.discountPrice = 0.0; |
||||
row.currencyCode = "CAD"; |
||||
row.rentPrice = 2.278; |
||||
return row; |
||||
} |
||||
|
||||
@Test |
||||
void mapsRowToDocument() { |
||||
BillingDocument doc = EdayunRentDetailMapper.toDocument(row(), "EDY-WH"); |
||||
|
||||
assertEquals("加西3仓", doc.warehouseCode()); |
||||
assertEquals("98-N9490-20260928", doc.documentNo()); |
||||
assertEquals("1679667136799649000", doc.serialNumber()); |
||||
assertEquals("仓租", doc.feeName()); |
||||
assertEquals(WarehouseFeeType.STORAGE, doc.feeType()); |
||||
assertEquals(Instant.ofEpochMilli(1790568000000L), doc.settledAt()); |
||||
assertEquals("RLB0011790104", doc.saleOrderNo()); |
||||
assertEquals("CANADA-TEST", doc.providerSku()); |
||||
assertEquals(Boolean.FALSE, doc.estimated()); |
||||
} |
||||
|
||||
/** 金额取 rentPrice,币种按原值(可能是 CAD 等非 USD)。 */ |
||||
@Test |
||||
void amountIsRentPriceWithOriginalCurrency() { |
||||
BillingDocument doc = EdayunRentDetailMapper.toDocument(row(), "W"); |
||||
|
||||
assertEquals(new BigDecimal("2.278"), doc.amount().amount()); |
||||
assertEquals("CAD", doc.amount().currencyCode()); |
||||
} |
||||
|
||||
/** rentPrice 缺失时用原价减折扣兜底。 */ |
||||
@Test |
||||
void fallsBackToOriginalMinusDiscount() { |
||||
EdayunRentDetailDtos.RentDetailRow r = row(); |
||||
r.rentPrice = null; |
||||
r.originalPrice = 10.0; |
||||
r.discountPrice = 1.5; |
||||
|
||||
assertEquals(new BigDecimal("8.5"), |
||||
EdayunRentDetailMapper.toDocument(r, "W").amount().amount()); |
||||
} |
||||
|
||||
/** 全缺时记零,不抛异常——仓租明细缺金额不该阻断整批。 */ |
||||
@Test |
||||
void missingAmountYieldsZero() { |
||||
EdayunRentDetailDtos.RentDetailRow r = row(); |
||||
r.rentPrice = null; |
||||
r.originalPrice = null; |
||||
r.discountPrice = null; |
||||
|
||||
assertEquals(BigDecimal.ZERO, |
||||
EdayunRentDetailMapper.toDocument(r, "W").amount().amount()); |
||||
} |
||||
|
||||
/** 仓名缺失时回退 OMS 仓编码,warehouseCode 不能为空。 */ |
||||
@Test |
||||
void warehouseNameFallsBackToCode() { |
||||
EdayunRentDetailDtos.RentDetailRow r = row(); |
||||
r.warehouseName = null; |
||||
|
||||
assertEquals("EDY-WH", EdayunRentDetailMapper.toDocument(r, "EDY-WH").warehouseCode()); |
||||
} |
||||
|
||||
/** 业务单号缺失时用订单号当单据号。 */ |
||||
@Test |
||||
void documentNoFallsBackToOrderNo() { |
||||
EdayunRentDetailDtos.RentDetailRow r = row(); |
||||
r.businessNum = null; |
||||
|
||||
assertEquals("RLB0011790104", |
||||
EdayunRentDetailMapper.toDocument(r, "W").documentNo()); |
||||
} |
||||
|
||||
/** 计费时间和 billingId 都可能缺;缺时不能抛异常。 */ |
||||
@Test |
||||
void missingBillingDateAndIdAreTolerated() { |
||||
EdayunRentDetailDtos.RentDetailRow r = row(); |
||||
r.billingDate = null; |
||||
r.billingId = null; |
||||
|
||||
BillingDocument doc = EdayunRentDetailMapper.toDocument(r, "W"); |
||||
|
||||
assertNull(doc.settledAt()); |
||||
assertNull(doc.serialNumber()); |
||||
} |
||||
|
||||
@Test |
||||
void mapsAllRows() { |
||||
List<BillingDocument> docs = EdayunRentDetailMapper.toDocuments( |
||||
java.util.Arrays.asList(row(), row()), "W"); |
||||
|
||||
assertEquals(2, docs.size()); |
||||
} |
||||
|
||||
@Test |
||||
void emptyRowsYieldEmptyList() { |
||||
assertTrue(EdayunRentDetailMapper.toDocuments(null, "W").isEmpty()); |
||||
assertTrue(EdayunRentDetailMapper.toDocuments( |
||||
java.util.Collections.<EdayunRentDetailDtos.RentDetailRow>emptyList(), "W").isEmpty()); |
||||
} |
||||
} |
||||
@ -0,0 +1,134 @@
@@ -0,0 +1,134 @@
|
||||
package common.ecommerce.edayun.probe; |
||||
|
||||
import common.ecommerce.edayun.EdayunConstants; |
||||
import common.ecommerce.edayun.adapter.EdayunAdapter; |
||||
import common.ecommerce.edayun.adapter.EdayunFeeEstimateMapper; |
||||
import common.ecommerce.edayun.dto.EdayunFeeEstimateDtos; |
||||
import common.ecommerce.http.JacksonJsonCodec; |
||||
import common.ecommerce.http.OkHttpTransport; |
||||
import common.ecommerce.shared.error.ChannelException; |
||||
import common.ecommerce.shared.spi.ChannelSecret; |
||||
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||
import common.ecommerce.warehouse.model.FeeEstimateQuery; |
||||
import common.ecommerce.warehouse.model.FeeEstimateResult; |
||||
import common.ecommerce.warehouse.sdk.WarehouseConnection; |
||||
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||
import org.junit.jupiter.api.Assumptions; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.condition.EnabledIfSystemProperty; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.time.Clock; |
||||
import java.util.List; |
||||
import java.util.UUID; |
||||
|
||||
/** |
||||
* 费用试算联调探针:<b>只读</b>,不会在仓侧产生任何数据。 |
||||
* |
||||
* <p>默认跳过,用 {@code -Dedayun.probe.estimate=true} 开启;凭据走系统属性, |
||||
* <b>真实值不入库</b>:</p> |
||||
* |
||||
* <pre> |
||||
* # 只看报文(不联网) |
||||
* mvn -pl warehouse-sdk-edayun -DfailIfNoTests=false \ |
||||
* -Dedayun.probe.estimate=true -Dtest=EdayunFeeEstimateProbeTest test |
||||
* |
||||
* # 真跑(只读) |
||||
* ... -Dedayun.probe.estimate=true -Dedayun.probe.call=true \ |
||||
* -Dedayun.probe.clientId=... -Dedayun.probe.clientSecret=... \ |
||||
* -Dedayun.probe.appKey=... -Dedayun.probe.appSecret=... \ |
||||
* [-Dedayun.probe.warehouseId=2] [-Dedayun.probe.zipcode=91761] |
||||
* </pre> |
||||
* |
||||
* <p>异常只打印不抛出,便于一次跑完对照真实报文。</p> |
||||
*/ |
||||
@EnabledIfSystemProperty(named = "edayun.probe.estimate", matches = "true") |
||||
class EdayunFeeEstimateProbeTest { |
||||
|
||||
private static final String BASE_URL = opt("edayun.probe.baseUrl", EdayunConstants.PR_BASE_URL); |
||||
private static final String CLIENT_ID = System.getProperty("edayun.probe.clientId", ""); |
||||
private static final String CLIENT_SECRET = System.getProperty("edayun.probe.clientSecret", ""); |
||||
private static final String APP_KEY = System.getProperty("edayun.probe.appKey", ""); |
||||
private static final String APP_SECRET = System.getProperty("edayun.probe.appSecret", ""); |
||||
private static final String WAREHOUSE_ID = opt("edayun.probe.warehouseId", "2"); |
||||
private static final String ZIPCODE = opt("edayun.probe.zipcode", "91761"); |
||||
private static final String PRODUCT_ID = System.getProperty("edayun.probe.productId", ""); |
||||
private static final boolean CALL = Boolean.getBoolean("edayun.probe.call"); |
||||
|
||||
@Test |
||||
void probeEstimate() { |
||||
FeeEstimateQuery.Builder query = FeeEstimateQuery.builder() |
||||
.lengthCm(new BigDecimal("22")) |
||||
.widthCm(new BigDecimal("22")) |
||||
.heightCm(new BigDecimal("22")) |
||||
.weightGrams(new BigDecimal("1000")) |
||||
.receiveCountry(opt("edayun.probe.country", "US")) |
||||
.receivePostal(ZIPCODE) |
||||
// 标准模型强制要求渠道码;易达云没有该概念,非数字会被映射成「不指定」
|
||||
.logisticsServiceCode(PRODUCT_ID.trim().isEmpty() ? "ALL" : PRODUCT_ID.trim()); |
||||
|
||||
EdayunFeeEstimateDtos.TrialRequest req = |
||||
EdayunFeeEstimateMapper.toRequest(query.build(), WAREHOUSE_ID); |
||||
String bodyJson = new JacksonJsonCodec().toJson(req); |
||||
|
||||
System.out.println("\n================ edayun / POST " |
||||
+ EdayunConstants.PATH_FEE_ESTIMATE + " ================"); |
||||
System.out.println("[probe] baseUrl=" + BASE_URL + " warehouseId=" + WAREHOUSE_ID |
||||
+ " zipcode=" + ZIPCODE); |
||||
System.out.println("[request] " + bodyJson); |
||||
if (!APP_SECRET.trim().isEmpty()) { |
||||
System.out.println("[sign] " + common.ecommerce.edayun.http.EdayunRequestFactory |
||||
.sign(bodyJson, APP_SECRET)); |
||||
} |
||||
|
||||
Assumptions.assumeTrue(CALL, "dry-run:未加 -Dedayun.probe.call=true,不实际调用"); |
||||
Assumptions.assumeTrue(!CLIENT_ID.trim().isEmpty() && !CLIENT_SECRET.trim().isEmpty() |
||||
&& !APP_KEY.trim().isEmpty() && !APP_SECRET.trim().isEmpty(), |
||||
"真跑需要 -Dedayun.probe.clientId / clientSecret / appKey / appSecret"); |
||||
|
||||
try { |
||||
WarehouseContext ctx = WarehouseContext.of("EDY-PROBE", WarehouseProvider.EDAYUN, |
||||
WAREHOUSE_ID, WarehouseConnection.of(BASE_URL, |
||||
ChannelSecret.builder() |
||||
.appKey(APP_KEY).appSecret(APP_SECRET) |
||||
.clientId(CLIENT_ID).clientSecret(CLIENT_SECRET) |
||||
.build()), |
||||
"probe-" + UUID.randomUUID(), Clock.systemUTC()); |
||||
EdayunAdapter adapter = new EdayunAdapter( |
||||
new OkHttpTransport("common-ecommerce/1.0.0 (edayun-probe)", 10_000, 120_000), |
||||
new JacksonJsonCodec()); |
||||
|
||||
List<FeeEstimateResult> results = adapter.estimate(ctx, query.build()); |
||||
for (FeeEstimateResult result : results) { |
||||
System.out.println("[OK] warehouse=" + result.shipOrgWarehouseCode() |
||||
+ " carriers=" + result.carriers().size()); |
||||
for (FeeEstimateResult.CarrierQuote quote : result.carriers()) { |
||||
System.out.println(" " + quote.logisticsServiceCode() |
||||
+ " " + quote.carrier() |
||||
+ " total=" + quote.totalRate().amount() |
||||
+ " " + quote.totalRate().currencyCode()); |
||||
for (FeeEstimateResult.CarrierQuote.CostItem item : quote.costItems()) { |
||||
System.out.println(" - " + item.costName() + " " |
||||
+ item.estimatedCost().amount() |
||||
+ " " + item.estimatedCost().currencyCode()); |
||||
} |
||||
} |
||||
} |
||||
} catch (RuntimeException e) { |
||||
String msg = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage(); |
||||
System.out.println("[ERROR] " + e.getClass().getSimpleName() + ": " |
||||
+ (msg.length() <= 800 ? msg : msg.substring(0, 800) + "…")); |
||||
if (e instanceof ChannelException) { |
||||
ChannelException ce = (ChannelException) e; |
||||
System.out.println(" platformCode=" + ce.platformCode() |
||||
+ " retryable=" + ce.retryable()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static String opt(String name, String fallback) { |
||||
String value = System.getProperty(name, ""); |
||||
String trimmed = value == null ? "" : value.trim(); |
||||
return trimmed.isEmpty() ? fallback : trimmed; |
||||
} |
||||
} |
||||
@ -0,0 +1,147 @@
@@ -0,0 +1,147 @@
|
||||
package common.ecommerce.edayun.probe; |
||||
|
||||
import common.ecommerce.edayun.EdayunConstants; |
||||
import common.ecommerce.edayun.adapter.EdayunAdapter; |
||||
import common.ecommerce.edayun.adapter.EdayunInboundMapper; |
||||
import common.ecommerce.edayun.dto.EdayunInboundDtos; |
||||
import common.ecommerce.http.JacksonJsonCodec; |
||||
import common.ecommerce.http.OkHttpTransport; |
||||
import common.ecommerce.shared.error.ChannelException; |
||||
import common.ecommerce.shared.spi.ChannelSecret; |
||||
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||
import common.ecommerce.warehouse.model.InboundCarton; |
||||
import common.ecommerce.warehouse.model.InboundCommand; |
||||
import common.ecommerce.warehouse.model.InboundLine; |
||||
import common.ecommerce.warehouse.model.InboundReceipt; |
||||
import common.ecommerce.warehouse.sdk.WarehouseConnection; |
||||
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||
import org.junit.jupiter.api.Assumptions; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.condition.EnabledIfSystemProperty; |
||||
|
||||
import java.time.LocalDate; |
||||
import java.util.UUID; |
||||
|
||||
/** |
||||
* 自发入库单探针:默认只打印报文,<b>不联网</b>。 |
||||
* |
||||
* <p>创建入库单是<b>写操作</b>,会真实建单,所以真跑要显式加 |
||||
* {@code -Dedayun.probe.write=true};客户单号用 {@code PROBE-} 前缀的时间戳,避免撞车。</p> |
||||
* |
||||
* <pre> |
||||
* # 只看报文(安全) |
||||
* mvn -pl warehouse-sdk-edayun -DfailIfNoTests=false \ |
||||
* -Dedayun.probe.inbound=true -Dtest=EdayunInboundProbeTest test |
||||
* |
||||
* # 真发一次(会在测试仓建入库单) |
||||
* ... -Dedayun.probe.inbound=true -Dedayun.probe.write=true \ |
||||
* -Dedayun.probe.clientId=... -Dedayun.probe.clientSecret=... \ |
||||
* -Dedayun.probe.appKey=... -Dedayun.probe.appSecret=... \ |
||||
* -Dedayun.probe.warehouseId=2 -Dedayun.probe.sku=ybtest |
||||
* </pre> |
||||
* |
||||
* <p>若只想验证「保存不发布」,把 {@code -Dedayun.probe.saveType=0}(新增草稿); |
||||
* 默认 2(保存并发布)。</p> |
||||
*/ |
||||
@EnabledIfSystemProperty(named = "edayun.probe.inbound", matches = "true") |
||||
class EdayunInboundProbeTest { |
||||
|
||||
private static final String BASE_URL = opt("edayun.probe.baseUrl", EdayunConstants.PR_BASE_URL); |
||||
private static final String CLIENT_ID = System.getProperty("edayun.probe.clientId", ""); |
||||
private static final String CLIENT_SECRET = System.getProperty("edayun.probe.clientSecret", ""); |
||||
private static final String APP_KEY = System.getProperty("edayun.probe.appKey", ""); |
||||
private static final String APP_SECRET = System.getProperty("edayun.probe.appSecret", ""); |
||||
private static final String WAREHOUSE_ID = System.getProperty("edayun.probe.warehouseId", ""); |
||||
private static final String SKU = opt("edayun.probe.sku", "ybtest"); |
||||
private static final int SAVE_TYPE = Integer.getInteger("edayun.probe.saveType", 2); |
||||
private static final boolean WRITE = Boolean.getBoolean("edayun.probe.write"); |
||||
|
||||
@Test |
||||
void probeSaveEntry() { |
||||
String customerOrderNo = "PROBE-" |
||||
+ Long.toString(System.currentTimeMillis(), 36).toUpperCase(); |
||||
|
||||
InboundCommand cmd = InboundCommand.builder() |
||||
.inboundRequestNo(customerOrderNo) |
||||
.warehouseId(WAREHOUSE_ID) |
||||
.predictionShipDate(LocalDate.now().plusDays(7)) |
||||
.estimateArriveDate(LocalDate.now().plusDays(30)) |
||||
.line(InboundLine.builder().omsSku(SKU).quantity(1).build()) |
||||
.carton(InboundCarton.builder() |
||||
.providerSku(SKU) |
||||
.quantity(1) |
||||
.cartonNo("PROBE-BOX-1") |
||||
.lengthCm(11.2).widthCm(11.2).heightCm(11.2) |
||||
.weightGrams(11200) |
||||
.build()) |
||||
.build(); |
||||
|
||||
EdayunInboundDtos.SaveEntryRequest req = EdayunInboundMapper.toRequest( |
||||
cmd, SAVE_TYPE, null, emptyToNull(WAREHOUSE_ID)); |
||||
String bodyJson = new JacksonJsonCodec().toJson(req); |
||||
|
||||
System.out.println("\n================ edayun / POST " |
||||
+ EdayunConstants.PATH_INBOUND_SAVE + " ================"); |
||||
System.out.println("[probe] baseUrl=" + BASE_URL |
||||
+ " saveType=" + SAVE_TYPE |
||||
+ " warehouseId=" + mask(WAREHOUSE_ID) |
||||
+ " sku=" + mask(SKU) |
||||
+ " customerOrderNo=" + customerOrderNo); |
||||
System.out.println("[request] " + bodyJson); |
||||
if (!APP_SECRET.trim().isEmpty()) { |
||||
System.out.println("[sign] " + common.ecommerce.edayun.http.EdayunRequestFactory |
||||
.sign(bodyJson, APP_SECRET)); |
||||
} |
||||
|
||||
Assumptions.assumeTrue(WRITE, "dry-run:未加 -Dedayun.probe.write=true,不实际建单"); |
||||
Assumptions.assumeTrue(!CLIENT_ID.trim().isEmpty() && !CLIENT_SECRET.trim().isEmpty() |
||||
&& !APP_KEY.trim().isEmpty() && !APP_SECRET.trim().isEmpty(), |
||||
"真跑需要 -Dedayun.probe.clientId / clientSecret / appKey / appSecret"); |
||||
|
||||
try { |
||||
WarehouseContext ctx = WarehouseContext.of("EDY-PROBE", WarehouseProvider.EDAYUN, |
||||
emptyToNull(WAREHOUSE_ID), |
||||
WarehouseConnection.of(BASE_URL, |
||||
ChannelSecret.builder() |
||||
.appKey(APP_KEY).appSecret(APP_SECRET) |
||||
.clientId(CLIENT_ID).clientSecret(CLIENT_SECRET) |
||||
.build()), |
||||
"probe-" + UUID.randomUUID(), java.time.Clock.systemUTC()); |
||||
EdayunAdapter adapter = new EdayunAdapter( |
||||
new OkHttpTransport("common-ecommerce/1.0.0 (edayun-probe)", 10_000, 60_000), |
||||
new JacksonJsonCodec()); |
||||
|
||||
InboundReceipt receipt = adapter.create(ctx, cmd); |
||||
System.out.println("[OK] inboundRequestNo=" + receipt.inboundRequestNo() |
||||
+ " providerInboundId=" + receipt.providerInboundId()); |
||||
System.out.println(" 建单后用 entryCode 查状态:目前 SDK 没有该接口,见 docs-warehouse/edayun/TODO.md"); |
||||
} catch (RuntimeException e) { |
||||
String msg = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage(); |
||||
System.out.println("[ERROR] " + e.getClass().getSimpleName() + ": " |
||||
+ (msg.length() <= 800 ? msg : msg.substring(0, 800) + "…")); |
||||
if (e instanceof ChannelException) { |
||||
ChannelException ce = (ChannelException) e; |
||||
System.out.println(" platformCode=" + ce.platformCode() |
||||
+ " retryable=" + ce.retryable()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static String opt(String name, String fallback) { |
||||
String value = System.getProperty(name, ""); |
||||
String trimmed = value == null ? "" : value.trim(); |
||||
return trimmed.isEmpty() ? fallback : trimmed; |
||||
} |
||||
|
||||
private static String emptyToNull(String v) { |
||||
return v == null || v.trim().isEmpty() ? null : v.trim(); |
||||
} |
||||
|
||||
private static String mask(String v) { |
||||
if (v == null || v.trim().isEmpty()) { |
||||
return "(empty)"; |
||||
} |
||||
String t = v.trim(); |
||||
return t.length() <= 6 ? "***" : t.substring(0, 3) + "***" + t.substring(t.length() - 2); |
||||
} |
||||
} |
||||
@ -0,0 +1,115 @@
@@ -0,0 +1,115 @@
|
||||
package common.ecommerce.edayun.probe; |
||||
|
||||
import common.ecommerce.edayun.EdayunConstants; |
||||
import common.ecommerce.edayun.adapter.EdayunAdapter; |
||||
import common.ecommerce.edayun.adapter.EdayunInboundQueryMapper; |
||||
import common.ecommerce.edayun.dto.EdayunInboundQueryDtos; |
||||
import common.ecommerce.http.JacksonJsonCodec; |
||||
import common.ecommerce.http.OkHttpTransport; |
||||
import common.ecommerce.shared.error.ChannelException; |
||||
import common.ecommerce.shared.spi.ChannelSecret; |
||||
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||
import common.ecommerce.warehouse.model.InboundOrder; |
||||
import common.ecommerce.warehouse.model.InboundOrderLine; |
||||
import common.ecommerce.warehouse.sdk.WarehouseConnection; |
||||
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||
import org.junit.jupiter.api.Assumptions; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.condition.EnabledIfSystemProperty; |
||||
|
||||
import java.time.Clock; |
||||
import java.util.UUID; |
||||
|
||||
/** |
||||
* 入库明细查询探针:<b>只读</b>,不会在仓侧产生任何数据。 |
||||
* |
||||
* <pre> |
||||
* # 只看报文(不联网) |
||||
* mvn -pl warehouse-sdk-edayun -DfailIfNoTests=false \ |
||||
* -Dedayun.probe.inboundQuery=true -Dtest=EdayunInboundQueryProbeTest test |
||||
* |
||||
* # 真查(只读) |
||||
* ... -Dedayun.probe.inboundQuery=true -Dedayun.probe.call=true \ |
||||
* -Dedayun.probe.clientId=... -Dedayun.probe.clientSecret=... \ |
||||
* -Dedayun.probe.appKey=... -Dedayun.probe.appSecret=... \ |
||||
* -Dedayun.probe.entryCode=REV24050738176 |
||||
* </pre> |
||||
*/ |
||||
@EnabledIfSystemProperty(named = "edayun.probe.inboundQuery", matches = "true") |
||||
class EdayunInboundQueryProbeTest { |
||||
|
||||
private static final String BASE_URL = opt("edayun.probe.baseUrl", EdayunConstants.PR_BASE_URL); |
||||
private static final String CLIENT_ID = System.getProperty("edayun.probe.clientId", ""); |
||||
private static final String CLIENT_SECRET = System.getProperty("edayun.probe.clientSecret", ""); |
||||
private static final String APP_KEY = System.getProperty("edayun.probe.appKey", ""); |
||||
private static final String APP_SECRET = System.getProperty("edayun.probe.appSecret", ""); |
||||
private static final String ENTRY_CODE = opt("edayun.probe.entryCode", "REV24050738176"); |
||||
private static final boolean CALL = Boolean.getBoolean("edayun.probe.call"); |
||||
|
||||
@Test |
||||
void probeEntrySkuDetail() { |
||||
EdayunInboundQueryDtos.SelectEntrySkuRequest req = |
||||
EdayunInboundQueryMapper.toRequest(ENTRY_CODE, 1); |
||||
String bodyJson = new JacksonJsonCodec().toJson(req); |
||||
|
||||
System.out.println("\n================ edayun / POST " |
||||
+ EdayunConstants.PATH_INBOUND_SKU_DETAIL + " ================"); |
||||
System.out.println("[probe] baseUrl=" + BASE_URL + " entryCode=" + ENTRY_CODE); |
||||
System.out.println("[request] " + bodyJson); |
||||
if (!APP_SECRET.trim().isEmpty()) { |
||||
System.out.println("[sign] " + common.ecommerce.edayun.http.EdayunRequestFactory |
||||
.sign(bodyJson, APP_SECRET)); |
||||
} |
||||
|
||||
Assumptions.assumeTrue(CALL, "dry-run:未加 -Dedayun.probe.call=true,不实际调用"); |
||||
Assumptions.assumeTrue(!CLIENT_ID.trim().isEmpty() && !CLIENT_SECRET.trim().isEmpty() |
||||
&& !APP_KEY.trim().isEmpty() && !APP_SECRET.trim().isEmpty(), |
||||
"真查需要 -Dedayun.probe.clientId / clientSecret / appKey / appSecret"); |
||||
|
||||
try { |
||||
WarehouseContext ctx = WarehouseContext.of("EDY-PROBE", WarehouseProvider.EDAYUN, null, |
||||
WarehouseConnection.of(BASE_URL, |
||||
ChannelSecret.builder() |
||||
.appKey(APP_KEY).appSecret(APP_SECRET) |
||||
.clientId(CLIENT_ID).clientSecret(CLIENT_SECRET) |
||||
.build()), |
||||
"probe-" + UUID.randomUUID(), Clock.systemUTC()); |
||||
EdayunAdapter adapter = new EdayunAdapter( |
||||
new OkHttpTransport("common-ecommerce/1.0.0 (edayun-probe)", 10_000, 60_000), |
||||
new JacksonJsonCodec()); |
||||
|
||||
InboundOrder order = adapter.get(ctx, ENTRY_CODE); |
||||
if (order == null) { |
||||
System.out.println("[OK] 空结果(单号不存在或账号无权查看)"); |
||||
return; |
||||
} |
||||
System.out.println("[OK] entryCode=" + order.providerInboundId() |
||||
+ " status=" + order.status() |
||||
+ " rawStatus=" + order.rawStatus() |
||||
+ " planned=" + order.plannedQuantity() |
||||
+ " received=" + order.receivedQuantity() |
||||
+ " skus=" + order.lines().size()); |
||||
for (InboundOrderLine line : order.lines()) { |
||||
System.out.println(" " + line.providerSku() |
||||
+ " plan=" + line.plannedQuantity() |
||||
+ " checked=" + line.packedQuantity() |
||||
+ " shelves=" + line.receivedQuantity()); |
||||
} |
||||
} catch (RuntimeException e) { |
||||
String msg = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage(); |
||||
System.out.println("[ERROR] " + e.getClass().getSimpleName() + ": " |
||||
+ (msg.length() <= 800 ? msg : msg.substring(0, 800) + "…")); |
||||
if (e instanceof ChannelException) { |
||||
ChannelException ce = (ChannelException) e; |
||||
System.out.println(" platformCode=" + ce.platformCode() |
||||
+ " retryable=" + ce.retryable()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static String opt(String name, String fallback) { |
||||
String value = System.getProperty(name, ""); |
||||
String trimmed = value == null ? "" : value.trim(); |
||||
return trimmed.isEmpty() ? fallback : trimmed; |
||||
} |
||||
} |
||||
@ -0,0 +1,140 @@
@@ -0,0 +1,140 @@
|
||||
package common.ecommerce.edayun.probe; |
||||
|
||||
import common.ecommerce.edayun.EdayunConstants; |
||||
import common.ecommerce.edayun.adapter.EdayunAdapter; |
||||
import common.ecommerce.edayun.adapter.EdayunInventoryMapper; |
||||
import common.ecommerce.edayun.dto.EdayunInventoryDtos; |
||||
import common.ecommerce.http.JacksonJsonCodec; |
||||
import common.ecommerce.http.OkHttpTransport; |
||||
import common.ecommerce.shared.error.ChannelException; |
||||
import common.ecommerce.shared.spi.ChannelSecret; |
||||
import common.ecommerce.shared.support.Page; |
||||
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||
import common.ecommerce.warehouse.model.InventoryQuery; |
||||
import common.ecommerce.warehouse.model.InventorySnapshot; |
||||
import common.ecommerce.warehouse.sdk.WarehouseConnection; |
||||
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||
import org.junit.jupiter.api.Assumptions; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.condition.EnabledIfSystemProperty; |
||||
|
||||
import java.time.Clock; |
||||
import java.util.UUID; |
||||
|
||||
/** |
||||
* 库存查询联调探针:<b>只读</b>,不会在仓侧产生任何数据。 |
||||
* |
||||
* <p>默认跳过,用 {@code -Dedayun.probe.inventory=true} 开启;凭据走系统属性, |
||||
* <b>真实值不入库</b>:</p> |
||||
* |
||||
* <pre> |
||||
* # 只看报文(不联网) |
||||
* mvn -pl warehouse-sdk-edayun -DfailIfNoTests=false \ |
||||
* -Dedayun.probe.inventory=true -Dtest=EdayunInventoryProbeTest test |
||||
* |
||||
* # 真查(只读) |
||||
* ... -Dedayun.probe.inventory=true -Dedayun.probe.call=true \ |
||||
* -Dedayun.probe.clientId=... -Dedayun.probe.clientSecret=... \ |
||||
* -Dedayun.probe.appKey=... -Dedayun.probe.appSecret=... \ |
||||
* [-Dedayun.probe.warehouseId=2] [-Dedayun.probe.sku=ybtest] \ |
||||
* [-Dedayun.probe.zeroStock=true] [-Dedayun.probe.page=1] |
||||
* </pre> |
||||
* |
||||
* <p>异常只打印不抛出,便于一次跑完对照真实报文。</p> |
||||
*/ |
||||
@EnabledIfSystemProperty(named = "edayun.probe.inventory", matches = "true") |
||||
class EdayunInventoryProbeTest { |
||||
|
||||
private static final String BASE_URL = opt("edayun.probe.baseUrl", EdayunConstants.PR_BASE_URL); |
||||
private static final String CLIENT_ID = System.getProperty("edayun.probe.clientId", ""); |
||||
private static final String CLIENT_SECRET = System.getProperty("edayun.probe.clientSecret", ""); |
||||
private static final String APP_KEY = System.getProperty("edayun.probe.appKey", ""); |
||||
private static final String APP_SECRET = System.getProperty("edayun.probe.appSecret", ""); |
||||
private static final String WAREHOUSE_ID = System.getProperty("edayun.probe.warehouseId", ""); |
||||
private static final String SKU = System.getProperty("edayun.probe.sku", ""); |
||||
private static final int PAGE = Integer.getInteger("edayun.probe.page", 1); |
||||
private static final boolean ZERO_STOCK = Boolean.getBoolean("edayun.probe.zeroStock"); |
||||
private static final boolean CALL = Boolean.getBoolean("edayun.probe.call"); |
||||
|
||||
@Test |
||||
void probeInventory() { |
||||
InventoryQuery query = InventoryQuery.builder() |
||||
.sku(emptyToNull(SKU)) |
||||
.cursor(PAGE <= 1 ? null : String.valueOf(PAGE)) |
||||
.includeZeroStock(ZERO_STOCK ? Boolean.TRUE : null) |
||||
.build(); |
||||
|
||||
EdayunInventoryDtos.QueryInventoryRequest req = |
||||
EdayunInventoryMapper.toRequest(query, emptyToNull(WAREHOUSE_ID), PAGE); |
||||
String bodyJson = new JacksonJsonCodec().toJson(req); |
||||
|
||||
System.out.println("\n================ edayun / POST " |
||||
+ EdayunConstants.PATH_INVENTORY + " ================"); |
||||
System.out.println("[probe] baseUrl=" + BASE_URL |
||||
+ " warehouseId=" + mask(WAREHOUSE_ID) |
||||
+ " sku=" + mask(SKU) + " page=" + PAGE |
||||
+ " includeZeroStock=" + ZERO_STOCK); |
||||
System.out.println("[request] " + bodyJson); |
||||
if (!APP_SECRET.trim().isEmpty()) { |
||||
System.out.println("[sign] " + common.ecommerce.edayun.http.EdayunRequestFactory |
||||
.sign(bodyJson, APP_SECRET)); |
||||
} |
||||
|
||||
Assumptions.assumeTrue(CALL, "dry-run:未加 -Dedayun.probe.call=true,不实际调用"); |
||||
Assumptions.assumeTrue(!CLIENT_ID.trim().isEmpty() && !CLIENT_SECRET.trim().isEmpty() |
||||
&& !APP_KEY.trim().isEmpty() && !APP_SECRET.trim().isEmpty(), |
||||
"真查需要 -Dedayun.probe.clientId / clientSecret / appKey / appSecret"); |
||||
|
||||
try { |
||||
WarehouseContext ctx = WarehouseContext.of("EDY-PROBE", WarehouseProvider.EDAYUN, |
||||
emptyToNull(WAREHOUSE_ID), |
||||
WarehouseConnection.of(BASE_URL, |
||||
ChannelSecret.builder() |
||||
.appKey(APP_KEY).appSecret(APP_SECRET) |
||||
.clientId(CLIENT_ID).clientSecret(CLIENT_SECRET) |
||||
.build()), |
||||
"probe-" + UUID.randomUUID(), Clock.systemUTC()); |
||||
EdayunAdapter adapter = new EdayunAdapter( |
||||
new OkHttpTransport("common-ecommerce/1.0.0 (edayun-probe)", 10_000, 60_000), |
||||
new JacksonJsonCodec()); |
||||
|
||||
Page<InventorySnapshot> page = adapter.query(ctx, query); |
||||
System.out.println("[OK] rows=" + page.size() + " hasMore=" + page.hasMore() |
||||
+ " nextCursor=" + page.nextCursor()); |
||||
for (InventorySnapshot s : page.items()) { |
||||
System.out.println(" " + s.warehouseCode() + " " + s.providerSku() |
||||
+ " avail=" + s.available() + " onHand=" + s.onHand() |
||||
+ " frozen=" + s.reserved() + " toDeliver=" + s.pendingOutbound() |
||||
+ " inTransit=" + s.inTransit() + " safe=" + s.alertQuantity()); |
||||
} |
||||
} catch (RuntimeException e) { |
||||
String msg = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage(); |
||||
System.out.println("[ERROR] " + e.getClass().getSimpleName() + ": " |
||||
+ (msg.length() <= 800 ? msg : msg.substring(0, 800) + "…")); |
||||
if (e instanceof ChannelException) { |
||||
ChannelException ce = (ChannelException) e; |
||||
System.out.println(" platformCode=" + ce.platformCode() |
||||
+ " retryable=" + ce.retryable()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static String opt(String name, String fallback) { |
||||
String value = System.getProperty(name, ""); |
||||
String trimmed = value == null ? "" : value.trim(); |
||||
return trimmed.isEmpty() ? fallback : trimmed; |
||||
} |
||||
|
||||
private static String emptyToNull(String v) { |
||||
return v == null || v.trim().isEmpty() ? null : v.trim(); |
||||
} |
||||
|
||||
/** 日志里只留首尾,避免凭据 / 仓 id 完整落盘。 */ |
||||
private static String mask(String v) { |
||||
if (v == null || v.trim().isEmpty()) { |
||||
return "(empty)"; |
||||
} |
||||
String t = v.trim(); |
||||
return t.length() <= 6 ? "***" : t.substring(0, 3) + "***" + t.substring(t.length() - 2); |
||||
} |
||||
} |
||||
@ -0,0 +1,152 @@
@@ -0,0 +1,152 @@
|
||||
package common.ecommerce.edayun.probe; |
||||
|
||||
import common.ecommerce.edayun.EdayunConstants; |
||||
import common.ecommerce.edayun.adapter.EdayunAdapter; |
||||
import common.ecommerce.edayun.adapter.EdayunRentDetailMapper; |
||||
import common.ecommerce.edayun.dto.EdayunRentDetailDtos; |
||||
import common.ecommerce.http.JacksonJsonCodec; |
||||
import common.ecommerce.http.OkHttpTransport; |
||||
import common.ecommerce.shared.error.ChannelException; |
||||
import common.ecommerce.shared.spi.ChannelSecret; |
||||
import common.ecommerce.warehouse.enums.WarehouseFeeType; |
||||
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||
import common.ecommerce.warehouse.model.BillingDocument; |
||||
import common.ecommerce.warehouse.model.FeeQuery; |
||||
import common.ecommerce.warehouse.sdk.WarehouseConnection; |
||||
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||
import org.junit.jupiter.api.Assumptions; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.condition.EnabledIfSystemProperty; |
||||
|
||||
import java.time.Clock; |
||||
import java.time.Instant; |
||||
import java.time.temporal.ChronoUnit; |
||||
import java.util.List; |
||||
import java.util.UUID; |
||||
|
||||
/** |
||||
* 仓租费用明细联调探针:<b>只读</b>,不会在仓侧产生任何数据。 |
||||
* |
||||
* <p>默认跳过,用 {@code -Dedayun.probe.rent=true} 开启;凭据走系统属性, |
||||
* <b>真实值不入库</b>:</p> |
||||
* |
||||
* <pre> |
||||
* # 只看报文(不联网) |
||||
* mvn -pl warehouse-sdk-edayun -DfailIfNoTests=false \ |
||||
* -Dedayun.probe.rent=true -Dtest=EdayunRentProbeTest test |
||||
* |
||||
* # 真查(只读) |
||||
* ... -Dedayun.probe.rent=true -Dedayun.probe.call=true \ |
||||
* -Dedayun.probe.clientId=... -Dedayun.probe.clientSecret=... \ |
||||
* -Dedayun.probe.appKey=... -Dedayun.probe.appSecret=... \ |
||||
* -Dedayun.probe.warehouseId=98 \ |
||||
* [-Dedayun.probe.days=30] [-Dedayun.probe.bizNo=98-N9490-20260928] |
||||
* </pre> |
||||
* |
||||
* <p>异常只打印不抛出,便于一次跑完对照真实报文。</p> |
||||
*/ |
||||
@EnabledIfSystemProperty(named = "edayun.probe.rent", matches = "true") |
||||
class EdayunRentProbeTest { |
||||
|
||||
private static final String BASE_URL = opt("edayun.probe.baseUrl", EdayunConstants.PR_BASE_URL); |
||||
private static final String CLIENT_ID = System.getProperty("edayun.probe.clientId", ""); |
||||
private static final String CLIENT_SECRET = System.getProperty("edayun.probe.clientSecret", ""); |
||||
private static final String APP_KEY = System.getProperty("edayun.probe.appKey", ""); |
||||
private static final String APP_SECRET = System.getProperty("edayun.probe.appSecret", ""); |
||||
private static final String WAREHOUSE_ID = System.getProperty("edayun.probe.warehouseId", ""); |
||||
private static final String BIZ_NO = System.getProperty("edayun.probe.bizNo", ""); |
||||
private static final boolean CALL = Boolean.getBoolean("edayun.probe.call"); |
||||
|
||||
/** 查询窗口天数;仓租文档上限 3 个月,默认取 30 天避免拉太多。 */ |
||||
private static final int DAYS = Integer.getInteger("edayun.probe.days", 30); |
||||
|
||||
@Test |
||||
void probeRentDetail() { |
||||
Instant end = Instant.now(); |
||||
Instant begin = end.minus(DAYS, ChronoUnit.DAYS); |
||||
|
||||
FeeQuery query = FeeQuery.builder() |
||||
.settledAfter(begin) |
||||
.settledBefore(end) |
||||
.costType(WarehouseFeeType.STORAGE) |
||||
.externalOrderNo(emptyToNull(BIZ_NO)) |
||||
.build(); |
||||
|
||||
EdayunRentDetailDtos.SelectRentDetailRequest req = |
||||
EdayunRentDetailMapper.toRequest(query, emptyToNull(WAREHOUSE_ID)); |
||||
String bodyJson = new JacksonJsonCodec().toJson(req); |
||||
|
||||
System.out.println("\n================ edayun / POST " |
||||
+ EdayunConstants.PATH_RENT_DETAIL + " ================"); |
||||
System.out.println("[probe] baseUrl=" + BASE_URL |
||||
+ " warehouseId=" + mask(WAREHOUSE_ID) |
||||
+ " begin=" + begin + " end=" + end); |
||||
System.out.println("[request] " + bodyJson); |
||||
if (!APP_SECRET.trim().isEmpty()) { |
||||
System.out.println("[sign] " + common.ecommerce.edayun.http.EdayunRequestFactory |
||||
.sign(bodyJson, APP_SECRET)); |
||||
} |
||||
|
||||
Assumptions.assumeTrue(CALL, "dry-run:未加 -Dedayun.probe.call=true,不实际调用"); |
||||
Assumptions.assumeTrue(!CLIENT_ID.trim().isEmpty() && !CLIENT_SECRET.trim().isEmpty() |
||||
&& !APP_KEY.trim().isEmpty() && !APP_SECRET.trim().isEmpty(), |
||||
"真查需要 -Dedayun.probe.clientId / clientSecret / appKey / appSecret"); |
||||
|
||||
try { |
||||
WarehouseContext ctx = WarehouseContext.of("EDY-PROBE", WarehouseProvider.EDAYUN, |
||||
emptyToNull(WAREHOUSE_ID), |
||||
WarehouseConnection.of(BASE_URL, |
||||
ChannelSecret.builder() |
||||
.appKey(APP_KEY).appSecret(APP_SECRET) |
||||
.clientId(CLIENT_ID).clientSecret(CLIENT_SECRET) |
||||
.build()), |
||||
"probe-" + UUID.randomUUID(), Clock.systemUTC()); |
||||
EdayunAdapter adapter = new EdayunAdapter( |
||||
// 仓租查询实测很慢:pageSize=200 单页 6~13 秒,默认 30 秒读超时不够稳
|
||||
new OkHttpTransport("common-ecommerce/1.0.0 (edayun-probe)", 10_000, 120_000), |
||||
new JacksonJsonCodec()); |
||||
|
||||
List<BillingDocument> docs = adapter.storageRents(ctx, query); |
||||
System.out.println("[OK] rows=" + docs.size()); |
||||
String currency = null; |
||||
java.math.BigDecimal total = java.math.BigDecimal.ZERO; |
||||
for (BillingDocument doc : docs) { |
||||
total = total.add(doc.amount().amount()); |
||||
currency = doc.amount().currencyCode(); |
||||
System.out.println(" " + doc.settledAt() |
||||
+ " " + doc.providerSku() |
||||
+ " " + doc.amount().amount() + " " + doc.amount().currencyCode() |
||||
+ " docNo=" + doc.documentNo() + " billingId=" + doc.serialNumber()); |
||||
} |
||||
System.out.println("[sum] " + total + " " + (currency == null ? "-" : currency)); |
||||
} catch (RuntimeException e) { |
||||
String msg = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage(); |
||||
System.out.println("[ERROR] " + e.getClass().getSimpleName() + ": " |
||||
+ (msg.length() <= 800 ? msg : msg.substring(0, 800) + "…")); |
||||
if (e instanceof ChannelException) { |
||||
ChannelException ce = (ChannelException) e; |
||||
System.out.println(" platformCode=" + ce.platformCode() |
||||
+ " retryable=" + ce.retryable()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static String opt(String name, String fallback) { |
||||
String value = System.getProperty(name, ""); |
||||
String trimmed = value == null ? "" : value.trim(); |
||||
return trimmed.isEmpty() ? fallback : trimmed; |
||||
} |
||||
|
||||
private static String emptyToNull(String v) { |
||||
return v == null || v.trim().isEmpty() ? null : v.trim(); |
||||
} |
||||
|
||||
/** 日志里只留首尾,避免凭据 / 仓 id 完整落盘。 */ |
||||
private static String mask(String v) { |
||||
if (v == null || v.trim().isEmpty()) { |
||||
return "(empty)"; |
||||
} |
||||
String t = v.trim(); |
||||
return t.length() <= 6 ? "***" : t.substring(0, 3) + "***" + t.substring(t.length() - 2); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue