From 1d597bdbea7cf427a015bef9242c94f257e45be7 Mon Sep 17 00:00:00 2001 From: ankio Date: Wed, 18 Dec 2024 10:26:57 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20(rule):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=8B=9B=E5=95=86=E9=93=B6=E8=A1=8C=E6=94=B6=E6=AC=BE=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E5=A4=84=E7=90=86=E8=A7=84=E5=88=99=E5=8F=8A=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=20#458?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增对招商银行收款通知的处理规则,支持解析“您账户6598于10月23日13:03收款人民币8650.00”格式文本。更新测试用例以验证新规则的正确性,并添加新的测试文件。 --- .../main.js" | 72 +++++++++++++------ .../main.test.js" | 12 ++++ ...\350\241\214\345\205\245\350\264\2463.txt" | 5 ++ 3 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 "src/rule/cmb.pb/notice/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\246\351\200\232\347\237\245/tests/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\2463.txt" diff --git "a/src/rule/cmb.pb/notice/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\246\351\200\232\347\237\245/main.js" "b/src/rule/cmb.pb/notice/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\246\351\200\232\347\237\245/main.js" index f8835a9..4ba0377 100644 --- "a/src/rule/cmb.pb/notice/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\246\351\200\232\347\237\245/main.js" +++ "b/src/rule/cmb.pb/notice/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\246\351\200\232\347\237\245/main.js" @@ -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; } diff --git "a/src/rule/cmb.pb/notice/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\246\351\200\232\347\237\245/main.test.js" "b/src/rule/cmb.pb/notice/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\246\351\200\232\347\237\245/main.test.js" index b1fb1a2..db86f6c 100644 --- "a/src/rule/cmb.pb/notice/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\246\351\200\232\347\237\245/main.test.js" +++ "b/src/rule/cmb.pb/notice/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\246\351\200\232\347\237\245/main.test.js" @@ -30,4 +30,16 @@ test('招商银行入账', () => "time": 1729137578155, "channel": '招商银行[入账]', }, + { + "type": "Income", + "money": 8650, + "fee": 0, + "shopName": '', + "shopItem": '入账', + "accountNameFrom": '招商银行(6598)', + "accountNameTo": '', + "currency": 'CNY', + "time": 1729659785984, + "channel": '招商银行[收款]', + }, ])); diff --git "a/src/rule/cmb.pb/notice/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\246\351\200\232\347\237\245/tests/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\2463.txt" "b/src/rule/cmb.pb/notice/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\246\351\200\232\347\237\245/tests/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\2463.txt" new file mode 100644 index 0000000..9625274 --- /dev/null +++ "b/src/rule/cmb.pb/notice/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\246\351\200\232\347\237\245/tests/\346\213\233\345\225\206\351\223\266\350\241\214\345\205\245\350\264\2463.txt" @@ -0,0 +1,5 @@ +{ +"title": "招商银行", +"text": "您账户6598于10月23日13:03收款人民币8650.00", +"t": 1729659785984 +}