123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- package controllers
- import (
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_web_mfyx/models"
- "hongze/hongze_web_mfyx/services"
- "hongze/hongze_web_mfyx/utils"
- "strconv"
- "strings"
- "time"
- )
- type HomeController struct {
- BaseAuthController
- }
- type BaseHomeController struct {
- BaseCommonController
- }
- type MobileHomeController struct {
- BaseAuthMobileController
- }
- // @Title 首页列表接口
- // @Description 首页列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ChartPermissionId query int true "品类id,最新传0"
- // @Param CtagId query int true "图表子类ID"
- // @Param ListType query int true "列表类型,1最新,2 纪要 ,3图表 默认1"
- // @Success 200 {object} models.HomeArtAndChartListResp
- // @router /list [get]
- func (this *MobileHomeController) List() {
- 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")
- chartPermissionId, _ := this.GetInt("ChartPermissionId")
- ctagId, _ := this.GetInt("CtagId")
- listType, _ := this.GetInt("ListType")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- if listType <= 0 {
- listType = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- var total, chartTotal int
- resp := new(models.HomeArtAndChartListResp)
- page := paging.GetPaging(currentIndex, pageSize, total)
- var chartList []*models.HomeChartListResp
- var err error
- if listType == 1 {
- if currentIndex <= 2 {
- listCtagId := [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
- var chartIds string
- for _, v := range listCtagId {
- chartListTwo, err := models.GetChartList(`AND ctag_id = `+strconv.Itoa(v), pars, 0, 2)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- for _, vChart := range chartListTwo {
- chartIds += strconv.Itoa(vChart.ChartId) + ","
- }
- }
- chartIds = strings.TrimRight(chartIds, ",")
- condition += ` AND chart_id IN (` + chartIds + `) `
- chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- }
- } else if listType == 3 {
- if chartPermissionId > 0 {
- condition += ` AND a.ptag_id =? `
- pars = append(pars, chartPermissionId)
- }
- if ctagId > 0 {
- condition += ` AND a.ctag_id =? `
- pars = append(pars, ctagId)
- }
- chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- chartTotal, err = models.GetChartCount(condition, pars)
- if err != nil {
- br.Msg = "获取信息失败"
- br.Msg = "获取帖子总数失败,Err:" + err.Error()
- return
- }
- }
- for k, v := range chartList {
- if v.PtagName != "" {
- chartList[k].CtagNamePc = v.PtagName
- }
- if v.CtagName != "" {
- chartList[k].CtagNamePc += "," + v.CtagName
- }
- if v.PtagNameTwo != "" {
- chartList[k].CtagNamePc += "," + v.PtagNameTwo
- }
- if v.CtagNameTwo != "" {
- chartList[k].CtagNamePc += "," + v.CtagNameTwo
- }
- chartList[k].IsNeedJump = true
- chartList[k].Source = 2
- if v.PtagName != "" {
- labelItem := new(models.LabelList)
- labelItem.PtagName = v.PtagName
- labelItem.CtagName = v.CtagName
- chartList[k].LabelList = append(chartList[k].LabelList, labelItem)
- }
- if v.PtagNameTwo != "" {
- labelItemTwo := new(models.LabelList)
- labelItemTwo.PtagName = v.PtagNameTwo
- labelItemTwo.CtagName = v.CtagNameTwo
- chartList[k].LabelList = append(chartList[k].LabelList, labelItemTwo)
- }
- if len(chartList[k].LabelList) == 0 {
- chartList[k].LabelList = make([]*models.LabelList, 0)
- }
- }
- if len(chartList) == 0 {
- chartList = make([]*models.HomeChartListResp, 0)
- }
- resp.ChartList = chartList
- if listType != 3 {
- userType, _, err := services.GetUserType(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- condition = ` AND is_summary = 1 `
- if chartPermissionId > 0 {
- categoryId, err := models.GetCategoryIdHome(chartPermissionId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
- return
- }
- categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if userType == 1 && strings.Contains(categoryinfo.PermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- if categoryId != "" {
- condition += ` AND category_id IN(` + categoryId + `)`
- //condition += ` OR ( category_name LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%' AND publish_status = 1 AND is_summary = 1 )`
- } else {
- condition += ` AND category_name LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
- }
- }
- //永续客户无法查看研选分类的内容
- if userType == 1 {
- condition += ` AND category_name NOT LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
- }
- total, err = models.GetHomeCount(condition, pars)
- if err != nil {
- br.Msg = "获取信息失败"
- br.Msg = "获取帖子总数失败,Err:" + err.Error()
- return
- }
- listPublic, err := models.GetHomeListPublic(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取信息失败"
- br.Msg = "获取帖子数据失败,Err:" + err.Error()
- return
- }
- listPublic, err = services.HandleArticleCategoryImg(listPublic, user)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取报告封面图片失败, Err:" + err.Error()
- return
- }
- var articleIds []int
- for _, v := range listPublic {
- articleIds = append(articleIds, v.ArticleId)
- }
- articleMapPv := services.GetArticleHistoryByArticleId(articleIds) //文章Pv
- articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId) //用户收藏的文章
- articleCollectNumMap, _ := services.GetCygxArticleCollectNumMapByArtcileIds(articleIds) //文章收藏的数量
- var list []*models.HomeArticle
- if len(listPublic) == 0 {
- list = make([]*models.HomeArticle, 0)
- } else {
- for _, v := range listPublic {
- list = append(list, &models.HomeArticle{
- ArticleId: v.ArticleId,
- Title: v.Title,
- Annotation: v.Annotation,
- Abstract: v.Abstract,
- ImgUrlPc: v.ImgUrlPc,
- PublishDate: v.PublishDate,
- IsResearch: v.IsResearch,
- Pv: articleMapPv[v.ArticleId],
- IsCollect: articleCollectMap[v.ArticleId],
- CollectNum: articleCollectNumMap[v.ArticleId],
- })
- }
- }
- resp.List = list
- }
- if chartTotal > total {
- total = chartTotal
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @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 *MobileHomeController) 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.CygxResourceDataNewResp
- var err error
- resp := new(models.HomeResourceDataListNewResp)
- 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
- }
|