You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
153 lines
7.2 KiB
153 lines
7.2 KiB
|
6 days ago
|
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);
|
||
|
|
}
|
||
|
|
}
|