Skip to content

Commit

Permalink
🐛 (utils): 修复无分隔符时 shopName 默认值为 null 的问题 #485
Browse files Browse the repository at this point in the history
无分隔符时,shopName 应为空字符串而不是 null,以确保数据一致性。

:sparkles: (rule): 更新工商银行短信解析规则及测试用例

- 引入 `splitShop` 函数,优化 shopName 和 shopItem 的解析逻辑。
- 更新测试用例,确保 shopName 和 shopItem 的正确分配。
- 新增测试文件 `工商银行支出3.txt`,包含新的短信样本。
  • Loading branch information
AnkioTomas committed Dec 18, 2024
1 parent 7d8d968 commit 5dd4aea
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/rule/com.android.phone/app/短信工商银行/main.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { BillType, formatDate, RuleObject, splitSms, toFloat } from 'common/index.js';
import { BillType, formatDate, RuleObject, splitShop, splitSms, toFloat } from 'common/index.js';

let rules = [
{
// 尾号1234卡9月27日18:55支出(消费支付宝-北京三快在线科技有限公司)45元,余额1,333.22元。【工商银行】
// 尾号1234卡10月9日19:12收入(微信零钱提现财付通)6.70元,余额0.64元。【工商银行】
// 尾号1234卡10月14日23:41网上银行支出(无卡支付)4.78元,余额3.46元。
'regex': /尾号(\d{4})卡(.*?)(网上银行支出|支出|收入)\((.*?)\)([\d,]+(.\d{2})?)元,余额([\d,]+.\d{2})元。/,
// 尾号5537卡11月11日12:39支出(消费支付宝-严)28.1元,余额6.66元。
'regex': /尾号(\d{4})卡(.*?)(网上银行支出|支出|收入)\((.*?)\)(.*?)元,余额(.*?)元。/,
'match': (match) => {
let [, number, date,type, shopName, money, ] = match;
let [, number, date,type, shopItem_, money, ] = match;
let obj = new RuleObject();

obj.money = toFloat(money);
obj.channel = `工商银行[${type}]`;
let {shopName,shopItem} = splitShop(shopItem_);
obj.shopName = shopName;
obj.shopItem = shopItem;
obj.time = formatDate(date, 'M月D日h:i');

if (type.indexOf('支出') !==-1) {
Expand Down
24 changes: 18 additions & 6 deletions src/rule/com.android.phone/app/短信工商银行/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ test('工商银行支出', () =>
"type": "Expend",
"money": 45,
"fee": 0,
"shopName": '消费支付宝-北京三快在线科技有限公司',
"shopItem": '',
"shopName": '消费支付宝',
"shopItem": '北京三快在线科技有限公司',
"accountNameFrom": '工商银行(1234)',
"accountNameTo": '',
"currency": 'CNY',
Expand All @@ -20,23 +20,35 @@ test('工商银行支出', () =>
"type": "Expend",
"money": 4.78,
"fee": 0,
"shopName": '无卡支付',
"shopItem": '',
"shopName": '',
"shopItem": '无卡支付',
"accountNameFrom": '工商银行(1234)',
"accountNameTo": '',
"currency": 'CNY',
"time": formatDate("10月14日23:41","M月D日h:i"),
"channel": '工商银行[网上银行支出]',
},
{
"type": "Expend",
"money": 28.1,
"fee": 0,
"shopName": '消费支付宝',
"shopItem": '严',
"accountNameFrom": '工商银行(5537)',
"accountNameTo": '',
"currency": 'CNY',
"time": formatDate("11月11日12:39","M月D日h:i"),
"channel": '工商银行[支出]',
},
]));
test('工商银行收入', () =>
testAnkio('工商银行收入', [
{
"type": "Income",
"money": 6.7,
"fee": 0,
"shopName": '微信零钱提现财付通',
"shopItem": '',
"shopName": '',
"shopItem": '微信零钱提现财付通',
"accountNameFrom": '工商银行(1234)',
"accountNameTo": '',
"currency": 'CNY',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sender": "95588",
"body": "尾号5537卡11月11日12:39支出(消费支付宝-严)28.1元,余额6.66元。【工商银行】",
"t": 1731299979528
}
2 changes: 1 addition & 1 deletion src/utils/Html.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function splitShop(shopItem, shopName, split) {
shopName = parts.slice(0, -1).join(split); // 前部分作为 shopName
shopItem = parts[parts.length - 1]; // 最后部分作为 shopItem
} else {
shopName = null; // 无分隔符时,默认 shopName 为 null
shopName = ''; // 无分隔符时,默认 shopName 为 null
}

return { shopName, shopItem };
Expand Down

0 comments on commit 5dd4aea

Please sign in to comment.