2026-02-10 17:49:19 +08:00
|
|
|
|
using Application;
|
|
|
|
|
|
using Application.Dto;
|
|
|
|
|
|
|
|
|
|
|
|
namespace WebApi.Controllers;
|
2025-12-25 11:20:56 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 账单导入控制器
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
|
public class BillImportController(
|
2026-02-10 17:49:19 +08:00
|
|
|
|
IImportApplication importApplication
|
2025-12-25 11:20:56 +08:00
|
|
|
|
) : ControllerBase
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 上传账单文件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="file">账单文件</param>
|
|
|
|
|
|
/// <param name="type">账单类型(Alipay | WeChat)</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
2026-01-04 16:43:32 +08:00
|
|
|
|
public async Task<BaseResponse> UploadFile(
|
2025-12-25 11:20:56 +08:00
|
|
|
|
[FromForm] IFormFile file,
|
|
|
|
|
|
[FromForm] string type
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
|
// 将IFormFile转换为ImportRequest
|
|
|
|
|
|
var stream = new MemoryStream();
|
|
|
|
|
|
await file.CopyToAsync(stream);
|
|
|
|
|
|
stream.Position = 0;
|
2025-12-25 11:20:56 +08:00
|
|
|
|
|
2026-02-10 17:49:19 +08:00
|
|
|
|
var request = new ImportRequest
|
|
|
|
|
|
{
|
|
|
|
|
|
FileStream = stream,
|
|
|
|
|
|
FileExtension = Path.GetExtension(file.FileName).ToLowerInvariant(),
|
|
|
|
|
|
FileName = file.FileName,
|
|
|
|
|
|
FileSize = file.Length
|
|
|
|
|
|
};
|
2025-12-25 11:20:56 +08:00
|
|
|
|
|
2026-02-10 17:49:19 +08:00
|
|
|
|
ImportResponse result;
|
2026-01-18 22:25:59 +08:00
|
|
|
|
|
2026-02-10 17:49:19 +08:00
|
|
|
|
if (type == "Alipay")
|
|
|
|
|
|
{
|
|
|
|
|
|
result = await importApplication.ImportAlipayAsync(request);
|
2025-12-25 11:20:56 +08:00
|
|
|
|
}
|
2026-02-10 17:49:19 +08:00
|
|
|
|
else if (type == "WeChat")
|
2025-12-25 11:20:56 +08:00
|
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
|
result = await importApplication.ImportWeChatAsync(request);
|
2025-12-25 11:20:56 +08:00
|
|
|
|
}
|
2026-02-10 17:49:19 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return "账单类型参数错误,必须是 Alipay 或 WeChat".Fail();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result.Message.Ok();
|
2025-12-25 11:20:56 +08:00
|
|
|
|
}
|
2026-01-18 22:25:59 +08:00
|
|
|
|
}
|