-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 添加宁波银行收入规则 - 收入类型为工资 - 交易对象为大夏公司 - 可通过 `main.test.js` 测试 - 添加 `宁波银行收入.txt` 用于测试数据 - 使用正则表达式匹配文本内容 - 解析匹配结果并构建 RuleObject 对象 - 使用 `formatDate` 函数格式化时间 - 使用 `toFloat` 函数格式化金额 - 使用 `testAnkio` 函数测试规则 - 使用 `Currency` 枚举类型表示币种 - 使用 `BillType` 枚举类型表示账单类型 - 使用 `RuleObject` 类构建账单对象 - 使用 `SOURCE_NAME_BOC` 定义银行名称 - 使用 `TITLES_BOC` 定义匹配标题 - 使用 `regexMapBOC` 定义正则表达式和处理函数映射 - 使用 `parseBOCText` 函数解析文本内容 - 使用 `get` 函数获取账单对象 - 使用 `testAnkioInit` 初始化测试环境
- Loading branch information
1 parent
d44d211
commit c551901
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { BillType, Currency, formatDate, RuleObject, toFloat } from 'common/index.js'; | ||
|
||
// 定义源名称和需要匹配的标题数组 | ||
const SOURCE_NAME_BOC = '宁波银行'; | ||
const TITLES_BOC = ['交易提醒']; | ||
|
||
// 正则表达式和处理函数的映射关系 | ||
const regexMapBOC = [ | ||
[ | ||
//交易类型:尾号2582-工资-人民币\n交易时间:09月15日 17:00\n交易对象:大夏公司\n交易金额:1696.49\n可用余额:428.97 | ||
/交易类型:尾号(\d{4})-(.*?)-人民币\n交易时间:(.*?)\n交易对象:(.*?)\n交易金额:([\d,]+.\d{2})\n可用余额:([\d,]+.\d{2})$/, | ||
match => { | ||
let [,number,shopItem,time,shopName,money,] = match | ||
|
||
|
||
return { | ||
"money": toFloat(money), | ||
"type": BillType.Income, | ||
"time": formatDate(time,"M月D日 h:i"), | ||
"shopItem": shopItem, | ||
"shopName":shopName, | ||
"accountNameFrom": `${SOURCE_NAME_BOC}(${number})`, | ||
"Currency": Currency["人民币"], | ||
"channel": `微信[${SOURCE_NAME_BOC}-收入]`, | ||
}; | ||
}, | ||
], | ||
]; | ||
|
||
/** | ||
* @param {string} text - 需要解析的文本 | ||
* @returns {Object|null} - 解析结果对象,如果解析失败则返回null | ||
*/ | ||
function parseBOCText(text) { | ||
for (let [regex, handler] of regexMapBOC) { | ||
const match = text.match(regex); | ||
if (match) { | ||
return handler(match); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* @param {string} data - JSON格式的数据 | ||
* @returns {RuleObject|null} - 规则对象,如果获取失败则返回null | ||
*/ | ||
export function get(data) { | ||
const mapItem = JSON.parse(data).mMap; | ||
if ( | ||
mapItem.source !== SOURCE_NAME_BOC || | ||
!TITLES_BOC.includes(mapItem.title) | ||
) { | ||
return null; | ||
} | ||
|
||
// 解析文本 | ||
const parsedText = parseBOCText(mapItem.description); | ||
if (!parsedText || parsedText.type === null) { | ||
return null; | ||
} | ||
|
||
// 创建并返回RuleObject对象 | ||
return new RuleObject( | ||
parsedText.type, | ||
parsedText.money, | ||
parsedText.shopName, | ||
parsedText.shopItem, | ||
parsedText.accountNameFrom, | ||
parsedText.accountNameTo, | ||
0, | ||
parsedText.Currency, //5月7日10:50 | ||
parsedText.time, | ||
parsedText.channel | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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": "Income", | ||
"money": 1696.49, | ||
"fee": 0, | ||
"shopName": '大夏公司', | ||
"shopItem": '工资', | ||
"accountNameFrom": '宁波银行(2582)', | ||
"accountNameTo": '', | ||
"currency": 'CNY', | ||
"time": formatDate('09月15日 17:00', 'M月D日 h:i'), | ||
"channel": '微信[宁波银行-收入]', | ||
}, | ||
])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"mMap":{"tableName":"AppMessage","description":"交易类型:尾号2582-工资-人民币\n交易时间:09月15日 17:00\n交易对象:大夏公司\n交易金额:1696.49\n可用余额:428.97","source":"宁波银行","arg":"msgId","type":5,"appId":"","msgId":553241,"title":"交易提醒"}} |