Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support price range in alipay/wechat providers #131

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*.out

.vscode/
.idea/
bin/
wasm-dist/

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ alipay:
> - `11:00-13:00`
> - `11:00:00-13:00:00`
> 24 灏忔椂鍒讹紝璧峰鏃堕棿鍜岀粓姝箣闂翠箣闂翠娇鐢� `-` 鍒嗛殧銆�
- `minPrice`锛堟渶灏忛噾棰濓級鍜� `maxPrice`锛堟渶澶ч噾棰濓級鐨勫尯闂村尮閰嶃��
Triple-Z marked this conversation as resolved.
Show resolved Hide resolved

鍦ㄥ崟鏉¤鍒欎腑鍙互浣跨敤鍒嗛殧绗︼紙sep锛夊~鍐欏涓叧閿瓧锛屽湪鍚屼竴瀵硅薄涓紝姣忎釜鍏抽敭瀛椾箣闂存槸鎴栫殑鍏崇郴銆�

Expand Down Expand Up @@ -556,6 +557,7 @@ wechat:
> - `11:00-13:00`
> - `11:00:00-13:00:00`
> 24 灏忔椂鍒讹紝璧峰鏃堕棿鍜岀粓姝箣闂翠箣闂翠娇鐢� `-` 鍒嗛殧銆�
- `minPrice`锛堟渶灏忛噾棰濓級鍜� `maxPrice`锛堟渶澶ч噾棰濓級鐨勫尯闂村尮閰嶃��

鍦ㄥ崟鏉¤鍒欎腑鍙互浣跨敤鍒嗛殧绗︼紙sep锛夊~鍐欏涓叧閿瓧锛屽湪鍚屼竴瀵硅薄涓紝姣忎釜鍏抽敭瀛椾箣闂存槸鎴栫殑鍏崇郴銆�

Expand Down
5 changes: 5 additions & 0 deletions example/alipay/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ alipay:
methodAccount: Assets:Alipay

- category: 鏃ョ敤鐧捐揣
minPrice: 10
targetAccount: Expenses:Groceries
- category: 鏃ョ敤鐧捐揣
minPrice: 0
maxPrice: 9.99
targetAccount: Expenses:Food:Drink
- category: 椁愰ギ缇庨
time: 11:00-14:00
targetAccount: Expenses:Food:Lunch
Expand Down
23 changes: 23 additions & 0 deletions example/alipay/example-alipay-output.beancount
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ option "operating_currency" "CNY"
1970-01-01 open Expenses:Electronics
1970-01-01 open Expenses:FIXME
1970-01-01 open Expenses:Food:Dinner
1970-01-01 open Expenses:Food:Drink
1970-01-01 open Expenses:Food:Lunch
1970-01-01 open Expenses:Groceries
1970-01-01 open Expenses:Insurance
Expand Down Expand Up @@ -75,3 +76,25 @@ option "operating_currency" "CNY"
Expenses:FIXME 49.74 CNY
Liabilities:CC:COMM:7449 -49.74 CNY

2023-07-10 * "xxxx" "xxxx"
category: "鏃ョ敤鐧捐揣"
merchantId: "xxxx"
orderId: "xxxx"
payTime: "2023-07-10 13:10:16 +0800 CST"
source: "鏀粯瀹�"
status: "浜ゆ槗鎴愬姛"
type: "鏀嚭"
Expenses:Food:Drink 9.90 CNY
Assets:FIXME -9.90 CNY

2023-07-10 * "xxxx" "xxxx"
category: "鏃ョ敤鐧捐揣"
merchantId: "xxxx"
orderId: "xxxx"
payTime: "2023-07-10 13:20:16 +0800 CST"
source: "鏀粯瀹�"
status: "浜ゆ槗鎴愬姛"
type: "鏀嚭"
Expenses:Groceries 82.00 CNY
Assets:FIXME -82.00 CNY

23 changes: 23 additions & 0 deletions example/alipay/example-alipay-output.ledger
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Expenses:Electronics 0 CNY
Expenses:FIXME 0 CNY
Expenses:Food:Dinner 0 CNY
Expenses:Food:Drink 0 CNY
Expenses:Food:Lunch 0 CNY
Expenses:Groceries 0 CNY
Expenses:Insurance 0 CNY
Expand Down Expand Up @@ -73,3 +74,25 @@
Expenses:FIXME 49.74 CNY
Liabilities:CC:COMM:7449 - 49.74 CNY

2023/07/10 * xxxx - xxxx
; category: "鏃ョ敤鐧捐揣"
; merchantId: "xxxx"
; orderId: "xxxx"
; payTime: "2023-07-10 13:10:16 +0800 CST"
; source: "鏀粯瀹�"
; status: "浜ゆ槗鎴愬姛"
; type: "鏀嚭"
Expenses:Food:Drink 9.90 CNY
Assets:FIXME - 9.90 CNY

2023/07/10 * xxxx - xxxx
; category: "鏃ョ敤鐧捐揣"
; merchantId: "xxxx"
; orderId: "xxxx"
; payTime: "2023-07-10 13:20:16 +0800 CST"
; source: "鏀粯瀹�"
; status: "浜ゆ槗鎴愬姛"
; type: "鏀嚭"
Expenses:Groceries 82.00 CNY
Assets:FIXME - 82.00 CNY

2 changes: 2 additions & 0 deletions example/alipay/example-alipay-records.csv
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@
2023-01-10 13:10:16,日用百货,xxxx,/,xxxx,不计收支,82.00,,交易关闭,xxxx ,xxxx ,,
2023-01-09 18:22:28,退款,一卡通,fin***@jieyisoft.com,退款-一卡通充值,不计收支,50.00,余额宝,退款成功,2023xxxxx88_2023xx57 ,D12*****14 ,,
2023-01-09 18:21:50,交通出行,一卡通,fin***@jieyisoft.com,一卡通充值,支出,50.00,余额宝,交易关闭,2023xxxxx88 ,D12*****14 ,,
2023-07-10 13:10:16,日用百货,xxxx,/,xxxx,支出,9.90,,交易成功,xxxx ,xxxx ,,
2023-07-10 13:20:16,日用百货,xxxx,/,xxxx,支出,82.00,,交易成功,xxxx ,xxxx ,,
10 changes: 10 additions & 0 deletions example/wechat/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ wechat:
time: 23:50-00:05 # test T-1
targetAccount: Expenses:Food:Meal:MidNight

- peer: 缇庡洟骞冲彴鍟嗘埛
type: 鏀嚭
minPrice: 0
maxPrice: 9.99
targetAccount: Expenses:Food:Drink
- peer: 缇庡洟骞冲彴鍟嗘埛
type: 鏀嚭
minPrice: 10
targetAccount: Expenses:Food:Meal

- peer: 鎴夸笢
type: 鏀嚭
targetAccount: Expenses:Housing:Rent
Expand Down
26 changes: 26 additions & 0 deletions example/wechat/example-wechat-output.beancount
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ option "operating_currency" "CNY"
1970-01-01 open Assets:FIXME
1970-01-01 open Assets:Trade:Tencent:LiCaiTong
1970-01-01 open Expenses:FIXME
1970-01-01 open Expenses:Food:Drink
1970-01-01 open Expenses:Food:Meal
1970-01-01 open Expenses:Food:Meal:Dinner
1970-01-01 open Expenses:Food:Meal:Lunch
1970-01-01 open Expenses:Food:Meal:MidNight
Expand Down Expand Up @@ -276,3 +278,27 @@ option "operating_currency" "CNY"
Assets:Digital:Wechat:Cash 5.00 CNY
Income:Wechat:RedPacket -5.00 CNY

2023-07-09 * "缇庡洟骞冲彴鍟嗘埛" "缇庡洟璁㈠崟-12345"
merchantId: "654321"
method: "宸ュ晢閾惰"
orderId: "123456"
payTime: "2023-07-09 13:25:22 +0800 CST"
source: "寰俊鏀粯"
status: "鏀粯鎴愬姛"
txType: "鍟嗘埛娑堣垂"
type: "鏀嚭"
Expenses:Food:Drink 9.90 CNY
Assets:Bank:CN:ICBC:Savings -9.90 CNY

2023-07-09 * "缇庡洟骞冲彴鍟嗘埛" "缇庡洟璁㈠崟-54321"
merchantId: "654321"
method: "宸ュ晢閾惰"
orderId: "123456"
payTime: "2023-07-09 13:30:22 +0800 CST"
source: "寰俊鏀粯"
status: "鏀粯鎴愬姛"
txType: "鍟嗘埛娑堣垂"
type: "鏀嚭"
Expenses:Food:Meal 50.00 CNY
Assets:Bank:CN:ICBC:Savings -50.00 CNY

26 changes: 26 additions & 0 deletions example/wechat/example-wechat-output.ledger
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Assets:FIXME 0 CNY
Assets:Trade:Tencent:LiCaiTong 0 CNY
Expenses:FIXME 0 CNY
Expenses:Food:Drink 0 CNY
Expenses:Food:Meal 0 CNY
Expenses:Food:Meal:Dinner 0 CNY
Expenses:Food:Meal:Lunch 0 CNY
Expenses:Food:Meal:MidNight 0 CNY
Expand Down Expand Up @@ -275,3 +277,27 @@
Assets:Digital:Wechat:Cash 5.00 CNY
Income:Wechat:RedPacket - 5.00 CNY

2023/07/09 * 缇庡洟骞冲彴鍟嗘埛 - 缇庡洟璁㈠崟-12345
; merchantId: "654321"
; method: "宸ュ晢閾惰"
; orderId: "123456"
; payTime: "2023-07-09 13:25:22 +0800 CST"
; source: "寰俊鏀粯"
; status: "鏀粯鎴愬姛"
; txType: "鍟嗘埛娑堣垂"
; type: "鏀嚭"
Expenses:Food:Drink 9.90 CNY
Assets:Bank:CN:ICBC:Savings - 9.90 CNY

2023/07/09 * 缇庡洟骞冲彴鍟嗘埛 - 缇庡洟璁㈠崟-54321
; merchantId: "654321"
; method: "宸ュ晢閾惰"
; orderId: "123456"
; payTime: "2023-07-09 13:30:22 +0800 CST"
; source: "寰俊鏀粯"
; status: "鏀粯鎴愬姛"
; txType: "鍟嗘埛娑堣垂"
; type: "鏀嚭"
Expenses:Food:Meal 50.00 CNY
Assets:Bank:CN:ICBC:Savings - 50.00 CNY

2 changes: 2 additions & 0 deletions example/wechat/example-wechat-records.csv
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@
2022-07-18 10:48:09,鍟嗘埛娑堣垂,娴嬭瘯鏃堕棿鎴筹紝鐐瑰嚮搴曢儴"澶氬瑙嗛","/",鏀跺叆,楼0.07,/,鍏呭�兼垚鍔�,160572459521071810106004542906137497131422938 ,10101265586742107189275763431049 ,"/"
2022-09-24 02:24:20,璧炶祻鐮�,YingDev,"/",鏀嚭,楼36.99,闆堕挶,鏈嬪弸宸叉敹閽�,100010810122092400064222561891707533 ,1000108101202209241820542253348 ,"/"
2023-06-23 11:01:51,鍏朵粬,璧炶祻浣滆�呯殑鏀舵_20230623,"/",鏀跺叆,楼5.00,/,宸插埌璐�,180000737623062310106004541373333333333333333 ,10101008588132306239222222222222 ,"璧炶祻浣滆�呯殑鏀舵_20230623"
2023-07-09 13:25:22,鍟嗘埛娑堣垂,缇庡洟骞冲彴鍟嗘埛,"缇庡洟璁㈠崟-12345",鏀嚭,楼9.90,宸ュ晢閾惰,鏀粯鎴愬姛,123456 ,654321 ,"/"
2023-07-09 13:30:22,鍟嗘埛娑堣垂,缇庡洟骞冲彴鍟嗘埛,"缇庡洟璁㈠崟-54321",鏀嚭,楼50.0,宸ュ晢閾惰,鏀粯鎴愬姛,123456 ,654321 ,"/"
10 changes: 8 additions & 2 deletions pkg/analyser/alipay/alipay.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,21 @@ func (a Alipay) GetAccountsAndTags(o *ir.Order, cfg *config.Config, target, prov
if r.Time != nil {
match, err = util.SplitFindTimeInterval(*r.Time, o.PayTime, match)
if err != nil {
log.Fatalf(err.Error())
log.Fatalf("%v", err)
}
}
if r.TimestampRange != nil {
match, err = util.SplitFindTimeStampInterval(*r.TimestampRange, o.PayTime, match)
if err != nil {
log.Fatalf(err.Error())
log.Fatalf("%v", err)
}
}
if r.MinPrice != nil && o.Money < *r.MinPrice {
match = false
}
if r.MaxPrice != nil && o.Money > *r.MaxPrice {
match = false
}

if match {
if r.Ignore {
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyser/htsec/htsec.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ func (h Htsec) GetAccountsAndTags(o *ir.Order, cfg *config.Config, target, provi
if r.Time != nil {
match, err = util.SplitFindTimeInterval(*r.Time, o.PayTime, match)
if err != nil {
log.Fatalf(err.Error())
log.Fatalf("%v", err)
}
}
if r.TimestampRange != nil {
match, err = util.SplitFindTimeStampInterval(*r.TimestampRange, o.PayTime, match)
if err != nil {
log.Fatalf(err.Error())
log.Fatalf("%v", err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/analyser/huobi/huobi.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ func (h Huobi) GetAccountsAndTags(o *ir.Order, cfg *config.Config, target, provi
if r.Time != nil {
match, err = util.SplitFindTimeInterval(*r.Time, o.PayTime, match)
if err != nil {
log.Fatalf(err.Error())
log.Fatalf("%v", err)
}
}
if r.TimestampRange != nil {
match, err = util.SplitFindTimeStampInterval(*r.TimestampRange, o.PayTime, match)
if err != nil {
log.Fatalf(err.Error())
log.Fatalf("%v", err)
}
}
if match {
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyser/jd/jd.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ func (a JD) GetAccountsAndTags(o *ir.Order, cfg *config.Config, target, provider
if r.Time != nil {
match, err = util.SplitFindTimeInterval(*r.Time, o.PayTime, match)
if err != nil {
log.Fatalf(err.Error())
log.Fatalf("%v", err)
}
}
if r.TimestampRange != nil {
match, err = util.SplitFindTimeStampInterval(*r.TimestampRange, o.PayTime, match)
if err != nil {
log.Fatalf(err.Error())
log.Fatalf("%v", err)
}
}

Expand Down
10 changes: 8 additions & 2 deletions pkg/analyser/wechat/wechat.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,21 @@ func (w Wechat) GetAccountsAndTags(o *ir.Order, cfg *config.Config, target, prov
if r.Time != nil {
match, err = util.SplitFindTimeInterval(*r.Time, o.PayTime, match)
if err != nil {
log.Fatalf(err.Error())
log.Fatalf("Error in SplitFindTimeInterval: %v", err)
}
}
if r.TimestampRange != nil {
match, err = util.SplitFindTimeStampInterval(*r.TimestampRange, o.PayTime, match)
if err != nil {
log.Fatalf(err.Error())
log.Fatalf("Error in SplitFindTimeStampInterval: %v", err)
}
}
if r.MinPrice != nil && o.Money < *r.MinPrice {
Triple-Z marked this conversation as resolved.
Show resolved Hide resolved
match = false
}
if r.MaxPrice != nil && o.Money > *r.MaxPrice {
match = false
}
Triple-Z marked this conversation as resolved.
Show resolved Hide resolved

if match {
if r.Ignore {
Expand Down
30 changes: 16 additions & 14 deletions pkg/provider/alipay/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ type Config struct {

// Rule is the type for match rules.
type Rule struct {
Peer *string `mapstructure:"peer,omitempty"`
Item *string `mapstructure:"item,omitempty"`
Category *string `mapstructure:"category,omitempty"`
Type *string `mapstructure:"type,omitempty"`
Method *string `mapstructure:"method,omitempty"`
Separator *string `mapstructure:"sep,omitempty"` // default: ,
Time *string `mapstructure:"time,omitempty"`
TimestampRange *string `mapstructure:"timestamp_range,omitempty"`
MethodAccount *string `mapstructure:"methodAccount,omitempty"`
TargetAccount *string `mapstructure:"targetAccount,omitempty"`
PnlAccount *string `mapstructure:"pnlAccount,omitempty"`
FullMatch bool `mapstructure:"fullMatch,omitempty"`
Tags *string `mapstructure:"tags,omitempty"`
Ignore bool `mapstructure:"ignore,omitempty"` // default: false
Peer *string `mapstructure:"peer,omitempty"`
Item *string `mapstructure:"item,omitempty"`
Category *string `mapstructure:"category,omitempty"`
Type *string `mapstructure:"type,omitempty"`
Method *string `mapstructure:"method,omitempty"`
Separator *string `mapstructure:"sep,omitempty"` // default: ,
Time *string `mapstructure:"time,omitempty"`
TimestampRange *string `mapstructure:"timestamp_range,omitempty"`
MethodAccount *string `mapstructure:"methodAccount,omitempty"`
TargetAccount *string `mapstructure:"targetAccount,omitempty"`
PnlAccount *string `mapstructure:"pnlAccount,omitempty"`
FullMatch bool `mapstructure:"fullMatch,omitempty"`
Tags *string `mapstructure:"tags,omitempty"`
Ignore bool `mapstructure:"ignore,omitempty"` // default: false
MinPrice *float64 `mapstructure:"minPrice,omitempty"`
MaxPrice *float64 `mapstructure:"maxPrice,omitempty"`
}
30 changes: 16 additions & 14 deletions pkg/provider/wechat/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ type Config struct {

// Rule is the type for match rules.
type Rule struct {
Peer *string `mapstructure:"peer,omitempty"`
Item *string `mapstructure:"item,omitempty"`
Type *string `mapstructure:"type,omitempty"`
TxType *string `mapstructure:"txType,omitempty"`
Separator *string `mapstructure:"sep,omitempty"` // default: ,
Method *string `mapstructure:"method,omitempty"`
Time *string `mapstructure:"time,omitempty"`
TimestampRange *string `mapstructure:"timestamp_range,omitempty"`
MethodAccount *string `mapstructure:"methodAccount,omitempty"`
TargetAccount *string `mapstructure:"targetAccount,omitempty"`
CommissionAccount *string `mapstructure:"commissionAccount,omitempty"`
FullMatch bool `mapstructure:"fullMatch,omitempty"`
Tag *string `mapstructure:"tag,omitempty"`
Ignore bool `mapstructure:"ignore,omitempty"` // default: false
Peer *string `mapstructure:"peer,omitempty"`
Item *string `mapstructure:"item,omitempty"`
Type *string `mapstructure:"type,omitempty"`
TxType *string `mapstructure:"txType,omitempty"`
Separator *string `mapstructure:"sep,omitempty"` // default: ,
Method *string `mapstructure:"method,omitempty"`
Time *string `mapstructure:"time,omitempty"`
TimestampRange *string `mapstructure:"timestamp_range,omitempty"`
MethodAccount *string `mapstructure:"methodAccount,omitempty"`
TargetAccount *string `mapstructure:"targetAccount,omitempty"`
CommissionAccount *string `mapstructure:"commissionAccount,omitempty"`
FullMatch bool `mapstructure:"fullMatch,omitempty"`
Tag *string `mapstructure:"tag,omitempty"`
Ignore bool `mapstructure:"ignore,omitempty"` // default: false
MinPrice *float64 `mapstructure:"minPrice,omitempty"`
MaxPrice *float64 `mapstructure:"maxPrice,omitempty"`
}
2 changes: 1 addition & 1 deletion pkg/provider/wechat/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func getTxType(tt string) TxType {
return TxTypeFamilyCard
} else if strings.Contains(tt, string(TxTypeSponsorCode)) {
return TxTypeSponsorCode
} else if strings.Contains(tt, string(TxTypeOther)){
} else if strings.Contains(tt, string(TxTypeOther)) {
return TxTypeOther
} else {
return TxTypeUnknown
Expand Down
Loading