Skip to content

Commit

Permalink
✨ (rule): 添加重庆公积金中心短信解析规则
Browse files Browse the repository at this point in the history
新增重庆公积金中心短信解析规则,包括:
- 新增 `main.js` 文件,实现短信解析逻辑
- 新增 `main.test.js` 文件,添加单元测试
- 新增 `重庆公积金中心收入.txt` 文件,作为测试数据
  • Loading branch information
AnkioTomas committed Dec 30, 2024
1 parent c271cbd commit 391ebe0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/rule/com.android.phone/app/短信重庆公积金中心/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { formatDate, isPaymentType, RuleObject, splitSms, toFloat } from 'common/index.js';

let senderName = '重庆公积金中心';

// 正则表达式和处理函数的映射关系
const rules = [
[
//【重庆公积金中心】您的个人账户于2024年12月13日汇缴公积金1980元,汇缴年月为202412, 余额9900元。
/您的个人账户于(\d{4}年\d{1,2}月\d{1,2}日)(.*?)公积金(.*?)元,汇缴年月为(\d{6}), 余额(.*?)元。/,
match => {
let [, date, type, money, month, balance] = match;

let obj = new RuleObject();

let { matchType, typeName } = isPaymentType(type);

obj.money = toFloat(money);
obj.channel = `${senderName}[${typeName}]`;
obj.shopItem = type;
obj.time = formatDate(date, 'Y年M月D日');
obj.type = matchType;
obj.accountNameFrom = `${senderName}`;
return obj;
}
]
];

/**
* @param {string} data - JSON格式的数据
* @returns {RuleObject|null} - 规则对象,如果获取失败则返回null
*/
export function get (data) {
let { sender, bankName, text, t } = splitSms(data);
if (bankName !== senderName) {
return null;
}
for (let rule of rules) {
const match = text.match(rule[0]);
if (match) {
return rule[1](match, t);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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': 1980,
'fee': 0,
'shopName': '',
'shopItem': '汇缴',
'accountNameFrom': '重庆公积金中心',
'accountNameTo': '',
'currency': 'CNY',
'time': formatDate('2024年12月13日', 'Y年M月D日'),
'channel': '重庆公积金中心[收入]'
}
]));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"sender":"12329","body":"【重庆公积金中心】您的个人账户于2024年12月13日汇缴公积金1980元,汇缴年月为202412, 余额9900元。","t":1734060747038}

0 comments on commit 391ebe0

Please sign in to comment.