add: bean-report all_prices

This commit is contained in:
BaoXuebin 2022-04-13 00:30:38 +08:00
parent 659c1d7e15
commit 4fd6a57215
3 changed files with 41 additions and 0 deletions

View File

@ -104,6 +104,15 @@ func BQLQueryListByCustomSelect(ledgerConfig *Config, selectBql string, queryPar
return nil
}
func BeanReportAllPrices(ledgerConfig *Config) string {
beanFilePath := ledgerConfig.DataPath + "/index.bean"
LogInfo(ledgerConfig.Mail, "bean-report "+beanFilePath+" all_prices")
cmd := exec.Command("bean-report", beanFilePath, "all_prices")
output, _ := cmd.Output()
return string(output)
}
func bqlRawQuery(ledgerConfig *Config, selectBql string, queryParamsPtr *QueryParams, queryResultPtr interface{}) (string, error) {
var bql string
if selectBql == "" {

View File

@ -75,6 +75,7 @@ func RegisterRouter(router *gin.Engine) {
authorized.GET("/stats/account/trend", service.StatsAccountTrend)
authorized.GET("/stats/account/balance", service.StatsAccountBalance)
authorized.GET("/stats/month/total", service.StatsMonthTotal)
authorized.GET("/stats/prices", service.StatsPrices)
authorized.GET("/transaction", service.QueryTransactions)
authorized.POST("/transaction", service.AddTransactions)
authorized.POST("/transaction/batch", service.AddBatchTransactions)

View File

@ -406,3 +406,34 @@ func StatsPayee(c *gin.Context) {
sort.Sort(StatsPayeeResultSort(result))
OK(c, result)
}
type StatsPricesResult struct {
Date string `json:"date"`
Price string `json:"price"`
Currency string `json:"operatingCurrency"`
Value string `json:"value"`
}
func StatsPrices(c *gin.Context) {
ledgerConfig := script.GetLedgerConfigFromContext(c)
output := script.BeanReportAllPrices(ledgerConfig)
script.LogInfo(ledgerConfig.Mail, output)
statsPricesResultList := make([]StatsPricesResult, 0)
lines := strings.Split(output, "\r\n")
// foreach lines
for _, line := range lines {
if strings.Trim(line, " ") == "" {
continue
}
// split line by " "
words := strings.Fields(line)
statsPricesResultList = append(statsPricesResultList, StatsPricesResult{
Date: words[0],
Price: words[2],
Value: words[3],
Currency: words[4],
})
}
OK(c, statsPricesResultList)
}