Skip to content

Commit

Permalink
✨ (rule): 添加招商银行收款通知处理规则及测试用例 #458
Browse files Browse the repository at this point in the history
新增对招商银行收款通知的处理规则,支持解析“您账户6598于10月23日13:03收款人民币8650.00”格式文本。更新测试用例以验证新规则的正确性,并添加新的测试文件。
  • Loading branch information
AnkioTomas committed Dec 18, 2024
1 parent 82991d0 commit 1d597bd
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 21 deletions.
72 changes: 51 additions & 21 deletions src/rule/cmb.pb/notice/招商银行入账通知/main.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,57 @@
import { BillType, Currency, RuleObject, toFloat } from 'common/index.js';
import { BillType, Currency, formatDate, RuleObject, toFloat, transferCurrency } from 'common/index.js';

// {"title":"招商银行","text":"您尾号6598的招行一卡通入账人民币1442.00元",t}
export function get(data) {
let json = JSON.parse(data)
// 您尾号6598的招行一卡通入账人民币1442.00元
let regex = /您尾号(\d{4})的(.*?)入账(.*?)([\d,]+.\d{2})元/
const match = json.text.match(regex);
if (!match) {
return null;
}
let [,number,cardName,currency,money] = match;

let obj = new RuleObject();
let rules = [
[
/您尾号(\d{4})的(.*?)入账(.*?)([\d,]+.\d{2})元/,
(match,json) => {
let [,number,cardName,currency,money] = match;

let obj = new RuleObject();

obj.money = toFloat(money);
obj.channel = `招商银行[入账]`;
obj.shopName =cardName;
obj.shopItem = "入账";
obj.currency = Currency[currency];
obj.time = json.t;

obj.type = BillType.Income

obj.accountNameFrom = `招商银行(${number})`;
return obj;
}
],
[
// 您账户6598于10月23日13:03收款人民币8650.00
/您账户(\d{4})于(.*?)收款(.*?)([\d,]+.\d{2})/,
(match,json) => {
let [,number,date,currency,money] = match;

obj.money = toFloat(money);
obj.channel = `招商银行[入账]`;
obj.shopName =cardName;
obj.shopItem = "入账";
obj.currency = Currency[currency];
obj.time = json.t;
let obj = new RuleObject();

obj.type = BillType.Income
obj.money = toFloat(money);
obj.channel = `招商银行[收款]`;
obj.shopItem = "入账";
obj.currency = Currency[currency];
obj.time = json.t;

obj.accountNameFrom = `招商银行(${number})`;
return obj;
obj.type = BillType.Income

obj.accountNameFrom = `招商银行(${number})`;
return obj;
}
],
]

export function get(data) {
let json = JSON.parse(data)

for (let [regex,handler] of rules) {
const match = json.text.match(regex);
if (match) {
return handler(match,json);
}
}
return null;
}
12 changes: 12 additions & 0 deletions src/rule/cmb.pb/notice/招商银行入账通知/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ test('招商银行入账', () =>
"time": 1729137578155,
"channel": '招商银行[入账]',
},
{
"type": "Income",
"money": 8650,
"fee": 0,
"shopName": '',
"shopItem": '入账',
"accountNameFrom": '招商银行(6598)',
"accountNameTo": '',
"currency": 'CNY',
"time": 1729659785984,
"channel": '招商银行[收款]',
},
]));
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "招商银行",
"text": "您账户6598于10月23日13:03收款人民币8650.00",
"t": 1729659785984
}

0 comments on commit 1d597bd

Please sign in to comment.