u
This commit is contained in:
1 parent
c62c9d080b
commit
6a8c31e20c
29 files changed
+1454
-357
No files matched your search
@@ -0,0 +1,105 @@
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package money
|
||||
|
||||
import (
|
||||
money "allapp/biz/model/money"
|
||||
"allapp/biz/router/middleware"
|
||||
"allapp/db"
|
||||
"allapp/db/repo"
|
||||
"allapp/utils/errorx"
|
||||
"allapp/utils/pgtypex"
|
||||
"allapp/utils/response"
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
)
|
||||
|
||||
// AnalysisMoneyLine .
|
||||
// @router /money/analysis/line [POST]
|
||||
func AnalysisMoneyLine(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req money.AnalysisMoneyParams
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
userID := middleware.GetUserID(ctx)
|
||||
|
||||
analysis, err := db.Queries.ListMoneyRecordsByLineAnalysis(ctx, repo.ListMoneyRecordsByLineAnalysisParams{
|
||||
Column1: req.PeriodType,
|
||||
UserID: userID,
|
||||
RecordTime: pgtypex.StringToDate(req.StartDate),
|
||||
RecordTime_2: pgtypex.StringToDate(req.EndDate),
|
||||
Type: req.Type,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
errorx.AddError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// 循环赋值到响应数据中
|
||||
records := make([]*money.AnalysisMoneyAmount, 0, len(analysis))
|
||||
|
||||
for _, record := range analysis {
|
||||
period, ok := record.Period.(string)
|
||||
if !ok {
|
||||
period = ""
|
||||
}
|
||||
|
||||
// 创建指向 AnalysisAmount 的指针
|
||||
records = append(records, &money.AnalysisMoneyAmount{
|
||||
X: period,
|
||||
Y: pgtypex.NumericToString(record.TotalAmount),
|
||||
})
|
||||
}
|
||||
|
||||
response.Success(c).Data(&money.AnalysisMoneyLineResult{
|
||||
Records: records,
|
||||
}).Send()
|
||||
}
|
||||
|
||||
// AnalysisMoneyPie .
|
||||
// @router /money/analysis/pie [POST]
|
||||
func AnalysisMoneyPie(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req money.AnalysisMoneyParams
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
userID := middleware.GetUserID(ctx)
|
||||
|
||||
analysis, err := db.Queries.ListMoneyRecordsByPieAnalysis(ctx, repo.ListMoneyRecordsByPieAnalysisParams{
|
||||
UserID: userID,
|
||||
RecordTime: pgtypex.StringToDate(req.StartDate),
|
||||
RecordTime_2: pgtypex.StringToDate(req.EndDate),
|
||||
Type: req.Type,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
errorx.AddError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// 使用值类型而不是指针类型
|
||||
records := make([]*money.AnalysisMoneyAmount, 0, len(analysis))
|
||||
|
||||
for _, record := range analysis {
|
||||
// 直接赋值而不是使用指针
|
||||
records = append(records, &money.AnalysisMoneyAmount{
|
||||
X: record.Name.String,
|
||||
Y: pgtypex.NumericToString(record.TotalAmount),
|
||||
})
|
||||
}
|
||||
|
||||
response.Success(c).Data(&money.AnalysisMoneyPieResult{
|
||||
Records: records,
|
||||
}).Send()
|
||||
}
|
||||
Reference in new issue
Block a user