2026-02-10 17:49:19 +08:00
|
|
|
using Application.Dto.Email;
|
|
|
|
|
using Application;
|
2026-01-01 12:32:08 +08:00
|
|
|
|
2026-01-18 22:25:59 +08:00
|
|
|
namespace WebApi.Controllers;
|
2025-12-25 11:20:56 +08:00
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
public class EmailMessageController(
|
2026-02-10 17:49:19 +08:00
|
|
|
IEmailMessageApplication emailApplication
|
2025-12-25 11:20:56 +08:00
|
|
|
) : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取邮件列表(分页)
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
2026-02-10 17:49:19 +08:00
|
|
|
public async Task<BaseResponse<EmailPagedResult>> GetListAsync(
|
2025-12-25 11:20:56 +08:00
|
|
|
[FromQuery] DateTime? lastReceivedDate = null,
|
|
|
|
|
[FromQuery] long? lastId = null
|
|
|
|
|
)
|
|
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
var request = new EmailQueryRequest
|
2025-12-25 11:20:56 +08:00
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
LastReceivedDate = lastReceivedDate,
|
|
|
|
|
LastId = lastId
|
|
|
|
|
};
|
|
|
|
|
var result = await emailApplication.GetListAsync(request);
|
|
|
|
|
return result.Ok();
|
2025-12-25 11:20:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据ID获取邮件详情
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("{id}")]
|
2026-02-10 17:49:19 +08:00
|
|
|
public async Task<BaseResponse<EmailMessageResponse>> GetByIdAsync(long id)
|
2025-12-25 11:20:56 +08:00
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
var email = await emailApplication.GetByIdAsync(id);
|
|
|
|
|
return email.Ok();
|
2025-12-25 11:20:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<BaseResponse> DeleteByIdAsync(long id)
|
|
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
await emailApplication.DeleteByIdAsync(id);
|
|
|
|
|
return BaseResponse.Done();
|
2025-12-25 11:20:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 重新分析邮件并刷新交易记录
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<BaseResponse> RefreshTransactionRecordsAsync([FromQuery] long id)
|
|
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
await emailApplication.RefreshTransactionRecordsAsync(id);
|
|
|
|
|
return BaseResponse.Done();
|
2025-12-25 11:20:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 立即同步邮件
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<BaseResponse> SyncEmailsAsync()
|
|
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
await emailApplication.SyncEmailsAsync();
|
|
|
|
|
return "邮件同步成功".Ok();
|
2025-12-25 11:20:56 +08:00
|
|
|
}
|
|
|
|
|
}
|