account.go 1.7 KB

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