task.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package rpc
  2. import (
  3. "context"
  4. "errors"
  5. "go-common/app/admin/main/aegis/model"
  6. acc "go-common/app/service/main/account/api"
  7. relmod "go-common/app/service/main/relation/model"
  8. uprpc "go-common/app/service/main/up/api/v1"
  9. "go-common/library/log"
  10. "go-common/library/net/metadata"
  11. terrors "github.com/pkg/errors"
  12. )
  13. //ERROR
  14. var (
  15. ErrEmptyReply = errors.New("rpc empty reply")
  16. )
  17. // FansCount 粉丝数
  18. func (d *Dao) FansCount(c context.Context, mids []int64) (fans map[int64]int64, err error) {
  19. arg := &relmod.ArgMids{Mids: mids}
  20. stats, err := d.relRPC.Stats(c, arg)
  21. if err != nil {
  22. log.Error("FansCount error(%v)", terrors.WithStack(err))
  23. return
  24. }
  25. fans = make(map[int64]int64)
  26. for mid, item := range stats {
  27. fans[mid] = item.Follower
  28. }
  29. log.Info("FansCount fans(%+v)", fans)
  30. return
  31. }
  32. // UserInfos 提供给资源列表批量查
  33. func (d *Dao) UserInfos(c context.Context, mids []int64) (res map[int64]*model.UserInfo, err error) {
  34. arg1 := &relmod.ArgMids{Mids: mids}
  35. stats, err := d.relRPC.Stats(c, arg1)
  36. if err != nil {
  37. log.Error("Stats error(%v)", terrors.WithStack(err))
  38. return
  39. }
  40. midsReq := &acc.MidsReq{
  41. Mids: mids,
  42. RealIp: metadata.String(c, metadata.RemoteIP),
  43. }
  44. cardsreply, err := d.AccountClient.Cards3(c, midsReq)
  45. if err != nil {
  46. log.Error("Cards3(%+v) error(%v)", mids, terrors.WithStack(err))
  47. return
  48. }
  49. if cardsreply == nil {
  50. err = ErrEmptyReply
  51. log.Error("Cards3(%+v) error(%v)", mids, terrors.WithStack(err))
  52. return
  53. }
  54. cards := cardsreply.Cards
  55. res = make(map[int64]*model.UserInfo)
  56. for _, mid := range mids {
  57. userinfo := &model.UserInfo{Mid: mid}
  58. if card, ok := cards[mid]; ok {
  59. userinfo.Name = card.Name
  60. userinfo.Official = card.Official
  61. }
  62. if stat, ok := stats[mid]; ok {
  63. userinfo.Follower = stat.Follower
  64. }
  65. res[mid] = userinfo
  66. }
  67. return
  68. }
  69. // Profile get account.
  70. func (d *Dao) Profile(c context.Context, mid int64) (userinfo *model.UserInfo, err error) {
  71. if mid <= 0 {
  72. return
  73. }
  74. midReq := &acc.MidReq{
  75. Mid: mid,
  76. RealIp: metadata.String(c, metadata.RemoteIP),
  77. }
  78. res, err := d.AccountClient.ProfileWithStat3(c, midReq)
  79. if err != nil {
  80. log.Error("d.acc.ProfileWithStat3() error(%v) arg(%+v)", err, midReq)
  81. }
  82. if res == nil {
  83. err = ErrEmptyReply
  84. log.Error("ProfileWithStat3(%+v) error(%v)", mid, terrors.WithStack(err))
  85. return
  86. }
  87. userinfo = &model.UserInfo{
  88. Mid: mid,
  89. Follower: res.Follower,
  90. }
  91. if res.Profile != nil {
  92. userinfo.Official = res.Profile.Official
  93. userinfo.Name = res.Profile.Name
  94. }
  95. return
  96. }
  97. // Info3 get Name.
  98. func (d *Dao) Info3(c context.Context, mid int64) (res *acc.Info, err error) {
  99. midReq := &acc.MidReq{
  100. Mid: mid,
  101. RealIp: metadata.String(c, metadata.RemoteIP),
  102. }
  103. info, err := d.AccountClient.Info3(c, midReq)
  104. if err != nil {
  105. log.Error("query info3 failed,mid(%v), err(%v)", mid, err)
  106. return
  107. }
  108. if info == nil {
  109. err = ErrEmptyReply
  110. log.Error("Info3(%+v) error(%v)", mid, terrors.WithStack(err))
  111. return
  112. }
  113. res = info.Info
  114. log.Info("getUserInfo userbase (%v)", res)
  115. return
  116. }
  117. // UpSpecial 分组信息
  118. func (d *Dao) UpSpecial(c context.Context, mid int64) (ups *uprpc.UpSpecial, err error) {
  119. midReq := &uprpc.UpSpecialReq{
  120. Mid: mid,
  121. }
  122. var reply *uprpc.UpSpecialReply
  123. if reply, err = d.UpClient.UpSpecial(c, midReq); err != nil {
  124. log.Error("UpSpecial(%d) error(%v)", mid, terrors.WithStack(err))
  125. return
  126. }
  127. if reply == nil {
  128. err = ErrEmptyReply
  129. log.Error("UpSpecial(%+v) error(%v)", mid, terrors.WithStack(err))
  130. return
  131. }
  132. ups = reply.UpSpecial
  133. return
  134. }
  135. //UpsSpecial 分组信息
  136. func (d *Dao) UpsSpecial(c context.Context, mids []int64) (ups map[int64]*uprpc.UpSpecial, err error) {
  137. midReq := &uprpc.UpsSpecialReq{
  138. Mids: mids,
  139. }
  140. var reply *uprpc.UpsSpecialReply
  141. if reply, err = d.UpClient.UpsSpecial(c, midReq); err != nil {
  142. log.Error("UpsSpecial(%d) error(%v)", mids, terrors.WithStack(err))
  143. return
  144. }
  145. if reply == nil {
  146. err = ErrEmptyReply
  147. log.Error("UpsSpecial(%+v) error(%v)", mids, terrors.WithStack(err))
  148. return
  149. }
  150. ups = reply.UpSpecials
  151. return
  152. }
  153. //UpGroups 所有分组
  154. func (d *Dao) UpGroups(c context.Context) (upgs map[int64]*uprpc.UpGroup, err error) {
  155. noReq := &uprpc.NoArgReq{}
  156. var reply *uprpc.UpGroupsReply
  157. if reply, err = d.UpClient.UpGroups(c, noReq); err != nil {
  158. log.Error("UpGroups error(%v)", terrors.WithStack(err))
  159. return
  160. }
  161. if reply == nil {
  162. err = ErrEmptyReply
  163. log.Error("UpGroups error(%v)", terrors.WithStack(err))
  164. return
  165. }
  166. upgs = reply.UpGroups
  167. return
  168. }