123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- package controllers
- import (
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_mfyx/models"
- "hongze/hongze_mfyx/services"
- "hongze/hongze_mfyx/utils"
- "time"
- )
- type HomeController struct {
- BaseAuthController
- }
- type BaseHomeController struct {
- BaseCommonController
- }
- // @Title 最新首页列表接口
- // @Description 最新首页列表接口
- // @Param LabelKeyword query string true "标签关键词"
- // @Param HashtagKeyword query string true "主题关键词"
- // @Param KeyWord query string true "搜索关键词"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} models.HomeArtAndChartListResp
- // @router /new [get]
- func (this *HomeController) NewList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- labelKeyword := this.GetString("LabelKeyword")
- hashtagKeyword := this.GetString("HashtagKeyword")
- keyWord := this.GetString("KeyWord")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- var yanxuanActivityIds []int
- var yanxuanArticleIds []int
- var conditionresp string
- //var yanxuanspecialIds []int
- if hashtagKeyword != "" {
- }
- var total int
- var list []*models.CygxResourceDataResp
- var err error
- resp := new(models.HomeResourceDataListResp)
- if keyWord == "" {
- condition += " AND source IN ('article','activity','yanxuanspecial','activityvoice','activityvideo') AND IF ( source IN('activityvoice','activityvideo') , chart_permission_id = 31 ,1=1 ) " // 只有研选的文章、研选的活动、研选的专栏这三种
- if labelKeyword == "" {
- //查询近一个月的数据
- condition += " AND search_order_time > '" + time.Now().AddDate(0, 0, -180).Format(utils.FormatDateTime) + "'"
- yanxuanActivityIds = services.GetYanxuanActivityIds(user, "1,2") // 获取所有的研选活动ID
- yanxuanArticleIds = services.GetYanxuanArticleIds() //获取所有研选文章ID
- } else {
- yanxuanActivityIds, yanxuanArticleIds, conditionresp, err = services.GetConditionInitByTagIds(user, labelKeyword)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取活动权限数据失败,GetConditionInitByTagIds Err:" + err.Error()
- return
- }
- condition += conditionresp
- //如果不是 "全部报告" 、 "专栏" 的关键词查询,就不做研选专栏的查询
- if labelKeyword != utils.LABEL_L2_1 && labelKeyword != utils.LABEL_L2_2 {
- condition += ` AND IF ( source = 'yanxuanspecial' , source_id IN (0) ,1=1 ) `
- }
- //任何筛选,都不展示对应的音视频
- condition += ` AND source NOT IN ('activityvoice','activityvideo') `
- }
- yanxuanArticleIds = append(yanxuanArticleIds, 0)
- yanxuanActivityIds = append(yanxuanActivityIds, 0)
- //yanxuanspecialIds = append(yanxuanspecialIds, 0)
- condition += ` AND IF ( source = 'article' , source_id IN (` + utils.GetOrmInReplace(len(yanxuanArticleIds)) + `) ,1=1 ) `
- pars = append(pars, yanxuanArticleIds)
- condition += ` AND IF ( source = 'activity' , source_id IN (` + utils.GetOrmInReplace(len(yanxuanActivityIds)) + `) ,1=1 ) `
- pars = append(pars, yanxuanActivityIds)
- total, err = models.GetResourceDataCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- list, err = services.GetResourceDataList(condition, pars, startSize, pageSize, user)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- } else {
- tmpResult, tmpTotalResult, err := services.SqlComprehensiveSearch(user, keyWord, startSize, pageSize)
- if err != nil {
- br.Msg = "检索失败"
- br.ErrMsg = "检索失败,Err:" + err.Error()
- return
- }
- total = tmpTotalResult
- list, err = services.GetResourceDataEsList(tmpResult, user)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- if currentIndex == 1 && keyWord != "" {
- go services.AddSearchKeyWord(user, keyWord, 1)
- }
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|