优化邮件解析正则表达式,增强交易信息提取能力;调整界面样式,增加删除功能
Some checks failed
Docker Build & Deploy / Build Docker Image (push) Failing after 5s
Docker Build & Deploy / Deploy to Production (push) Has been skipped

This commit is contained in:
2025-12-31 11:49:25 +08:00
parent e7d5c076d4
commit 545796aba9
5 changed files with 115 additions and 16 deletions

View File

@@ -35,13 +35,16 @@ public class EmailParseForm95555(
DateTime? occurredAt
)[]> ParseEmailContentAsync(string emailContent)
{
// 示例1您账户8826于12月31日09:34在财付通-微信支付-这有电快捷支付1.00元余额30.21
// 示例2: 您账户8826于12月31日10:47入账款项人民币1000.00余额人民币1030.21。
var pattern =
"您账户(?<card>\\d+)" +
"于.*?" + // 时间等信息统统吞掉
"(?:(?<type>收入|支出|消费|转入|转出).*?)?" + // 可选 type
"(?:在(?<reason>.*?))?" + // 可选 reason“财付通-微信支付-这有电快捷支付”
"(?<amount>\\d+\\.\\d{1,2})元,余额" +
"(?<balance>\\d+\\.\\d{1,2})";
"您账户(?<card>\\d+)" + // 卡号
"于(?<time>\\d{1,2}月\\d{1,2}日\\d{1,2}:\\d{2})" + // 交易时间
"(?:(?<type>收入|支出|消费|转入|转出|入账款项))?" + // 交易类型(可选)
"(?:在(?<reason>[^\\d。]*?))?" + // 交易原因(可选
"?(?:人民币)?(?<amount>\\d+\\.\\d{1,2})(?:元)?" + // 金额,“元” 可有可无
",余额(?:人民币)?(?<balance>\\d+\\.\\d{1,2})" + // 余额
"。?"; // 句号可有可无
var matches = Regex.Matches(emailContent, pattern);
@@ -63,10 +66,14 @@ public class EmailParseForm95555(
foreach (Match match in matches)
{
var card = match.Groups["card"].Value;
var reason = match.Groups["reason"].Value;
var amountStr = match.Groups["amount"].Value;
var balanceStr = match.Groups["balance"].Value;
var typeStr = match.Groups["type"].Value;
var reason = match.Groups["reason"].Value;
if(string.IsNullOrEmpty(reason))
{
reason = typeStr;
}
if (!string.IsNullOrEmpty(card) &&
!string.IsNullOrEmpty(reason) &&
@@ -74,9 +81,27 @@ public class EmailParseForm95555(
decimal.TryParse(balanceStr, out var balance))
{
var type = DetermineTransactionType(typeStr, reason, amount);
results.Add((card, reason, amount, balance, type, null));
var occurredAt = ParseOccurredAt(match.Groups["time"].Value);
results.Add((card, reason, amount, balance, type, occurredAt));
}
}
return results.ToArray();
}
private DateTime? ParseOccurredAt(string value)
{
// "12月31日09:34"
var now = DateTime.Now;
var dateTimeStr = $"{now.Year}年{value}";
if (DateTime.TryParse(dateTimeStr, out var occurredAt))
{
// 如果解析结果在未来,说明是上一年的交易
if (occurredAt > now)
{
occurredAt = occurredAt.AddYears(-1);
}
return occurredAt;
}
return null;
}
}