fix(warehouse): reject invalid import files with validation code

This commit is contained in:
2026-08-08 15:54:31 +08:00
parent 931009a518
commit d49b4128bc
6 changed files with 46 additions and 3 deletions
@@ -94,7 +94,11 @@ public class PlatformExpressCompanyController {
requirePlatform(user);
requirePlatformScope(tenantId);
try {
return ApiResponse.success(importService.importFile(tenantId, file.getOriginalFilename(), file.getBytes()));
ExpressCompanyImportResult result = importService.importFile(tenantId, file.getOriginalFilename(), file.getBytes());
if (!result.success()) {
throw new BizException(ResultCode.VALIDATION_FAILED, "快递公司导入文件校验失败");
}
return ApiResponse.success(result);
} catch (IOException exception) {
throw new BizException(ResultCode.BAD_REQUEST, "导入文件读取失败");
}
@@ -75,7 +75,11 @@ public class PlatformPartnerController {
requirePlatform(user);
requirePlatformScope(tenantId);
try {
return ApiResponse.success(importService.importFile(0L, file.getOriginalFilename(), file.getBytes()));
PartnerImportResult result = importService.importFile(0L, file.getOriginalFilename(), file.getBytes());
if (!result.success()) {
throw new BizException(ResultCode.VALIDATION_FAILED, "往来单位导入文件校验失败");
}
return ApiResponse.success(result);
} catch (IOException exception) {
throw new BizException(ResultCode.BAD_REQUEST, "导入文件读取失败");
}
@@ -163,7 +163,11 @@ public class PlatformWarehouseController {
requireImportPermission(user, mode);
if (tenantId != null) requireTenant(tenantId);
try {
return ApiResponse.success(importService.importFile(0L, file.getOriginalFilename(), file.getBytes(), mode, dryRun));
WarehouseImportResult result = importService.importFile(0L, file.getOriginalFilename(), file.getBytes(), mode, dryRun);
if (!result.success()) {
throw new BizException(ResultCode.VALIDATION_FAILED, "仓库导入文件校验失败");
}
return ApiResponse.success(result);
} catch (IOException exception) {
throw new BizException(ResultCode.BAD_REQUEST, "导入文件读取失败");
}