diff --git a/Service/EmailHandleService.cs b/Service/EmailHandleService.cs index 98b2819..83c9a1f 100644 --- a/Service/EmailHandleService.cs +++ b/Service/EmailHandleService.cs @@ -50,9 +50,10 @@ public class EmailHandleService( } var parsed = await ParseEmailBodyAsync( - from, - string.IsNullOrEmpty(emailMessage.Body) - ? emailMessage.HtmlBody + from, + subject, + string.IsNullOrEmpty(emailMessage.Body) + ? emailMessage.HtmlBody : emailMessage.Body ); if (parsed == null || parsed.Length == 0) @@ -112,7 +113,8 @@ public class EmailHandleService( var parsed = await ParseEmailBodyAsync( emailMessage.From, - string.IsNullOrEmpty(emailMessage.Body) + emailMessage.Subject, + string.IsNullOrEmpty(emailMessage.Body) ? emailMessage.HtmlBody : emailMessage.Body ); @@ -159,7 +161,7 @@ public class EmailHandleService( { From = from, Subject = subject, - + ReceivedDate = date, }; @@ -260,9 +262,9 @@ public class EmailHandleService( return inserted; } - private async Task<(string card, string reason, decimal amount, decimal balance, TransactionType type, DateTime? occurredAt)[]?> ParseEmailBodyAsync(string from, string body) + private async Task<(string card, string reason, decimal amount, decimal balance, TransactionType type, DateTime? occurredAt)[]?> ParseEmailBodyAsync(string from, string subject, string body) { - var service = emailParsers.FirstOrDefault(s => s.CanParse(from, body)); + var service = emailParsers.FirstOrDefault(s => s.CanParse(from, subject, body)); if (service == null) { diff --git a/Service/EmailParseServices/EmailParseForm95555.cs b/Service/EmailParseServices/EmailParseForm95555.cs index 334d27b..d5f9f16 100644 --- a/Service/EmailParseServices/EmailParseForm95555.cs +++ b/Service/EmailParseServices/EmailParseForm95555.cs @@ -5,13 +5,18 @@ public class EmailParseForm95555( IOpenAiService openAiService ) : EmailParseServicesBase(logger, openAiService) { - public override bool CanParse(string from, string body) + public override bool CanParse(string from, string subject, string body) { if (!from.Contains("95555@message.cmbchina.com")) { return false; } + if (!subject.Contains("账户变动通知")) + { + return false; + } + // 不能包含HTML标签 if (Regex.IsMatch(body, "<.*?>")) { diff --git a/Service/EmailParseServices/EmailParseFormCCSVC.cs b/Service/EmailParseServices/EmailParseFormCCSVC.cs index bcf49ba..063c5b5 100644 --- a/Service/EmailParseServices/EmailParseFormCCSVC.cs +++ b/Service/EmailParseServices/EmailParseFormCCSVC.cs @@ -7,13 +7,18 @@ public class EmailParseFormCCSVC( IOpenAiService openAiService ) : EmailParseServicesBase(logger, openAiService) { - public override bool CanParse(string from, string body) + public override bool CanParse(string from, string subject, string body) { if (!from.Contains("ccsvc@message.cmbchina.com")) { return false; } + if (!subject.Contains("每日信用管家")) + { + return false; + } + // 必须包含HTML标签 if (!Regex.IsMatch(body, "<.*?>")) { diff --git a/Service/EmailParseServices/IEmailParseServices.cs b/Service/EmailParseServices/IEmailParseServices.cs index 4d757f6..767e1ab 100644 --- a/Service/EmailParseServices/IEmailParseServices.cs +++ b/Service/EmailParseServices/IEmailParseServices.cs @@ -2,7 +2,7 @@ public interface IEmailParseServices { - bool CanParse(string from, string body); + bool CanParse(string from, string subject, string body); /// /// 解析邮件内容,提取交易信息 @@ -22,7 +22,7 @@ public abstract class EmailParseServicesBase( IOpenAiService openAiService ) : IEmailParseServices { - public abstract bool CanParse(string from, string body); + public abstract bool CanParse(string from, string subject, string body); public async Task<( string card, diff --git a/Web/index.html b/Web/index.html index b19040a..c86fb8d 100644 --- a/Web/index.html +++ b/Web/index.html @@ -3,8 +3,15 @@ - - Vite App + + + + + + + + + 账单管理