extra_func.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package service
  2. import (
  3. "context"
  4. "errors"
  5. tmod "go-common/app/admin/main/videoup-task/model"
  6. account "go-common/app/service/main/account/api"
  7. upsrpc "go-common/app/service/main/up/api/v1"
  8. "go-common/library/log"
  9. "go-common/library/sync/errgroup"
  10. )
  11. //ERROR
  12. var (
  13. ErrRPCEmpty = errors.New("rpc reply empty")
  14. )
  15. func (s *Service) profile(c context.Context, mid int64) (profile *account.ProfileStatReply, err error) {
  16. if profile, err = s.accRPC.ProfileWithStat3(c, &account.MidReq{Mid: mid}); err != nil {
  17. log.Error("s.accRPC.ProfileWithStat3(%d) error(%v)", mid, err)
  18. }
  19. return
  20. }
  21. func (s *Service) upSpecial(c context.Context) (ups map[int8]map[int64]struct{}, err error) {
  22. var (
  23. g errgroup.Group
  24. whitegroup, blackgroup, policesgroup, enterprisegroup, signedgroup map[int64]struct{}
  25. )
  26. ups = make(map[int8]map[int64]struct{})
  27. f := func(gid int8) (map[int64]struct{}, error) {
  28. group := make(map[int64]struct{})
  29. mids, e := s.upGroupMids(c, int64(gid))
  30. if e != nil {
  31. return group, e
  32. }
  33. for _, mid := range mids {
  34. group[mid] = struct{}{}
  35. }
  36. return group, nil
  37. }
  38. g.Go(func() error {
  39. whitegroup, err = f(tmod.UpperTypeWhite)
  40. return err
  41. })
  42. g.Go(func() error {
  43. blackgroup, err = f(tmod.UpperTypeBlack)
  44. return err
  45. })
  46. g.Go(func() error {
  47. policesgroup, err = f(tmod.UpperTypePolitices)
  48. return err
  49. })
  50. g.Go(func() error {
  51. enterprisegroup, err = f(tmod.UpperTypeEnterprise)
  52. return err
  53. })
  54. g.Go(func() error {
  55. signedgroup, err = f(tmod.UpperTypeSigned)
  56. return err
  57. })
  58. if err = g.Wait(); err != nil {
  59. return
  60. }
  61. ups[tmod.UpperTypeWhite] = whitegroup
  62. ups[tmod.UpperTypeBlack] = blackgroup
  63. ups[tmod.UpperTypePolitices] = policesgroup
  64. ups[tmod.UpperTypeEnterprise] = enterprisegroup
  65. ups[tmod.UpperTypeSigned] = signedgroup
  66. return
  67. }
  68. func (s *Service) upGroupMids(c context.Context, gid int64) (mids []int64, err error) {
  69. var (
  70. total int
  71. maxps = 10000
  72. req = &upsrpc.UpGroupMidsReq{
  73. Pn: 1,
  74. GroupID: gid,
  75. Ps: maxps,
  76. }
  77. reply *upsrpc.UpGroupMidsReply
  78. )
  79. for {
  80. reply, err = s.upsRPC.UpGroupMids(c, req)
  81. if err == nil && (reply == nil || reply.Mids == nil) {
  82. err = ErrRPCEmpty
  83. }
  84. if err != nil {
  85. log.Error("UpGroupMids req(%+v) error(%v)", req, err)
  86. return
  87. }
  88. total = reply.Total
  89. mids = append(mids, reply.Mids...)
  90. if reply.Size() != maxps {
  91. break
  92. }
  93. req.Pn++
  94. }
  95. log.Info("upGroupMids(%d) reply total(%d) len(%d)", gid, total, len(mids))
  96. return
  97. }