From b14efd8d1661340f200e2db6da3dde4ff4aaf68b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E8=AF=9A?= Date: Thu, 25 Dec 2025 13:40:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=82=AE=E4=BB=B6=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E6=9C=8D=E5=8A=A1=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=E5=8F=82=E6=95=B0=E4=BB=A5=E5=A2=9E=E5=BC=BA=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E8=83=BD=E5=8A=9B=EF=BC=9B=E4=BF=AE=E6=94=B9HTML?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=BB=A5=E6=94=AF=E6=8C=81PWA=E5=92=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A7=86=E5=9B=BE=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/EmailHandleService.cs | 16 +++++++++------- .../EmailParseServices/EmailParseForm95555.cs | 7 ++++++- .../EmailParseServices/EmailParseFormCCSVC.cs | 7 ++++++- .../EmailParseServices/IEmailParseServices.cs | 4 ++-- Web/index.html | 11 +++++++++-- 5 files changed, 32 insertions(+), 13 deletions(-) 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 + + + + + + + + + 账单管理