feat: 重构消息服务,替换消息记录服务为消息服务,更新相关依赖和逻辑
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 20s
Docker Build & Deploy / Deploy to Production (push) Successful in 7s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s

This commit is contained in:
2026-01-10 17:47:09 +08:00
parent b757f18765
commit 6a9c879dee
4 changed files with 17 additions and 14 deletions

View File

@@ -20,7 +20,7 @@ public class BudgetService(
ITransactionRecordRepository transactionRecordRepository, ITransactionRecordRepository transactionRecordRepository,
IOpenAiService openAiService, IOpenAiService openAiService,
IConfigService configService, IConfigService configService,
IMessageRecordService messageService, IMessageService messageService,
ILogger<BudgetService> logger ILogger<BudgetService> logger
) : IBudgetService ) : IBudgetService
{ {
@@ -398,7 +398,8 @@ public class BudgetService(
await messageService.AddAsync( await messageService.AddAsync(
title: $"{year}年{month}月 - 预算归档报告", title: $"{year}年{month}月 - 预算归档报告",
content: htmlReport, content: htmlReport,
type: MessageType.Html); type: MessageType.Html,
url: "/balance?tab=message");
} }
} }
catch (Exception ex) catch (Exception ex)

View File

@@ -21,7 +21,7 @@ public class EmailHandleService(
IEmailMessageRepository emailRepo, IEmailMessageRepository emailRepo,
ITransactionRecordRepository trxRepo, ITransactionRecordRepository trxRepo,
IEnumerable<IEmailParseServices> emailParsers, IEnumerable<IEmailParseServices> emailParsers,
IMessageRecordService messageRecordService, IMessageService messageService,
ISmartHandleService smartHandleService ISmartHandleService smartHandleService
) : IEmailHandleService ) : IEmailHandleService
{ {
@@ -62,18 +62,15 @@ public class EmailHandleService(
); );
if (parsed == null || parsed.Length == 0) if (parsed == null || parsed.Length == 0)
{ {
await messageRecordService.AddAsync( await messageService.AddAsync(
"邮件解析失败", "邮件解析失败",
$"来自 {from} 发送给 {to} 的邮件(主题:{subject})未能成功解析内容,可能格式已变更或不受支持。" $"来自 {from} 发送给 {to} 的邮件(主题:{subject})未能成功解析内容,可能格式已变更或不受支持。",
url: $"/balance?tab=email"
); );
logger.LogWarning("未能成功解析邮件内容,跳过账单处理"); logger.LogWarning("未能成功解析邮件内容,跳过账单处理");
return true; return true;
} }
await messageRecordService.AddAsync(
"邮件解析成功",
$"来自 {from} 发送给 {to} 的邮件(主题:{subject})已成功解析出 {parsed.Length} 条交易记录。"
);
logger.LogInformation("成功解析邮件,共 {Count} 条交易记录", parsed.Length); logger.LogInformation("成功解析邮件,共 {Count} 条交易记录", parsed.Length);
bool allSuccess = true; bool allSuccess = true;
@@ -191,7 +188,7 @@ public class EmailHandleService(
await trxRepo.UpdateRangeAsync(records); await trxRepo.UpdateRangeAsync(records);
// 消息 // 消息
await messageRecordService.AddAsync( await messageService.AddAsync(
"交易记录待确认分类", "交易记录待确认分类",
$"共有 {records.Length} 条交易记录待确认分类,请点击前往确认。", $"共有 {records.Length} 条交易记录待确认分类,请点击前往确认。",
MessageType.Url, MessageType.Url,

View File

@@ -1,6 +1,6 @@
namespace Service; namespace Service;
public interface IMessageRecordService public interface IMessageService
{ {
Task<(IEnumerable<MessageRecord> List, long Total)> GetPagedListAsync(int pageIndex, int pageSize); Task<(IEnumerable<MessageRecord> List, long Total)> GetPagedListAsync(int pageIndex, int pageSize);
Task<MessageRecord?> GetByIdAsync(long id); Task<MessageRecord?> GetByIdAsync(long id);
@@ -12,7 +12,7 @@ public interface IMessageRecordService
Task<long> GetUnreadCountAsync(); Task<long> GetUnreadCountAsync();
} }
public class MessageRecordService(IMessageRecordRepository messageRepo, INotificationService notificationService) : IMessageRecordService public class MessageService(IMessageRecordRepository messageRepo, INotificationService notificationService) : IMessageService
{ {
public async Task<(IEnumerable<MessageRecord> List, long Total)> GetPagedListAsync(int pageIndex, int pageSize) public async Task<(IEnumerable<MessageRecord> List, long Total)> GetPagedListAsync(int pageIndex, int pageSize)
{ {
@@ -29,7 +29,12 @@ public class MessageRecordService(IMessageRecordRepository messageRepo, INotific
return await messageRepo.AddAsync(message); return await messageRepo.AddAsync(message);
} }
public async Task<bool> AddAsync(string title, string content, MessageType type = MessageType.Text, string? url = null) public async Task<bool> AddAsync(
string title,
string content,
MessageType type = MessageType.Text,
string? url = null
)
{ {
var message = new MessageRecord var message = new MessageRecord
{ {

View File

@@ -5,7 +5,7 @@ namespace WebApi.Controllers;
[Authorize] [Authorize]
[ApiController] [ApiController]
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
public class MessageRecordController(IMessageRecordService messageService, ILogger<MessageRecordController> logger) : ControllerBase public class MessageRecordController(IMessageService messageService, ILogger<MessageRecordController> logger) : ControllerBase
{ {
/// <summary> /// <summary>
/// 获取消息列表 /// 获取消息列表