report_billboard.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package services
  2. import (
  3. "context"
  4. "errors"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/utils"
  7. "time"
  8. )
  9. // UpdateDailyMonthReadBillboard 每日更新-月阅读飙升榜单
  10. func UpdateDailyMonthReadBillboard(cont context.Context) (err error) {
  11. defer func() {
  12. if err != nil {
  13. go utils.SendAlarmMsg("查研观向-每日更新月阅读飙升榜单失败, ErrMsg: "+err.Error(), 3)
  14. }
  15. }()
  16. // 获取上个月至昨日报告阅读增量最多的报告
  17. nowTime := time.Now().Local()
  18. startTime := nowTime.AddDate(0, -1, 0)
  19. endTime := nowTime.AddDate(0, 0, -1)
  20. list, e := models.GetTopReadRecordArticleListFromSource(startTime, endTime)
  21. if e != nil {
  22. err = errors.New("获取阅读量排行榜失败, Err: " + e.Error())
  23. return
  24. }
  25. if len(list) == 0 {
  26. return
  27. }
  28. for i := range list {
  29. list[i].CreateTime = nowTime
  30. }
  31. // 清除昨日榜单并记录新榜单
  32. if e = models.UpdateTopReadRecordArticleList(list); e != nil {
  33. err = errors.New("更新阅读量排行榜失败, Err: " + e.Error())
  34. return
  35. }
  36. return
  37. }