user.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/interface/bbq/app-bbq/api/http/v1"
  5. "go-common/app/interface/bbq/app-bbq/model"
  6. user "go-common/app/service/bbq/user/api"
  7. accountv1 "go-common/app/service/main/account/api"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. )
  11. //GetUserBProfile 获取用户全量b站信息
  12. func (d *Dao) GetUserBProfile(c context.Context, mid int64) (res *accountv1.ProfileReply, err error) {
  13. req := &accountv1.MidReq{
  14. Mid: mid,
  15. RealIp: "",
  16. }
  17. res, err = d.accountClient.Profile3(c, req)
  18. return
  19. }
  20. // Login .
  21. func (d *Dao) Login(c context.Context, userBase *user.UserBase) (res *user.UserBase, err error) {
  22. res, err = d.userClient.Login(c, userBase)
  23. if err != nil {
  24. log.Errorv(c, log.KV("log", "login fail"))
  25. }
  26. return
  27. }
  28. // BatchUserInfo 提供批量获取UserInfo的方法
  29. // 由于user service返回的结构和video的回包不同,因此这里进行映射,返回video-c的结构,避免外部使用方多次映射
  30. func (d *Dao) BatchUserInfo(c context.Context, visitorMID int64, MIDs []int64, needDesc, needStat, needFollowState bool) (res map[int64]*v1.UserInfo, err error) {
  31. res = make(map[int64]*v1.UserInfo)
  32. if len(MIDs) == 0 {
  33. return
  34. }
  35. if len(MIDs) > model.BatchUserLen {
  36. err = ecode.BatchUserTooLong
  37. return
  38. }
  39. userReq := &user.ListUserInfoReq{Mid: visitorMID, UpMid: MIDs, NeedDesc: needDesc, NeedStat: needStat, NeedFollowState: needFollowState}
  40. reply, err := d.userClient.ListUserInfo(c, userReq)
  41. if err != nil {
  42. log.Errorv(c, log.KV("log", "get user info fail: req=%s"+userReq.String()))
  43. return
  44. }
  45. for _, userInfo := range reply.List {
  46. newUserInfo := &v1.UserInfo{UserBase: *userInfo.UserBase}
  47. if userInfo.UserStat != nil {
  48. newUserInfo.UserStat = *userInfo.UserStat
  49. }
  50. newUserInfo.FollowState = userInfo.FollowState
  51. res[userInfo.UserBase.Mid] = newUserInfo
  52. }
  53. return
  54. }
  55. //JustGetUserBase 只取UserBase,不要其他
  56. func (d *Dao) JustGetUserBase(c context.Context, mids []int64) (res map[int64]*user.UserBase, err error) {
  57. res = make(map[int64]*user.UserBase)
  58. userInfos, err := d.BatchUserInfo(c, 0, mids, false, false, false)
  59. if err != nil {
  60. log.Warnv(c, log.KV("log", "get user info fail"))
  61. return
  62. }
  63. for mid, userInfo := range userInfos {
  64. res[mid] = &userInfo.UserBase
  65. }
  66. return
  67. }
  68. // EditUserBase .
  69. func (d *Dao) EditUserBase(c context.Context, userBase *user.UserBase) (err error) {
  70. _, err = d.userClient.UserEdit(c, userBase)
  71. if err != nil {
  72. log.Warnw(c, "log", "edit user base fail: req="+userBase.String(), "err", err.Error())
  73. return
  74. }
  75. return
  76. }
  77. // PhoneCheck .
  78. func (d *Dao) PhoneCheck(c context.Context, mid int64) (telStatus int32, err error) {
  79. req := &user.PhoneCheckReq{Mid: mid}
  80. res, err := d.userClient.PhoneCheck(c, req)
  81. if err != nil {
  82. log.Errorw(c, "log", "call phone check fail", "err", err, "mid", mid)
  83. return
  84. }
  85. telStatus = res.TelStatus
  86. return
  87. }