Skip to content

Commit

Permalink
♻️ (rule): 重构微信公众号广发银行规则逻辑,优化交易类型判断
Browse files Browse the repository at this point in the history
- 使用 `isPaymentType` 函数统一处理交易类型判断,简化代码逻辑
- 更新测试用例中的 `type` 和 `channel` 字段以匹配新逻辑
- 移除冗余的 `switch` 语句,提高代码可维护性
  • Loading branch information
AnkioTomas committed Dec 29, 2024
1 parent 753922f commit 0195636
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
22 changes: 7 additions & 15 deletions src/rule/com.tencent.mm/app/微信公众号广发银行/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BillType, formatDate, parseWechat, RuleObject, toFloat, transferCurrency } from 'common/index.js';
import { formatDate, isPaymentType, parseWechat, RuleObject, toFloat, transferCurrency } from 'common/index.js';

// 定义源名称和需要匹配的标题数组
const SOURCE = '广发银行';
Expand All @@ -7,23 +7,15 @@ const TITLE = ['交易提醒'];
// 正则表达式和处理函数的映射关系
const rules = [
[
// 交易时间:尾号8206广发卡10月23日18:09\n交易类型:消费\n交易金额:人民币9.90元\n交易商户:抖音支付-抖音生活服务商家\n可用额度:人民币1771.74元。点详情借钱,利息1.9折起
//交易时间:您尾号5005卡 10月16日00:12\n交易类型:转账支出\n交易金额:人民币40.00元
/交易时间:您尾号(\d+)卡 (.*?)\n交易类型:(.*?)\n交易金额:(.*?)([\d,]+.\d{2})元/,
match => {
const [, number, time, type, currency, money] = match;
let billType = BillType.Income;
let channel = `收入`;
switch (type) {
case '消费':
billType = BillType.Expend;
channel = `支出`;
break;
case '转账支出':
billType = BillType.Transfer;
channel = `转账`;
}
let { matchType, typeName } = isPaymentType(type);
// let {shopName,shopItem} = splitShop(item)
return new RuleObject(
billType,
matchType,
toFloat(money),
'',
'',
Expand All @@ -32,10 +24,10 @@ const rules = [
0.0,
transferCurrency(currency),
formatDate(time, 'M月D日h:i'),
`微信[${SOURCE}-${channel}]`
`微信[${SOURCE}-${typeName}]`
);
}
]
],
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ testAnkioInit(get, __dirname, 'com.tencent.mm');
test('广发借记卡转账', () =>
testAnkio('广发借记卡转账', [
{
'type': 'Transfer',
'type': 'Expend',
'money': 40,
'fee': 0,
'shopName': '',
Expand All @@ -19,6 +19,6 @@ test('广发借记卡转账', () =>
'accountNameTo': '',
'currency': 'CNY',
'time': formatDate('10月16日00:12', 'M月D日h:i'),
'channel': '微信[广发银行-转账]'
'channel': '微信[广发银行-支出]'
}
]));

0 comments on commit 0195636

Please sign in to comment.