优化邮件处理记录的导入来源信息,简化通知内容
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 21s
Docker Build & Deploy / Deploy to Production (push) Successful in 7s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s

This commit is contained in:
2026-01-03 12:04:26 +08:00
parent 5c108d27df
commit 53d8470e88
2 changed files with 15 additions and 8 deletions

View File

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

View File

@@ -40,7 +40,7 @@ public class MessageRecordService(IMessageRecordRepository messageRepo, INotific
var result = await messageRepo.AddAsync(message); var result = await messageRepo.AddAsync(message);
if (result) if (result)
{ {
await notificationService.SendNotificationAsync($"新增的账单通知: {title}"); await notificationService.SendNotificationAsync(title);
} }
return result; return result;
} }