Skip to content

Commit

Permalink
✨ (rule): 新增光大银行信用卡消费测试用例并优化规则解析逻辑 #611
Browse files Browse the repository at this point in the history
- 新增测试用例 `光大银行信用卡消费2.txt`,覆盖中国石化消费场景
- 优化 `main.js` 中的规则解析逻辑,使用 `splitShop` 和 `isPaymentType` 工具函数简化代码
- 更新 `main.test.js`,添加新的测试数据以验证规则解析的正确性
  • Loading branch information
AnkioTomas committed Dec 28, 2024
1 parent b3e0feb commit dce8557
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BillType, Currency, formatDate, parseWechat, RuleObject, toFloat } from 'common/index.js';
import { Currency, formatDate, isPaymentType, parseWechat, RuleObject, splitShop, toFloat } from 'common/index.js';

// 定义源名称和需要匹配的标题数组
const SOURCE = '光大银行信用卡';
Expand All @@ -7,33 +7,20 @@ const TITLE = ['信用卡交易提醒'];
// 正则表达式和处理函数的映射关系
const rules = [
[
/交易时间:(.*?)[\s\n]交易类型:尾号(\d+)信用卡,(.*?)[\s\n]交易金额:(\d+(?:\.\d+)?)元[\s\n]交易商户:(.*?)[\s\n]可用额度:/,
//交易时间:2024年11月25日 18:55\n交易类型:尾号5338信用卡,消费\n交易金额:10000元\n交易商户:财付通 华强电子世界\n可用额度:23358.81元","source":"光大银行信用卡
// 交易时间:2024年12月18日 10:10交易类型:尾号7558信用卡,消费\n交易金额:100元\n交易商户:中国石化销售股份有限公司安徽石油\n可用额度:36120.67元
/交易时间:(.*?)(\n)?交易类型:尾号(\d+)信用卡,(.*?)[\s\n]交易金额:(\d+(?:\.\d+)?)元[\s\n]交易商户:(.*?)[\s\n]可用额度:/,
match => {
let [, time, cardNumber, type, money, merchant] = match;
console.log(cardNumber,)
// 解析商户名称
let shopName = '';
let shopItem = merchant;
let [, time, , cardNumber, type, money, merchant] = match;

// 检查商户名称是否包含空格,如果包含则分割
const merchantParts = merchant.trim().split(' ');
if (merchantParts.length > 1) {
shopName = merchantParts[0];
shopItem = merchantParts[1];
}

// 判断交易类型
let billType = BillType.Expend;
let typeName = "支出";

// 如果交易类型包含特定关键词,则认为是收入
const incomeKeywords = ['退货', '转入', '退款', '还款'];
if (incomeKeywords.some(keyword => type.includes(keyword))) {
billType = BillType.Income;
typeName = "收入";
}
let { shopName, shopItem } = splitShop(merchant, null, ' ');

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


return new RuleObject(
billType,
matchType,
toFloat(money),
shopName,
shopItem,
Expand All @@ -54,4 +41,4 @@ const rules = [
*/
export function get(data) {
return parseWechat(data, rules, SOURCE, TITLE);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

const { get } = require('./main');
const { testAnkioInit, testAnkio } = require('../../../../tests/TestUtils');
const { formatDate } = require('common/index.js');
Expand All @@ -17,5 +18,18 @@ test('光大银行信用卡消费', () =>
"currency": 'CNY',
"time": formatDate('2024年11月25日 18:55', 'Y年M月D日 h:i'),
"channel": '微信[光大银行信用卡-支出]',
},
{
'type': 'Expend',
'money': 100,
'fee': 0,
'shopName': '',
'shopItem': '中国石化销售股份有限公司安徽石油',
'accountNameFrom': '光大银行信用卡(7558)',
'accountNameTo': '',
'currency': 'CNY',
'time': formatDate('2024年12月18日 10:10', 'Y年M月D日 h:i'),
'channel': '微信[光大银行信用卡-支出]'
}
]));
]));

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"mMap":{"tableName":"AppMessage","description":"交易时间:2024年12月18日 10:10交易类型:尾号7558信用卡,消费\n交易金额:100元\n交易商户:中国石化销售股份有限公司安徽石油\n可用额度:36120.67元","source":"光大银行信用卡","t":1734487849087,"arg":"msgId","type":5,"appId":"","msgId":10305271,"title":"信用卡交易提醒"}}

0 comments on commit dce8557

Please sign in to comment.