From 9b3a3d2399ead924893c2ea2d5d403554c385f12 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Tue, 12 Nov 2024 10:12:08 +0800 Subject: [PATCH] update --- .../egg_Energy/hdl_basic.go | 89 ++++++++++--------- .../egg_energy/md_egg_energy.go | 7 +- 2 files changed, 46 insertions(+), 50 deletions(-) diff --git a/app/hdl/institutional_management/egg_Energy/hdl_basic.go b/app/hdl/institutional_management/egg_Energy/hdl_basic.go index 2c326b5..e019a6a 100644 --- a/app/hdl/institutional_management/egg_Energy/hdl_basic.go +++ b/app/hdl/institutional_management/egg_Energy/hdl_basic.go @@ -5,6 +5,7 @@ import ( "applet/app/e" md "applet/app/md/institutional_management/egg_energy" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "github.com/gin-gonic/gin" ) @@ -58,20 +59,28 @@ func GetActivePointsUserCoinList(c *gin.Context) { } activePointsWalletList := make([]md.ActivePointsWalletNode, len(wallets)) userDb := implement.NewUserDb(db.Db) + userIDs := make([]int64, len(wallets)) + for i, wallet := range wallets { + userIDs[i] = wallet.Uid + } + users, err := userDb.UserFindByParams(map[string]interface{}{ + "key": "id", + "value": userIDs, + }) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + userMap := make(map[int64]model.User) + for _, user := range users { + userMap[user.Id] = user + } for _, wallet := range wallets { - user, err4 := userDb.UserGetOneByParams(map[string]interface{}{ - "key": "uid", - "value": wallet.Id, - }) - if err4 != nil { - e.OutErr(c, e.ERR_DB_ORM, err4.Error()) - return - } activePointsWallet := md.ActivePointsWalletNode{ Amount: wallet.Amount, - Uid: user.Id, - UserName: user.Nickname, - UserPhone: user.Phone, + Uid: userMap[wallet.Uid].Id, + UserName: userMap[wallet.Uid].Nickname, + UserPhone: userMap[wallet.Uid].Phone, } activePointsWalletList = append(activePointsWalletList, activePointsWallet) } @@ -123,17 +132,9 @@ func GetActivePointsUserCoinFlowList(c *gin.Context) { Total: total, } - map1 := md.DirectionMap{ - Key: "1", - Value: "收入", - } - map2 := md.DirectionMap{ - Key: "2", - Value: "支出", - } - - direction := []md.DirectionMap{ - map1, map2, + direction := []map[string]string{ + {"key": "1", "value": "收入"}, + {"key": "2", "value": "支出"}, } selectData := md.SelectData{Direction: direction} @@ -215,20 +216,28 @@ func GetGreenEnergyUserCoinList(c *gin.Context) { } activePointsWalletList := make([]md.ActivePointsWalletNode, len(wallets)) userDb := implement.NewUserDb(db.Db) + userIDs := make([]int64, len(wallets)) + for i, wallet := range wallets { + userIDs[i] = wallet.Uid + } + users, err := userDb.UserFindByParams(map[string]interface{}{ + "key": "id", + "value": userIDs, + }) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + userMap := make(map[int64]model.User) + for _, user := range users { + userMap[user.Id] = user + } for _, wallet := range wallets { - user, err4 := userDb.UserGetOneByParams(map[string]interface{}{ - "key": "uid", - "value": wallet.Id, - }) - if err4 != nil { - e.OutErr(c, e.ERR_DB_ORM, err4.Error()) - return - } activePointsWallet := md.ActivePointsWalletNode{ Amount: wallet.Amount, - Uid: user.Id, - UserName: user.Nickname, - UserPhone: user.Phone, + Uid: userMap[wallet.Uid].Id, + UserName: userMap[wallet.Uid].Nickname, + UserPhone: userMap[wallet.Uid].Phone, } activePointsWalletList = append(activePointsWalletList, activePointsWallet) } @@ -280,17 +289,9 @@ func GetGreenEnergyUserCoinFlowList(c *gin.Context) { Total: total, } - map1 := md.DirectionMap{ - Key: "1", - Value: "收入", - } - map2 := md.DirectionMap{ - Key: "2", - Value: "支出", - } - - direction := []md.DirectionMap{ - map1, map2, + direction := []map[string]string{ + {"key": "1", "value": "收入"}, + {"key": "2", "value": "支出"}, } selectData := md.SelectData{Direction: direction} diff --git a/app/md/institutional_management/egg_energy/md_egg_energy.go b/app/md/institutional_management/egg_energy/md_egg_energy.go index 5dd7a90..35ff21c 100644 --- a/app/md/institutional_management/egg_energy/md_egg_energy.go +++ b/app/md/institutional_management/egg_energy/md_egg_energy.go @@ -47,13 +47,8 @@ type Paginate struct { Total int64 `json:"total"` // 总数据量 } -type DirectionMap struct { - Key string `json:"key"` - Value string `json:"value"` -} - type SelectData struct { - Direction []DirectionMap `json:"direction"` + Direction []map[string]string `json:"direction"` } type UserVirtualCoinFlow struct {