account.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package account
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-show/conf"
  5. account "go-common/app/service/main/account/model"
  6. accrpc "go-common/app/service/main/account/rpc/client"
  7. "go-common/library/log"
  8. "go-common/library/net/metadata"
  9. )
  10. // Dao is rpc dao.
  11. type Dao struct {
  12. // account rpc
  13. accRPC *accrpc.Service3
  14. }
  15. // New new a account dao.
  16. func New(c *conf.Config) (d *Dao) {
  17. d = &Dao{
  18. // account rpc
  19. accRPC: accrpc.New3(c.AccountRPC),
  20. }
  21. return
  22. }
  23. // Cards3 users card
  24. func (d *Dao) Cards3(ctx context.Context, mids []int64) (res map[int64]*account.Card, err error) {
  25. arg := &account.ArgMids{
  26. Mids: mids,
  27. }
  28. if res, err = d.accRPC.Cards3(ctx, arg); err != nil {
  29. log.Error("d.accRPC.Infos(%v) error(%v)", arg, err)
  30. res = nil
  31. return
  32. }
  33. return
  34. }
  35. // Relations3 users info
  36. func (d *Dao) Relations3(ctx context.Context, mid int64, owners []int64) (res map[int64]*account.Relation, err error) {
  37. arg := &account.ArgRelations{
  38. Mid: mid,
  39. Owners: owners,
  40. }
  41. if res, err = d.accRPC.Relations3(ctx, arg); err != nil {
  42. log.Error("d.accRPC.Relations2(%v) error(%v)", arg, err)
  43. res = nil
  44. return
  45. }
  46. return
  47. }
  48. func (d *Dao) IsAttention(c context.Context, owners []int64, mid int64) (isAtten map[int64]int8) {
  49. if len(owners) == 0 || mid == 0 {
  50. return
  51. }
  52. ip := metadata.String(c, metadata.RemoteIP)
  53. arg := &account.ArgRelations{Owners: owners, Mid: mid, RealIP: ip}
  54. res, err := d.accRPC.Relations3(c, arg)
  55. if err != nil {
  56. return
  57. }
  58. isAtten = make(map[int64]int8, len(res))
  59. for mid, rel := range res {
  60. if rel.Following {
  61. isAtten[mid] = 1
  62. }
  63. }
  64. return
  65. }