diff --git a/Service/BudgetService.cs b/Service/BudgetService.cs index 03f2435..8b14592 100644 --- a/Service/BudgetService.cs +++ b/Service/BudgetService.cs @@ -20,7 +20,7 @@ public class BudgetService( ITransactionRecordRepository transactionRecordRepository, IOpenAiService openAiService, IConfigService configService, - IMessageRecordService messageService, + IMessageService messageService, ILogger logger ) : IBudgetService { @@ -398,7 +398,8 @@ public class BudgetService( await messageService.AddAsync( title: $"{year}年{month}月 - 预算归档报告", content: htmlReport, - type: MessageType.Html); + type: MessageType.Html, + url: "/balance?tab=message"); } } catch (Exception ex) diff --git a/Service/EmailServices/EmailHandleService.cs b/Service/EmailServices/EmailHandleService.cs index 9a2f7cd..b4e86c9 100644 --- a/Service/EmailServices/EmailHandleService.cs +++ b/Service/EmailServices/EmailHandleService.cs @@ -21,7 +21,7 @@ public class EmailHandleService( IEmailMessageRepository emailRepo, ITransactionRecordRepository trxRepo, IEnumerable emailParsers, - IMessageRecordService messageRecordService, + IMessageService messageService, ISmartHandleService smartHandleService ) : IEmailHandleService { @@ -62,18 +62,15 @@ public class EmailHandleService( ); if (parsed == null || parsed.Length == 0) { - await messageRecordService.AddAsync( + await messageService.AddAsync( "邮件解析失败", - $"来自 {from} 发送给 {to} 的邮件(主题:{subject})未能成功解析内容,可能格式已变更或不受支持。" + $"来自 {from} 发送给 {to} 的邮件(主题:{subject})未能成功解析内容,可能格式已变更或不受支持。", + url: $"/balance?tab=email" ); logger.LogWarning("未能成功解析邮件内容,跳过账单处理"); return true; } - await messageRecordService.AddAsync( - "邮件解析成功", - $"来自 {from} 发送给 {to} 的邮件(主题:{subject})已成功解析出 {parsed.Length} 条交易记录。" - ); logger.LogInformation("成功解析邮件,共 {Count} 条交易记录", parsed.Length); bool allSuccess = true; @@ -191,7 +188,7 @@ public class EmailHandleService( await trxRepo.UpdateRangeAsync(records); // 消息 - await messageRecordService.AddAsync( + await messageService.AddAsync( "交易记录待确认分类", $"共有 {records.Length} 条交易记录待确认分类,请点击前往确认。", MessageType.Url, diff --git a/Service/MessageRecordService.cs b/Service/MessageService.cs similarity index 86% rename from Service/MessageRecordService.cs rename to Service/MessageService.cs index 82e3700..e7c4114 100644 --- a/Service/MessageRecordService.cs +++ b/Service/MessageService.cs @@ -1,6 +1,6 @@ namespace Service; -public interface IMessageRecordService +public interface IMessageService { Task<(IEnumerable List, long Total)> GetPagedListAsync(int pageIndex, int pageSize); Task GetByIdAsync(long id); @@ -12,7 +12,7 @@ public interface IMessageRecordService Task GetUnreadCountAsync(); } -public class MessageRecordService(IMessageRecordRepository messageRepo, INotificationService notificationService) : IMessageRecordService +public class MessageService(IMessageRecordRepository messageRepo, INotificationService notificationService) : IMessageService { public async Task<(IEnumerable List, long Total)> GetPagedListAsync(int pageIndex, int pageSize) { @@ -29,7 +29,12 @@ public class MessageRecordService(IMessageRecordRepository messageRepo, INotific return await messageRepo.AddAsync(message); } - public async Task AddAsync(string title, string content, MessageType type = MessageType.Text, string? url = null) + public async Task AddAsync( + string title, + string content, + MessageType type = MessageType.Text, + string? url = null + ) { var message = new MessageRecord { diff --git a/WebApi/Controllers/MessageRecordController.cs b/WebApi/Controllers/MessageRecordController.cs index 07142ad..02b1da5 100644 --- a/WebApi/Controllers/MessageRecordController.cs +++ b/WebApi/Controllers/MessageRecordController.cs @@ -5,7 +5,7 @@ namespace WebApi.Controllers; [Authorize] [ApiController] [Route("api/[controller]/[action]")] -public class MessageRecordController(IMessageRecordService messageService, ILogger logger) : ControllerBase +public class MessageRecordController(IMessageService messageService, ILogger logger) : ControllerBase { /// /// 获取消息列表