research.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. package controllers
  2. import (
  3. "hongze/hongze_cygx/models"
  4. "strconv"
  5. )
  6. //研选
  7. type ResearchController struct {
  8. BaseAuthController
  9. }
  10. // @Title 近期更新主题列表
  11. // @Description 近期更新主题列表接口
  12. // @Param ChartPermissionId query int true "分类ID"
  13. // @Success 200 {object} models.IndustrialManagementNewList
  14. // @router /theme/newList [get]
  15. func (this *ResearchController) NewList() {
  16. br := new(models.BaseResponse).Init()
  17. defer func() {
  18. this.Data["json"] = br
  19. this.ServeJSON()
  20. }()
  21. user := this.User
  22. if user == nil {
  23. br.Msg = "请重新登录"
  24. br.Ret = 408
  25. return
  26. }
  27. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  28. if chartPermissionId < 1 {
  29. br.Msg = "请输入分类ID"
  30. return
  31. }
  32. categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
  33. if err != nil {
  34. br.Msg = "获取信息失败"
  35. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  36. return
  37. }
  38. list, err := models.GetIndustrialManagementNewList(categoryinfo.PermissionName)
  39. if err != nil {
  40. br.Msg = "获取信息失败"
  41. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  42. return
  43. }
  44. detailHot3, err := models.GetIndustrialManagementHot3(chartPermissionId)
  45. if err != nil {
  46. br.Msg = "获取信息失败"
  47. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  48. return
  49. }
  50. for k, v := range list {
  51. if v.ArticleReadNum >= detailHot3.ArticleReadNum {
  52. list[k].IsHot = true
  53. }
  54. }
  55. resp := new(models.IndustrialManagementNewList)
  56. resp.List = list
  57. br.Ret = 200
  58. br.Success = true
  59. br.Msg = "获取成功"
  60. br.Data = resp
  61. }
  62. // @Title 用户收藏列表
  63. // @Description 用户收藏列表接口
  64. // @Param ChartPermissionId query int true "分类ID"
  65. // @Success 200 {object} models.ArticleCollectionLIstResp
  66. // @router /collectionList [get]
  67. func (this *ResearchController) CollectionList() {
  68. br := new(models.BaseResponse).Init()
  69. defer func() {
  70. this.Data["json"] = br
  71. this.ServeJSON()
  72. }()
  73. user := this.User
  74. if user == nil {
  75. br.Msg = "请重新登录"
  76. br.Ret = 408
  77. return
  78. }
  79. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  80. if chartPermissionId < 1 {
  81. br.Msg = "请输入分类ID"
  82. return
  83. }
  84. categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
  85. if err != nil {
  86. br.Msg = "获取信息失败"
  87. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  88. return
  89. }
  90. var condition string
  91. condition = ` AND a.category_name LIKE '%` + categoryinfo.PermissionName + `%' AND publish_status = 1 GROUP BY m.industrial_management_id ORDER BY collect_num DESC, publish_date DESC LIMIT 15 `
  92. list, err := models.GetArticleCollectionList(condition, user.UserId)
  93. if err != nil {
  94. br.Msg = "获取信息失败"
  95. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  96. return
  97. }
  98. for k, v := range list {
  99. if v.MyCollectNum > 0 {
  100. list[k].IsCollect = true
  101. }
  102. }
  103. resp := new(models.ArticleCollectionLIstResp)
  104. resp.List = list
  105. br.Ret = 200
  106. br.Success = true
  107. br.Msg = "获取成功"
  108. br.Data = resp
  109. }
  110. // @Title 主题热度/近期更新更多,列表
  111. // @Description 主题热度/近期更新更多,列表接口
  112. // @Param ChartPermissionId query int true "分类ID"
  113. // @Param ThemeType query int true "主题类型,1主题热度、2近期更新 默认1"
  114. // @Success 200 {object} models.IndustrialManagementHotListResp
  115. // @router /hotList [get]
  116. func (this *ResearchController) HotList() {
  117. br := new(models.BaseResponse).Init()
  118. defer func() {
  119. this.Data["json"] = br
  120. this.ServeJSON()
  121. }()
  122. user := this.User
  123. if user == nil {
  124. br.Msg = "请重新登录"
  125. br.Ret = 408
  126. return
  127. }
  128. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  129. themeType, _ := this.GetInt("ThemeType")
  130. if chartPermissionId < 1 {
  131. br.Msg = "请输入分类ID"
  132. return
  133. }
  134. var condition string
  135. if themeType != 2 {
  136. themeType = 1
  137. condition = `ORDER BY sum_num DESC LIMIT 15`
  138. } else {
  139. condition = `ORDER BY publish_date DESC LIMIT 30`
  140. }
  141. categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
  142. if err != nil {
  143. br.Msg = "获取信息失败"
  144. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  145. return
  146. }
  147. list, err := models.GetThemeHeatList(categoryinfo.PermissionName, user.UserId, condition)
  148. if err != nil {
  149. br.Msg = "获取信息失败"
  150. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  151. return
  152. }
  153. newMap := make(map[int]string)
  154. listNew, err := models.GetIndustrialManagementNewList(categoryinfo.PermissionName)
  155. if err != nil {
  156. br.Msg = "获取信息失败"
  157. br.ErrMsg = "获取产业最新信息失败,Err:" + err.Error()
  158. return
  159. }
  160. for _, v := range listNew {
  161. newMap[v.IndustrialManagementId] = v.IndustryName
  162. }
  163. condition = ` AND a.category_name LIKE '%` + categoryinfo.PermissionName + `%' `
  164. listSubjcet, err := models.GetThemeHeatSubjectList(condition)
  165. if err != nil {
  166. br.Msg = "获取信息失败"
  167. br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
  168. return
  169. }
  170. detailHot3, err := models.GetIndustrialManagementHot3(chartPermissionId)
  171. if err != nil {
  172. br.Msg = "获取信息失败"
  173. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  174. return
  175. }
  176. for k, v := range list {
  177. if newMap[v.IndustrialManagementId] != "" {
  178. list[k].IsNew = true
  179. }
  180. if v.FllowNum > 0 {
  181. list[k].IsFollw = true
  182. }
  183. for _, v2 := range listSubjcet {
  184. if v2.IndustrialManagementId == v.IndustrialManagementId {
  185. list[k].IndustrialSubjectList = append(list[k].IndustrialSubjectList, v2)
  186. }
  187. }
  188. if v.ArticleReadNum >= detailHot3.ArticleReadNum {
  189. list[k].IsHot = true
  190. }
  191. }
  192. resp := new(models.IndustrialManagementHotListResp)
  193. resp.List = list
  194. br.Ret = 200
  195. br.Success = true
  196. br.Msg = "获取成功"
  197. br.Data = resp
  198. }
  199. // @Title KOL榜列表
  200. // @Description KOL榜列表接口
  201. // @Param ChartPermissionId query int true "分类ID"
  202. // @Success 200 {object} models.DepartmentListResp
  203. // @router /kolList [get]
  204. func (this *ResearchController) KolList() {
  205. br := new(models.BaseResponse).Init()
  206. defer func() {
  207. this.Data["json"] = br
  208. this.ServeJSON()
  209. }()
  210. user := this.User
  211. if user == nil {
  212. br.Msg = "请重新登录"
  213. br.Ret = 408
  214. return
  215. }
  216. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  217. if chartPermissionId < 1 {
  218. br.Msg = "请输入分类ID"
  219. return
  220. }
  221. categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
  222. if err != nil {
  223. br.Msg = "获取信息失败"
  224. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  225. return
  226. }
  227. list, err := models.GetDepartmentList(categoryinfo.PermissionName, user.UserId)
  228. if err != nil {
  229. br.Msg = "获取信息失败"
  230. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  231. return
  232. }
  233. listIndustrial, err := models.GetIndustrialDepartmentList(categoryinfo.PermissionName)
  234. if err != nil {
  235. br.Msg = "获取信息失败"
  236. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  237. return
  238. }
  239. departmentMap := make(map[string]string)
  240. for k, v := range list {
  241. if v.FllowNum > 0 {
  242. list[k].IsFollw = true
  243. }
  244. for _, v2 := range listIndustrial {
  245. if v2.DepartmentId == v.DepartmentId {
  246. if departmentMap["D"+strconv.Itoa(v2.DepartmentId)+"In"+strconv.Itoa(v2.IndustrialManagementId)] == "" && len(list[k].List) < 4 {
  247. list[k].List = append(list[k].List, v2)
  248. departmentMap["D"+strconv.Itoa(v2.DepartmentId)+"In"+strconv.Itoa(v2.IndustrialManagementId)] = v.NickName
  249. }
  250. }
  251. }
  252. }
  253. resp := new(models.DepartmentListResp)
  254. resp.List = list
  255. br.Ret = 200
  256. br.Success = true
  257. br.Msg = "获取成功"
  258. br.Data = resp
  259. }
  260. // @Title 主题详情
  261. // @Description 主题详情接口
  262. // @Param IndustrialManagementId query int true "分类ID"
  263. // @Success 200 {object} models.GetThemeDetailResp
  264. // @router /theme/detail [get]
  265. func (this *ResearchController) ThemeDetail() {
  266. br := new(models.BaseResponse).Init()
  267. defer func() {
  268. this.Data["json"] = br
  269. this.ServeJSON()
  270. }()
  271. user := this.User
  272. if user == nil {
  273. br.Msg = "请重新登录"
  274. br.Ret = 408
  275. return
  276. }
  277. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  278. if industrialManagementId < 1 {
  279. br.Msg = "请输入产业ID"
  280. return
  281. }
  282. resp := new(models.GetThemeDetailResp)
  283. list, err := models.GetThemeDetail(user.UserId, industrialManagementId)
  284. if err != nil {
  285. br.Msg = "获取信息失败"
  286. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  287. return
  288. }
  289. var itemsNull []*models.GetThemeAericleListResp
  290. subjectMap := make(map[string]string)
  291. for _, v := range list {
  292. resp.IndustryName = v.IndustryName
  293. resp.IndustrialManagementId = v.IndustrialManagementId
  294. itemSubJect := new(models.IndustrialSubject)
  295. itemSubJect.SubjectName = v.SubjectName
  296. itemSubJect.IndustrialSubjectId = v.IndustrialSubjectId
  297. if subjectMap[v.SubjectName] == "" && v.SubjectName != "" {
  298. resp.ListSubject = append(resp.ListSubject, itemSubJect)
  299. }
  300. subjectMap[v.SubjectName] = v.IndustryName
  301. if v.FllowNum > 0 {
  302. resp.IsFollw = true
  303. }
  304. if v.SubjectName == "" {
  305. item := new(models.GetThemeAericleListResp)
  306. item.ArticleId = v.ArticleId
  307. item.Title = v.Title
  308. item.PublishDate = v.PublishDate
  309. item.SubjectName = v.SubjectName
  310. item.DepartmentId = v.DepartmentId
  311. item.Pv = v.Pv
  312. item.CollectNum = v.CollectNum
  313. itemsNull = append(itemsNull, item)
  314. }
  315. }
  316. for _, v := range resp.ListSubject {
  317. subjetcGroup := new(models.GetThemeAericleListBuSubjectResp)
  318. for _, v2 := range list {
  319. if v2.IndustrialSubjectId == v.IndustrialSubjectId {
  320. item := new(models.GetThemeAericleListResp)
  321. item.ArticleId = v2.ArticleId
  322. item.Title = v2.Title
  323. item.PublishDate = v2.PublishDate
  324. item.SubjectName = v2.SubjectName
  325. item.IndustrialSubjectId = v2.IndustrialSubjectId
  326. for _, v3 := range list {
  327. if v3.ArticleId == v2.ArticleId && v3.SubjectName != v2.SubjectName && v3.SubjectName != "" {
  328. item.SubjectName += "/" + v3.SubjectName
  329. }
  330. }
  331. item.DepartmentId = v2.DepartmentId
  332. item.Pv = v2.Pv
  333. item.CollectNum = v2.CollectNum
  334. item.MyCollectNum = v2.MyCollectNum
  335. if v2.MyCollectNum > 0 {
  336. item.IsCollect = true
  337. }
  338. resp.List = append(resp.List, item)
  339. //subjetcGroup.List = append(subjetcGroup.List, item)
  340. }
  341. subjetcGroup.SubjectName = v.SubjectName
  342. }
  343. }
  344. //当标的为空时进行合并
  345. if len(itemsNull) > 0 {
  346. for _, v := range itemsNull {
  347. resp.List = append(resp.List, v)
  348. }
  349. }
  350. br.Ret = 200
  351. br.Success = true
  352. br.Msg = "获取成功"
  353. br.Data = resp
  354. }
  355. // @Title 研选作者详情
  356. // @Description 研选作者详情接口
  357. // @Param DepartmentId query int true "作者ID"
  358. // @Success 200 {object} models.DepartmentDetailResp
  359. // @router /departmentId/detail [get]
  360. func (this *ResearchController) DepartmentIdDetail() {
  361. br := new(models.BaseResponse).Init()
  362. defer func() {
  363. this.Data["json"] = br
  364. this.ServeJSON()
  365. }()
  366. user := this.User
  367. if user == nil {
  368. br.Msg = "请重新登录"
  369. br.Ret = 408
  370. return
  371. }
  372. departmentId, _ := this.GetInt("DepartmentId")
  373. if departmentId < 1 {
  374. br.Msg = "请输入作者ID"
  375. return
  376. }
  377. resp := new(models.DepartmentDetailResp)
  378. detail, err := models.GetDepartmentDetail(user.UserId, departmentId)
  379. if err != nil {
  380. br.Msg = "获取信息失败"
  381. br.ErrMsg = "获取作者信息失败,Err:" + err.Error()
  382. return
  383. }
  384. resp.DepartmentId = detail.DepartmentId
  385. resp.NickName = detail.NickName
  386. resp.ImgUrl = detail.ImgUrl
  387. resp.FllowNum = detail.FllowNum
  388. resp.ArticleNum = detail.ArticleNum
  389. resp.CollectNum = detail.CollectNum
  390. if detail.MyFllowNum > 0 {
  391. resp.IsFllow = true
  392. }
  393. var condition string
  394. condition = ` AND a.department_id = ` + strconv.Itoa(departmentId) + ` ORDER BY a.publish_date DESC `
  395. list, err := models.GetArticleCollectionList(condition, user.UserId)
  396. if err != nil {
  397. br.Msg = "获取信息失败"
  398. br.ErrMsg = "获取文章列表失败,Err:" + err.Error()
  399. return
  400. }
  401. for k, v := range list {
  402. if v.MyCollectNum > 0 {
  403. list[k].IsCollect = true
  404. }
  405. }
  406. resp.List = list
  407. br.Ret = 200
  408. br.Success = true
  409. br.Msg = "获取成功"
  410. br.Data = resp
  411. }
  412. // @Title 文章相关热门收藏
  413. // @Description 文章相关热门收藏接口
  414. // @Param ArticleId query int true "文章ID"
  415. // @Success 200 {object} models.ArticleCollectionLIstResp
  416. // @router /article/hotList [get]
  417. func (this *ResearchController) ArticleHotList() {
  418. br := new(models.BaseResponse).Init()
  419. defer func() {
  420. this.Data["json"] = br
  421. this.ServeJSON()
  422. }()
  423. user := this.User
  424. if user == nil {
  425. br.Msg = "请重新登录"
  426. br.Ret = 408
  427. return
  428. }
  429. articleId, _ := this.GetInt("ArticleId")
  430. if articleId < 1 {
  431. br.Msg = "请输入分类ID"
  432. return
  433. }
  434. var condition string
  435. condition = ` AND a.article_id IN (SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id IN (SELECT industrial_management_id FROM cygx_industrial_article_group_management WHERE article_id = ` + strconv.Itoa(articleId) + ` ) ) AND a.article_id != ` + strconv.Itoa(articleId) + ` AND a.category_name LIKE '%研选%' AND publish_status = 1 GROUP BY a.article_id ORDER BY collect_num DESC, publish_date DESC LIMIT 3 `
  436. list, err := models.GetArticleCollectionList(condition, user.UserId)
  437. if err != nil {
  438. br.Msg = "获取信息失败"
  439. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  440. return
  441. }
  442. for k, v := range list {
  443. if v.MyCollectNum > 0 {
  444. list[k].IsCollect = true
  445. }
  446. }
  447. resp := new(models.ArticleCollectionLIstResp)
  448. resp.List = list
  449. br.Ret = 200
  450. br.Success = true
  451. br.Msg = "获取成功"
  452. br.Data = resp
  453. }
  454. // @Title 热搜关键词
  455. // @Description 热搜关键词接口
  456. // @Success 200 {object} models.UserSearchKeyWordListResp
  457. // @router /hotKeyWord [get]
  458. func (this *ResearchController) HotKeyWord() {
  459. br := new(models.BaseResponse).Init()
  460. defer func() {
  461. this.Data["json"] = br
  462. this.ServeJSON()
  463. }()
  464. user := this.User
  465. if user == nil {
  466. br.Msg = "请重新登录"
  467. br.Ret = 408
  468. return
  469. }
  470. //本来应该放在config控制器下,与未上线的代码冲突,所以放在这里
  471. list, err := models.GetUserSearchKeyWord()
  472. if err != nil {
  473. br.Msg = "获取信息失败"
  474. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  475. return
  476. }
  477. resp := new(models.UserSearchKeyWordListResp)
  478. resp.List = list
  479. br.Ret = 200
  480. br.Success = true
  481. br.Msg = "获取成功"
  482. br.Data = resp
  483. }