home.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package controllers
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hongze_mfyx/models"
  5. "hongze/hongze_mfyx/services"
  6. "hongze/hongze_mfyx/utils"
  7. "time"
  8. )
  9. type HomeController struct {
  10. BaseAuthController
  11. }
  12. type BaseHomeController struct {
  13. BaseCommonController
  14. }
  15. // @Title 最新首页列表接口
  16. // @Description 最新首页列表接口
  17. // @Param LabelKeyword query string true "标签关键词"
  18. // @Param HashtagKeyword query string true "主题关键词"
  19. // @Param KeyWord query string true "搜索关键词"
  20. // @Param PageSize query int true "每页数据条数"
  21. // @Param CurrentIndex query int true "当前页页码,从1开始"
  22. // @Success 200 {object} models.HomeArtAndChartListResp
  23. // @router /new [get]
  24. func (this *HomeController) NewList() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. user := this.User
  31. if user == nil {
  32. br.Msg = "请登录"
  33. br.ErrMsg = "请登录,用户信息为空"
  34. br.Ret = 408
  35. return
  36. }
  37. pageSize, _ := this.GetInt("PageSize")
  38. currentIndex, _ := this.GetInt("CurrentIndex")
  39. labelKeyword := this.GetString("LabelKeyword")
  40. hashtagKeyword := this.GetString("HashtagKeyword")
  41. keyWord := this.GetString("KeyWord")
  42. var startSize int
  43. if pageSize <= 0 {
  44. pageSize = utils.PageSize20
  45. }
  46. if currentIndex <= 0 {
  47. currentIndex = 1
  48. }
  49. startSize = paging.StartIndex(currentIndex, pageSize)
  50. var condition string
  51. var pars []interface{}
  52. var yanxuanActivityIds []int
  53. var yanxuanArticleIds []int
  54. var conditionresp string
  55. //var yanxuanspecialIds []int
  56. if hashtagKeyword != "" {
  57. }
  58. var total int
  59. var list []*models.CygxResourceDataResp
  60. var err error
  61. resp := new(models.HomeResourceDataListResp)
  62. if keyWord == "" {
  63. condition += " AND source IN ('article','activity','yanxuanspecial','activityvoice','activityvideo') AND IF ( source IN('activityvoice','activityvideo') , chart_permission_id = 31 ,1=1 ) " // 只有研选的文章、研选的活动、研选的专栏这三种
  64. if labelKeyword == "" {
  65. //查询近一个月的数据
  66. condition += " AND search_order_time > '" + time.Now().AddDate(0, 0, -180).Format(utils.FormatDateTime) + "'"
  67. yanxuanActivityIds = services.GetYanxuanActivityIds(user, "1,2") // 获取所有的研选活动ID
  68. yanxuanArticleIds = services.GetYanxuanArticleIds() //获取所有研选文章ID
  69. } else {
  70. yanxuanActivityIds, yanxuanArticleIds, conditionresp, err = services.GetConditionInitByTagIds(user, labelKeyword)
  71. if err != nil {
  72. br.Msg = "获取失败"
  73. br.ErrMsg = "获取活动权限数据失败,GetConditionInitByTagIds Err:" + err.Error()
  74. return
  75. }
  76. condition += conditionresp
  77. //如果不是 "全部报告" 、 "专栏" 的关键词查询,就不做研选专栏的查询
  78. if labelKeyword != utils.LABEL_L2_1 && labelKeyword != utils.LABEL_L2_2 {
  79. condition += ` AND IF ( source = 'yanxuanspecial' , source_id IN (0) ,1=1 ) `
  80. }
  81. //任何筛选,都不展示对应的音视频
  82. condition += ` AND source NOT IN ('activityvoice','activityvideo') `
  83. }
  84. yanxuanArticleIds = append(yanxuanArticleIds, 0)
  85. yanxuanActivityIds = append(yanxuanActivityIds, 0)
  86. //yanxuanspecialIds = append(yanxuanspecialIds, 0)
  87. condition += ` AND IF ( source = 'article' , source_id IN (` + utils.GetOrmInReplace(len(yanxuanArticleIds)) + `) ,1=1 ) `
  88. pars = append(pars, yanxuanArticleIds)
  89. condition += ` AND IF ( source = 'activity' , source_id IN (` + utils.GetOrmInReplace(len(yanxuanActivityIds)) + `) ,1=1 ) `
  90. pars = append(pars, yanxuanActivityIds)
  91. total, err = models.GetResourceDataCount(condition, pars)
  92. if err != nil {
  93. br.Msg = "获取失败"
  94. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  95. return
  96. }
  97. list, err = services.GetResourceDataList(condition, pars, startSize, pageSize, user)
  98. if err != nil {
  99. br.Msg = "获取失败"
  100. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  101. return
  102. }
  103. } else {
  104. tmpResult, tmpTotalResult, err := services.SqlComprehensiveSearch(user, keyWord, startSize, pageSize)
  105. if err != nil {
  106. br.Msg = "检索失败"
  107. br.ErrMsg = "检索失败,Err:" + err.Error()
  108. return
  109. }
  110. total = tmpTotalResult
  111. list, err = services.GetResourceDataEsList(tmpResult, user)
  112. if err != nil {
  113. br.Msg = "获取失败"
  114. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  115. return
  116. }
  117. }
  118. page := paging.GetPaging(currentIndex, pageSize, total)
  119. if currentIndex == 1 && keyWord != "" {
  120. go services.AddSearchKeyWord(user, keyWord, 1)
  121. }
  122. resp.Paging = page
  123. resp.List = list
  124. br.Ret = 200
  125. br.Success = true
  126. br.Msg = "获取成功"
  127. br.Data = resp
  128. }