research.go 15 KB

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