Skip to content

Commit

Permalink
✨ (utils): 添加 splitShop 函数用于处理店铺名称和商品名称的分隔逻辑 #475
Browse files Browse the repository at this point in the history
✨ (rule): 新增招商银行微信公众号交易提醒规则及测试用例

✅ (test): 添加招商银行消费测试用例
  • Loading branch information
AnkioTomas committed Dec 18, 2024
1 parent d319fe9 commit 1b38b9e
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/rule/com.tencent.mm/app/微信公众号招商银行/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { BillType, Currency, formatDate, parseWechat, RuleObject, toFloat } from 'common/index.js';
import { splitShop } from 'common/Html.js';

// 定义源名称和需要匹配的标题数组
const SOURCE = '招商银行';
const TITLE = ['交易提醒'];

// 正则表达式和处理函数的映射关系
const rules = [
[
// 交易卡号:**** 5157\n交易时间:11月07日 11:50\n交易类型:财付通-微信支付-群收款快捷支付扣款\n交易金额:人民币20.00元
/交易卡号:.*? (\d+)\n交易时间:(.*?)\n交易类型:(.*?)\n交易金额:人民币(.*?)元/,
match => {
const [,number, time, shopItem_, money] = match;
let {shopName,shopItem} = splitShop(shopItem_);
return new RuleObject(
BillType.Expend,
toFloat(money),
shopName,
shopItem,
`${SOURCE}(${number})`,
'',
0.0,
Currency['人民币'],
formatDate(time, 'M月D日 h:i'),
`微信[${SOURCE}-消费]`)
}
],
];


/**
* @param {string} data - JSON格式的数据
* @returns {RuleObject|null} - 规则对象,如果获取失败则返回null
*/
export function get(data) {
return parseWechat(data, rules, SOURCE, TITLE)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { get } = require('./main');
const fs = require('fs');
const path = require('path');
const { testAnkioInit, testAnkio } = require('../../../../tests/TestUtils');

const { formatDate } = require('common/index.js');

testAnkioInit(get, __dirname, 'com.tencent.mm');

test('招商银行消费', () =>
testAnkio('招商银行消费', [
{
"type": "Expend",
"money": 20,
"fee": 0,
"shopName": '财付通-微信支付',
"shopItem": '群收款快捷支付扣款',
"accountNameFrom": '招商银行(5157)',
"accountNameTo": '',
"currency": 'CNY',
"time": formatDate('11月07日 11:50', 'M月D日 h:i'),
"channel": '微信[招商银行-消费]',
},

]));
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"mMap": {
"tableName": "AppMessage",
"description": "交易卡号:**** 5157\n交易时间:11月07日 11:50\n交易类型:财付通-微信支付-群收款快捷支付扣款\n交易金额:人民币20.00元",
"source": "招商银行",
"t": 1730951431953,
"arg": "msgId",
"type": 5,
"appId": "",
"msgId": 254303,
"title": "交易提醒"
}
}
26 changes: 26 additions & 0 deletions src/utils/Html.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,29 @@ export function findNonEmptyString() {
}
return '';
}

export function splitShop(shopItem, shopName, split) {
split = split || "-"; // 默认分隔符为 "-"

// 如果 shopName 已有值,直接返回
if (shopName) {
return { shopName, shopItem };
}

if (!shopItem) {
return { shopName, shopItem }; // 如果 shopItem 为空,直接返回
}

const parts = shopItem.split(split);

// 分隔逻辑
if (parts.length > 1) {
shopName = parts.slice(0, -1).join(split); // 前部分作为 shopName
shopItem = parts[parts.length - 1]; // 最后部分作为 shopItem
} else {
shopName = null; // 无分隔符时,默认 shopName 为 null
}

return { shopName, shopItem };
}

0 comments on commit 1b38b9e

Please sign in to comment.