根据手机号拉取买家订儿拉取买家订单。

This commit is contained in:
2026-06-06 08:27:36 +08:00
parent 1477ec943b
commit 7413485718
9 changed files with 309 additions and 118 deletions

View File

@@ -1,9 +1,13 @@
package com.rj.util;
import com.rj.common.LbThirdIntegrationConstants;
import com.rj.dto.hxr.BuyerOrderListEndpoint;
import com.rj.entity.LbThirdIntegrationConfig;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.Map;
/**
* 从 {@link LbThirdIntegrationConfig} 解析第三方 API 地址与请求头。
*/
@@ -166,19 +170,56 @@ public final class LbThirdIntegrationConfigUtil {
}
public static String resolveBuyerOrderListBaseUrl(LbThirdIntegrationConfig config) {
String base = trimTrailingSlash(requireText(config.getAdminBaseUrl(), "adminBaseUrl"));
String path = config.getBuyerOrderListPath();
if (!StringUtils.hasText(path)) {
path = LbThirdIntegrationConstants.DEFAULT_BUYER_ORDER_LIST_PATH;
}
path = path.trim();
if (!path.startsWith("/")) {
path = "/" + path;
}
return base + path;
return resolveBuyerOrderListEndpoint(config).baseUrl();
}
public static int resolveBuyerOrderListLimit(LbThirdIntegrationConfig config) {
return resolveBuyerOrderListEndpoint(config).pageLimit();
}
public static int resolveBuyerOrderListCate(LbThirdIntegrationConfig config) {
return resolveBuyerOrderListEndpoint(config).cate();
}
public static int resolveBuyerOrderListType(LbThirdIntegrationConfig config) {
return resolveBuyerOrderListEndpoint(config).type();
}
/**
* 解析买方订单列表 API支持 {@code buyer_order_list_path} 内嵌 {@code ?cate=&type=} 查询参数。
*/
public static BuyerOrderListEndpoint resolveBuyerOrderListEndpoint(LbThirdIntegrationConfig config) {
String adminBase = trimTrailingSlash(requireText(config.getAdminBaseUrl(), "adminBaseUrl"));
String rawPath = config.getBuyerOrderListPath();
if (!StringUtils.hasText(rawPath)) {
rawPath = LbThirdIntegrationConstants.DEFAULT_BUYER_ORDER_LIST_PATH;
}
rawPath = rawPath.trim();
String pathOnly = rawPath;
int cate = LbThirdIntegrationConstants.DEFAULT_BUYER_ORDER_LIST_CATE;
int type = LbThirdIntegrationConstants.DEFAULT_BUYER_ORDER_LIST_TYPE;
int queryIdx = rawPath.indexOf('?');
if (queryIdx >= 0) {
pathOnly = rawPath.substring(0, queryIdx);
Map<String, String> queryParams = parseQueryString(rawPath.substring(queryIdx + 1));
cate = parsePositiveInt(queryParams.get("cate"), cate);
type = parsePositiveInt(queryParams.get("type"), type);
}
if (!pathOnly.startsWith("/")) {
pathOnly = "/" + pathOnly;
}
return new BuyerOrderListEndpoint(
adminBase + pathOnly,
cate,
type,
resolveBuyerOrderListLimitRaw(config));
}
private static int resolveBuyerOrderListLimitRaw(LbThirdIntegrationConfig config) {
Integer limit = config.getBuyerOrderListLimit();
if (limit == null || limit < 1) {
return LbThirdIntegrationConstants.DEFAULT_BUYER_ORDER_LIST_LIMIT;
@@ -186,6 +227,36 @@ public final class LbThirdIntegrationConfigUtil {
return limit;
}
private static Map<String, String> parseQueryString(String query) {
Map<String, String> params = new HashMap<>();
if (query == null || query.isBlank()) {
return params;
}
for (String pair : query.split("&")) {
if (pair.isBlank()) {
continue;
}
int eq = pair.indexOf('=');
if (eq <= 0) {
continue;
}
params.put(pair.substring(0, eq).trim(), pair.substring(eq + 1).trim());
}
return params;
}
private static int parsePositiveInt(String text, int defaultValue) {
if (text == null || text.isBlank()) {
return defaultValue;
}
try {
int value = Integer.parseInt(text.trim());
return value > 0 ? value : defaultValue;
} catch (NumberFormatException e) {
return defaultValue;
}
}
/**
* 组装 Cookie 请求头:优先完整 cookie否则 {@code PHPSID=} + phpsid。
*/