home.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 yanxuanspecialIds []int
  55. if hashtagKeyword != "" {
  56. }
  57. var total int
  58. var list []*models.CygxResourceDataResp
  59. var err error
  60. resp := new(models.HomeResourceDataListResp)
  61. if keyWord == "" {
  62. condition += " AND source IN ('article','activity','yanxuanspecial') " // 只有研选的文章、研选的活动、研选的专栏这三种
  63. if labelKeyword == "" {
  64. //查询近一个月的数据
  65. condition += " AND search_order_time > '" + time.Now().AddDate(0, 0, -60).Format(utils.FormatDateTime) + "'"
  66. yanxuanActivityIds = services.GetYanxuanActivityIds(user) // 获取所有的研选活动ID
  67. yanxuanArticleIds = services.GetYanxuanArticleIds() //获取所有研选文章ID
  68. } else {
  69. yanxuanActivityIds, yanxuanArticleIds, err = services.GetConditionInitByTagIds(user, labelKeyword)
  70. if err != nil {
  71. br.Msg = "获取失败"
  72. br.ErrMsg = "获取活动权限数据失败,GetConditionInitByTagIds Err:" + err.Error()
  73. return
  74. }
  75. //如果不是 "全部报告" 、 "专栏" 的关键词查询,就不做研选专栏的查询
  76. if labelKeyword != utils.LABEL_L2_1 && labelKeyword != utils.LABEL_L2_2 {
  77. condition += ` AND IF ( source = 'yanxuanspecial' , source_id IN (0) ,1=1 ) `
  78. }
  79. }
  80. yanxuanArticleIds = append(yanxuanArticleIds, 0)
  81. yanxuanActivityIds = append(yanxuanActivityIds, 0)
  82. //yanxuanspecialIds = append(yanxuanspecialIds, 0)
  83. condition += ` AND IF ( source = 'article' , source_id IN (` + utils.GetOrmInReplace(len(yanxuanArticleIds)) + `) ,1=1 ) `
  84. pars = append(pars, yanxuanArticleIds)
  85. condition += ` AND IF ( source = 'activity' , source_id IN (` + utils.GetOrmInReplace(len(yanxuanActivityIds)) + `) ,1=1 ) `
  86. pars = append(pars, yanxuanActivityIds)
  87. total, err = models.GetResourceDataCount(condition, pars)
  88. if err != nil {
  89. br.Msg = "获取失败"
  90. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  91. return
  92. }
  93. list, err = services.GetResourceDataList(condition, pars, startSize, pageSize, user)
  94. if err != nil {
  95. br.Msg = "获取失败"
  96. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  97. return
  98. }
  99. } else {
  100. tmpResult, tmpTotalResult, err := services.SqlComprehensiveSearch(user, keyWord, startSize, pageSize)
  101. if err != nil {
  102. br.Msg = "检索失败"
  103. br.ErrMsg = "检索失败,Err:" + err.Error()
  104. return
  105. }
  106. total = tmpTotalResult
  107. list, err = services.GetResourceDataEsList(tmpResult, user)
  108. if err != nil {
  109. br.Msg = "获取失败"
  110. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  111. return
  112. }
  113. }
  114. page := paging.GetPaging(currentIndex, pageSize, total)
  115. if currentIndex == 1 && keyWord != "" {
  116. go services.AddSearchKeyWord(user, keyWord, 1)
  117. }
  118. resp.Paging = page
  119. resp.List = list
  120. br.Ret = 200
  121. br.Success = true
  122. br.Msg = "获取成功"
  123. br.Data = resp
  124. }