rpc.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package account
  2. import (
  3. "context"
  4. accapi "go-common/app/service/main/account/api"
  5. relaMdl "go-common/app/service/main/relation/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. // Profile get profile from rpc
  10. func (d *Dao) Profile(c context.Context, mid int64, ip string) (p *accapi.Profile, err error) {
  11. arg := &accapi.MidReq{
  12. Mid: mid,
  13. }
  14. var rpcRes *accapi.ProfileReply
  15. if rpcRes, err = d.acc.Profile3(c, arg); err != nil {
  16. log.Error("d.acc.Profile3 error(%v) | mid(%d) ip(%s) arg(%v)", err, mid, ip, arg)
  17. err = ecode.CreativeAccServiceErr
  18. }
  19. if rpcRes != nil {
  20. p = rpcRes.Profile
  21. }
  22. return
  23. }
  24. // Cards get cards from rpc
  25. func (d *Dao) Cards(c context.Context, mids []int64, ip string) (cards map[int64]*accapi.Card, err error) {
  26. var res *accapi.CardsReply
  27. if len(mids) == 0 {
  28. return
  29. }
  30. arg := &accapi.MidsReq{
  31. Mids: mids,
  32. }
  33. if res, err = d.acc.Cards3(c, arg); err != nil {
  34. log.Error("d.acc.Cards3 error(%v) | mids(%v) ip(%s) arg(%v)", err, mids, ip, arg)
  35. err = ecode.CreativeAccServiceErr
  36. }
  37. if res != nil {
  38. cards = res.Cards
  39. }
  40. return
  41. }
  42. // Infos get infos from rpc
  43. func (d *Dao) Infos(c context.Context, mids []int64, ip string) (infos map[int64]*accapi.Info, err error) {
  44. var res *accapi.InfosReply
  45. arg := &accapi.MidsReq{
  46. Mids: mids,
  47. }
  48. infos = make(map[int64]*accapi.Info)
  49. if res, err = d.acc.Infos3(c, arg); err != nil {
  50. log.Error("d.acc.Infos3 error(%v) | mids(%v) ip(%s) arg(%v)", err, mids, ip, arg)
  51. err = ecode.CreativeAccServiceErr
  52. }
  53. if res != nil {
  54. infos = res.Infos
  55. }
  56. return
  57. }
  58. // Relations get all relation state.
  59. func (d *Dao) Relations(c context.Context, mid int64, fids []int64, ip string) (res map[int64]int, err error) {
  60. var rls map[int64]*relaMdl.Following
  61. if rls, err = d.rela.Relations(c, &relaMdl.ArgRelations{Mid: mid, Fids: fids, RealIP: ip}); err != nil {
  62. log.Error("d.rela.Relations mid(%d)|ip(%s)|error(%v)", mid, ip, err)
  63. err = ecode.CreativeAccServiceErr
  64. return
  65. }
  66. if len(rls) == 0 {
  67. log.Info("d.rela.Relations mid(%d)|ip(%s)", mid, ip)
  68. return
  69. }
  70. res = make(map[int64]int, len(rls))
  71. for _, v := range rls {
  72. res[v.Mid] = int(v.Attribute)
  73. }
  74. log.Info("d.rela.Relations mid(%d)|res(%+v)|rls(%+v)|ip(%s)", mid, res, rls, ip)
  75. return
  76. }