Skip to content

Commit

Permalink
✨ (rule): 添加泉州公积金中心短信解析规则及测试用例 #469
Browse files Browse the repository at this point in the history
新增泉州公积金中心短信解析规则,支持解析公积金缴存信息并生成收入账单对象。同时添加了相应的测试用例和测试数据,确保规则的正确性和稳定性。
  • Loading branch information
AnkioTomas committed Dec 18, 2024
1 parent ab15ec0 commit 0c0a444
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/rule/com.android.phone/app/短信泉州公积金中心/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { BillType, Currency, formatDate, RuleObject, splitSms, toFloat } from 'common/index.js';

let rules = [
{
// *辉您公积金账号[尾号6864]于10月30日缴存2186元,余额12611.76元。【泉州公积金中心】
'regex': /(.*?)您公积金账号\[尾号(\d+)\]于(.*?)缴存(.*?)元,余额(.*?)元。【泉州公积金中心】/,
'match': (match,t) => {
let [, shopName,number,date, money,shopItem, ] = match;
let obj = new RuleObject();

obj.money = toFloat(money);
obj.channel = `泉州公积金中心[收入]`;
obj.shopName = shopName;
obj.shopItem = `余额:${shopItem}`;
obj.time = t;

obj.type = BillType.Income;

obj.accountNameFrom = `泉州公积金中心(${number})`;
return obj;
}

},
];

export function get (data) {
let { sender, bankName, text, t } = splitSms(data);
if (bankName !== '福建12329') {
return null;
}
for (let rule of rules) {
const match = text.match(rule.regex);
if (match) {
return rule.match(match,t);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { get } = require('./main');
const { testAnkio, testAnkioInit } = require('../../../../tests/TestUtils');
const { formatDate } = require('common/Time.js');
testAnkioInit(get, __dirname, 'com.android.phone');
test('泉州公积金中心收入', () =>
testAnkio('泉州公积金中心收入', [
{
"type": "Income",
"money": 2186,
"fee": 0,
"shopName": '*辉',
"shopItem": '余额:12611.76',
"accountNameFrom": '泉州公积金中心(6864)',
"accountNameTo": '',
"currency": 'CNY',
"time": 1730341259074,
"channel": '泉州公积金中心[收入]',
},
]));


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sender": "12329",
"body": "【福建12329】*辉您公积金账号[尾号6864]于10月30日缴存2186元,余额12611.76元。【泉州公积金中心】",
"t": 1730341259074
}

0 comments on commit 0c0a444

Please sign in to comment.