配置迁移到表
This commit is contained in:
64
src/main/java/com/rj/util/LbThirdIntegrationConfigUtil.java
Normal file
64
src/main/java/com/rj/util/LbThirdIntegrationConfigUtil.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user