beancount-gs/script/bql.go

278 lines
7.3 KiB
Go
Raw Normal View History

2021-11-21 14:37:13 +00:00
package script
import (
2021-11-22 08:47:49 +00:00
"encoding/json"
2021-11-21 14:37:13 +00:00
"fmt"
"os/exec"
"reflect"
2021-11-22 14:50:10 +00:00
"strconv"
2021-11-21 14:37:13 +00:00
"strings"
"github.com/gin-gonic/gin"
2021-11-21 14:37:13 +00:00
)
type QueryParams struct {
2021-12-02 14:48:45 +00:00
From bool `bql:"From"`
FromYear int `bql:"year ="`
FromMonth int `bql:"month ="`
Where bool `bql:"where"`
2021-11-26 09:12:07 +00:00
Currency string `bql:"currency ="`
2021-11-21 14:37:13 +00:00
Year int `bql:"year ="`
Month int `bql:"month ="`
2021-11-24 10:04:02 +00:00
Tag string `bql:"in tags"`
2021-11-24 09:32:24 +00:00
Account string `bql:"account ="`
2021-11-24 15:45:45 +00:00
AccountLike string `bql:"account ~"`
GroupBy string `bql:"group by"`
OrderBy string `bql:"order by"`
Limit int `bql:"limit"`
2021-11-23 15:33:14 +00:00
Path string
2021-11-21 14:37:13 +00:00
}
2021-11-22 14:50:10 +00:00
func GetQueryParams(c *gin.Context) QueryParams {
var queryParams QueryParams
var hasWhere bool
if c.Query("year") != "" {
val, err := strconv.Atoi(c.Query("year"))
if err == nil {
queryParams.Year = val
hasWhere = true
}
}
if c.Query("month") != "" {
val, err := strconv.Atoi(c.Query("month"))
if err == nil {
queryParams.Month = val
hasWhere = true
}
}
2021-11-24 10:04:02 +00:00
if c.Query("tag") != "" {
queryParams.Tag = c.Query("tag")
hasWhere = true
}
2021-11-22 14:50:10 +00:00
if c.Query("type") != "" {
2021-11-24 15:45:45 +00:00
queryParams.AccountLike = c.Query("type")
2021-11-22 14:50:10 +00:00
hasWhere = true
}
2021-11-24 09:32:24 +00:00
if c.Query("account") != "" {
queryParams.Account = c.Query("account")
queryParams.Limit = 100
hasWhere = true
}
2021-11-22 14:50:10 +00:00
queryParams.Where = hasWhere
2021-11-23 15:33:14 +00:00
if c.Query("path") != "" {
queryParams.Path = c.Query("path")
}
2021-11-22 14:50:10 +00:00
return queryParams
}
Squashed commit of the following: commit 7dc209490ba5aeca44ab736bc48727437e2af569 Author: liangzai450 <liangzai450@sina.com> Date: Tue Mar 12 00:47:07 2024 +0800 fixbug: 换行符导致的数组越界 commit 5875a7872b4f0a70e1cfbe38b81e62f7e788a9b5 Author: liangzai450 <liangzai450@sina.com> Date: Mon Mar 11 23:51:18 2024 +0800 暂存 commit 037e17569f49cc9ecea1ef1f5ca5c966e2a0a547 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 10 23:42:22 2024 +0800 fixbug: 换行符导致的数组越界 commit 9012ef633be647af212caa5d6d61316d7a7c3a1c Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 10 23:30:05 2024 +0800 v1.1.15 commit 254e3e81bcae54cf146f615d54edf43e3a77babc Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 10 23:29:20 2024 +0800 update view, event sort rule commit 70ddfe9d5de8489632a0457f3b5054a19ec082a2 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 10 22:44:29 2024 +0800 update viewpage commit cc66151531e7fc9298b656f13022f0a03618c8c7 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 10 22:30:56 2024 +0800 add: event api commit dfc2f1b36a4488428ffd3c06aab5c7799047a09a Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 10 22:05:40 2024 +0800 fixbug: 账户多次关闭或打开处理逻辑异常 commit 942c8595721a09076648e5703aee3f577d813ff4 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Mar 9 10:43:07 2024 +0800 fix: #71 account startDate endDate commit 51597551099cc37ec43dbe401527e1a8fcfef239 Author: RenLangMan <34146131+RenLangMan@users.noreply.github.com> Date: Fri Mar 8 13:00:30 2024 +0800 Update stats.go 商户消费排行某个月份返回无效值 解决方案 [#14 ](https://github.com/BaoXuebin/beancount-gs/issues/14) commit a339e1afe83c365efd03cf9a36601f78410d85cd Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Mar 4 22:51:25 2024 +0800 fix: #66 multi currency transactions commit 344a6782ae2827e4862caae5639c80e5a8b41452 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 23:10:16 2023 +0800 add empty file commit 986e19b00f6e93ea96b7c0e34f905ae821638102 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 23:02:23 2023 +0800 update readme commit 618355a07d6dc2d37bf276ccc8e08e3b5a645eed Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 22:54:58 2023 +0800 v1.1.14 commit 01966ce2ec476fcb3220315bdb394eca7baa14ad Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 22:54:09 2023 +0800 update webview commit 017bf20c562de43a1aea73004a2b1a8a707bd7f2 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 22:52:24 2023 +0800 update: auto refresh currency cache commit f0aa8ab0c0da53bf2d84c6230f2d42888ea32be3 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 18:52:23 2023 +0800 update viewpage commit 0743e59458677da80b31dcab5d190a12154f2c88 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 18:50:57 2023 +0800 update viewpage commit fd72ba8a2bc25865c2e5162c3139e9867158f509 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 18:47:49 2023 +0800 refactor price var commit e905eebf60ba51825d1c99a0100809b9fd04f110 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 17:56:21 2023 +0800 temp commit commit 19dae50c072bdd4e240f64c7b7aaf25a1c8bce84 Author: BaoXuebin <baoxbin@hotmail.com> Date: Thu Dec 7 23:59:28 2023 +0800 multi currency transaction commit 89f287fe9053bd3dc96c70038971195c6aabd3bc Author: BaoXuebin <baoxbin@hotmail.com> Date: Thu Dec 7 13:57:43 2023 +0800 feat: currency account add excahnge rate value and currency flag commit 512a6799c59172a76717d47253b942b6c4574354 Author: BaoXuebin <baoxbin@hotmail.com> Date: Thu Dec 7 01:24:24 2023 +0800 opti: multi currency appi commit 4ffe60112c936643c41662c1777b510f4278704c Author: BaoXuebin <baoxbin@hotmail.com> Date: Wed Dec 6 00:29:38 2023 +0800 add event api commit 727d504f2f0a765e5e2d2af0d20b3b3d90aba0ba Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Dec 5 17:57:48 2023 +0800 define event api commit a40875e78b57142e47c159efb48d4c637f6e11d1 Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Dec 5 16:21:12 2023 +0800 opti: multi commodity commit 29ca04a4763defe4eaf617fef6dda09f9f5c0042 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Jul 3 00:01:40 2023 +0800 v1.1.13 commit 2e77a053c1d25e6f5be9ee51174091121c6acb17 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Jul 3 00:01:26 2023 +0800 update webview commit 4841fe346a8c0f6c1e324394315e10813d6534e2 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Jul 2 23:32:52 2023 +0800 update webview commit ef9d5dd7c8ed72a412da477243a7df823e01396a Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Jul 2 23:31:30 2023 +0800 update: stats account balance api add year and month query condition commit d88cd008a5ab5583eec8c80fa4ef955e22f8a8aa Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Jul 1 23:23:59 2023 +0800 update: change alipay ledger template #54 commit 650f1e955fd786f3ccea3d302026e84436490d2a Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Apr 10 02:14:01 2023 +0800 upgrade python version commit 0c5b866064e329dc86ad2cec720a544dc8de26ff Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Apr 10 02:00:03 2023 +0800 fixbug commit a36aed000baeea4c6ca96fd86cdd7673fff728a4 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Apr 10 01:27:41 2023 +0800 fixbug commit b427d649b63cd7f66731d6dcb155c0d86f43aaf9 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Apr 10 00:18:08 2023 +0800 update docker.yml commit 3da869bdd573a5a21ffab62faacb87e9c213fb06 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Apr 10 00:04:24 2023 +0800 add logs folder commit 1f92f1ac7649abf3d7e2afcc7d63027332a69961 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 23:56:18 2023 +0800 update: github action commit cc6331cc81da2ed7ca3250bf59d55210d9203f2d Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 23:46:16 2023 +0800 update: dockerfile commit f4ce2fcef40bfe35b92fd455872b30b76c5ca411 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 23:13:16 2023 +0800 update: github action commit 40929240958d6aab2f776302f1d129e07f5ac894 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 22:56:22 2023 +0800 version 1.1.12 commit 8c027f1d0c1532037766dbde4088a23ecdb9ecb8 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 22:55:12 2023 +0800 update webview commit f497cfb000068ae64db6ac340dc75c0c7b5ce85e Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 22:54:43 2023 +0800 update webview commit 878b17f049685befc52439654b9eb489ce604f99 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 22:53:42 2023 +0800 doc: README.md commit 20afafd138f43c73586cfbeb4577b8b5044cae27 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 22:53:26 2023 +0800 update: docker compose add env and default port change 10000 commit 222dc6af3ace1eaa950f40622e7ef884f0dda1da Author: BaoXuebin <baoxbin@hotmail.com> Date: Thu Feb 16 13:43:39 2023 +0800 fix: cannot include bean file #46 commit 7375c2b7d454aef8657fb6fb45abe139b143cfd2 Author: BaoXuebin <baoxbin@hotmail.com> Date: Wed Dec 28 00:03:40 2022 +0800 v1.1.11 commit a035dcfe1e0b726d229655ac17100bec84e8443c Author: BaoXuebin <baoxbin@hotmail.com> Date: Wed Dec 28 00:03:13 2022 +0800 update webview commit 1da322e0938ba40a348bd406f18daec7401b0706 Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Dec 27 23:55:53 2022 +0800 add: icbc and abc batch import commit 46ea0c14604cf559cb91ebbc16092e56e07c0f32 Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Dec 27 22:12:05 2022 +0800 del: source file content required validator commit 3ad974e4eba88446da4bf1baca1b83ad66531ac0 Author: baoxuebin <baoxuebin@ienglish.cn> Date: Tue Dec 27 18:41:34 2022 +0800 update: config dir from .beancount-ns change to .beancount-gs commit 7f83b3a3807141d3bbde1aae57dde05072682aa0 Author: baoxuebin <baoxuebin@ienglish.cn> Date: Tue Dec 27 17:22:06 2022 +0800 docs: update readme guide link url commit f2d1e7329b48570afce7a0a8309abac1ecd14f88 Author: baoxuebin <baoxuebin@ienglish.cn> Date: Sat Oct 22 23:34:28 2022 +0800 fix: account balance failed when file is not exist. commit 09f58fef642d46eab7211ea543427351b2cad5e4 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Oct 15 19:35:21 2022 +0800 version 1.1.10 commit 0d172a3988ea2a819a251a9e95d6599deaa205db Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Oct 15 19:24:49 2022 +0800 check ledger api default return empty list commit ab6188da2b577379204c98cf9d2f1154f6a0275b Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Oct 15 19:02:06 2022 +0800 fixbug commit 0522600cde6a6a7276c7fa53c83aa15e999a5083 Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Oct 11 23:30:13 2022 +0800 version: 1.1.9 commit 264c9f584aab633f7e49514e97525fba6597b669 Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Oct 11 23:29:16 2022 +0800 update new webview commit cb72b18513ffc4c0fb9ec5a10e209875c4bfbfbd Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Sep 3 23:21:25 2022 +0800 update: 月份查询改为时间倒序 commit 735e32294201b67f16a67aa2e4dc135015cae400 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Aug 15 00:38:50 2022 +0800 add beancount syntax check api commit 2839749306057e50f570684639fdbe5d53729923 Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Jul 26 22:59:51 2022 +0800 update readme commit 6d85a8ab993db7345e1d2ce5caf204aa556eaebf Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Jul 26 22:30:48 2022 +0800 update webview commit 8c8b635f2e65ec16081219b365ae61ff88556a2b Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Jul 26 22:28:40 2022 +0800 优化docker镜像大小#23 commit 19862e8e7138904883758739c6c416cc86fba2ca Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Jul 26 22:09:27 2022 +0800 fix: 支付宝账单过滤关闭的交易 commit 2c9b83c907d99a986fb061c96480cccc357d0d7d Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Jul 25 03:35:20 2022 +0800 version 1.1.8 commit 506e606591af391557612fc9c40d84d36f18a9c5 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Jul 23 12:20:28 2022 +0800 fix: cannot close account #22 commit 517cb25e73afbc64e17625ed4135dfb515e829e6 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Jul 23 12:19:35 2022 +0800 fix: failed to bak file cause by linux file system case sensitivity #20 commit 81738c09d902cbd8307f14efbe3bc970ed1b584c Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Jul 3 23:26:48 2022 +0800 lint code commit 4f0284c5a066b646edd08fb594f4a5f8ad3fa968 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Jul 3 22:59:01 2022 +0800 inte:golangci-lint commit 14cf8b3dec4e9b52a0b543a09e67ad1f1a828952 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Jun 5 11:15:29 2022 +0800 version 1.1.7 commit f3a88c4b36bf135d4f2c61a99a2accc862f708e4 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Jun 5 11:14:29 2022 +0800 update webview commit 8520e7d75fd280646b22c935331937df81f68676 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Jun 5 11:07:03 2022 +0800 add: query month calendar api commit 108dba4ea944356a8def92f03e89f68e55d90abd Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Jun 4 13:31:40 2022 +0800 fix: unix 换行符 change to '\n' commit 7cb64969b673e69590312142cca2302939d9ed45 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat May 28 22:04:59 2022 +0800 version 1.1.6 commit 7b2a06e5e28ab9d63b429490d9ebf5683b737f16 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat May 28 22:04:05 2022 +0800 update webview commit ad591921f7fd05b524c4aeec2c861a4d8fbeb09a Author: BaoXuebin <baoxbin@hotmail.com> Date: Thu Apr 14 00:23:08 2022 +0800 add: query commodity prices api commit 4fd6a57215d5542bf4d9ada7f6229ac6bebcf4ae Author: BaoXuebin <baoxbin@hotmail.com> Date: Wed Apr 13 00:30:38 2022 +0800 add: bean-report all_prices commit 659c1d7e151bf1d740cbd6b4d68bfbe830efdd53 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Apr 11 21:25:34 2022 +0800 fixbug: 账户平衡计算导致新增交易异常 commit 15a79c5790dd32aa47d82b398969a3e6433d6753 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Mar 21 00:44:45 2022 +0800 update readme commit 8250e96c876ed2209cf06b4c7a7a95d96eb012d6 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Mar 21 00:12:50 2022 +0800 update 1.1.5 static file commit cae95602c5dcb8159047b2ec0cff1ffaa99908b6 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Mar 21 00:01:15 2022 +0800 update 1.1.5 static file commit 5f28dec14df73f4f04ea10044a34a1951ff11173 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 20 23:57:14 2022 +0800 version 1.1.5 commit 8fcdbb43e6538cd47351d748abebc2a49db4532c Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 20 23:55:05 2022 +0800 add multi stage transaction commit a2a29702d3767dc0a24179547822576e92110bba Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Mar 19 16:18:27 2022 +0800 delete ledger add error handle commit 9f05766287230f99fd97846e052aa2199973dc55 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Mar 19 15:44:15 2022 +0800 fix: alipay mobile csv file cannot import (#8) # Conflicts: # dockerfile
2024-03-17 15:57:21 +00:00
//func BQLQueryOne(ledgerConfig *Config, queryParams *QueryParams, queryResultPtr interface{}) error {
// assertQueryResultIsPointer(queryResultPtr)
// output, err := bqlRawQuery(ledgerConfig, "", queryParams, queryResultPtr)
// if err != nil {
// return err
// }
// err = parseResult(output, queryResultPtr, true)
// if err != nil {
// return err
// }
// return nil
//}
2021-11-22 08:47:49 +00:00
func BQLQueryList(ledgerConfig *Config, queryParams *QueryParams, queryResultPtr interface{}) error {
assertQueryResultIsPointer(queryResultPtr)
2021-11-22 14:50:10 +00:00
output, err := bqlRawQuery(ledgerConfig, "", queryParams, queryResultPtr)
2021-11-22 08:47:49 +00:00
if err != nil {
return err
}
err = parseResult(output, queryResultPtr, false)
if err != nil {
return err
}
return nil
}
2021-11-22 14:50:10 +00:00
func BQLQueryListByCustomSelect(ledgerConfig *Config, selectBql string, queryParams *QueryParams, queryResultPtr interface{}) error {
assertQueryResultIsPointer(queryResultPtr)
output, err := bqlRawQuery(ledgerConfig, selectBql, queryParams, queryResultPtr)
if err != nil {
return err
2021-11-22 08:47:49 +00:00
}
2021-11-22 14:50:10 +00:00
err = parseResult(output, queryResultPtr, false)
if err != nil {
return err
}
return nil
}
Squashed commit of the following: commit 7dc209490ba5aeca44ab736bc48727437e2af569 Author: liangzai450 <liangzai450@sina.com> Date: Tue Mar 12 00:47:07 2024 +0800 fixbug: 换行符导致的数组越界 commit 5875a7872b4f0a70e1cfbe38b81e62f7e788a9b5 Author: liangzai450 <liangzai450@sina.com> Date: Mon Mar 11 23:51:18 2024 +0800 暂存 commit 037e17569f49cc9ecea1ef1f5ca5c966e2a0a547 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 10 23:42:22 2024 +0800 fixbug: 换行符导致的数组越界 commit 9012ef633be647af212caa5d6d61316d7a7c3a1c Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 10 23:30:05 2024 +0800 v1.1.15 commit 254e3e81bcae54cf146f615d54edf43e3a77babc Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 10 23:29:20 2024 +0800 update view, event sort rule commit 70ddfe9d5de8489632a0457f3b5054a19ec082a2 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 10 22:44:29 2024 +0800 update viewpage commit cc66151531e7fc9298b656f13022f0a03618c8c7 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 10 22:30:56 2024 +0800 add: event api commit dfc2f1b36a4488428ffd3c06aab5c7799047a09a Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 10 22:05:40 2024 +0800 fixbug: 账户多次关闭或打开处理逻辑异常 commit 942c8595721a09076648e5703aee3f577d813ff4 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Mar 9 10:43:07 2024 +0800 fix: #71 account startDate endDate commit 51597551099cc37ec43dbe401527e1a8fcfef239 Author: RenLangMan <34146131+RenLangMan@users.noreply.github.com> Date: Fri Mar 8 13:00:30 2024 +0800 Update stats.go 商户消费排行某个月份返回无效值 解决方案 [#14 ](https://github.com/BaoXuebin/beancount-gs/issues/14) commit a339e1afe83c365efd03cf9a36601f78410d85cd Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Mar 4 22:51:25 2024 +0800 fix: #66 multi currency transactions commit 344a6782ae2827e4862caae5639c80e5a8b41452 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 23:10:16 2023 +0800 add empty file commit 986e19b00f6e93ea96b7c0e34f905ae821638102 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 23:02:23 2023 +0800 update readme commit 618355a07d6dc2d37bf276ccc8e08e3b5a645eed Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 22:54:58 2023 +0800 v1.1.14 commit 01966ce2ec476fcb3220315bdb394eca7baa14ad Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 22:54:09 2023 +0800 update webview commit 017bf20c562de43a1aea73004a2b1a8a707bd7f2 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 22:52:24 2023 +0800 update: auto refresh currency cache commit f0aa8ab0c0da53bf2d84c6230f2d42888ea32be3 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 18:52:23 2023 +0800 update viewpage commit 0743e59458677da80b31dcab5d190a12154f2c88 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 18:50:57 2023 +0800 update viewpage commit fd72ba8a2bc25865c2e5162c3139e9867158f509 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 18:47:49 2023 +0800 refactor price var commit e905eebf60ba51825d1c99a0100809b9fd04f110 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Dec 10 17:56:21 2023 +0800 temp commit commit 19dae50c072bdd4e240f64c7b7aaf25a1c8bce84 Author: BaoXuebin <baoxbin@hotmail.com> Date: Thu Dec 7 23:59:28 2023 +0800 multi currency transaction commit 89f287fe9053bd3dc96c70038971195c6aabd3bc Author: BaoXuebin <baoxbin@hotmail.com> Date: Thu Dec 7 13:57:43 2023 +0800 feat: currency account add excahnge rate value and currency flag commit 512a6799c59172a76717d47253b942b6c4574354 Author: BaoXuebin <baoxbin@hotmail.com> Date: Thu Dec 7 01:24:24 2023 +0800 opti: multi currency appi commit 4ffe60112c936643c41662c1777b510f4278704c Author: BaoXuebin <baoxbin@hotmail.com> Date: Wed Dec 6 00:29:38 2023 +0800 add event api commit 727d504f2f0a765e5e2d2af0d20b3b3d90aba0ba Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Dec 5 17:57:48 2023 +0800 define event api commit a40875e78b57142e47c159efb48d4c637f6e11d1 Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Dec 5 16:21:12 2023 +0800 opti: multi commodity commit 29ca04a4763defe4eaf617fef6dda09f9f5c0042 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Jul 3 00:01:40 2023 +0800 v1.1.13 commit 2e77a053c1d25e6f5be9ee51174091121c6acb17 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Jul 3 00:01:26 2023 +0800 update webview commit 4841fe346a8c0f6c1e324394315e10813d6534e2 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Jul 2 23:32:52 2023 +0800 update webview commit ef9d5dd7c8ed72a412da477243a7df823e01396a Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Jul 2 23:31:30 2023 +0800 update: stats account balance api add year and month query condition commit d88cd008a5ab5583eec8c80fa4ef955e22f8a8aa Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Jul 1 23:23:59 2023 +0800 update: change alipay ledger template #54 commit 650f1e955fd786f3ccea3d302026e84436490d2a Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Apr 10 02:14:01 2023 +0800 upgrade python version commit 0c5b866064e329dc86ad2cec720a544dc8de26ff Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Apr 10 02:00:03 2023 +0800 fixbug commit a36aed000baeea4c6ca96fd86cdd7673fff728a4 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Apr 10 01:27:41 2023 +0800 fixbug commit b427d649b63cd7f66731d6dcb155c0d86f43aaf9 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Apr 10 00:18:08 2023 +0800 update docker.yml commit 3da869bdd573a5a21ffab62faacb87e9c213fb06 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Apr 10 00:04:24 2023 +0800 add logs folder commit 1f92f1ac7649abf3d7e2afcc7d63027332a69961 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 23:56:18 2023 +0800 update: github action commit cc6331cc81da2ed7ca3250bf59d55210d9203f2d Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 23:46:16 2023 +0800 update: dockerfile commit f4ce2fcef40bfe35b92fd455872b30b76c5ca411 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 23:13:16 2023 +0800 update: github action commit 40929240958d6aab2f776302f1d129e07f5ac894 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 22:56:22 2023 +0800 version 1.1.12 commit 8c027f1d0c1532037766dbde4088a23ecdb9ecb8 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 22:55:12 2023 +0800 update webview commit f497cfb000068ae64db6ac340dc75c0c7b5ce85e Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 22:54:43 2023 +0800 update webview commit 878b17f049685befc52439654b9eb489ce604f99 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 22:53:42 2023 +0800 doc: README.md commit 20afafd138f43c73586cfbeb4577b8b5044cae27 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Apr 9 22:53:26 2023 +0800 update: docker compose add env and default port change 10000 commit 222dc6af3ace1eaa950f40622e7ef884f0dda1da Author: BaoXuebin <baoxbin@hotmail.com> Date: Thu Feb 16 13:43:39 2023 +0800 fix: cannot include bean file #46 commit 7375c2b7d454aef8657fb6fb45abe139b143cfd2 Author: BaoXuebin <baoxbin@hotmail.com> Date: Wed Dec 28 00:03:40 2022 +0800 v1.1.11 commit a035dcfe1e0b726d229655ac17100bec84e8443c Author: BaoXuebin <baoxbin@hotmail.com> Date: Wed Dec 28 00:03:13 2022 +0800 update webview commit 1da322e0938ba40a348bd406f18daec7401b0706 Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Dec 27 23:55:53 2022 +0800 add: icbc and abc batch import commit 46ea0c14604cf559cb91ebbc16092e56e07c0f32 Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Dec 27 22:12:05 2022 +0800 del: source file content required validator commit 3ad974e4eba88446da4bf1baca1b83ad66531ac0 Author: baoxuebin <baoxuebin@ienglish.cn> Date: Tue Dec 27 18:41:34 2022 +0800 update: config dir from .beancount-ns change to .beancount-gs commit 7f83b3a3807141d3bbde1aae57dde05072682aa0 Author: baoxuebin <baoxuebin@ienglish.cn> Date: Tue Dec 27 17:22:06 2022 +0800 docs: update readme guide link url commit f2d1e7329b48570afce7a0a8309abac1ecd14f88 Author: baoxuebin <baoxuebin@ienglish.cn> Date: Sat Oct 22 23:34:28 2022 +0800 fix: account balance failed when file is not exist. commit 09f58fef642d46eab7211ea543427351b2cad5e4 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Oct 15 19:35:21 2022 +0800 version 1.1.10 commit 0d172a3988ea2a819a251a9e95d6599deaa205db Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Oct 15 19:24:49 2022 +0800 check ledger api default return empty list commit ab6188da2b577379204c98cf9d2f1154f6a0275b Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Oct 15 19:02:06 2022 +0800 fixbug commit 0522600cde6a6a7276c7fa53c83aa15e999a5083 Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Oct 11 23:30:13 2022 +0800 version: 1.1.9 commit 264c9f584aab633f7e49514e97525fba6597b669 Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Oct 11 23:29:16 2022 +0800 update new webview commit cb72b18513ffc4c0fb9ec5a10e209875c4bfbfbd Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Sep 3 23:21:25 2022 +0800 update: 月份查询改为时间倒序 commit 735e32294201b67f16a67aa2e4dc135015cae400 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Aug 15 00:38:50 2022 +0800 add beancount syntax check api commit 2839749306057e50f570684639fdbe5d53729923 Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Jul 26 22:59:51 2022 +0800 update readme commit 6d85a8ab993db7345e1d2ce5caf204aa556eaebf Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Jul 26 22:30:48 2022 +0800 update webview commit 8c8b635f2e65ec16081219b365ae61ff88556a2b Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Jul 26 22:28:40 2022 +0800 优化docker镜像大小#23 commit 19862e8e7138904883758739c6c416cc86fba2ca Author: BaoXuebin <baoxbin@hotmail.com> Date: Tue Jul 26 22:09:27 2022 +0800 fix: 支付宝账单过滤关闭的交易 commit 2c9b83c907d99a986fb061c96480cccc357d0d7d Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Jul 25 03:35:20 2022 +0800 version 1.1.8 commit 506e606591af391557612fc9c40d84d36f18a9c5 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Jul 23 12:20:28 2022 +0800 fix: cannot close account #22 commit 517cb25e73afbc64e17625ed4135dfb515e829e6 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Jul 23 12:19:35 2022 +0800 fix: failed to bak file cause by linux file system case sensitivity #20 commit 81738c09d902cbd8307f14efbe3bc970ed1b584c Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Jul 3 23:26:48 2022 +0800 lint code commit 4f0284c5a066b646edd08fb594f4a5f8ad3fa968 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Jul 3 22:59:01 2022 +0800 inte:golangci-lint commit 14cf8b3dec4e9b52a0b543a09e67ad1f1a828952 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Jun 5 11:15:29 2022 +0800 version 1.1.7 commit f3a88c4b36bf135d4f2c61a99a2accc862f708e4 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Jun 5 11:14:29 2022 +0800 update webview commit 8520e7d75fd280646b22c935331937df81f68676 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Jun 5 11:07:03 2022 +0800 add: query month calendar api commit 108dba4ea944356a8def92f03e89f68e55d90abd Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Jun 4 13:31:40 2022 +0800 fix: unix 换行符 change to '\n' commit 7cb64969b673e69590312142cca2302939d9ed45 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat May 28 22:04:59 2022 +0800 version 1.1.6 commit 7b2a06e5e28ab9d63b429490d9ebf5683b737f16 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat May 28 22:04:05 2022 +0800 update webview commit ad591921f7fd05b524c4aeec2c861a4d8fbeb09a Author: BaoXuebin <baoxbin@hotmail.com> Date: Thu Apr 14 00:23:08 2022 +0800 add: query commodity prices api commit 4fd6a57215d5542bf4d9ada7f6229ac6bebcf4ae Author: BaoXuebin <baoxbin@hotmail.com> Date: Wed Apr 13 00:30:38 2022 +0800 add: bean-report all_prices commit 659c1d7e151bf1d740cbd6b4d68bfbe830efdd53 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Apr 11 21:25:34 2022 +0800 fixbug: 账户平衡计算导致新增交易异常 commit 15a79c5790dd32aa47d82b398969a3e6433d6753 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Mar 21 00:44:45 2022 +0800 update readme commit 8250e96c876ed2209cf06b4c7a7a95d96eb012d6 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Mar 21 00:12:50 2022 +0800 update 1.1.5 static file commit cae95602c5dcb8159047b2ec0cff1ffaa99908b6 Author: BaoXuebin <baoxbin@hotmail.com> Date: Mon Mar 21 00:01:15 2022 +0800 update 1.1.5 static file commit 5f28dec14df73f4f04ea10044a34a1951ff11173 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 20 23:57:14 2022 +0800 version 1.1.5 commit 8fcdbb43e6538cd47351d748abebc2a49db4532c Author: BaoXuebin <baoxbin@hotmail.com> Date: Sun Mar 20 23:55:05 2022 +0800 add multi stage transaction commit a2a29702d3767dc0a24179547822576e92110bba Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Mar 19 16:18:27 2022 +0800 delete ledger add error handle commit 9f05766287230f99fd97846e052aa2199973dc55 Author: BaoXuebin <baoxbin@hotmail.com> Date: Sat Mar 19 15:44:15 2022 +0800 fix: alipay mobile csv file cannot import (#8) # Conflicts: # dockerfile
2024-03-17 15:57:21 +00:00
func BeanReportAllPrices(ledgerConfig *Config) string {
beanFilePath := GetLedgerPriceFilePath(ledgerConfig.DataPath)
LogInfo(ledgerConfig.Mail, "bean-report "+beanFilePath+" all_prices")
cmd := exec.Command("bean-report", beanFilePath, "all_prices")
output, _ := cmd.Output()
return string(output)
}
2021-11-22 14:50:10 +00:00
func bqlRawQuery(ledgerConfig *Config, selectBql string, queryParamsPtr *QueryParams, queryResultPtr interface{}) (string, error) {
2021-11-25 07:41:28 +00:00
var bql string
2021-11-22 14:50:10 +00:00
if selectBql == "" {
2021-11-25 07:41:28 +00:00
bql = "select"
2021-11-22 14:50:10 +00:00
queryResultPtrType := reflect.TypeOf(queryResultPtr)
queryResultType := queryResultPtrType.Elem()
2021-11-22 08:47:49 +00:00
2021-11-22 14:50:10 +00:00
if queryResultType.Kind() == reflect.Slice {
queryResultType = queryResultType.Elem()
}
for i := 0; i < queryResultType.NumField(); i++ {
typeField := queryResultType.Field(i)
// 字段的 tag 不带 bql 的不进行拼接
b := typeField.Tag.Get("bql")
if b != "" {
if strings.Contains(b, "distinct") {
b = strings.ReplaceAll(b, "distinct", "")
bql = fmt.Sprintf("%s distinct '\\', %s, ", bql, b)
} else {
bql = fmt.Sprintf("%s '\\', %s, ", bql, typeField.Tag.Get("bql"))
}
2021-11-21 14:37:13 +00:00
}
2021-11-22 08:47:49 +00:00
}
2021-11-22 14:50:10 +00:00
bql += " '\\'"
} else {
bql = selectBql
2021-11-22 08:47:49 +00:00
}
2021-11-22 14:50:10 +00:00
2021-11-22 08:47:49 +00:00
// 查询条件不为空时,拼接查询条件
if queryParamsPtr != nil {
queryParamsType := reflect.TypeOf(queryParamsPtr).Elem()
queryParamsValue := reflect.ValueOf(queryParamsPtr).Elem()
for i := 0; i < queryParamsType.NumField(); i++ {
typeField := queryParamsType.Field(i)
valueField := queryParamsValue.Field(i)
switch valueField.Kind() {
case reflect.String:
val := valueField.String()
if val != "" {
2021-11-24 15:45:45 +00:00
if typeField.Name == "OrderBy" || typeField.Name == "GroupBy" {
// 去除上一个条件后缀的 AND 关键字
bql = strings.Trim(bql, " AND")
bql = fmt.Sprintf("%s %s %s", bql, typeField.Tag.Get("bql"), val)
2021-11-24 10:04:02 +00:00
} else if typeField.Name == "Tag" {
bql = fmt.Sprintf("%s '%s' %s", bql, strings.Trim(val, " "), typeField.Tag.Get("bql"))
} else {
bql = fmt.Sprintf("%s %s '%s' AND", bql, typeField.Tag.Get("bql"), val)
}
2021-11-22 08:47:49 +00:00
}
case reflect.Int:
val := valueField.Int()
if val != 0 {
bql = fmt.Sprintf("%s %s %d AND", bql, typeField.Tag.Get("bql"), val)
}
case reflect.Bool:
val := valueField.Bool()
2021-12-02 14:48:45 +00:00
// where 前的 from 可能会带有 and
if typeField.Name == "Where" {
bql = strings.Trim(bql, " AND")
}
if val {
bql = fmt.Sprintf("%s %s ", bql, typeField.Tag.Get("bql"))
}
2021-11-22 08:47:49 +00:00
}
}
bql = strings.TrimRight(bql, " AND")
}
return queryByBQL(ledgerConfig, bql)
}
func parseResult(output string, queryResultPtr interface{}, selectOne bool) error {
queryResultPtrType := reflect.TypeOf(queryResultPtr)
queryResultType := queryResultPtrType.Elem()
if queryResultType.Kind() == reflect.Slice {
queryResultType = queryResultType.Elem()
}
lines := strings.Split(output, "\n")[2:]
if selectOne && len(lines) >= 3 {
lines = lines[2:3]
}
l := make([]map[string]interface{}, 0)
for _, line := range lines {
if line != "" {
values := strings.Split(line, "\\")
// 去除 '\' 分割带来的空字符串
values = values[1 : len(values)-1]
temp := make(map[string]interface{})
for i, val := range values {
field := queryResultType.Field(i)
jsonName := field.Tag.Get("json")
if jsonName == "" {
jsonName = field.Name
}
switch field.Type.Kind() {
2021-11-26 09:12:07 +00:00
case reflect.Int, reflect.Int32:
2021-11-25 07:41:28 +00:00
i, err := strconv.Atoi(strings.Trim(val, " "))
if err != nil {
panic(err)
}
temp[jsonName] = i
2021-11-22 14:50:10 +00:00
// decimal
case reflect.String, reflect.Struct:
v := strings.Trim(val, " ")
if v != "" {
temp[jsonName] = v
}
2021-11-22 08:47:49 +00:00
case reflect.Array, reflect.Slice:
// 去除空格
strArray := strings.Split(val, ",")
notBlanks := make([]string, 0)
for _, s := range strArray {
if strings.Trim(s, " ") != "" {
notBlanks = append(notBlanks, s)
}
}
temp[jsonName] = notBlanks
default:
panic("Unsupported field type")
}
2021-11-21 14:37:13 +00:00
}
2021-11-22 08:47:49 +00:00
l = append(l, temp)
2021-11-21 14:37:13 +00:00
}
}
2021-11-22 08:47:49 +00:00
var jsonBytes []byte
var err error
if selectOne {
jsonBytes, err = json.Marshal(l[0])
} else {
jsonBytes, err = json.Marshal(l)
}
if err != nil {
return err
}
err = json.Unmarshal(jsonBytes, queryResultPtr)
2021-11-21 14:37:13 +00:00
if err != nil {
return err
}
return nil
}
func queryByBQL(ledgerConfig *Config, bql string) (string, error) {
beanFilePath := ledgerConfig.DataPath + "/index.bean"
LogInfo(ledgerConfig.Mail, bql)
cmd := exec.Command("bean-query", beanFilePath, bql)
output, err := cmd.Output()
if err != nil {
return "", err
}
return string(output), nil
}
2021-11-22 08:47:49 +00:00
func assertQueryResultIsPointer(queryResult interface{}) {
k := reflect.TypeOf(queryResult).Kind()
if k != reflect.Ptr {
panic("QueryResult type must be pointer, it's " + k.String())
}
}