whitelist.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package service
  2. import (
  3. "context"
  4. "sort"
  5. "go-common/app/admin/main/creative/model/whitelist"
  6. accapi "go-common/app/service/main/account/api"
  7. "go-common/library/log"
  8. "golang.org/x/sync/errgroup"
  9. )
  10. // Cards fn
  11. func (s *Service) Cards(c context.Context, wls []*whitelist.Whitelist) (wlsWithAcc []*whitelist.Whitelist, err error) {
  12. wlsWithAcc = []*whitelist.Whitelist{}
  13. var (
  14. g errgroup.Group
  15. )
  16. ch := make(chan *whitelist.Whitelist, len(wls))
  17. for _, wl := range wls {
  18. id := wl.ID
  19. mid := wl.MID
  20. adminMid := wl.AdminMID
  21. comment := wl.Comment
  22. state := wl.State
  23. tp := wl.Type
  24. ctime := wl.Ctime
  25. mtime := wl.Mtime
  26. g.Go(func() (err error) {
  27. pfl, err := s.dao.ProfileStat(c, mid)
  28. if err != nil {
  29. log.Error("s.dao.Card mid(%+v)|err(%+v)", mid, err)
  30. return
  31. }
  32. var name string
  33. if pfl.Profile != nil {
  34. name = pfl.Profile.Name
  35. }
  36. ch <- &whitelist.Whitelist{
  37. ID: id,
  38. MID: mid,
  39. AdminMID: adminMid,
  40. Comment: comment,
  41. State: state,
  42. Type: tp,
  43. Fans: pfl.Follower,
  44. CurrentLevel: pfl.LevelInfo.Cur,
  45. Name: name,
  46. Ctime: ctime,
  47. Mtime: mtime,
  48. }
  49. return
  50. })
  51. }
  52. g.Wait()
  53. close(ch)
  54. for c := range ch {
  55. wlsWithAcc = append(wlsWithAcc, c)
  56. }
  57. sort.Slice(wlsWithAcc, func(i, j int) bool { return wlsWithAcc[i].Ctime > wlsWithAcc[j].Ctime })
  58. return
  59. }
  60. // ProfileStat fn
  61. func (s *Service) ProfileStat(c context.Context, mid int64) (pfl *accapi.ProfileStatReply, err error) {
  62. if pfl, err = s.dao.ProfileStat(c, mid); err != nil {
  63. log.Error("s.dao.Profile mid(%+v)|err(%+v)", mid, err)
  64. }
  65. return
  66. }