|
@@ -98,56 +98,112 @@ func (s *Synthesis) Overview(req entity.OverviewReq) (*entity.OverviewResp, *cod
|
|
func (s *Synthesis) UserList(req entity.UserListReq) (*entity.UserListResp, *code.Result) {
|
|
func (s *Synthesis) UserList(req entity.UserListReq) (*entity.UserListResp, *code.Result) {
|
|
page, pageSize := checkPageParam(req.Page, req.Size)
|
|
page, pageSize := checkPageParam(req.Page, req.Size)
|
|
|
|
|
|
- // 构建查询条件
|
|
|
|
- filter := bson.M{}
|
|
|
|
|
|
+ playerMgr := NewPlayerManage()
|
|
|
|
+
|
|
|
|
+ // 根据条件查询
|
|
if req.UserName != "" {
|
|
if req.UserName != "" {
|
|
- filter["userName"] = req.UserName
|
|
|
|
- }
|
|
|
|
|
|
+ detail, codeResult := s.getUserDetail(req.UserName)
|
|
|
|
+ if codeResult != nil {
|
|
|
|
+ mhayaLogger.Warnf("UserList getUserDetail error:%v", codeResult)
|
|
|
|
+ return nil, codeResult
|
|
|
|
+ }
|
|
|
|
|
|
- // 设置分页选项
|
|
|
|
- findOptions := options.Find()
|
|
|
|
- findOptions.SetSkip(int64((page - 1) * pageSize))
|
|
|
|
- findOptions.SetLimit(int64(pageSize))
|
|
|
|
- findOptions.SetSort(bson.D{{"createTime", -1}})
|
|
|
|
|
|
+ if detail == nil {
|
|
|
|
+ return nil, nil
|
|
|
|
+ }
|
|
|
|
|
|
- ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
|
|
|
|
- defer cancel()
|
|
|
|
|
|
+ var results []*entity.UserListDetail
|
|
|
|
+ results = append(results, detail)
|
|
|
|
|
|
- collection := mdb.MDB.Collection(constant.CNamePlayer)
|
|
|
|
|
|
+ return &entity.UserListResp{
|
|
|
|
+ Details: results,
|
|
|
|
+ Total: 1,
|
|
|
|
+ }, nil
|
|
|
|
+ }
|
|
|
|
|
|
- // 查询数据
|
|
|
|
- var results []*entity.UserListDetail
|
|
|
|
- cursor, err := collection.Find(ctx, filter, findOptions)
|
|
|
|
- if err != nil {
|
|
|
|
- mhayaLogger.Warnf("UserList Find error:%v", err)
|
|
|
|
- return nil, common.NewResult(code.InternalError)
|
|
|
|
|
|
+ // 查询列表
|
|
|
|
+ listResp, codeResult := playerMgr.List(context.Background(), entity.PlayerListReq{
|
|
|
|
+ Page: page,
|
|
|
|
+ Size: pageSize,
|
|
|
|
+ })
|
|
|
|
+ if codeResult != nil {
|
|
|
|
+ mhayaLogger.Warnf("UserList List error:%v", codeResult)
|
|
|
|
+ return nil, codeResult
|
|
}
|
|
}
|
|
|
|
|
|
- defer cursor.Close(ctx)
|
|
|
|
- // 解析结果
|
|
|
|
- for cursor.Next(ctx) {
|
|
|
|
- var result entity.UserListDetail
|
|
|
|
- if err := cursor.Decode(&result); err != nil {
|
|
|
|
- mhayaLogger.Warnf("UserList Decode error:%v", err)
|
|
|
|
- return nil, common.NewResult(code.InternalError)
|
|
|
|
|
|
+ var results []*entity.UserListDetail
|
|
|
|
+ for _, detail := range listResp.Details {
|
|
|
|
+ ret, codeResult := s.getUserDetail(detail.UserName)
|
|
|
|
+ if codeResult != nil {
|
|
|
|
+ mhayaLogger.Warnf("UserList getUserDetail error:%v", codeResult)
|
|
|
|
+ return nil, codeResult
|
|
}
|
|
}
|
|
|
|
|
|
- results = append(results, &result)
|
|
|
|
|
|
+ if detail != nil {
|
|
|
|
+ results = append(results, ret)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- if err := cursor.Err(); err != nil {
|
|
|
|
- mhayaLogger.Warnf("UserList cursor error:%v", err)
|
|
|
|
- return nil, common.NewResult(code.InternalError)
|
|
|
|
|
|
+ count, codeResult := playerMgr.GetPlayerTotalCount()
|
|
|
|
+ if codeResult != nil {
|
|
|
|
+ mhayaLogger.Warnf("UserList GetPlayerTotalCount codeResult:%v", codeResult)
|
|
|
|
+ return nil, codeResult
|
|
}
|
|
}
|
|
|
|
|
|
- // TODO UserList 统计用户相关信息
|
|
|
|
-
|
|
|
|
- // TODO 获取总数total
|
|
|
|
- var count int64
|
|
|
|
-
|
|
|
|
return &entity.UserListResp{
|
|
return &entity.UserListResp{
|
|
Details: results,
|
|
Details: results,
|
|
- Total: count,
|
|
|
|
|
|
+ Total: int64(count),
|
|
|
|
+ }, nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s *Synthesis) getUserDetail(userName string) (*entity.UserListDetail, *code.Result) {
|
|
|
|
+ playerMgr := NewPlayerManage()
|
|
|
|
+
|
|
|
|
+ // 获取注册记录
|
|
|
|
+ registerRecord, codeResult := playerMgr.GetRegisterRecord(userName)
|
|
|
|
+ if codeResult != nil {
|
|
|
|
+ mhayaLogger.Warnf("getUserDetail GetRegisterRecord error:%v", codeResult)
|
|
|
|
+ return nil, codeResult
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if registerRecord == nil {
|
|
|
|
+ mhayaLogger.Warnf("getUserDetail registerRecord:%v", registerRecord)
|
|
|
|
+ return nil, nil
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 获取用户的首次登录记录
|
|
|
|
+ firstLoginRecord, codeResult := playerMgr.GetPlayerFirstLoginRecord(userName)
|
|
|
|
+ if codeResult != nil {
|
|
|
|
+ mhayaLogger.Warnf("getUserDetail GetPlayerFirstLoginRecord error:%v", codeResult)
|
|
|
|
+ return nil, codeResult
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if firstLoginRecord == nil {
|
|
|
|
+ mhayaLogger.Warnf("getUserDetail firstLoginRecord:%v", firstLoginRecord)
|
|
|
|
+ return nil, nil
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 获取最新的用户登录记录
|
|
|
|
+ loginRecord, codeResult := playerMgr.GetPlayerLastestLoginRecord(userName)
|
|
|
|
+ if codeResult != nil {
|
|
|
|
+ mhayaLogger.Warnf("getUserDetail GetPlayerLastestLoginRecord error:%v", codeResult)
|
|
|
|
+ return nil, codeResult
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if loginRecord == nil {
|
|
|
|
+ mhayaLogger.Warnf("getUserDetail loginRecord:%v", loginRecord)
|
|
|
|
+ return nil, nil
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return &entity.UserListDetail{
|
|
|
|
+ UserName: userName,
|
|
|
|
+ OpenId: loginRecord.TgId,
|
|
|
|
+ CreateTime: registerRecord.CreateAt,
|
|
|
|
+ FirstLoginDate: firstLoginRecord.CreateAt,
|
|
|
|
+ LoginIP: loginRecord.Ip,
|
|
|
|
+ LastLoginTime: loginRecord.CreateAt,
|
|
|
|
+ TonWall: loginRecord.TonWall,
|
|
|
|
+ Fingerprint: loginRecord.Fingerprint,
|
|
}, nil
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1033,7 +1089,9 @@ func (s *Synthesis) Active(req entity.ActiveReq) (*entity.ActiveResp, *code.Resu
|
|
return nil, codeResult
|
|
return nil, codeResult
|
|
}
|
|
}
|
|
|
|
|
|
- results = append(results, detail)
|
|
|
|
|
|
+ if detail != nil {
|
|
|
|
+ results = append(results, detail)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
count, codeResult := playerMgr.GetPlayerTotalCount()
|
|
count, codeResult := playerMgr.GetPlayerTotalCount()
|
|
@@ -1178,55 +1236,32 @@ func (s *Synthesis) TaskCompletion(req entity.TaskCompletionReq) (*entity.TaskCo
|
|
func (s *Synthesis) BehaviorMonitoring(req entity.BehaviorMonitoringReq) (*entity.BehaviorMonitoringResp, *code.Result) {
|
|
func (s *Synthesis) BehaviorMonitoring(req entity.BehaviorMonitoringReq) (*entity.BehaviorMonitoringResp, *code.Result) {
|
|
page, pageSize := checkPageParam(req.Page, req.Size)
|
|
page, pageSize := checkPageParam(req.Page, req.Size)
|
|
|
|
|
|
- // 构建查询条件
|
|
|
|
- filter := bson.M{}
|
|
|
|
- if req.UserName != "" {
|
|
|
|
- filter["userName"] = req.UserName
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 设置分页选项
|
|
|
|
- findOptions := options.Find()
|
|
|
|
- findOptions.SetSkip(int64((page - 1) * pageSize))
|
|
|
|
- findOptions.SetLimit(int64(pageSize))
|
|
|
|
- findOptions.SetSort(bson.D{{"createTime", -1}})
|
|
|
|
-
|
|
|
|
- ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
|
|
|
|
- defer cancel()
|
|
|
|
|
|
+ var records []*eventmodels.DiceEventContent
|
|
|
|
|
|
- collection := mdb.MDB.Collection(constant.CNamePlayer)
|
|
|
|
|
|
+ where := &eventmodels.DiceEventContent{
|
|
|
|
+ UserBasic: eventmodels.UserBasic{
|
|
|
|
+ UserId: req.UserName,
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ db := mdb.LogstashDB.Model(&eventmodels.DiceEventContent{}).Where(where).Order("create_at")
|
|
|
|
|
|
- // 查询数据
|
|
|
|
- var results []*entity.BehaviorMonitoringDetail
|
|
|
|
- cursor, err := collection.Find(ctx, filter, findOptions)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ pages := Paginate(db, page, pageSize)
|
|
|
|
+ err := db.Scopes(pages.Limit).Find(&records).Error
|
|
|
|
+ if err != nil && err != gorm.ErrRecordNotFound {
|
|
mhayaLogger.Warnf("BehaviorMonitoring Find error:%v", err)
|
|
mhayaLogger.Warnf("BehaviorMonitoring Find error:%v", err)
|
|
return nil, common.NewResult(code.InternalError)
|
|
return nil, common.NewResult(code.InternalError)
|
|
}
|
|
}
|
|
|
|
|
|
- defer cursor.Close(ctx)
|
|
|
|
- // 解析结果
|
|
|
|
- for cursor.Next(ctx) {
|
|
|
|
- var result entity.BehaviorMonitoringDetail
|
|
|
|
- if err := cursor.Decode(&result); err != nil {
|
|
|
|
- mhayaLogger.Warnf("BehaviorMonitoring Decode error:%v", err)
|
|
|
|
- return nil, common.NewResult(code.InternalError)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- results = append(results, &result)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if err := cursor.Err(); err != nil {
|
|
|
|
- mhayaLogger.Warnf("BehaviorMonitoring cursor error:%v", err)
|
|
|
|
- return nil, common.NewResult(code.InternalError)
|
|
|
|
|
|
+ var results []*entity.BehaviorMonitoringDetail
|
|
|
|
+ for _, v := range records {
|
|
|
|
+ results = append(results, &entity.BehaviorMonitoringDetail{
|
|
|
|
+ UserName: v.UserName,
|
|
|
|
+ DieExecutionTime: v.CreateAt,
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
- // TODO 用户行为检测相关信息
|
|
|
|
-
|
|
|
|
- // TODO 获取总数total
|
|
|
|
- var count int64
|
|
|
|
-
|
|
|
|
return &entity.BehaviorMonitoringResp{
|
|
return &entity.BehaviorMonitoringResp{
|
|
Details: results,
|
|
Details: results,
|
|
- Total: count,
|
|
|
|
|
|
+ Total: pages.Count,
|
|
}, nil
|
|
}, nil
|
|
}
|
|
}
|