research.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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. themeType, _ := this.GetInt("ThemeType")
  127. if chartPermissionId < 1 {
  128. br.Msg = "请输入分类ID"
  129. return
  130. }
  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. // @Success 200 {object} models.GetThemeDetailResp
  271. // @router /theme/detail [get]
  272. func (this *ResearchController) ThemeDetail() {
  273. br := new(models.BaseResponse).Init()
  274. defer func() {
  275. this.Data["json"] = br
  276. this.ServeJSON()
  277. }()
  278. user := this.User
  279. if user == nil {
  280. br.Msg = "请重新登录"
  281. br.Ret = 408
  282. return
  283. }
  284. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  285. if industrialManagementId < 1 {
  286. br.Msg = "请输入产业ID"
  287. return
  288. }
  289. resp := new(models.GetThemeDetailResp)
  290. list, err := models.GetThemeDetail(user.UserId, industrialManagementId)
  291. if err != nil {
  292. br.Msg = "获取信息失败"
  293. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  294. return
  295. }
  296. var itemsNull []*models.GetThemeAericleListResp
  297. subjectMap := make(map[string]string)
  298. articleMap := make(map[int]int)
  299. for _, v := range list {
  300. resp.IndustryName = v.IndustryName
  301. resp.IndustrialManagementId = v.IndustrialManagementId
  302. itemSubJect := new(models.IndustrialSubject)
  303. itemSubJect.SubjectName = v.SubjectName
  304. itemSubJect.IndustrialSubjectId = v.IndustrialSubjectId
  305. if subjectMap[v.SubjectName] == "" && v.SubjectName != "" {
  306. resp.ListSubject = append(resp.ListSubject, itemSubJect)
  307. }
  308. subjectMap[v.SubjectName] = v.IndustryName
  309. if v.FllowNum > 0 {
  310. resp.IsFollw = true
  311. }
  312. if v.SubjectName == "" {
  313. item := new(models.GetThemeAericleListResp)
  314. item.ArticleId = v.ArticleId
  315. item.Title = v.Title
  316. item.PublishDate = v.PublishDate
  317. item.SubjectName = v.SubjectName
  318. item.DepartmentId = v.DepartmentId
  319. item.NickName = v.NickName
  320. item.Pv = v.Pv
  321. item.CollectNum = v.CollectNum
  322. itemsNull = append(itemsNull, item)
  323. }
  324. }
  325. for _, v := range resp.ListSubject {
  326. subjetcGroup := new(models.GetThemeAericleListBuSubjectResp)
  327. for _, v2 := range list {
  328. if v2.IndustrialSubjectId == v.IndustrialSubjectId && articleMap[v2.ArticleId] == 0 {
  329. item := new(models.GetThemeAericleListResp)
  330. item.ArticleId = v2.ArticleId
  331. item.Title = v2.Title
  332. item.PublishDate = v2.PublishDate
  333. item.SubjectName = v2.SubjectName
  334. item.IndustrialSubjectId = v2.IndustrialSubjectId
  335. for _, v3 := range list {
  336. if v3.ArticleId == v2.ArticleId && v3.SubjectName != v2.SubjectName && v3.SubjectName != "" {
  337. item.SubjectName += "/" + v3.SubjectName
  338. }
  339. }
  340. item.DepartmentId = v2.DepartmentId
  341. item.NickName = v2.NickName
  342. item.Pv = v2.Pv
  343. item.CollectNum = v2.CollectNum
  344. item.MyCollectNum = v2.MyCollectNum
  345. if v2.MyCollectNum > 0 {
  346. item.IsCollect = true
  347. }
  348. resp.List = append(resp.List, item)
  349. articleMap[v2.ArticleId] = v2.ArticleId
  350. //subjetcGroup.List = append(subjetcGroup.List, item)
  351. }
  352. subjetcGroup.SubjectName = v.SubjectName
  353. }
  354. }
  355. //当标的为空时进行合并
  356. if len(itemsNull) > 0 {
  357. for _, v := range itemsNull {
  358. resp.List = append(resp.List, v)
  359. }
  360. }
  361. br.Ret = 200
  362. br.Success = true
  363. br.Msg = "获取成功"
  364. br.Data = resp
  365. }
  366. // @Title 研选作者详情
  367. // @Description 研选作者详情接口
  368. // @Param DepartmentId query int true "作者ID"
  369. // @Success 200 {object} models.DepartmentDetailResp
  370. // @router /departmentId/detail [get]
  371. func (this *ResearchController) DepartmentIdDetail() {
  372. br := new(models.BaseResponse).Init()
  373. defer func() {
  374. this.Data["json"] = br
  375. this.ServeJSON()
  376. }()
  377. user := this.User
  378. if user == nil {
  379. br.Msg = "请重新登录"
  380. br.Ret = 408
  381. return
  382. }
  383. departmentId, _ := this.GetInt("DepartmentId")
  384. if departmentId < 1 {
  385. br.Msg = "请输入作者ID"
  386. return
  387. }
  388. resp := new(models.DepartmentDetailResp)
  389. detail, err := models.GetDepartmentDetail(user.UserId, departmentId)
  390. if err != nil {
  391. br.Msg = "获取信息失败"
  392. br.ErrMsg = "获取作者信息失败,Err:" + err.Error()
  393. return
  394. }
  395. resp.DepartmentId = detail.DepartmentId
  396. resp.NickName = detail.NickName
  397. resp.ImgUrl = detail.ImgUrl
  398. resp.FllowNum = detail.FllowNum
  399. resp.ArticleNum = detail.ArticleNum
  400. resp.CollectNum = detail.CollectNum
  401. if detail.MyFllowNum > 0 {
  402. resp.IsFllow = true
  403. }
  404. var condition string
  405. condition = ` AND a.department_id = ` + strconv.Itoa(departmentId) + ` ORDER BY a.publish_date DESC `
  406. list, err := models.GetArticleCollectionList(condition, user.UserId)
  407. if err != nil {
  408. br.Msg = "获取信息失败"
  409. br.ErrMsg = "获取文章列表失败,Err:" + err.Error()
  410. return
  411. }
  412. for k, v := range list {
  413. if v.MyCollectNum > 0 {
  414. list[k].IsCollect = true
  415. }
  416. }
  417. resp.List = list
  418. br.Ret = 200
  419. br.Success = true
  420. br.Msg = "获取成功"
  421. br.Data = resp
  422. }
  423. // @Title 文章相关热门收藏
  424. // @Description 文章相关热门收藏接口
  425. // @Param ArticleId query int true "文章ID"
  426. // @Success 200 {object} models.ArticleCollectionLIstResp
  427. // @router /article/hotList [get]
  428. func (this *ResearchController) ArticleHotList() {
  429. br := new(models.BaseResponse).Init()
  430. defer func() {
  431. this.Data["json"] = br
  432. this.ServeJSON()
  433. }()
  434. user := this.User
  435. if user == nil {
  436. br.Msg = "请重新登录"
  437. br.Ret = 408
  438. return
  439. }
  440. articleId, _ := this.GetInt("ArticleId")
  441. if articleId < 1 {
  442. br.Msg = "请输入分类ID"
  443. return
  444. }
  445. var condition string
  446. 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 `
  447. list, err := models.GetArticleCollectionList(condition, user.UserId)
  448. if err != nil {
  449. br.Msg = "获取信息失败"
  450. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  451. return
  452. }
  453. for k, v := range list {
  454. if v.MyCollectNum > 0 {
  455. list[k].IsCollect = true
  456. }
  457. }
  458. resp := new(models.ArticleCollectionLIstResp)
  459. resp.List = list
  460. br.Ret = 200
  461. br.Success = true
  462. br.Msg = "获取成功"
  463. br.Data = resp
  464. }
  465. // @Title 热搜关键词
  466. // @Description 热搜关键词接口
  467. // @Success 200 {object} models.UserSearchKeyWordListResp
  468. // @router /hotKeyWord [get]
  469. func (this *ResearchController) HotKeyWord() {
  470. br := new(models.BaseResponse).Init()
  471. defer func() {
  472. this.Data["json"] = br
  473. this.ServeJSON()
  474. }()
  475. user := this.User
  476. if user == nil {
  477. br.Msg = "请重新登录"
  478. br.Ret = 408
  479. return
  480. }
  481. //本来应该放在config控制器下,与未上线的代码冲突,所以放在这里
  482. list, err := models.GetUserSearchKeyWord()
  483. if err != nil {
  484. br.Msg = "获取信息失败"
  485. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  486. return
  487. }
  488. resp := new(models.UserSearchKeyWordListResp)
  489. resp.List = list
  490. br.Ret = 200
  491. br.Success = true
  492. br.Msg = "获取成功"
  493. br.Data = resp
  494. }