This commit is contained in:
2026-08-07 17:46:23 +08:00
parent 98ac9840c2
commit 645c483649
22 changed files with 370 additions and 29 deletions
@@ -29,7 +29,7 @@ class InternalMeasurementImageControllerTest {
var file = new MockMultipartFile("file", "measure.png", MediaType.IMAGE_PNG_VALUE,
new byte[]{1, 2, 3});
var result = new MeasurementImageService.UploadResult(41L, "measure.png",
MediaType.IMAGE_PNG_VALUE, 3L, "NOT_REQUIRED", null, null, null, null);
MediaType.IMAGE_PNG_VALUE, 3L, "NOT_REQUIRED", null, null, null, null, null);
when(images.uploadMeasurementEvidence(11L, 21L, 31L, file)).thenReturn(result);
var response = controller.upload("internal-token", 31L, 11L, 21L, file);
@@ -1,5 +1,6 @@
package com.baiyue.file.service;
import com.baiyue.common.core.api.ApiResponse;
import com.baiyue.file.client.WeightOcrClient;
import com.baiyue.file.entity.FileObjectEntity;
import com.baiyue.file.mapper.FileObjectMapper;
@@ -18,6 +19,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import jakarta.annotation.Resource;
import java.nio.file.Path;
import java.math.BigDecimal;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -91,4 +93,27 @@ class MeasurementImageServiceEvidenceTest {
.isInstanceOf(com.baiyue.common.core.exception.BizException.class);
verifyNoInteractions(storage);
}
@Test
void forwardsSafeOcrTextAndCanonicalConfidence() {
FileObjectEntity object = new FileObjectEntity();
object.setId(41L);
object.setTenantId(11L);
object.setBusinessType("INBOUND_WEIGHT_IMAGE");
object.setBusinessId("21");
object.setOriginalName("weight.jpg");
object.setContentType(MediaType.IMAGE_JPEG_VALUE);
object.setObjectKey("measurements/11/21/weight.jpg");
object.setSizeBytes(3L);
when(files.selectOne(any())).thenReturn(object);
when(storage.read(object.getObjectKey())).thenReturn(new byte[]{1, 2, 3});
when(ocr.recognize(org.mockito.ArgumentMatchers.eq("internal-token"), any()))
.thenReturn(ApiResponse.success(new WeightOcrClient.Result("RECOGNIZED",
new BigDecimal("285.5"), new BigDecimal("0.5097191334"), "285.5\nKG", null)));
var result = service.retryRecognition(11L, 21L, 41L);
assertThat(result.confidence()).isEqualByComparingTo("0.50972");
assertThat(result.ocrRawText()).isEqualTo("285.5\nKG");
}
}