report_billboard.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package controllers
  2. import (
  3. "hongze/hongze_clpt/models"
  4. "hongze/hongze_clpt/utils"
  5. "time"
  6. )
  7. //报告
  8. type ReportBillboardController struct {
  9. BaseAuthController
  10. }
  11. type ReportBillboardCommonController struct {
  12. BaseCommonController
  13. }
  14. type MobileReportBillboardController struct {
  15. BaseAuthMobileController
  16. }
  17. // @Title 阅读飙升榜/报告收藏榜
  18. // @Description 获取阅读飙升榜/报告收藏榜接口
  19. // @Param ChartPermissionId query int false "分类ID"
  20. // @Param Source query int true "来源 1:阅读飙升 ,2:报告收藏"
  21. // @Success 200 {object} models.ArticleReportBillboardLIstResp
  22. // @router /list [get]
  23. func (this *MobileReportBillboardController) ReadList() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. user := this.User
  30. if user == nil {
  31. br.Msg = "请重新登录"
  32. br.Ret = 408
  33. return
  34. }
  35. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  36. source, _ := this.GetInt("Source")
  37. sourceArr := []int{1, 2}
  38. if !utils.InArrayByInt(sourceArr, source) {
  39. br.Msg = "来源有误"
  40. return
  41. }
  42. topNum := utils.PageSize15
  43. list := make([]*models.HomeArticle, 0)
  44. // 阅读飙升榜
  45. if source == 1 {
  46. var topCond string
  47. var topPars []interface{}
  48. if chartPermissionId > 0 {
  49. topCond += ` AND chart_permission_id = ?`
  50. topPars = append(topPars, chartPermissionId)
  51. }
  52. topList, e := models.GetTopReadRecordArticleListByCondition(topNum, topCond, topPars)
  53. if e != nil {
  54. br.Msg = "获取失败"
  55. br.ErrMsg = "获取报告阅读增量排行榜失败, Err:" + e.Error()
  56. return
  57. }
  58. for i := range topList {
  59. list = append(list, &models.HomeArticle{
  60. ArticleId: topList[i].ArticleId,
  61. Title: topList[i].Title,
  62. PublishDate: topList[i].PublishDate,
  63. })
  64. }
  65. }
  66. // 报告收藏榜
  67. if source == 2 {
  68. var collectCond string
  69. var collectPars []interface{}
  70. if chartPermissionId > 0 {
  71. collectCond += ` AND m.chart_permission_id = ?`
  72. collectPars = append(collectPars, chartPermissionId)
  73. }
  74. // 根据关注时间一个月前至昨日的增量数据排序
  75. nowTime := time.Now().Local()
  76. startTime := nowTime.AddDate(0, -1, 0)
  77. endTime := nowTime.AddDate(0, 0, -1)
  78. collectCond += ` AND ac.create_time BETWEEN ? AND ?`
  79. collectPars = append(collectPars, startTime, endTime)
  80. collectList, e := models.GetReportCollectionBillboardList(topNum, collectPars, collectCond)
  81. if e != nil {
  82. br.Msg = "获取失败"
  83. br.ErrMsg = "获取报告收藏排行榜失败, Err:" + e.Error()
  84. return
  85. }
  86. list = collectList
  87. }
  88. articleIds := make([]int, 0)
  89. for i := range list {
  90. articleIds = append(articleIds, list[i].ArticleId)
  91. }
  92. // 报告关联产业信息
  93. industryMap := make(map[int][]*models.IndustrialManagementIdInt, 0)
  94. if len(articleIds) > 0 {
  95. var industryCond string
  96. var industryPars []interface{}
  97. industryCond += ` AND mg.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  98. industryPars = append(industryPars, articleIds)
  99. industryList, e := models.GetIndustrialListByarticleId(industryPars, industryCond)
  100. if e != nil {
  101. br.Msg = "获取失败"
  102. br.ErrMsg = "获取报告关联的产业信息失败, Err: " + e.Error()
  103. return
  104. }
  105. for i := range industryList {
  106. v := industryList[i]
  107. industryMap[v.ArticleId] = append(industryMap[v.ArticleId], &models.IndustrialManagementIdInt{
  108. ArticleId: v.ArticleId,
  109. IndustrialManagementId: v.IndustrialManagementId,
  110. IndustryName: v.IndustryName,
  111. ChartPermissionId: v.ChartPermissionId,
  112. })
  113. }
  114. }
  115. for k, v := range list {
  116. if len(industryMap[v.ArticleId]) > 0 {
  117. list[k].List = industryMap[v.ArticleId]
  118. } else {
  119. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  120. }
  121. }
  122. resp := new(models.HomeArtAndChartListResp)
  123. resp.List = list
  124. br.Ret = 200
  125. br.Success = true
  126. br.Msg = "获取成功"
  127. br.Data = resp
  128. }