feat(file): support overseas exception evidence

This commit is contained in:
2026-09-08 18:26:26 +08:00
parent 3b88e5f6ab
commit 047ed674b8
6 changed files with 190 additions and 1 deletions
@@ -315,4 +315,45 @@ class InternalBusinessFileServiceTest {
.isInstanceOf(BizException.class).hasMessageContaining("明确客户");
}
@Test void overseasExceptionEvidenceUsesExactCustomerAndExceptionOwnership() {
MockMultipartFile file = new MockMultipartFile(
"file", "异常处理证据.pdf", "application/pdf", "%PDF-1.4".getBytes());
when(storage.store(10001L, "701", file, BusinessFileCategory.OVERSEAS_EXCEPTION_EVIDENCE))
.thenReturn(new BusinessFileStorage.Stored("business-files/10001/701/evidence.pdf",
"application/pdf", file.getSize(), "b".repeat(64), "异常处理证据.pdf"));
when(files.insert(any(FileObjectEntity.class))).thenAnswer(invocation -> {
((FileObjectEntity) invocation.getArgument(0)).setId(801L);
return 1;
});
var result = service.upload(10001L, "OVERSEAS_EXCEPTION_EVIDENCE", "701", 7L, file);
assertThat(result).extracting(InternalBusinessFileService.Metadata::ownerScope,
InternalBusinessFileService.Metadata::tenantId,
InternalBusinessFileService.Metadata::businessType,
InternalBusinessFileService.Metadata::businessId)
.containsExactly("CUSTOMER", 10001L, "OVERSEAS_EXCEPTION_EVIDENCE", "701");
verify(storage).store(10001L, "701", file, BusinessFileCategory.OVERSEAS_EXCEPTION_EVIDENCE);
assertThatThrownBy(() -> service.upload(0L, "OVERSEAS_EXCEPTION_EVIDENCE", "701", 7L, file))
.isInstanceOf(BizException.class).hasMessageContaining("明确客户");
}
@Test void overseasExceptionEvidenceMetadataFailsClosedForEveryOwnershipMismatch() {
FileObjectEntity value = new FileObjectEntity();
value.setId(801L); value.setTenantId(10001L);
value.setBusinessType("OVERSEAS_EXCEPTION_EVIDENCE"); value.setBusinessId("701");
value.setOriginalName("evidence.pdf"); value.setObjectKey("business-files/10001/701/evidence.pdf");
value.setContentType("application/pdf"); value.setSha256("b".repeat(64)); value.setSizeBytes(8L);
when(files.selectOne(any())).thenReturn(value, null, null, null);
assertThat(service.metadata(10001L, "OVERSEAS_EXCEPTION_EVIDENCE", "701", 801L).fileId())
.isEqualTo(801L);
assertThatThrownBy(() -> service.metadata(10002L, "OVERSEAS_EXCEPTION_EVIDENCE", "701", 801L))
.isInstanceOf(BizException.class).hasMessageContaining("归属不匹配");
assertThatThrownBy(() -> service.metadata(10001L, "OVERSEAS_EXCEPTION_EVIDENCE", "702", 801L))
.isInstanceOf(BizException.class).hasMessageContaining("归属不匹配");
assertThatThrownBy(() -> service.metadata(10001L, "INBOUND_HOLD_EVIDENCE", "701", 801L))
.isInstanceOf(BizException.class).hasMessageContaining("归属不匹配");
}
}
@@ -0,0 +1,37 @@
package com.baiyue.file.service;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import static org.assertj.core.api.Assertions.assertThat;
class OverseasExceptionEvidenceContractTest {
@Test
void categoryAndOpenApiFreezeCustomerExceptionOwnership() throws Exception {
BusinessFileCategory category = BusinessFileCategory.require("OVERSEAS_EXCEPTION_EVIDENCE");
assertThat(category.maxSizeBytes()).isEqualTo(10L * 1024 * 1024);
assertThat(category.formatPolicy()).isEqualTo(BusinessFileCategory.FormatPolicy.STANDARD);
try (var stream = getClass().getResourceAsStream(
"/openapi/overseas-exception-evidence-v1.yaml")) {
assertThat(stream).isNotNull();
String yaml = new String(stream.readAllBytes(), StandardCharsets.UTF_8);
assertThat(yaml).contains(
"/internal/file/v1/business-files/{tenantId}/OVERSEAS_EXCEPTION_EVIDENCE/{exceptionOrderId}:",
"ownerScope: {type: string, enum: [CUSTOMER]}",
"businessType: {type: string, enum: [OVERSEAS_EXCEPTION_EVIDENCE]}",
"maximum: 10485760");
}
}
@Test
void initializationSqlHasEnoughWidthAndDocumentsTheCategory() throws Exception {
try (var stream = getClass().getResourceAsStream("/db/file.sql")) {
assertThat(stream).isNotNull();
String sql = new String(stream.readAllBytes(), StandardCharsets.UTF_8);
assertThat(sql).contains("business_type VARCHAR(32)", "OVERSEAS_EXCEPTION_EVIDENCE");
assertThat("OVERSEAS_EXCEPTION_EVIDENCE").hasSizeLessThanOrEqualTo(32);
}
}
}