|
@@ -1179,56 +1179,142 @@ func (s *Synthesis) getActive(userName string) (*entity.ActiveDetail, *code.Resu
|
|
|
func (s *Synthesis) TaskCompletion(req entity.TaskCompletionReq) (*entity.TaskCompletionResp, *code.Result) {
|
|
|
page, pageSize := checkPageParam(req.Page, req.Size)
|
|
|
|
|
|
- // 构建查询条件
|
|
|
- filter := bson.M{}
|
|
|
+ playerMgr := NewPlayerManage()
|
|
|
+
|
|
|
+ // 根据条件查询
|
|
|
if req.UserName != "" {
|
|
|
- filter["userName"] = req.UserName
|
|
|
- }
|
|
|
+ detail, codeResult := s.getTaskCompletionDetail(req.UserName)
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("TaskCompletion getTaskCompletionDetail 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.TaskCompletionDetail
|
|
|
+ results = append(results, detail)
|
|
|
|
|
|
- collection := mdb.MDB.Collection(constant.CNamePlayer)
|
|
|
+ return &entity.TaskCompletionResp{
|
|
|
+ Details: results,
|
|
|
+ Total: 1,
|
|
|
+ }, nil
|
|
|
+ }
|
|
|
|
|
|
- // 查询数据
|
|
|
- var results []*entity.TaskCompletionDetail
|
|
|
- cursor, err := collection.Find(ctx, filter, findOptions)
|
|
|
- if err != nil {
|
|
|
- mhayaLogger.Warnf("TaskCompletion 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("TaskCompletion List error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
}
|
|
|
|
|
|
- defer cursor.Close(ctx)
|
|
|
- // 解析结果
|
|
|
- for cursor.Next(ctx) {
|
|
|
- var result entity.TaskCompletionDetail
|
|
|
- if err := cursor.Decode(&result); err != nil {
|
|
|
- mhayaLogger.Warnf("TaskCompletion Decode error:%v", err)
|
|
|
- return nil, common.NewResult(code.InternalError)
|
|
|
+ var results []*entity.TaskCompletionDetail
|
|
|
+ for _, detail := range listResp.Details {
|
|
|
+ ret, codeResult := s.getTaskCompletionDetail(detail.UserName)
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("TaskCompletion getTaskCompletionDetail 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("TaskCompletion cursor error:%v", err)
|
|
|
- return nil, common.NewResult(code.InternalError)
|
|
|
+ count, codeResult := playerMgr.GetPlayerTotalCount()
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("TaskCompletion GetPlayerTotalCount codeResult:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
}
|
|
|
|
|
|
- // TODO 任务完成度统计相关信息
|
|
|
-
|
|
|
- // TODO 获取总数total
|
|
|
- var count int64
|
|
|
-
|
|
|
return &entity.TaskCompletionResp{
|
|
|
Details: results,
|
|
|
- Total: count,
|
|
|
+ Total: int64(count),
|
|
|
+ }, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (s *Synthesis) getTaskCompletionDetail(userName string) (*entity.TaskCompletionDetail, *code.Result) {
|
|
|
+ playerMgr := NewPlayerManage()
|
|
|
+
|
|
|
+ // 获取注册记录
|
|
|
+ registerRecord, codeResult := playerMgr.GetRegisterRecord(userName)
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("getTaskCompletionDetail GetRegisterRecord error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
+ }
|
|
|
+
|
|
|
+ if registerRecord == nil {
|
|
|
+ mhayaLogger.Warnf("getTaskCompletionDetail registerRecord:%v", registerRecord)
|
|
|
+ return nil, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取用户加入频道的记录
|
|
|
+ // TODO 需要定义tg频道
|
|
|
+ joinTgRecord, codeResult := playerMgr.GetJoinRecord(userName, "TgChannel")
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("getTaskCompletionDetail GetJoinRecord error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO 需要定义DC频道
|
|
|
+ joinDcRecord, codeResult := playerMgr.GetJoinRecord(userName, "DcChannel")
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("getTaskCompletionDetail GetJoinRecord error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取用户关注的记录
|
|
|
+ // TODO 需要定义Twitter
|
|
|
+ followTwitterRecord, codeResult := playerMgr.GetFollowRecord(userName, "Twitter")
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("getTaskCompletionDetail GetFollowRecord error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO 需要定义Youtube
|
|
|
+ followYoutubeRecord, codeResult := playerMgr.GetFollowRecord(userName, "Youtube")
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("getTaskCompletionDetail GetFollowRecord error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取最新的用户信息更新记录
|
|
|
+ updateRecord, codeResult := playerMgr.GetPlayerLastestUpdateRecord(userName)
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("getTaskCompletionDetail GetPlayerLastestUpdateRecord error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
+ }
|
|
|
+
|
|
|
+ // 邀请成功人数
|
|
|
+ inviteCount, codeResult := playerMgr.GetSuccessfulInvitations(userName, 0)
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("getTaskCompletionDetail GetSuccessfulInvitations error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
+ }
|
|
|
+
|
|
|
+ return &entity.TaskCompletionDetail{
|
|
|
+ UserName: userName,
|
|
|
+ DicePerDay: 0, // TODO
|
|
|
+ IsJoinTgChannel: func() bool {
|
|
|
+ return joinTgRecord != nil
|
|
|
+ }(),
|
|
|
+ IsFollowTwitter: func() bool {
|
|
|
+ return followTwitterRecord != nil
|
|
|
+ }(),
|
|
|
+ IsJoinDcChannel: func() bool {
|
|
|
+ return joinDcRecord != nil
|
|
|
+ }(),
|
|
|
+ IsBindTwitter: func() bool {
|
|
|
+ return updateRecord.XId == ""
|
|
|
+ }(),
|
|
|
+ IsFollowYoutube: func() bool {
|
|
|
+ return followYoutubeRecord != nil
|
|
|
+ }(),
|
|
|
+ InviteNumber: inviteCount,
|
|
|
}, nil
|
|
|
}
|
|
|
|