archive.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package income
  2. import (
  3. "context"
  4. "time"
  5. model "go-common/app/job/main/growup/model/income"
  6. )
  7. func (s *DateStatis) getArchiveByDate(c context.Context, archiveCh chan []*model.ArchiveIncome, startDate, endDate time.Time, typ, limit int) (err error) {
  8. defer close(archiveCh)
  9. var aid, table string
  10. switch typ {
  11. case _video:
  12. aid, table = "av_id", "av_income"
  13. case _column:
  14. aid, table = "aid", "column_income"
  15. case _bgm:
  16. aid, table = "sid", "bgm_income"
  17. default:
  18. return
  19. }
  20. endDate = endDate.AddDate(0, 0, 1)
  21. for startDate.Before(endDate) {
  22. err = s.getArchiveIncome(c, archiveCh, aid, table, startDate.Format(_layout), limit)
  23. if err != nil {
  24. return
  25. }
  26. startDate = startDate.AddDate(0, 0, 1)
  27. }
  28. return
  29. }
  30. func (s *DateStatis) getArchiveIncome(c context.Context, archiveCh chan []*model.ArchiveIncome, aid, table, date string, limit int) (err error) {
  31. var id int64
  32. for {
  33. var archive []*model.ArchiveIncome
  34. if aid == "sid" {
  35. archive, err = s.dao.GetBgmIncomeByDate(c, date, id, limit)
  36. } else {
  37. archive, err = s.dao.GetArchiveByDate(c, aid, table, date, id, limit)
  38. }
  39. if err != nil {
  40. return
  41. }
  42. archiveCh <- archive
  43. if len(archive) < limit {
  44. break
  45. }
  46. id = archive[len(archive)-1].ID
  47. }
  48. return
  49. }