u
This commit is contained in:
1 parent
d51eacb8ad
commit
44b3ef27d2
50 files changed
+3141
-9734
No files matched your search
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
// RefreshAccessToken .
|
||||
// @router /auth/refreshToken [POST]
|
||||
// @router /auth/refresh/token [GET]
|
||||
func RefreshAccessToken(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req auth.RefreshAccessTokenReq
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
package money
|
||||
|
||||
import (
|
||||
"cn/oneao/base-go/biz/model/money"
|
||||
"cn/oneao/base-go/biz/router/middleware"
|
||||
"cn/oneao/base-go/db"
|
||||
"cn/oneao/base-go/db/repo"
|
||||
@@ -11,6 +10,7 @@ import (
|
||||
"cn/oneao/base-go/utils/response"
|
||||
"context"
|
||||
|
||||
money "cn/oneao/base-go/biz/model/money"
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
)
|
||||
|
||||
@@ -7,23 +7,23 @@ import (
|
||||
"cn/oneao/base-go/db"
|
||||
"cn/oneao/base-go/db/repo"
|
||||
"cn/oneao/base-go/utils/errorx"
|
||||
"cn/oneao/base-go/utils/idgen"
|
||||
"cn/oneao/base-go/utils/pgtypex"
|
||||
"cn/oneao/base-go/utils/response"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/shopspring/decimal"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
money "cn/oneao/base-go/biz/model/money"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/shopspring/decimal"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
// QueryMoneyRecord .
|
||||
// @router /money/record [POST]
|
||||
// @router /money/record/query [POST]
|
||||
func QueryMoneyRecord(ctx context.Context, c *app.RequestContext) {
|
||||
var req money.QueryMoneyRecordsParams
|
||||
if err := c.BindAndValidate(&req); err != nil {
|
||||
@@ -76,25 +76,20 @@ func QueryMoneyRecord(ctx context.Context, c *app.RequestContext) {
|
||||
|
||||
// 构造单条记录
|
||||
item := &money.MoneyRecordItem{
|
||||
Base: &money.MoneyRecordBase{
|
||||
Id: r.ID,
|
||||
CategoryId: r.CategoryID,
|
||||
UserId: r.UserID,
|
||||
Amount: r.Amount.Int.String(),
|
||||
Remark: r.Remark.String,
|
||||
RecordTime: timestamppb.New(r.RecordTime.Time),
|
||||
CreateTime: timestamppb.New(r.CreateTime.Time),
|
||||
UpdateTime: timestamppb.New(r.UpdateTime.Time),
|
||||
},
|
||||
CategoryName: r.CategoryName.String,
|
||||
CategoryIcon: r.CategoryIcon.String,
|
||||
CategoryType: r.CategoryType.Int32,
|
||||
Id: r.ID,
|
||||
CategoryId: r.CategoryID,
|
||||
UserId: r.UserID,
|
||||
Amount: pgtypex.NumericToString(r.Amount),
|
||||
Remark: r.Remark.String,
|
||||
RecordTime: pgtypex.TimestampToDateString(r.RecordTime),
|
||||
CreateTime: pgtypex.TimestampToDateTimeString(r.CreateTime),
|
||||
UpdateTime: pgtypex.TimestampToDateTimeString(r.UpdateTime),
|
||||
}
|
||||
|
||||
group.Records = append(group.Records, item)
|
||||
|
||||
// 收支累加
|
||||
amount, _ := decimal.NewFromString(r.Amount.Int.String())
|
||||
amount := pgtypex.NumericToDecimal(r.Amount)
|
||||
if r.CategoryType.Int32 == 1 {
|
||||
incomeDec, _ := decimal.NewFromString(group.Income)
|
||||
incomeDec = incomeDec.Add(amount)
|
||||
@@ -129,3 +124,98 @@ func QueryMoneyRecord(ctx context.Context, c *app.RequestContext) {
|
||||
|
||||
response.Success(c).Data(result).Send()
|
||||
}
|
||||
|
||||
// InsertMoneyRecord .
|
||||
// @router /money/record/insert [POST]
|
||||
func InsertMoneyRecord(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req money.InsertMoneyRecordParams
|
||||
err = c.BindAndValidate(&req)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(money.InsertMoneyRecordResult)
|
||||
|
||||
params := repo.InsertMoneyRecordParams{
|
||||
ID: idgen.NextId(),
|
||||
CategoryID: req.CategoryId,
|
||||
UserID: middleware.GetUserID(ctx),
|
||||
Amount: pgtypex.StringToNumeric(req.Amount),
|
||||
Remark: pgtypex.StringToText(req.Remark),
|
||||
RecordTime: pgtypex.StringToTimestamp(req.RecordTime),
|
||||
}
|
||||
|
||||
record, err := db.Queries.InsertMoneyRecord(ctx, params)
|
||||
|
||||
resp.Id = record.ID
|
||||
resp.CategoryId = record.CategoryID
|
||||
resp.UserId = record.UserID
|
||||
resp.Amount = pgtypex.NumericToString(record.Amount)
|
||||
resp.Remark = record.Remark.String
|
||||
resp.RecordTime = pgtypex.TimestampToDateString(record.RecordTime)
|
||||
resp.CreateTime = pgtypex.TimestampToDateTimeString(record.CreateTime)
|
||||
resp.UpdateTime = pgtypex.TimestampToDateTimeString(record.UpdateTime)
|
||||
|
||||
response.Success(c).Data(resp).Message("新增成功").Send()
|
||||
}
|
||||
|
||||
// UpdateMoneyRecord .
|
||||
// @router /money/record/update [POST]
|
||||
func UpdateMoneyRecord(ctx context.Context, c *app.RequestContext) {
|
||||
var req money.UpdateMoneyRecordParams
|
||||
if err := c.BindAndValidate(&req); err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
id := req.Id
|
||||
_, err := db.Queries.GetMoneyRecordById(ctx, id)
|
||||
if err != nil {
|
||||
if errorx.IsNotFound(err) {
|
||||
response.Success(c).Send()
|
||||
return
|
||||
}
|
||||
errorx.AddError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
params := repo.UpdateMoneyRecordParams{
|
||||
ID: id,
|
||||
CategoryID: req.CategoryId,
|
||||
Amount: pgtypex.StringToNumeric(req.Amount),
|
||||
Remark: pgtypex.StringToText(req.Remark),
|
||||
RecordTime: pgtypex.StringToTimestamp(req.RecordTime),
|
||||
}
|
||||
|
||||
if err := db.Queries.UpdateMoneyRecord(ctx, params); err != nil {
|
||||
errorx.AddError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c).Send()
|
||||
}
|
||||
|
||||
// DeleteMoneyRecord .
|
||||
// @router /money/record/delete [POST]
|
||||
func DeleteMoneyRecord(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req money.DeleteMoneyRecordParams
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = db.Queries.DeleteMoneyRecord(ctx, req.Id)
|
||||
|
||||
if err != nil {
|
||||
errorx.AddError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c).Send()
|
||||
}
|
||||
Reference in new issue
Block a user