优化邮件处理记录的导入来源信息,简化通知内容
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user