fix: complete single-order acceptance and add Lingxing WMS integration
This commit is contained in:
+49
@@ -0,0 +1,49 @@
|
||||
package com.baiyue.integration.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.bind.DefaultValue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
|
||||
@ConfigurationProperties(prefix = "baiyue.integration.lingxing-wms")
|
||||
public record LingxingWmsProperties(
|
||||
@DefaultValue("false") boolean enabled,
|
||||
@DefaultValue("https://api.xlwms.com") URI baseUri,
|
||||
String appKey,
|
||||
String appSecret,
|
||||
@DefaultValue("5s") Duration connectTimeout,
|
||||
@DefaultValue("15s") Duration requestTimeout,
|
||||
@DefaultValue("1s") Duration minRequestInterval
|
||||
) {
|
||||
public LingxingWmsProperties {
|
||||
baseUri = baseUri == null ? URI.create("https://api.xlwms.com") : baseUri;
|
||||
connectTimeout = connectTimeout == null ? Duration.ofSeconds(5) : connectTimeout;
|
||||
requestTimeout = requestTimeout == null ? Duration.ofSeconds(15) : requestTimeout;
|
||||
minRequestInterval = minRequestInterval == null ? Duration.ofSeconds(1) : minRequestInterval;
|
||||
if (connectTimeout.isZero() || connectTimeout.isNegative()
|
||||
|| requestTimeout.isZero() || requestTimeout.isNegative()
|
||||
|| minRequestInterval.isNegative() || minRequestInterval.compareTo(Duration.ofDays(1)) > 0) {
|
||||
throw new IllegalArgumentException("领星 WMS 超时必须为正数,最小请求间隔须在 0 至 1 天之间");
|
||||
}
|
||||
String host = baseUri.getHost();
|
||||
boolean loopback = "localhost".equalsIgnoreCase(host) || "127.0.0.1".equals(host)
|
||||
|| "[::1]".equals(host);
|
||||
boolean secureScheme = "https".equalsIgnoreCase(baseUri.getScheme())
|
||||
|| ("http".equalsIgnoreCase(baseUri.getScheme()) && loopback);
|
||||
if (host == null || !secureScheme || baseUri.getUserInfo() != null
|
||||
|| baseUri.getQuery() != null || baseUri.getFragment() != null
|
||||
|| (!baseUri.getPath().isEmpty() && !"/".equals(baseUri.getPath()))) {
|
||||
throw new IllegalArgumentException("领星 WMS base-uri 必须是 HTTPS 源地址;仅本机测试允许 HTTP");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasCredentials() {
|
||||
return appKey != null && !appKey.isBlank() && appSecret != null && !appSecret.isBlank();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LingxingWmsProperties[enabled=" + enabled + ", credentialsConfigured=" + hasCredentials() + "]";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user