base.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/main/up-rating/model"
  6. )
  7. // BaseInfoOffEnd get offset and end
  8. func (s *Service) BaseInfoOffEnd(c context.Context, date time.Time) (offset, end int, err error) {
  9. start, err := s.dao.BaseInfoStart(c, date)
  10. if err != nil {
  11. return
  12. }
  13. offset = start - 1
  14. end, err = s.dao.BaseInfoEnd(c, date)
  15. return
  16. }
  17. // RatingOffEnd get offset and end
  18. func (s *Service) RatingOffEnd(c context.Context, date time.Time) (offset, end, count int, err error) {
  19. start, err := s.dao.RatingStart(c, date)
  20. if err != nil {
  21. return
  22. }
  23. offset = start - 1
  24. end, err = s.dao.RatingEnd(c, date)
  25. if err != nil {
  26. return
  27. }
  28. count, err = s.dao.RatingCount(c, date)
  29. return
  30. }
  31. // BaseInfo get base infos
  32. func (s *Service) BaseInfo(c context.Context, date time.Time, start, end int, ch chan []*model.BaseInfo) (err error) {
  33. defer close(ch)
  34. for {
  35. var bs []*model.BaseInfo
  36. bs, start, err = s.dao.GetBaseInfo(c, date.Month(), start, end, _limit)
  37. if err != nil {
  38. return
  39. }
  40. if len(bs) == 0 {
  41. break
  42. }
  43. ch <- bs
  44. }
  45. return
  46. }
  47. // BaseTotal get total base
  48. func (s *Service) BaseTotal(c context.Context, date time.Time) (total map[int64]*model.BaseInfo, err error) {
  49. total = make(map[int64]*model.BaseInfo)
  50. var id int64
  51. for {
  52. var bs []*model.BaseInfo
  53. bs, err = s.dao.GetBaseTotal(c, date, id, int64(_limit))
  54. if err != nil {
  55. return
  56. }
  57. for _, b := range bs {
  58. total[b.MID] = b
  59. }
  60. if len(bs) < _limit {
  61. break
  62. }
  63. id = bs[len(bs)-1].ID
  64. }
  65. return
  66. }