home.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. package controllers
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hongze_web_mfyx/models"
  5. "hongze/hongze_web_mfyx/services"
  6. "hongze/hongze_web_mfyx/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. type HomeController struct {
  12. BaseAuthController
  13. }
  14. type BaseHomeController struct {
  15. BaseCommonController
  16. }
  17. type MobileHomeController struct {
  18. BaseAuthMobileController
  19. }
  20. // @Title 首页列表接口
  21. // @Description 首页列表接口
  22. // @Param PageSize query int true "每页数据条数"
  23. // @Param CurrentIndex query int true "当前页页码,从1开始"
  24. // @Param ChartPermissionId query int true "品类id,最新传0"
  25. // @Param CtagId query int true "图表子类ID"
  26. // @Param ListType query int true "列表类型,1最新,2 纪要 ,3图表 默认1"
  27. // @Success 200 {object} models.HomeArtAndChartListResp
  28. // @router /list [get]
  29. func (this *MobileHomeController) List() {
  30. br := new(models.BaseResponse).Init()
  31. defer func() {
  32. this.Data["json"] = br
  33. this.ServeJSON()
  34. }()
  35. user := this.User
  36. if user == nil {
  37. br.Msg = "请登录"
  38. br.ErrMsg = "请登录,用户信息为空"
  39. br.Ret = 408
  40. return
  41. }
  42. pageSize, _ := this.GetInt("PageSize")
  43. currentIndex, _ := this.GetInt("CurrentIndex")
  44. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  45. ctagId, _ := this.GetInt("CtagId")
  46. listType, _ := this.GetInt("ListType")
  47. var startSize int
  48. if pageSize <= 0 {
  49. pageSize = utils.PageSize20
  50. }
  51. if currentIndex <= 0 {
  52. currentIndex = 1
  53. }
  54. if listType <= 0 {
  55. listType = 1
  56. }
  57. startSize = paging.StartIndex(currentIndex, pageSize)
  58. var condition string
  59. var pars []interface{}
  60. var total, chartTotal int
  61. resp := new(models.HomeArtAndChartListResp)
  62. page := paging.GetPaging(currentIndex, pageSize, total)
  63. var chartList []*models.HomeChartListResp
  64. var err error
  65. if listType == 1 {
  66. if currentIndex <= 2 {
  67. listCtagId := [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
  68. var chartIds string
  69. for _, v := range listCtagId {
  70. chartListTwo, err := models.GetChartList(`AND ctag_id = `+strconv.Itoa(v), pars, 0, 2)
  71. if err != nil {
  72. br.Msg = "获取信息失败"
  73. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  74. return
  75. }
  76. for _, vChart := range chartListTwo {
  77. chartIds += strconv.Itoa(vChart.ChartId) + ","
  78. }
  79. }
  80. chartIds = strings.TrimRight(chartIds, ",")
  81. condition += ` AND chart_id IN (` + chartIds + `) `
  82. chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
  83. if err != nil {
  84. br.Msg = "获取信息失败"
  85. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  86. return
  87. }
  88. }
  89. } else if listType == 3 {
  90. if chartPermissionId > 0 {
  91. condition += ` AND a.ptag_id =? `
  92. pars = append(pars, chartPermissionId)
  93. }
  94. if ctagId > 0 {
  95. condition += ` AND a.ctag_id =? `
  96. pars = append(pars, ctagId)
  97. }
  98. chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
  99. if err != nil {
  100. br.Msg = "获取信息失败"
  101. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  102. return
  103. }
  104. chartTotal, err = models.GetChartCount(condition, pars)
  105. if err != nil {
  106. br.Msg = "获取信息失败"
  107. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  108. return
  109. }
  110. }
  111. for k, v := range chartList {
  112. if v.PtagName != "" {
  113. chartList[k].CtagNamePc = v.PtagName
  114. }
  115. if v.CtagName != "" {
  116. chartList[k].CtagNamePc += "," + v.CtagName
  117. }
  118. if v.PtagNameTwo != "" {
  119. chartList[k].CtagNamePc += "," + v.PtagNameTwo
  120. }
  121. if v.CtagNameTwo != "" {
  122. chartList[k].CtagNamePc += "," + v.CtagNameTwo
  123. }
  124. chartList[k].IsNeedJump = true
  125. chartList[k].Source = 2
  126. if v.PtagName != "" {
  127. labelItem := new(models.LabelList)
  128. labelItem.PtagName = v.PtagName
  129. labelItem.CtagName = v.CtagName
  130. chartList[k].LabelList = append(chartList[k].LabelList, labelItem)
  131. }
  132. if v.PtagNameTwo != "" {
  133. labelItemTwo := new(models.LabelList)
  134. labelItemTwo.PtagName = v.PtagNameTwo
  135. labelItemTwo.CtagName = v.CtagNameTwo
  136. chartList[k].LabelList = append(chartList[k].LabelList, labelItemTwo)
  137. }
  138. if len(chartList[k].LabelList) == 0 {
  139. chartList[k].LabelList = make([]*models.LabelList, 0)
  140. }
  141. }
  142. if len(chartList) == 0 {
  143. chartList = make([]*models.HomeChartListResp, 0)
  144. }
  145. resp.ChartList = chartList
  146. if listType != 3 {
  147. userType, _, err := services.GetUserType(user.CompanyId)
  148. if err != nil {
  149. br.Msg = "获取信息失败"
  150. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  151. return
  152. }
  153. condition = ` AND is_summary = 1 `
  154. if chartPermissionId > 0 {
  155. categoryId, err := models.GetCategoryIdHome(chartPermissionId)
  156. if err != nil && err.Error() != utils.ErrNoRow() {
  157. br.Msg = "获取信息失败"
  158. br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
  159. return
  160. }
  161. categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
  162. if err != nil {
  163. br.Msg = "获取信息失败"
  164. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  165. return
  166. }
  167. if userType == 1 && strings.Contains(categoryinfo.PermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  168. resp.Paging = page
  169. br.Ret = 200
  170. br.Success = true
  171. br.Msg = "获取成功"
  172. br.Data = resp
  173. return
  174. }
  175. page = paging.GetPaging(currentIndex, pageSize, total)
  176. if categoryId != "" {
  177. condition += ` AND category_id IN(` + categoryId + `)`
  178. //condition += ` OR ( category_name LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%' AND publish_status = 1 AND is_summary = 1 )`
  179. } else {
  180. condition += ` AND category_name LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
  181. }
  182. }
  183. //永续客户无法查看研选分类的内容
  184. if userType == 1 {
  185. condition += ` AND category_name NOT LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
  186. }
  187. total, err = models.GetHomeCount(condition, pars)
  188. if err != nil {
  189. br.Msg = "获取信息失败"
  190. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  191. return
  192. }
  193. listPublic, err := models.GetHomeListPublic(condition, pars, startSize, pageSize)
  194. if err != nil {
  195. br.Msg = "获取信息失败"
  196. br.Msg = "获取帖子数据失败,Err:" + err.Error()
  197. return
  198. }
  199. listPublic, err = services.HandleArticleCategoryImg(listPublic, user)
  200. if err != nil {
  201. br.Msg = "获取失败"
  202. br.ErrMsg = "获取报告封面图片失败, Err:" + err.Error()
  203. return
  204. }
  205. var articleIds []int
  206. for _, v := range listPublic {
  207. articleIds = append(articleIds, v.ArticleId)
  208. }
  209. articleMapPv := services.GetArticleHistoryByArticleId(articleIds) //文章Pv
  210. articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId) //用户收藏的文章
  211. articleCollectNumMap, _ := services.GetCygxArticleCollectNumMapByArtcileIds(articleIds) //文章收藏的数量
  212. var list []*models.HomeArticle
  213. if len(listPublic) == 0 {
  214. list = make([]*models.HomeArticle, 0)
  215. } else {
  216. for _, v := range listPublic {
  217. list = append(list, &models.HomeArticle{
  218. ArticleId: v.ArticleId,
  219. Title: v.Title,
  220. Annotation: v.Annotation,
  221. Abstract: v.Abstract,
  222. ImgUrlPc: v.ImgUrlPc,
  223. PublishDate: v.PublishDate,
  224. IsResearch: v.IsResearch,
  225. Pv: articleMapPv[v.ArticleId],
  226. IsCollect: articleCollectMap[v.ArticleId],
  227. CollectNum: articleCollectNumMap[v.ArticleId],
  228. })
  229. }
  230. }
  231. resp.List = list
  232. }
  233. if chartTotal > total {
  234. total = chartTotal
  235. }
  236. page = paging.GetPaging(currentIndex, pageSize, total)
  237. resp.Paging = page
  238. br.Ret = 200
  239. br.Success = true
  240. br.Msg = "获取成功"
  241. br.Data = resp
  242. }
  243. // @Title 首页列表接口
  244. // @Description 首页列表接口
  245. // @Param LabelKeyword query string true "标签关键词"
  246. // @Param HashtagKeyword query string true "主题关键词"
  247. // @Param KeyWord query string true "搜索关键词"
  248. // @Param PageSize query int true "每页数据条数"
  249. // @Param CurrentIndex query int true "当前页页码,从1开始"
  250. // @Success 200 {object} models.HomeArtAndChartListResp
  251. // @router /new [get]
  252. func (this *MobileHomeController) NewList() {
  253. br := new(models.BaseResponse).Init()
  254. defer func() {
  255. this.Data["json"] = br
  256. this.ServeJSON()
  257. }()
  258. user := this.User
  259. if user == nil {
  260. br.Msg = "请登录"
  261. br.ErrMsg = "请登录,用户信息为空"
  262. br.Ret = 408
  263. return
  264. }
  265. pageSize, _ := this.GetInt("PageSize")
  266. currentIndex, _ := this.GetInt("CurrentIndex")
  267. labelKeyword := this.GetString("LabelKeyword")
  268. hashtagKeyword := this.GetString("HashtagKeyword")
  269. keyWord := this.GetString("KeyWord")
  270. var startSize int
  271. if pageSize <= 0 {
  272. pageSize = utils.PageSize20
  273. }
  274. if currentIndex <= 0 {
  275. currentIndex = 1
  276. }
  277. startSize = paging.StartIndex(currentIndex, pageSize)
  278. var condition string
  279. var pars []interface{}
  280. var yanxuanActivityIds []int
  281. var yanxuanArticleIds []int
  282. var conditionresp string
  283. //var yanxuanspecialIds []int
  284. if hashtagKeyword != "" {
  285. }
  286. var total int
  287. var list []*models.CygxResourceDataNewResp
  288. var err error
  289. resp := new(models.HomeResourceDataListNewResp)
  290. if keyWord == "" {
  291. condition += " AND source IN ('article','activity','yanxuanspecial','activityvoice','activityvideo') AND IF ( source IN('activityvoice','activityvideo') , chart_permission_id = 31 ,1=1 ) " // 只有研选的文章、研选的活动、研选的专栏这三种
  292. if labelKeyword == "" {
  293. //查询近一个月的数据
  294. condition += " AND search_order_time > '" + time.Now().AddDate(0, 0, -180).Format(utils.FormatDateTime) + "'"
  295. yanxuanActivityIds = services.GetYanxuanActivityIds(user, "1,2") // 获取所有的研选活动ID
  296. yanxuanArticleIds = services.GetYanxuanArticleIds() //获取所有研选文章ID
  297. } else {
  298. yanxuanActivityIds, yanxuanArticleIds, conditionresp, err = services.GetConditionInitByTagIds(user, labelKeyword)
  299. if err != nil {
  300. br.Msg = "获取失败"
  301. br.ErrMsg = "获取活动权限数据失败,GetConditionInitByTagIds Err:" + err.Error()
  302. return
  303. }
  304. condition += conditionresp
  305. //如果不是 "全部报告" 、 "专栏" 的关键词查询,就不做研选专栏的查询
  306. if labelKeyword != utils.LABEL_L2_1 && labelKeyword != utils.LABEL_L2_2 {
  307. condition += ` AND IF ( source = 'yanxuanspecial' , source_id IN (0) ,1=1 ) `
  308. }
  309. //任何筛选,都不展示对应的音视频
  310. condition += ` AND source NOT IN ('activityvoice','activityvideo') `
  311. }
  312. yanxuanArticleIds = append(yanxuanArticleIds, 0)
  313. yanxuanActivityIds = append(yanxuanActivityIds, 0)
  314. //yanxuanspecialIds = append(yanxuanspecialIds, 0)
  315. condition += ` AND IF ( source = 'article' , source_id IN (` + utils.GetOrmInReplace(len(yanxuanArticleIds)) + `) ,1=1 ) `
  316. pars = append(pars, yanxuanArticleIds)
  317. condition += ` AND IF ( source = 'activity' , source_id IN (` + utils.GetOrmInReplace(len(yanxuanActivityIds)) + `) ,1=1 ) `
  318. pars = append(pars, yanxuanActivityIds)
  319. total, err = models.GetResourceDataCount(condition, pars)
  320. if err != nil {
  321. br.Msg = "获取失败"
  322. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  323. return
  324. }
  325. list, err = services.GetResourceDataList(condition, pars, startSize, pageSize, user)
  326. if err != nil {
  327. br.Msg = "获取失败"
  328. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  329. return
  330. }
  331. } else {
  332. tmpResult, tmpTotalResult, err := services.SqlComprehensiveSearch(user, keyWord, startSize, pageSize)
  333. if err != nil {
  334. br.Msg = "检索失败"
  335. br.ErrMsg = "检索失败,Err:" + err.Error()
  336. return
  337. }
  338. total = tmpTotalResult
  339. list, err = services.GetResourceDataEsList(tmpResult, user)
  340. if err != nil {
  341. br.Msg = "获取失败"
  342. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  343. return
  344. }
  345. }
  346. page := paging.GetPaging(currentIndex, pageSize, total)
  347. if currentIndex == 1 && keyWord != "" {
  348. go services.AddSearchKeyWord(user, keyWord, 1)
  349. }
  350. resp.Paging = page
  351. resp.List = list
  352. br.Ret = 200
  353. br.Success = true
  354. br.Msg = "获取成功"
  355. br.Data = resp
  356. }