57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
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();
|
||
}
|
||
} |