优化
This commit is contained in:
@@ -17,7 +17,6 @@ public interface WeightOcrClient {
|
||||
ApiResponse<Result> recognize(@RequestHeader("X-Internal-Service-Token") String token,
|
||||
@RequestPart("file") MultipartFile file);
|
||||
|
||||
record Result(String sourceImage, String croppedImage, String rawResponseFile,
|
||||
String status, BigDecimal weight, Double confidence,
|
||||
java.util.List<?> candidates, String error) {}
|
||||
record Result(String status, BigDecimal weight, BigDecimal confidence,
|
||||
String ocrRawText, String error) {}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
@@ -39,7 +40,7 @@ public class MeasurementImageService {
|
||||
FileObjectEntity object = storeObject(
|
||||
tenantId, inboundId, operatorId, file, "INBOUND_MEASUREMENT_IMAGE");
|
||||
return new UploadResult(object.getId(), object.getOriginalName(), object.getContentType(),
|
||||
object.getSizeBytes(), "NOT_REQUIRED", null, null, null, null);
|
||||
object.getSizeBytes(), "NOT_REQUIRED", null, null, null, null, null);
|
||||
}
|
||||
|
||||
private FileObjectEntity storeObject(long tenantId, long inboundId, long operatorId,
|
||||
@@ -116,7 +117,8 @@ public class MeasurementImageService {
|
||||
}
|
||||
var result = response.data();
|
||||
return new UploadResult(object.getId(), object.getOriginalName(), object.getContentType(),
|
||||
object.getSizeBytes(), result.status(), result.weight(), "KG", result.confidence(), result.error());
|
||||
object.getSizeBytes(), result.status(), result.weight(), "KG",
|
||||
normalizeConfidence(result.confidence()), result.ocrRawText(), result.error());
|
||||
} catch (FeignException exception) {
|
||||
return failed(object, "OCR服务不可用,可稍后重试或人工录入");
|
||||
}
|
||||
@@ -124,12 +126,19 @@ public class MeasurementImageService {
|
||||
|
||||
private UploadResult failed(FileObjectEntity object, String message) {
|
||||
return new UploadResult(object.getId(), object.getOriginalName(), object.getContentType(),
|
||||
object.getSizeBytes(), "FAILED", null, null, null, message);
|
||||
object.getSizeBytes(), "FAILED", null, null, null, null, message);
|
||||
}
|
||||
|
||||
private BigDecimal normalizeConfidence(BigDecimal value) {
|
||||
if (value == null) return null;
|
||||
if (value.compareTo(BigDecimal.ZERO) < 0) value = BigDecimal.ZERO;
|
||||
if (value.compareTo(BigDecimal.ONE) > 0) value = BigDecimal.ONE;
|
||||
return value.setScale(5, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
public record UploadResult(Long fileId, String fileName, String contentType, Long sizeBytes,
|
||||
String recognitionStatus, BigDecimal weightValue, String weightUnit,
|
||||
Double confidence, String error) {}
|
||||
BigDecimal confidence, String ocrRawText, String error) {}
|
||||
public record Download(String fileName, String contentType, byte[] content) {}
|
||||
|
||||
private record StoredImageMultipartFile(String originalFilename, String contentType, byte[] bytes)
|
||||
|
||||
Reference in New Issue
Block a user