diff --git a/Service/EmailServices/EmailHandleService.cs b/Service/EmailServices/EmailHandleService.cs index 89f0373..d1a0872 100644 --- a/Service/EmailServices/EmailHandleService.cs +++ b/Service/EmailServices/EmailHandleService.cs @@ -76,15 +76,14 @@ public class EmailHandleService( ); logger.LogInformation("成功解析邮件,共 {Count} 条交易记录", parsed.Length); - // TODO 接入AI分类 - // 目前已经 - bool allSuccess = true; var records = new List(); foreach (var (card, reason, amount, balance, type, occurredAt) in parsed) { logger.LogInformation("处理交易记录: 卡号 {Card}, 交易原因 {Reason}, 金额 {Amount}, 余额 {Balance}, 类型 {Type}", card, reason, amount, balance, type); + + var record = await SaveTransactionRecordAsync( card, reason, @@ -92,7 +91,8 @@ public class EmailHandleService( balance, type, occurredAt ?? date, - emailMessage.Id + emailMessage.Id, + $"邮件 By {GetEmailByName(to)}" ); if (record == null) @@ -160,7 +160,8 @@ public class EmailHandleService( balance, type, occurredAt ?? emailMessage.ReceivedDate, - emailMessage.Id + emailMessage.Id, + $"邮件 By {GetEmailByName(emailMessage.To)}" ); if (record == null) @@ -177,6 +178,11 @@ public class EmailHandleService( return allSuccess; } + private string GetEmailByName(string to) + { + return emailSettings.Value.SmtpList.FirstOrDefault(s => s.Email == to)?.Name ?? to; + } + private async Task SaveEmailAsync( string to, string from, @@ -241,7 +247,8 @@ public class EmailHandleService( decimal balance, TransactionType type, DateTime occurredAt, - long emailMessageId + long emailMessageId, + string importFrom ) { // 根据 emailMessageId 检查是否已存在记录:存在则更新,否则新增 @@ -279,7 +286,7 @@ public class EmailHandleService( Type = type, OccurredAt = occurredAt, EmailMessageId = emailMessageId, - ImportFrom = $"邮件" + ImportFrom = importFrom }; var inserted = await trxRepo.AddAsync(trx); diff --git a/Service/MessageRecordService.cs b/Service/MessageRecordService.cs index 69dfd29..8b98b49 100644 --- a/Service/MessageRecordService.cs +++ b/Service/MessageRecordService.cs @@ -40,7 +40,7 @@ public class MessageRecordService(IMessageRecordRepository messageRepo, INotific var result = await messageRepo.AddAsync(message); if (result) { - await notificationService.SendNotificationAsync($"新增的账单通知: {title}"); + await notificationService.SendNotificationAsync(title); } return result; }