add: bean-report all_prices
This commit is contained in:
parent
659c1d7e15
commit
4fd6a57215
|
|
@ -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 == "" {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue