配置迁移到表

This commit is contained in:
2026-05-30 22:03:52 +08:00
parent 1b596e10a7
commit bf685417e7
7 changed files with 194 additions and 12 deletions

View File

@@ -0,0 +1,64 @@
package com.rj.util;
import com.rj.common.LbThirdIntegrationConstants;
import com.rj.entity.LbThirdIntegrationConfig;
import org.springframework.util.StringUtils;
/**
* 从 {@link LbThirdIntegrationConfig} 解析第三方 API 地址与请求头。
*/
public final class LbThirdIntegrationConfigUtil {
private LbThirdIntegrationConfigUtil() {
}
public static String resolveGoodsApiBaseUrl(LbThirdIntegrationConfig config) {
String base = trimTrailingSlash(requireText(config.getAdminBaseUrl(), "adminBaseUrl"));
String path = config.getGoodsApiPath();
if (!StringUtils.hasText(path)) {
path = LbThirdIntegrationConstants.DEFAULT_GOODS_API_PATH;
}
path = path.trim();
if (!path.startsWith("/")) {
path = "/" + path;
}
return base + path;
}
public static String resolveGoodsApiOrigin(LbThirdIntegrationConfig config) {
if (StringUtils.hasText(config.getGoodsApiOrigin())) {
return config.getGoodsApiOrigin().trim();
}
return trimTrailingSlash(requireText(config.getWebBaseUrl(), "webBaseUrl"));
}
public static String resolveGoodsApiReferer(LbThirdIntegrationConfig config) {
if (StringUtils.hasText(config.getGoodsApiReferer())) {
return config.getGoodsApiReferer().trim();
}
return trimTrailingSlash(requireText(config.getWebBaseUrl(), "webBaseUrl")) + "/";
}
public static int resolveGoodsPageLimit(LbThirdIntegrationConfig config) {
Integer limit = config.getGoodsPageLimit();
if (limit == null || limit < 1) {
return LbThirdIntegrationConstants.DEFAULT_GOODS_PAGE_LIMIT;
}
return limit;
}
private static String requireText(String value, String fieldName) {
if (!StringUtils.hasText(value)) {
throw new IllegalStateException(fieldName + " 未配置");
}
return value.trim();
}
private static String trimTrailingSlash(String url) {
String trimmed = url.trim();
while (trimmed.endsWith("/")) {
trimmed = trimmed.substring(0, trimmed.length() - 1);
}
return trimmed;
}
}