api.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package rankdb
  2. import (
  3. "context"
  4. "github.com/pkg/errors"
  5. "go-common/app/interface/live/app-interface/dao"
  6. "go-common/app/service/live/rankdb/api/liverpc/v1"
  7. accountM "go-common/app/service/main/account/model"
  8. actmdl "go-common/app/service/main/account/model"
  9. "go-common/library/ecode"
  10. "go-common/library/log"
  11. "time"
  12. )
  13. // GetUserInfoData ...
  14. // 调用account grpc接口cards获取用户信息
  15. func (d *Dao) GetUserInfoData(c context.Context, UIDs []int64) (userResult map[int64]*accountM.Card, err error) {
  16. userResult = make(map[int64]*accountM.Card)
  17. lens := len(UIDs)
  18. if lens <= 0 {
  19. return
  20. }
  21. ret, err := d.accountRPC.Cards3(c, &actmdl.ArgMids{Mids: UIDs})
  22. if err != nil {
  23. err = errors.WithMessage(ecode.AccountGRPCError, "GET SEA PATROL FAIL")
  24. log.Error("Call main.Account.Cards Error.Infos(%+v) error(%+v)", UIDs, err)
  25. }
  26. // 整理数据
  27. for _, item := range ret {
  28. if item != nil {
  29. userResult[item.Mid] = item
  30. }
  31. }
  32. return
  33. }
  34. // GetLastHourTop3 ...
  35. // 获取小时榜前三
  36. func (d *Dao) GetLastHourTop3(c context.Context) (uids []int64, err error) {
  37. uids = make([]int64, 0)
  38. lastHour := time.Now().Add(-time.Hour).Format("06010215")
  39. req := &v1.Rank2018GetHourRankReq{
  40. AreaV2ParentId: 0,
  41. AreaV2Id: 0,
  42. Hour: lastHour,
  43. // rankDB begin from 0
  44. Top: 2,
  45. }
  46. resp, err := dao.RankdbApi.V1Rank2018.GetHourRank(c, req)
  47. if err != nil || resp.Data == nil {
  48. log.Error("[app-interface][rankDbItem] liveRpc call rankDb failed")
  49. return
  50. }
  51. if 0 != resp.Code || 0 == len(resp.Data) {
  52. log.Error("[app-interface][rankDbItem] liveRpc call rankDb return error, code:%d, msg:%s", resp.Code, resp.Data)
  53. return
  54. }
  55. uids = resp.Data
  56. return
  57. }