Files
EmailBill/WebApi/Controllers/BillImportController.cs
SunCheng d052ae5197 fix
2026-02-10 17:49:19 +08:00

57 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Application;
using Application.Dto;
namespace WebApi.Controllers;
/// <summary>
/// 账单导入控制器
/// </summary>
[ApiController]
[Route("api/[controller]/[action]")]
public class BillImportController(
IImportApplication importApplication
) : ControllerBase
{
/// <summary>
/// 上传账单文件
/// </summary>
/// <param name="file">账单文件</param>
/// <param name="type">账单类型Alipay | WeChat</param>
/// <returns></returns>
[HttpPost]
public async Task<BaseResponse> UploadFile(
[FromForm] IFormFile file,
[FromForm] string type
)
{
// 将IFormFile转换为ImportRequest
var stream = new MemoryStream();
await file.CopyToAsync(stream);
stream.Position = 0;
var request = new ImportRequest
{
FileStream = stream,
FileExtension = Path.GetExtension(file.FileName).ToLowerInvariant(),
FileName = file.FileName,
FileSize = file.Length
};
ImportResponse result;
if (type == "Alipay")
{
result = await importApplication.ImportAlipayAsync(request);
}
else if (type == "WeChat")
{
result = await importApplication.ImportWeChatAsync(request);
}
else
{
return "账单类型参数错误,必须是 Alipay 或 WeChat".Fail();
}
return result.Message.Ok();
}
}