fix: preserve qualification file names across uploads
This commit is contained in:
@@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class QualificationPackageService {
|
public class QualificationPackageService {
|
||||||
@@ -45,9 +46,10 @@ public class QualificationPackageService {
|
|||||||
String legalPersonIdDocumentUrl = storedLegalPersonId == null ? null : storedLegalPersonId.documentUrl();
|
String legalPersonIdDocumentUrl = storedLegalPersonId == null ? null : storedLegalPersonId.documentUrl();
|
||||||
|
|
||||||
var request = new IamQualificationClient.RequiredPackageRequest(
|
var request = new IamQualificationClient.RequiredPackageRequest(
|
||||||
tenantId, normalizedCreditCode, storedBusinessLicense.documentUrl(), businessLicense.getOriginalFilename(),
|
tenantId, normalizedCreditCode, storedBusinessLicense.documentUrl(),
|
||||||
|
originalFileName(businessLicense, storedBusinessLicense, "business-license"),
|
||||||
businessLicenseValidTo, replaceBusinessLicense, legalPersonIdDocumentUrl,
|
businessLicenseValidTo, replaceBusinessLicense, legalPersonIdDocumentUrl,
|
||||||
legalPersonId == null ? null : legalPersonId.getOriginalFilename(),
|
legalPersonId == null ? null : originalFileName(legalPersonId, storedLegalPersonId, "legal-person-id"),
|
||||||
legalPersonIdValidTo, replaceLegalPersonId);
|
legalPersonIdValidTo, replaceLegalPersonId);
|
||||||
try {
|
try {
|
||||||
var response = platform
|
var response = platform
|
||||||
@@ -87,6 +89,13 @@ public class QualificationPackageService {
|
|||||||
if (storedFile != null) storage.delete(storedFile);
|
if (storedFile != null) storage.delete(storedFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String originalFileName(MultipartFile file, LocalQualificationStorage.StoredFile stored, String fallback) {
|
||||||
|
String original = file.getOriginalFilename();
|
||||||
|
if (StringUtils.hasText(original)) return original;
|
||||||
|
String storedName = stored == null ? null : stored.fileName();
|
||||||
|
return StringUtils.hasText(storedName) ? storedName : fallback;
|
||||||
|
}
|
||||||
|
|
||||||
public record PackageUploadResult(Long businessLicenseQualificationId,
|
public record PackageUploadResult(Long businessLicenseQualificationId,
|
||||||
Long legalPersonIdQualificationId,
|
Long legalPersonIdQualificationId,
|
||||||
String tenantStatus,
|
String tenantStatus,
|
||||||
|
|||||||
@@ -83,6 +83,25 @@ class QualificationPackageServiceTest {
|
|||||||
verify(fixture.storage, never()).store(TENANT_ID, fixture.legalPersonId);
|
verify(fixture.storage, never()).store(TENANT_ID, fixture.legalPersonId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void missingMultipartOriginalNamesUseStoredNamesForIamRegistration() {
|
||||||
|
var fixture = fixture();
|
||||||
|
var businessLicense = new MockMultipartFile("businessLicense", "", "image/png", new byte[] {1});
|
||||||
|
var legalPersonId = new MockMultipartFile("legalPersonId", "", "image/png", new byte[] {2});
|
||||||
|
when(fixture.storage.store(TENANT_ID, businessLicense)).thenReturn(fixture.businessStored);
|
||||||
|
when(fixture.storage.store(TENANT_ID, legalPersonId)).thenReturn(fixture.legalPersonStored);
|
||||||
|
when(fixture.iamClient.submitRequiredPackage(eq("internal-token"), any())).thenReturn(ApiResponse.success(
|
||||||
|
new IamQualificationClient.RequiredPackageResponse(31L, 32L, "PROFILE_REQUIRED", null, null)));
|
||||||
|
|
||||||
|
fixture.service.upload(TENANT_ID, businessLicense, legalPersonId,
|
||||||
|
"91310101abcde12345", null, null, false, false, false);
|
||||||
|
|
||||||
|
var captor = ArgumentCaptor.forClass(IamQualificationClient.RequiredPackageRequest.class);
|
||||||
|
verify(fixture.iamClient).submitRequiredPackage(eq("internal-token"), captor.capture());
|
||||||
|
assertEquals("business.pdf", captor.getValue().businessLicenseOriginalFileName());
|
||||||
|
assertEquals("legal-person.png", captor.getValue().legalPersonIdOriginalFileName());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void missingBusinessLicenseAndOrphanedLegalPersonParametersStillFailClosed() {
|
void missingBusinessLicenseAndOrphanedLegalPersonParametersStillFailClosed() {
|
||||||
var fixture = fixture();
|
var fixture = fixture();
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ export async function run(context, { publishEnvironment = true } = {}) {
|
|||||||
if (!tenantId || !username || !password) throw new Error('创建下单客户未返回完整管理员凭据')
|
if (!tenantId || !username || !password) throw new Error('创建下单客户未返回完整管理员凭据')
|
||||||
|
|
||||||
const packageForm = new FormData()
|
const packageForm = new FormData()
|
||||||
packageForm.append('businessLicense', new Blob([QUALIFICATION_IMAGE], { type: 'image/png' }), `business-${suffix}.png`)
|
packageForm.append('businessLicense', new File([QUALIFICATION_IMAGE], `business-${suffix}.png`, { type: 'image/png' }))
|
||||||
packageForm.append('legalPersonId', new Blob([QUALIFICATION_IMAGE], { type: 'image/png' }), `legal-person-${suffix}.png`)
|
packageForm.append('legalPersonId', new File([QUALIFICATION_IMAGE], `legal-person-${suffix}.png`, { type: 'image/png' }))
|
||||||
const unifiedSocialCreditCode = `91440300${suffix}`
|
const unifiedSocialCreditCode = `91440300${suffix}`
|
||||||
const packageResponse = await context.requestWithBody('POST',
|
const packageResponse = await context.requestWithBody('POST',
|
||||||
`/api/platform/v1/files/qualifications/${encodeURIComponent(tenantId)}/required-package?unifiedSocialCreditCode=${encodeURIComponent(unifiedSocialCreditCode)}`,
|
`/api/platform/v1/files/qualifications/${encodeURIComponent(tenantId)}/required-package?unifiedSocialCreditCode=${encodeURIComponent(unifiedSocialCreditCode)}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user