格式修改
This commit is contained in:
+3
-5
@@ -1,16 +1,14 @@
|
||||
package com.baiyue.integration.provider;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import com.baiyue.integration.config.IntegrationProperties;
|
||||
import com.baiyue.integration.dto.ProviderStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AmazonLogisticsAdapter implements IntegrationProviderAdapter {
|
||||
private final IntegrationProperties properties;
|
||||
|
||||
public AmazonLogisticsAdapter(IntegrationProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
@Resource private IntegrationProperties properties;
|
||||
|
||||
@Override
|
||||
public ProviderStatus status() {
|
||||
|
||||
+3
-5
@@ -1,16 +1,14 @@
|
||||
package com.baiyue.integration.provider;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import com.baiyue.integration.config.IntegrationProperties;
|
||||
import com.baiyue.integration.dto.ProviderStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class BaiduOcrAdapter implements IntegrationProviderAdapter {
|
||||
private final IntegrationProperties properties;
|
||||
|
||||
public BaiduOcrAdapter(IntegrationProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
@Resource private IntegrationProperties properties;
|
||||
|
||||
@Override
|
||||
public ProviderStatus status() {
|
||||
|
||||
+11
-7
@@ -1,5 +1,8 @@
|
||||
package com.baiyue.integration.provider.ocr;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.integration.config.IntegrationProperties;
|
||||
@@ -31,18 +34,19 @@ public class BaiduMeterClient {
|
||||
private static final int QPS_LIMIT_ERROR_CODE = 18;
|
||||
private static final long INITIAL_RETRY_DELAY_MILLIS = 1_000;
|
||||
|
||||
private final IntegrationProperties.BaiduOcr config;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final HttpClient httpClient;
|
||||
@Resource private IntegrationProperties properties;
|
||||
@Resource private ObjectMapper objectMapper;
|
||||
private IntegrationProperties.BaiduOcr config;
|
||||
private HttpClient httpClient;
|
||||
private final Object requestRateLock = new Object();
|
||||
|
||||
private volatile CachedToken cachedToken;
|
||||
private long nextRequestAtMillis;
|
||||
|
||||
public BaiduMeterClient(IntegrationProperties properties, ObjectMapper objectMapper) {
|
||||
this.config = properties.baiduOcr();
|
||||
this.objectMapper = objectMapper;
|
||||
this.httpClient = HttpClient.newBuilder()
|
||||
@PostConstruct
|
||||
void initializeClient() {
|
||||
config = properties.baiduOcr();
|
||||
httpClient = HttpClient.newBuilder()
|
||||
.connectTimeout(config == null ? java.time.Duration.ofSeconds(10)
|
||||
: config.effectiveConnectTimeout())
|
||||
.build();
|
||||
|
||||
+6
-2
@@ -1,5 +1,7 @@
|
||||
package com.baiyue.integration.security;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -10,9 +12,11 @@ import java.security.MessageDigest;
|
||||
|
||||
@Component
|
||||
public class InternalServiceTokenGuard {
|
||||
private final byte[] expectedToken;
|
||||
@Value("${baiyue.security.internal-service-token}") private String token;
|
||||
private byte[] expectedToken;
|
||||
|
||||
public InternalServiceTokenGuard(@Value("${baiyue.security.internal-service-token}") String token) {
|
||||
@PostConstruct
|
||||
void initializeToken() {
|
||||
if (token == null || token.getBytes(StandardCharsets.UTF_8).length < 32) {
|
||||
throw new IllegalStateException("INTERNAL_SERVICE_TOKEN 至少需要 32 字节");
|
||||
}
|
||||
|
||||
+3
-5
@@ -1,5 +1,7 @@
|
||||
package com.baiyue.integration.service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import com.baiyue.integration.dto.ProviderStatus;
|
||||
import com.baiyue.integration.provider.IntegrationProviderAdapter;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -8,11 +10,7 @@ import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ProviderStatusService {
|
||||
private final List<IntegrationProviderAdapter> adapters;
|
||||
|
||||
public ProviderStatusService(List<IntegrationProviderAdapter> adapters) {
|
||||
this.adapters = adapters;
|
||||
}
|
||||
@Resource private List<IntegrationProviderAdapter> adapters;
|
||||
|
||||
public List<ProviderStatus> providers() {
|
||||
return adapters.stream().map(IntegrationProviderAdapter::status).toList();
|
||||
|
||||
+8
-20
@@ -1,5 +1,7 @@
|
||||
package com.baiyue.integration.service.ocr;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.integration.config.IntegrationProperties;
|
||||
@@ -33,28 +35,14 @@ import java.util.stream.Stream;
|
||||
public class WeightOcrBatchService {
|
||||
private static final Set<String> SUPPORTED_EXTENSIONS = Set.of("jpg", "jpeg", "png", "bmp");
|
||||
|
||||
private final IntegrationProperties properties;
|
||||
private final WeightOcrStoragePolicy storagePolicy;
|
||||
private final ImageCropper imageCropper;
|
||||
private final BaiduMeterClient baiduMeterClient;
|
||||
private final WeightCandidateSelector candidateSelector;
|
||||
private final ObjectMapper objectMapper;
|
||||
@Resource private IntegrationProperties properties;
|
||||
@Resource private WeightOcrStoragePolicy storagePolicy;
|
||||
@Resource private ImageCropper imageCropper;
|
||||
@Resource private BaiduMeterClient baiduMeterClient;
|
||||
@Resource private WeightCandidateSelector candidateSelector;
|
||||
@Resource private ObjectMapper objectMapper;
|
||||
private final Semaphore batchSlot = new Semaphore(1);
|
||||
|
||||
public WeightOcrBatchService(IntegrationProperties properties,
|
||||
WeightOcrStoragePolicy storagePolicy,
|
||||
ImageCropper imageCropper,
|
||||
BaiduMeterClient baiduMeterClient,
|
||||
WeightCandidateSelector candidateSelector,
|
||||
ObjectMapper objectMapper) {
|
||||
this.properties = properties;
|
||||
this.storagePolicy = storagePolicy;
|
||||
this.imageCropper = imageCropper;
|
||||
this.baiduMeterClient = baiduMeterClient;
|
||||
this.candidateSelector = candidateSelector;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
public WeightOcrBatchResult recognize(WeightOcrBatchRequest request) throws IOException {
|
||||
baiduMeterClient.validateReady();
|
||||
if (!batchSlot.tryAcquire()) {
|
||||
|
||||
+4
-7
@@ -1,5 +1,7 @@
|
||||
package com.baiyue.integration.service.ocr;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.integration.config.IntegrationProperties;
|
||||
@@ -19,13 +21,8 @@ import java.util.UUID;
|
||||
@Service
|
||||
public class WeightOcrSingleImageService {
|
||||
private static final Set<String> CONTENT_TYPES = Set.of("image/jpeg", "image/png", "image/bmp");
|
||||
private final IntegrationProperties properties;
|
||||
private final WeightOcrBatchService batches;
|
||||
|
||||
public WeightOcrSingleImageService(IntegrationProperties properties, WeightOcrBatchService batches) {
|
||||
this.properties = properties;
|
||||
this.batches = batches;
|
||||
}
|
||||
@Resource private IntegrationProperties properties;
|
||||
@Resource private WeightOcrBatchService batches;
|
||||
|
||||
public WeightOcrImageResult recognize(MultipartFile file) throws IOException {
|
||||
IntegrationProperties.BaiduOcr config = properties.baiduOcr();
|
||||
|
||||
+3
-5
@@ -1,5 +1,7 @@
|
||||
package com.baiyue.integration.service.ocr;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.integration.config.IntegrationProperties;
|
||||
@@ -14,11 +16,7 @@ import java.nio.file.Path;
|
||||
*/
|
||||
@Component
|
||||
public class WeightOcrStoragePolicy {
|
||||
private final IntegrationProperties properties;
|
||||
|
||||
public WeightOcrStoragePolicy(IntegrationProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
@Resource private IntegrationProperties properties;
|
||||
|
||||
public BatchPaths resolve(String inputValue, String outputValue, String batchId) throws IOException {
|
||||
IntegrationProperties.BaiduOcr config = requireConfig();
|
||||
|
||||
Reference in New Issue
Block a user