Procházet zdrojové kódy

Revert "update 完善优化代码"

This reverts commit b3c1eb42c6c340fe8676a70afb475417c34a760c.
Alvin před 8 měsíci
rodič
revize
5ebb9f496c

+ 4 - 1
game/game_cluster/nodes/webadmin/common/packResponse.go

@@ -33,7 +33,10 @@ func PackOkResult(c *gin.Context, statusCode int32, data ...interface{}) {
 	result := &code.Result{
 		Code:    statusCode,
 		Message: code.GetMessage(statusCode),
-		Data:    data,
+	}
+
+	if len(data) > 0 {
+		result.Data = data
 	}
 
 	c.JSON(http.StatusOK, result)

+ 1 - 18
game/game_cluster/nodes/webadmin/controller/admin.go

@@ -86,23 +86,6 @@ func (a *Admin) Del(ctx *gin.Context) {
 	common.PackOkResult(ctx, code.OK, nil)
 }
 
-// Find 获取管理员信息
-func (a *Admin) Find(ctx *gin.Context) {
-	var req entity.AdminFindReq
-	if err := ctx.ShouldBindJSON(&req); err != nil {
-		common.PackOkResult(ctx, code.ParamError)
-		return
-	}
-
-	resp, err := a.sev.Find(ctx, req)
-	if err != nil {
-		common.PackOkResult(ctx, err.Code)
-		return
-	}
-
-	common.PackOkResult(ctx, code.OK, resp)
-}
-
 // FindAll 获取所有管理员
 func (a *Admin) FindAll(ctx *gin.Context) {
 	var req entity.AdminFindAllReq
@@ -111,7 +94,7 @@ func (a *Admin) FindAll(ctx *gin.Context) {
 		return
 	}
 
-	resp, err := a.sev.FindAll(ctx, req)
+	resp, err := a.sev.FindAll(ctx, req.Page, req.Size, req.Username)
 	if err != nil {
 		common.PackOkResult(ctx, err.Code)
 		return

+ 5 - 5
game/game_cluster/nodes/webadmin/controller/synthesis.go

@@ -21,7 +21,7 @@ func NewSynthesis() *Synthesis {
 // FindUserLogDaily 查询用户日活跃
 func (s *Synthesis) FindUserLogDaily(ctx *gin.Context) {
 	var req entity.UserLogDailyReq
-	if err := ctx.ShouldBindJSON(&req); err != nil {
+	if err := ctx.ShouldBindJSON(req); err != nil {
 		common.PackOkResult(ctx, code.ParamError)
 		return
 	}
@@ -38,7 +38,7 @@ func (s *Synthesis) FindUserLogDaily(ctx *gin.Context) {
 // FindUserRetention 查询用户留存
 func (s *Synthesis) FindUserRetention(ctx *gin.Context) {
 	var req entity.UserRetentionReq
-	if err := ctx.ShouldBindJSON(&req); err != nil {
+	if err := ctx.ShouldBindJSON(req); err != nil {
 		common.PackOkResult(ctx, code.ParamError)
 		return
 	}
@@ -66,7 +66,7 @@ func (s *Synthesis) FindUserCountryCount(ctx *gin.Context) {
 // FindWithdrawal 查询提现记录
 func (s *Synthesis) FindWithdrawal(ctx *gin.Context) {
 	var req entity.UserWithdrawalReq
-	if err := ctx.ShouldBindJSON(&req); err != nil {
+	if err := ctx.ShouldBindJSON(req); err != nil {
 		common.PackOkResult(ctx, code.ParamError)
 		return
 	}
@@ -83,7 +83,7 @@ func (s *Synthesis) FindWithdrawal(ctx *gin.Context) {
 // WithdrawalStatus 修改提现状态
 func (s *Synthesis) WithdrawalStatus(ctx *gin.Context) {
 	var req entity.UserWithdrawalStatus
-	if err := ctx.ShouldBindJSON(&req); err != nil {
+	if err := ctx.ShouldBindJSON(req); err != nil {
 		common.PackOkResult(ctx, code.ParamError)
 		return
 	}
@@ -100,7 +100,7 @@ func (s *Synthesis) WithdrawalStatus(ctx *gin.Context) {
 // WithdrawalStatusBatch 修改提现状态批量
 func (s *Synthesis) WithdrawalStatusBatch(ctx *gin.Context) {
 	var req entity.UserWithdrawalStatusBatch
-	if err := ctx.ShouldBindJSON(&req); err != nil {
+	if err := ctx.ShouldBindJSON(req); err != nil {
 		common.PackOkResult(ctx, code.ParamError)
 		return
 	}

+ 3 - 3
game/game_cluster/nodes/webadmin/controller/whitelist.go

@@ -29,7 +29,7 @@ func NewWhitelist() *Whitelist {
 // @Router /v1/admin/whitelist/list [post]
 func (w *Whitelist) GetWhitelist(ctx *gin.Context) {
 	var req entity.WhitelistListReq
-	if err := ctx.ShouldBindJSON(&req); err != nil {
+	if err := ctx.ShouldBindJSON(req); err != nil {
 		common.PackOkResult(ctx, code.ParamError)
 		return
 	}
@@ -54,7 +54,7 @@ func (w *Whitelist) GetWhitelist(ctx *gin.Context) {
 // @Router /v1/admin/whitelist/add [post]
 func (w *Whitelist) AddWhitelist(ctx *gin.Context) {
 	var req entity.WhitelistAddReq
-	if err := ctx.ShouldBindJSON(&req); err != nil {
+	if err := ctx.ShouldBindJSON(req); err != nil {
 		common.PackOkResult(ctx, code.ParamError)
 		return
 	}
@@ -79,7 +79,7 @@ func (w *Whitelist) AddWhitelist(ctx *gin.Context) {
 // @Router /v1/admin/whitelist/remove [post]
 func (w *Whitelist) RemoveWhitelist(ctx *gin.Context) {
 	var req entity.WhitelistRemoveReq
-	if err := ctx.ShouldBindJSON(&req); err != nil {
+	if err := ctx.ShouldBindJSON(req); err != nil {
 		common.PackOkResult(ctx, code.ParamError)
 		return
 	}

+ 5 - 7
game/game_cluster/nodes/webadmin/entity/admin.go

@@ -41,7 +41,9 @@ type AdminListDetail struct {
 }
 
 type AdminChangePasswordReq struct {
-	Password string `json:"password"`
+	Password string `json:"
+
+"`
 	Username string `json:"username"`
 }
 
@@ -49,15 +51,11 @@ type AdminDelReq struct {
 	Username string `json:"username"`
 }
 
-type AdminFindReq struct {
+type AdminFindAllReq struct {
 	Page     int    `json:"page"`
 	Size     int    `json:"size"`
 	Username string `json:"username"`
-}
-
-type AdminFindAllReq struct {
-	Page int `json:"page"`
-	Size int `json:"size"`
+	Total    int64  `json:"total"`
 }
 
 type AdminUpdateStatusReq struct {

+ 1 - 0
game/game_cluster/nodes/webadmin/entity/user_country_count.go

@@ -2,6 +2,7 @@ package entity
 
 type UserCountryResp struct {
 	Details []*UserCountryDetail `json:"details"`
+	Total   int64                `json:"total"`
 }
 
 type UserCountryDetail struct {

+ 1 - 0
game/game_cluster/nodes/webadmin/entity/user_log_daily.go

@@ -29,4 +29,5 @@ type UserLogDailyReq struct {
 	Channel   string `json:"channel"`
 	Page      int    `json:"page"`
 	Size      int    `json:"size"`
+	Total     int64  `json:"total"`
 }

+ 2 - 3
game/game_cluster/nodes/webadmin/router/router.go

@@ -48,10 +48,9 @@ func (c *Controller) InitApiRouter(u *gin.RouterGroup) {
 	u.POST("/user/changePassword", controller.NewAdmin().ChangePassword)
 	u.POST("/user/add", controller.NewAdmin().Add)
 	u.POST("/user/del", controller.NewAdmin().Del)
-	u.POST("/user/find", controller.NewAdmin().Find)
-	u.POST("/user/findAll", controller.NewAdmin().FindAll)
+	u.POST("/user/find", controller.NewAdmin().FindAll)
 	u.POST("/user/update", controller.NewAdmin().UpdateStatus)
-	u.POST("/user/serverStatus", controller.NewAdmin().GetServerStatus)
+	u.POST("/user/server_status", controller.NewAdmin().GetServerStatus)
 	u.POST("/role/add", controller.NewRole().Add)
 	u.POST("/role/update", controller.NewRole().Update)
 	u.POST("/role/del", controller.NewRole().Del)

+ 8 - 98
game/game_cluster/nodes/webadmin/service/admin.go

@@ -277,115 +277,26 @@ func (a *Admin) UpdateStatus(ctx context.Context, username string, status int) *
 	return nil
 }
 
-// Find 获取管理员信息
-func (a *Admin) Find(ctx context.Context, req entity.AdminFindReq) (*entity.AdminListResp, *code.Result) {
+// FindAll 查找所有管理员信息
+func (a *Admin) FindAll(ctx context.Context, page int, pageSize int, username string) (*entity.AdminListResp, *code.Result) {
 	// 日志记录
-	mhayaLogger.Warnf("Find req: %#v", req)
+	mhayaLogger.Warnf("Finding admins with page %d and page size %d, username: %s", page, pageSize, maskUsername(username))
 
 	// 验证参数
-	page := req.Page
-	if req.Page <= 0 {
+	if page <= 0 {
 		page = 1
 	}
-	pageSize := req.Size
-	if req.Size <= 0 {
+	if pageSize <= 0 {
 		pageSize = 10
 	}
 
 	// 构建查询条件
 	filter := bson.M{}
-	if req.Username != "" {
-		filter["username"] = bson.M{"$regex": escapeRegex(req.Username), "$options": "i"}
+	if username != "" {
+		filter["username"] = bson.M{"$regex": escapeRegex(username), "$options": "i"}
 	}
 	// 查询总数
 	count, err := mdb.MDB.Collection("admin").CountDocuments(ctx, filter)
-	if err != nil {
-		mhayaLogger.Warnf("Find CountDocuments error:", err)
-		return nil, common.NewResult(code.InternalError)
-	}
-
-	// 设置分页选项
-	skip := (page - 1) * pageSize
-	limit := pageSize
-	findOptions := options.Find().SetSkip(int64(skip)).SetLimit(int64(limit))
-
-	// 执行查询
-	cursor, err := mdb.MDB.Collection("admin").Find(ctx, filter, findOptions)
-	if err != nil {
-		mhayaLogger.Warnf("Find Find error:", err)
-		return nil, common.NewResult(code.InternalError)
-	}
-	defer func() {
-		if closeErr := cursor.Close(ctx); closeErr != nil {
-			mhayaLogger.Warnf("Error closing cursor: %v", closeErr)
-		}
-	}()
-
-	// 解析结果
-	admins := make([]*model.Admin, 0)
-	for cursor.Next(ctx) {
-		var admin model.Admin
-		err := cursor.Decode(&admin)
-		if err != nil {
-			mhayaLogger.Warnf("Find Decode error:", err)
-			return nil, common.NewResult(code.InternalError)
-		}
-		admins = append(admins, &admin)
-	}
-
-	if err := cursor.Err(); err != nil {
-		mhayaLogger.Warnf("Find cursor error:", err)
-		return nil, common.NewResult(code.InternalError)
-	}
-
-	var details []*entity.AdminListDetail
-	for _, admin := range admins {
-		roleName := ""
-		roleName, _ = a.GetRoleName(admin.RoleId)
-
-		details = append(details, &entity.AdminListDetail{
-			Id:            admin.GetID(),
-			Username:      admin.Username,
-			RealName:      admin.RealName,
-			RoleId:        admin.RoleId,
-			RoleName:      roleName,
-			Status:        admin.Status,
-			CreatedAt:     admin.CreatedAt,
-			UpdatedAt:     admin.UpdatedAt,
-			LastLoginIp:   admin.LastLoginIp,
-			LastLoginTime: admin.LastLoginTime,
-		})
-	}
-
-	return &entity.AdminListResp{
-		Details: details,
-		Total:   count,
-	}, nil
-}
-
-// FindAll 查找所有管理员信息
-func (a *Admin) FindAll(ctx context.Context, req entity.AdminFindAllReq) (*entity.AdminListResp, *code.Result) {
-	// 日志记录
-	mhayaLogger.Warnf("FindAll req: %#v", req)
-
-	// 验证参数
-	page := req.Page
-	if req.Page <= 0 {
-		page = 1
-	}
-	pageSize := req.Size
-	if req.Size <= 0 {
-		pageSize = 10
-	}
-
-	// 构建查询条件
-	// filter := bson.M{}
-	// if req.Username != "" {
-	// 	filter["username"] = bson.M{"$regex": escapeRegex(req.Username), "$options": "i"}
-	// }
-	// 查询总数
-	// count, err := mdb.MDB.Collection("admin").CountDocuments(ctx, filter)
-	count, err := mdb.MDB.Collection("admin").CountDocuments(ctx, map[string]interface{}{})
 	if err != nil {
 		mhayaLogger.Warnf("FindAll CountDocuments error:", err)
 		return nil, common.NewResult(code.InternalError)
@@ -397,8 +308,7 @@ func (a *Admin) FindAll(ctx context.Context, req entity.AdminFindAllReq) (*entit
 	findOptions := options.Find().SetSkip(int64(skip)).SetLimit(int64(limit))
 
 	// 执行查询
-	// cursor, err := mdb.MDB.Collection("admin").Find(ctx, filter, findOptions)
-	cursor, err := mdb.MDB.Collection("admin").Find(ctx, map[string]interface{}{}, findOptions)
+	cursor, err := mdb.MDB.Collection("admin").Find(ctx, filter, findOptions)
 	if err != nil {
 		mhayaLogger.Warnf("FindAll Find error:", err)
 		return nil, common.NewResult(code.InternalError)

+ 1 - 0
game/game_cluster/nodes/webadmin/service/synthesis.go

@@ -57,6 +57,7 @@ func (s *Synthesis) FindMDBUserLogDaily(req entity.UserLogDailyReq) (*entity.Use
 
 	// 分页参数
 	skip := (req.Page - 1) * req.Size
+	req.Total = 0
 	// 计算总数
 	count, err := collection.CountDocuments(ctx, filter)
 	if err != nil {