report_billboard.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package controllers
  2. import (
  3. "hongze/hongze_web_mfyx/models"
  4. "hongze/hongze_web_mfyx/services"
  5. "hongze/hongze_web_mfyx/utils"
  6. "time"
  7. )
  8. // 报告榜单
  9. type ReportBillboardController struct {
  10. BaseAuthController
  11. }
  12. type ReportBillboardCommonController struct {
  13. BaseCommonController
  14. }
  15. type MobileReportBillboardController struct {
  16. BaseAuthMobileController
  17. }
  18. // @Title 阅读飙升榜/报告收藏榜
  19. // @Description 获取阅读飙升榜/报告收藏榜接口
  20. // @Param ChartPermissionId query int false "分类ID"
  21. // @Param PageSize query int true "每页数据条数"
  22. // @Param Source query int true "来源 1:阅读飙升 ,2:报告收藏"
  23. // @Success 200 {object} models.ReportBillboardListResp
  24. // @router /list [get]
  25. func (this *MobileReportBillboardController) ReadList() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. user := this.User
  32. if user == nil {
  33. br.Msg = "请重新登录"
  34. br.Ret = 408
  35. return
  36. }
  37. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  38. pageSize, _ := this.GetInt("PageSize")
  39. source, _ := this.GetInt("Source")
  40. sourceArr := []int{1, 2}
  41. if !utils.InArrayByInt(sourceArr, source) {
  42. br.Msg = "来源有误"
  43. return
  44. }
  45. var topNum int
  46. if pageSize == 0 {
  47. topNum = utils.PageSize15
  48. } else {
  49. topNum = pageSize
  50. }
  51. list := make([]*models.ArticleListResp, 0)
  52. // 阅读飙升榜
  53. if source == 1 {
  54. var topCond string
  55. var topPars []interface{}
  56. if chartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  57. nowTime := time.Now().Local()
  58. startTime := nowTime.AddDate(0, -1, 0)
  59. endTime := nowTime.AddDate(0, 0, -1)
  60. topCond += ` AND l.create_time BETWEEN ? AND ? AND a.article_id > ? `
  61. topPars = append(topPars, startTime, endTime, utils.SummaryArticleId)
  62. topList, e := models.GetTopReadRecordArticleListByConditionYx(topNum, topCond, topPars)
  63. if e != nil {
  64. br.Msg = "获取失败"
  65. br.ErrMsg = "获取报告阅读增量排行榜失败, Err:" + e.Error()
  66. return
  67. }
  68. list = topList
  69. } else {
  70. if chartPermissionId > 0 {
  71. categoryId, err := models.GetCategoryId(chartPermissionId)
  72. if err != nil && err.Error() != utils.ErrNoRow() {
  73. br.Msg = "获取信息失败"
  74. br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
  75. return
  76. }
  77. if categoryId != "" {
  78. topCond += ` AND a.category_id IN (` + categoryId + `)`
  79. }
  80. }
  81. topList, e := models.GetTopReadRecordArticleListByCondition(topNum, topCond, topPars)
  82. if e != nil {
  83. br.Msg = "获取失败"
  84. br.ErrMsg = "获取报告阅读增量排行榜失败, Err:" + e.Error()
  85. return
  86. }
  87. list = topList
  88. }
  89. }
  90. // 报告收藏榜
  91. if source == 2 {
  92. var collectCond string
  93. var collectPars []interface{}
  94. // 根据关注时间一个月前至昨日的增量数据排序
  95. nowTime := time.Now().Local()
  96. startTime := nowTime.AddDate(0, -1, 0)
  97. endTime := nowTime.AddDate(0, 0, -1)
  98. collectCond += ` AND ac.create_time BETWEEN ? AND ?`
  99. collectPars = append(collectPars, startTime, endTime)
  100. if chartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  101. topList, e := models.GetReportCollectionBillboardListYx(topNum, collectPars, collectCond)
  102. if e != nil {
  103. br.Msg = "获取失败"
  104. br.ErrMsg = "获取报告阅读增量排行榜失败, Err:" + e.Error()
  105. return
  106. }
  107. list = topList
  108. } else {
  109. if chartPermissionId > 0 {
  110. categoryId, err := models.GetCategoryId(chartPermissionId)
  111. if err != nil && err.Error() != utils.ErrNoRow() {
  112. br.Msg = "获取信息失败"
  113. br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
  114. return
  115. }
  116. if categoryId != "" {
  117. collectCond += ` AND a.category_id IN (` + categoryId + `)`
  118. }
  119. }
  120. collectList, e := models.GetReportCollectionBillboardList(topNum, collectPars, collectCond)
  121. if e != nil {
  122. br.Msg = "获取失败"
  123. br.ErrMsg = "获取报告收藏排行榜失败, Err:" + e.Error()
  124. return
  125. }
  126. list = collectList
  127. }
  128. }
  129. var err error
  130. resp := new(models.ReportBillboardListResp)
  131. resp.List, err = services.HandleArticleCategoryImg(list, user)
  132. if err != nil {
  133. br.Msg = "获取失败"
  134. br.ErrMsg = "获取报告封面图片失败, Err:" + err.Error()
  135. return
  136. }
  137. br.Ret = 200
  138. br.Success = true
  139. br.Msg = "获取成功"
  140. br.Data = resp
  141. }