home.go 13 KB

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