优化代码
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 23s
Docker Build & Deploy / Deploy to Production (push) Successful in 6s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s

This commit is contained in:
孙诚
2026-01-04 16:43:32 +08:00
parent ab22325ca7
commit 557d44aed8
11 changed files with 200 additions and 460 deletions

View File

@@ -17,7 +17,7 @@ public class BillImportController(
/// <param name="type">账单类型Alipay | WeChat</param>
/// <returns></returns>
[HttpPost]
public async Task<BaseResponse<object>> UploadFile(
public async Task<BaseResponse> UploadFile(
[FromForm] IFormFile file,
[FromForm] string type
)
@@ -27,12 +27,12 @@ public class BillImportController(
// 验证参数
if (file.Length == 0)
{
return BaseResponse<object>.Fail("请选择要上传的文件");
return "请选择要上传的文件".Fail();
}
if (string.IsNullOrWhiteSpace(type) || (type != "Alipay" && type != "WeChat"))
{
return BaseResponse<object>.Fail("账单类型参数错误,必须是 Alipay 或 WeChat");
return "账单类型参数错误,必须是 Alipay 或 WeChat".Fail();
}
// 验证文件类型
@@ -40,14 +40,14 @@ public class BillImportController(
var fileExtension = Path.GetExtension(file.FileName).ToLowerInvariant();
if (!allowedExtensions.Contains(fileExtension))
{
return BaseResponse<object>.Fail("只支持 CSV 或 Excel 文件格式");
return "只支持 CSV 或 Excel 文件格式".Fail();
}
// 验证文件大小10MB限制
const long maxFileSize = 10 * 1024 * 1024;
if (file.Length > maxFileSize)
{
return BaseResponse<object>.Fail("文件大小不能超过 10MB");
return "文件大小不能超过 10MB".Fail();
}
// 生成唯一文件名
@@ -69,16 +69,12 @@ public class BillImportController(
}
}
return new BaseResponse<object>
{
Success = ok,
Message = message
};
return message.Ok();
}
catch (Exception ex)
{
logger.LogError(ex, "文件上传失败,类型: {Type}", type);
return BaseResponse<object>.Fail($"文件上传失败: {ex.Message}");
return $"文件上传失败: {ex.Message}".Fail();
}
}
}