Update stats.go
商户消费排行某个月份返回无效值 解决方案 [#14 ](https://github.com/BaoXuebin/beancount-gs/issues/14)
This commit is contained in:
parent
a339e1afe8
commit
5159755109
|
|
@ -442,25 +442,37 @@ func StatsPayee(c *gin.Context) {
|
||||||
|
|
||||||
result := make([]StatsPayeeResult, 0)
|
result := make([]StatsPayeeResult, 0)
|
||||||
for _, l := range statsPayeeQueryResultList {
|
for _, l := range statsPayeeQueryResultList {
|
||||||
|
// 交易账户名称非空
|
||||||
if l.Payee != "" {
|
if l.Payee != "" {
|
||||||
payee := StatsPayeeResult{
|
payee := StatsPayeeResult{
|
||||||
Payee: l.Payee,
|
Payee: l.Payee,
|
||||||
Currency: ledgerConfig.OperatingCurrency,
|
Currency: ledgerConfig.OperatingCurrency,
|
||||||
}
|
}
|
||||||
|
//查询交易次数
|
||||||
if statsQuery.Type == "cot" {
|
if statsQuery.Type == "cot" {
|
||||||
payee.Value = json.Number(decimal.NewFromInt32(l.Count).String())
|
payee.Value = json.Number(decimal.NewFromInt32(l.Count).String())
|
||||||
} else {
|
} else {
|
||||||
|
//查询交易金额,要过滤掉空白交易金额的科目,
|
||||||
|
// 比如 记账购买后又全额退款导致科目交易条目数>0但是累计金额=0
|
||||||
|
if l.Position != "" {
|
||||||
|
// 读取交易金额相关信息
|
||||||
fields := strings.Fields(l.Position)
|
fields := strings.Fields(l.Position)
|
||||||
|
// 交易金额
|
||||||
total, err := decimal.NewFromString(fields[0])
|
total, err := decimal.NewFromString(fields[0])
|
||||||
|
// 错误处理
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if statsQuery.Type == "avg" {
|
if statsQuery.Type == "avg" {
|
||||||
|
// 如果是查询平均交易金额
|
||||||
payee.Value = json.Number(total.Div(decimal.NewFromInt32(l.Count)).Round(2).String())
|
payee.Value = json.Number(total.Div(decimal.NewFromInt32(l.Count)).Round(2).String())
|
||||||
} else {
|
} else {
|
||||||
|
// 如果是查询总交易金额
|
||||||
payee.Value = json.Number(fields[0])
|
payee.Value = json.Number(fields[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
result = append(result, payee)
|
result = append(result, payee)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue