research.go 14 KB

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