research.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/services"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. )
  11. // 研选
  12. type ResearchController struct {
  13. BaseAuthController
  14. }
  15. // @Title 近期更新主题列表
  16. // @Description 近期更新主题列表接口
  17. // @Param ChartPermissionId query int true "分类ID"
  18. // @Success 200 {object} models.IndustrialManagementNewList
  19. // @router /theme/newList [get]
  20. func (this *ResearchController) NewList() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. user := this.User
  27. if user == nil {
  28. br.Msg = "请重新登录"
  29. br.Ret = 408
  30. return
  31. }
  32. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  33. if err != nil {
  34. br.Msg = "获取信息失败"
  35. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  36. return
  37. }
  38. if articleTypeIds == "" {
  39. br.Msg = "获取信息失败"
  40. br.ErrMsg = "研选分类ID不能为空"
  41. return
  42. }
  43. var condition string
  44. var conditionOrder string
  45. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  46. list, err := models.GetIndustrialManagementNewList(condition)
  47. if err != nil {
  48. br.Msg = "获取信息失败"
  49. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  50. return
  51. }
  52. mapHot := make(map[string]int)
  53. conditionOrder = ` ORDER BY sum_num DESC `
  54. listHot, err := models.GetThemeHeatList(user.UserId, condition, conditionOrder, 0, 3)
  55. if err != nil {
  56. br.Msg = "获取信息失败"
  57. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  58. return
  59. }
  60. for _, v := range listHot {
  61. mapHot[v.IndustryName] = v.IndustrialManagementId
  62. }
  63. for k, v := range list {
  64. if mapHot[v.IndustryName] > 0 {
  65. list[k].IsHot = true
  66. }
  67. }
  68. resp := new(models.IndustrialManagementNewList)
  69. resp.List = list
  70. br.Ret = 200
  71. br.Success = true
  72. br.Msg = "获取成功"
  73. br.Data = resp
  74. }
  75. // @Title 用户收藏列表
  76. // @Description 用户收藏列表接口
  77. // @Param ChartPermissionId query int true "分类ID"
  78. // @Success 200 {object} models.ArticleCollectionLIstResp
  79. // @router /collectionList [get]
  80. func (this *ResearchController) CollectionList() {
  81. br := new(models.BaseResponse).Init()
  82. defer func() {
  83. this.Data["json"] = br
  84. this.ServeJSON()
  85. }()
  86. user := this.User
  87. if user == nil {
  88. br.Msg = "请重新登录"
  89. br.Ret = 408
  90. return
  91. }
  92. var condition string
  93. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  94. if err != nil {
  95. br.Msg = "获取信息失败"
  96. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  97. return
  98. }
  99. if articleTypeIds == "" {
  100. br.Msg = "获取信息失败"
  101. br.ErrMsg = "研选分类ID不能为空"
  102. return
  103. }
  104. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  105. condition += ` AND publish_status = 1 GROUP BY a.article_id ORDER BY collect_num_order DESC, publish_date DESC LIMIT 15 `
  106. list, err := models.GetArticleCollectionList(condition, user.UserId)
  107. if err != nil {
  108. br.Msg = "获取信息失败"
  109. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  110. return
  111. }
  112. for k, v := range list {
  113. if v.MyCollectNum > 0 {
  114. list[k].IsCollect = true
  115. }
  116. }
  117. resp := new(models.ArticleCollectionLIstResp)
  118. resp.List = list
  119. br.Ret = 200
  120. br.Success = true
  121. br.Msg = "获取成功"
  122. br.Data = resp
  123. }
  124. // @Title 主题热度/近期更新更多,列表
  125. // @Description 主题热度/近期更新更多,列表接口
  126. // @Param ChartPermissionId query int true "分类ID"
  127. // @Param ThemeType query int true "主题类型,1主题热度、2近期更新 默认1"
  128. // @Param PageSize query int true "每页数据条数"
  129. // @Param CurrentIndex query int true "当前页页码,从1开始"
  130. // @Success 200 {object} models.IndustrialManagementHotListResp
  131. // @router /hotList [get]
  132. func (this *ResearchController) HotList() {
  133. br := new(models.BaseResponse).Init()
  134. defer func() {
  135. this.Data["json"] = br
  136. this.ServeJSON()
  137. }()
  138. user := this.User
  139. if user == nil {
  140. br.Msg = "请重新登录"
  141. br.Ret = 408
  142. return
  143. }
  144. themeType, _ := this.GetInt("ThemeType")
  145. pageSize, _ := this.GetInt("PageSize")
  146. currentIndex, _ := this.GetInt("CurrentIndex")
  147. var startSize int
  148. if pageSize <= 0 {
  149. pageSize = utils.PageSize15
  150. }
  151. if currentIndex <= 0 {
  152. currentIndex = 1
  153. }
  154. startSize = utils.StartIndex(currentIndex, pageSize)
  155. var condition string
  156. var conditionOrder string
  157. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  158. if err != nil {
  159. br.Msg = "获取信息失败"
  160. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  161. return
  162. }
  163. if articleTypeIds == "" {
  164. br.Msg = "获取信息失败"
  165. br.ErrMsg = "研选分类ID不能为空"
  166. return
  167. }
  168. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  169. if themeType == 2 {
  170. conditionOrder = `ORDER BY publish_date DESC `
  171. } else {
  172. conditionOrder = `ORDER BY sum_num DESC `
  173. }
  174. total, err := models.GetThemeHeatListCount(condition)
  175. if err != nil {
  176. br.Msg = "获取失败"
  177. br.ErrMsg = "获取失败,Err:" + err.Error()
  178. return
  179. }
  180. list, err := models.GetThemeHeatList(user.UserId, condition, conditionOrder, startSize, pageSize)
  181. if err != nil {
  182. br.Msg = "获取信息失败"
  183. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  184. return
  185. }
  186. condition = ` AND a.article_type_id > 0 `
  187. listSubjcet, err := models.GetThemeHeatSubjectList(condition)
  188. if err != nil {
  189. br.Msg = "获取信息失败"
  190. br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
  191. return
  192. }
  193. mapHot := make(map[int]bool)
  194. mapNew, err := services.GetYanXuanIndustrialManagementIdNewMap(articleTypeIds)
  195. if err != nil {
  196. br.Msg = "获取信息失败"
  197. br.ErrMsg = "GetYanXuanIndustrialManagementIdNewMap,Err:" + err.Error()
  198. return
  199. }
  200. if themeType == 2 {
  201. mapHot, err = services.GetYanXuanIndustrialManagementIdHotMap(articleTypeIds)
  202. if err != nil {
  203. br.Msg = "获取信息失败"
  204. br.ErrMsg = "GetYanXuanIndustrialManagementIdNewMap,Err:" + err.Error()
  205. return
  206. }
  207. }
  208. for k, v := range list {
  209. list[k].IsNew = mapNew[v.IndustrialManagementId]
  210. list[k].IsHot = mapHot[v.IndustrialManagementId]
  211. if v.FllowNum > 0 {
  212. list[k].IsFollw = true
  213. }
  214. for _, v2 := range listSubjcet {
  215. if v2.IndustrialManagementId == v.IndustrialManagementId {
  216. list[k].IndustrialSubjectList = append(list[k].IndustrialSubjectList, v2)
  217. }
  218. }
  219. }
  220. page := paging.GetPaging(currentIndex, pageSize, total)
  221. resp := new(models.IndustrialManagementHotListResp)
  222. resp.Paging = page
  223. resp.List = list
  224. br.Ret = 200
  225. br.Success = true
  226. br.Msg = "获取成功"
  227. br.Data = resp
  228. }
  229. // @Title KOL榜列表
  230. // @Description KOL榜列表接口
  231. // @Param ChartPermissionId query int true "分类ID"
  232. // @Param PageSize query int true "每页数据条数"
  233. // @Param CurrentIndex query int true "当前页页码,从1开始"
  234. // @Param ThemeType query int true "主题类型,1关注度、2更新时间 "
  235. // @Success 200 {object} models.DepartmentListResp
  236. // @router /kolList [get]
  237. func (this *ResearchController) KolList() {
  238. br := new(models.BaseResponse).Init()
  239. defer func() {
  240. this.Data["json"] = br
  241. this.ServeJSON()
  242. }()
  243. user := this.User
  244. if user == nil {
  245. br.Msg = "请重新登录"
  246. br.Ret = 408
  247. return
  248. }
  249. themeType, _ := this.GetInt("ThemeType")
  250. pageSize, _ := this.GetInt("PageSize")
  251. currentIndex, _ := this.GetInt("CurrentIndex")
  252. var startSize int
  253. if pageSize <= 0 {
  254. pageSize = utils.PageSize15
  255. }
  256. if currentIndex <= 0 {
  257. currentIndex = 1
  258. }
  259. startSize = utils.StartIndex(currentIndex, pageSize)
  260. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  261. if err != nil {
  262. br.Msg = "获取信息失败"
  263. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  264. return
  265. }
  266. if articleTypeIds == "" {
  267. br.Msg = "获取信息失败"
  268. br.ErrMsg = "研选分类ID不能为空"
  269. return
  270. }
  271. var condition string
  272. var conditionOrder string
  273. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  274. total, err := models.GetDepartmentlistCount(condition)
  275. if err != nil {
  276. br.Msg = "获取失败"
  277. br.ErrMsg = "获取失败,Err:" + err.Error()
  278. return
  279. }
  280. if themeType == 2 {
  281. conditionOrder = `ORDER BY publish_date DESC `
  282. } else {
  283. conditionOrder = `ORDER BY fllow_num DESC `
  284. }
  285. mapHot := make(map[int]bool)
  286. if themeType == 2 {
  287. conditionHot := `ORDER BY fllow_num DESC `
  288. listhot, err := models.GetDepartmentList(condition, conditionHot, user.UserId, 0, 3)
  289. if err != nil {
  290. br.Msg = "获取信息失败"
  291. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  292. return
  293. }
  294. for _, v := range listhot {
  295. mapHot[v.DepartmentId] = true
  296. }
  297. }
  298. list, err := models.GetDepartmentList(condition, conditionOrder, user.UserId, startSize, pageSize)
  299. if err != nil {
  300. br.Msg = "获取信息失败"
  301. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  302. return
  303. }
  304. listIndustrial, err := models.GetIndustrialDepartmentList()
  305. if err != nil {
  306. br.Msg = "获取信息失败"
  307. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  308. return
  309. }
  310. departmentMap := make(map[string]string)
  311. for k, v := range list {
  312. if v.FllowNum > 0 {
  313. list[k].IsFollw = true
  314. }
  315. for _, v2 := range listIndustrial {
  316. if v2.DepartmentId == v.DepartmentId {
  317. if departmentMap["D"+strconv.Itoa(v2.DepartmentId)+"In"+strconv.Itoa(v2.IndustrialManagementId)] == "" && len(list[k].List) < 4 {
  318. list[k].List = append(list[k].List, v2)
  319. departmentMap["D"+strconv.Itoa(v2.DepartmentId)+"In"+strconv.Itoa(v2.IndustrialManagementId)] = v.NickName
  320. }
  321. }
  322. }
  323. if themeType == 2 {
  324. v.IsHot = mapHot[v.DepartmentId]
  325. }
  326. }
  327. resp := new(models.DepartmentListResp)
  328. page := paging.GetPaging(currentIndex, pageSize, total)
  329. resp.Paging = page
  330. resp.List = list
  331. br.Ret = 200
  332. br.Success = true
  333. br.Msg = "获取成功"
  334. br.Data = resp
  335. }
  336. // @Title 主题详情
  337. // @Description 主题详情接口
  338. // @Param IndustrialManagementId query int true "分类ID"
  339. // @Param Source query int true "来源 1:研选,2:报告 默认1"
  340. // @Success 200 {object} models.GetThemeDetailResp
  341. // @router /theme/detail [get]
  342. func (this *ResearchController) ThemeDetail() {
  343. br := new(models.BaseResponse).Init()
  344. defer func() {
  345. this.Data["json"] = br
  346. this.ServeJSON()
  347. }()
  348. user := this.User
  349. if user == nil {
  350. br.Msg = "请重新登录"
  351. br.Ret = 408
  352. return
  353. }
  354. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  355. if industrialManagementId < 1 {
  356. br.Msg = "请输入产业ID"
  357. return
  358. }
  359. source, _ := this.GetInt("Source")
  360. if source != 2 {
  361. source = 1
  362. }
  363. var condition string
  364. if source == 1 {
  365. condition = ` AND a.category_name LIKE '%研选%' `
  366. } else {
  367. condition = ` AND a.category_name NOT LIKE '%研选%' `
  368. }
  369. resp := new(models.GetThemeDetailResp)
  370. list, err := models.GetThemeDetail(user.UserId, industrialManagementId, condition)
  371. if err != nil {
  372. br.Msg = "获取信息失败"
  373. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  374. return
  375. }
  376. var itemsNull []*models.GetThemeAericleListResp
  377. subjectMap := make(map[string]string)
  378. articleMap := make(map[int]int)
  379. for _, v := range list {
  380. resp.IndustryName = v.IndustryName
  381. resp.IndustrialManagementId = v.IndustrialManagementId
  382. itemSubJect := new(models.IndustrialSubject)
  383. itemSubJect.SubjectName = v.SubjectName
  384. itemSubJect.IndustrialSubjectId = v.IndustrialSubjectId
  385. if subjectMap[v.SubjectName] == "" && v.SubjectName != "" {
  386. resp.ListSubject = append(resp.ListSubject, itemSubJect)
  387. }
  388. subjectMap[v.SubjectName] = v.IndustryName
  389. if v.FllowNum > 0 {
  390. resp.IsFollw = true
  391. }
  392. if v.SubjectName == "" {
  393. item := new(models.GetThemeAericleListResp)
  394. item.ArticleId = v.ArticleId
  395. item.Title = v.Title
  396. item.PublishDate = v.PublishDate
  397. item.SubjectName = v.SubjectName
  398. item.DepartmentId = v.DepartmentId
  399. item.NickName = v.NickName
  400. item.Pv = v.Pv
  401. item.CollectNum = v.CollectNum
  402. itemsNull = append(itemsNull, item)
  403. }
  404. }
  405. for _, v := range resp.ListSubject {
  406. subjetcGroup := new(models.GetThemeAericleListBuSubjectResp)
  407. for _, v2 := range list {
  408. if v2.IndustrialSubjectId == v.IndustrialSubjectId && articleMap[v2.ArticleId] == 0 {
  409. item := new(models.GetThemeAericleListResp)
  410. item.ArticleId = v2.ArticleId
  411. item.Title = v2.Title
  412. item.PublishDate = v2.PublishDate
  413. item.SubjectName = v2.SubjectName
  414. item.IndustrialSubjectId = v2.IndustrialSubjectId
  415. for _, v3 := range list {
  416. if v3.ArticleId == v2.ArticleId && v3.SubjectName != v2.SubjectName && v3.SubjectName != "" {
  417. item.SubjectName += "/" + v3.SubjectName
  418. }
  419. }
  420. item.DepartmentId = v2.DepartmentId
  421. item.NickName = v2.NickName
  422. item.Pv = v2.Pv
  423. item.CollectNum = v2.CollectNum
  424. item.MyCollectNum = v2.MyCollectNum
  425. if v2.MyCollectNum > 0 {
  426. item.IsCollect = true
  427. }
  428. resp.List = append(resp.List, item)
  429. articleMap[v2.ArticleId] = v2.ArticleId
  430. //subjetcGroup.List = append(subjetcGroup.List, item)
  431. }
  432. subjetcGroup.SubjectName = v.SubjectName
  433. }
  434. }
  435. //当标的为空时进行合并
  436. if len(itemsNull) > 0 {
  437. for _, v := range itemsNull {
  438. resp.List = append(resp.List, v)
  439. }
  440. }
  441. br.Ret = 200
  442. br.Success = true
  443. br.Msg = "获取成功"
  444. br.Data = resp
  445. }
  446. // @Title 研选作者详情
  447. // @Description 研选作者详情接口
  448. // @Param DepartmentId query int true "作者ID"
  449. // @Success 200 {object} models.DepartmentDetailResp
  450. // @router /departmentId/detail [get]
  451. func (this *ResearchController) DepartmentIdDetail() {
  452. br := new(models.BaseResponse).Init()
  453. defer func() {
  454. this.Data["json"] = br
  455. this.ServeJSON()
  456. }()
  457. user := this.User
  458. if user == nil {
  459. br.Msg = "请重新登录"
  460. br.Ret = 408
  461. return
  462. }
  463. departmentId, _ := this.GetInt("DepartmentId")
  464. if departmentId < 1 {
  465. br.Msg = "请输入作者ID"
  466. return
  467. }
  468. resp := new(models.DepartmentDetailResp)
  469. detail, err := models.GetDepartmentDetail(user.UserId, departmentId)
  470. if err != nil {
  471. br.Msg = "获取信息失败"
  472. br.ErrMsg = "获取作者信息失败,Err:" + err.Error()
  473. return
  474. }
  475. resp.DepartmentId = detail.DepartmentId
  476. resp.NickName = detail.NickName
  477. resp.ImgUrl = detail.ImgUrl
  478. resp.FllowNum = detail.FllowNum
  479. resp.ArticleNum = detail.ArticleNum
  480. resp.CollectNum = detail.CollectNum
  481. if detail.MyFllowNum > 0 {
  482. resp.IsFllow = true
  483. }
  484. var condition string
  485. condition = ` AND a.department_id = ` + strconv.Itoa(departmentId) + ` ORDER BY a.publish_date DESC `
  486. list, err := models.GetArticleCollectionList(condition, user.UserId)
  487. if err != nil {
  488. br.Msg = "获取信息失败"
  489. br.ErrMsg = "获取文章列表失败,Err:" + err.Error()
  490. return
  491. }
  492. for k, v := range list {
  493. if v.MyCollectNum > 0 {
  494. list[k].IsCollect = true
  495. }
  496. }
  497. condition = ` AND a.department_id = ` + strconv.Itoa(departmentId)
  498. listIndustrial, err := models.GetIndustrialManagementNewList(condition)
  499. if err != nil {
  500. br.Msg = "获取信息失败"
  501. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  502. return
  503. }
  504. resp.List = list
  505. resp.ListIndustrial = listIndustrial
  506. br.Ret = 200
  507. br.Success = true
  508. br.Msg = "获取成功"
  509. br.Data = resp
  510. }
  511. // @Title 文章相关热门收藏
  512. // @Description 文章相关热门收藏接口
  513. // @Param ArticleId query int true "文章ID"
  514. // @Success 200 {object} models.ArticleCollectionLIstResp
  515. // @router /article/hotList [get]
  516. func (this *ResearchController) ArticleHotList() {
  517. br := new(models.BaseResponse).Init()
  518. defer func() {
  519. this.Data["json"] = br
  520. this.ServeJSON()
  521. }()
  522. user := this.User
  523. if user == nil {
  524. br.Msg = "请重新登录"
  525. br.Ret = 408
  526. return
  527. }
  528. articleId, _ := this.GetInt("ArticleId")
  529. if articleId < 1 {
  530. br.Msg = "请输入分类ID"
  531. return
  532. }
  533. var condition string
  534. 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 `
  535. list, err := models.GetArticleCollectionList(condition, user.UserId)
  536. if err != nil {
  537. br.Msg = "获取信息失败"
  538. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  539. return
  540. }
  541. for k, v := range list {
  542. if v.MyCollectNum > 0 {
  543. list[k].IsCollect = true
  544. }
  545. }
  546. resp := new(models.ArticleCollectionLIstResp)
  547. resp.List = list
  548. br.Ret = 200
  549. br.Success = true
  550. br.Msg = "获取成功"
  551. br.Data = resp
  552. }
  553. // @Title 热搜关键词
  554. // @Description 热搜关键词接口
  555. // @Success 200 {object} models.UserSearchKeyWordListResp
  556. // @router /hotKeyWord [get]
  557. func (this *ResearchController) HotKeyWord() {
  558. br := new(models.BaseResponse).Init()
  559. defer func() {
  560. this.Data["json"] = br
  561. this.ServeJSON()
  562. }()
  563. user := this.User
  564. if user == nil {
  565. br.Msg = "请重新登录"
  566. br.Ret = 408
  567. return
  568. }
  569. //本来应该放在config控制器下,与未上线的代码冲突,所以放在这里
  570. list, err := models.GetUserSearchKeyWord()
  571. if err != nil {
  572. br.Msg = "获取信息失败"
  573. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  574. return
  575. }
  576. resp := new(models.UserSearchKeyWordListResp)
  577. resp.List = list
  578. br.Ret = 200
  579. br.Success = true
  580. br.Msg = "获取成功"
  581. br.Data = resp
  582. }
  583. // @Title 研选文章类型列表
  584. // @Description 研选文章类型列表接口
  585. // @Success 200 {object} models.CygxArticleTypeListResp
  586. // @router /article/typeList [get]
  587. func (this *ResearchController) ArticleType() {
  588. br := new(models.BaseResponse).Init()
  589. defer func() {
  590. this.Data["json"] = br
  591. this.ServeJSON()
  592. }()
  593. user := this.User
  594. if user == nil {
  595. br.Msg = "请重新登录"
  596. br.Ret = 408
  597. return
  598. }
  599. key := utils.YAN_XUAN_TAB_KEY
  600. conf, e := models.GetConfigByCode(key)
  601. if e != nil {
  602. br.Msg = "获取失败"
  603. br.ErrMsg = "获取首页头部导航失败, Err: " + e.Error()
  604. return
  605. }
  606. if conf.ConfigValue == "" {
  607. br.Msg = "获取失败"
  608. br.ErrMsg = "首页头部导航配置值有误"
  609. return
  610. }
  611. list := new(models.CygxArticleTypeListResp)
  612. if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
  613. br.Msg = "获取失败"
  614. br.ErrMsg = "首页头部导航配置值解析失败, Err: " + e.Error()
  615. return
  616. }
  617. resp := new(models.CygxArticleTypeListResp)
  618. resp = list
  619. br.Ret = 200
  620. br.Success = true
  621. br.Msg = "获取成功"
  622. br.Data = resp
  623. }
  624. // @Title 研选最新报告列表
  625. // @Description 研选最新报告列表接口
  626. // @Param PageSize query int true "每页数据条数"
  627. // @Param CurrentIndex query int true "当前页页码,从1开始"
  628. // @Param ArticleTypeIds query array true "文章类型ID多个用 , 隔开"
  629. // @Success 200 {object} models.IndustrialManagementNewList
  630. // @router /article/newList [get]
  631. func (this *ResearchController) ArticleNewList() {
  632. br := new(models.BaseResponse).Init()
  633. defer func() {
  634. this.Data["json"] = br
  635. this.ServeJSON()
  636. }()
  637. user := this.User
  638. if user == nil {
  639. br.Msg = "请重新登录"
  640. br.Ret = 408
  641. return
  642. }
  643. pageSize, _ := this.GetInt("PageSize")
  644. currentIndex, _ := this.GetInt("CurrentIndex")
  645. articleTypeIds := this.GetString("ArticleTypeIds")
  646. var startSize int
  647. if pageSize <= 0 {
  648. pageSize = utils.PageSize20
  649. }
  650. if currentIndex <= 0 {
  651. currentIndex = 1
  652. }
  653. startSize = paging.StartIndex(currentIndex, pageSize)
  654. var condition string
  655. var conditiontype string
  656. var pars []interface{}
  657. condition = ` AND publish_status = 1 `
  658. if articleTypeIds == "" {
  659. conditiontype = " AND is_show_yanx = 1 "
  660. } else {
  661. conditiontype = ` AND group_id IN (` + articleTypeIds + `) `
  662. }
  663. listType, err := models.GetCygxArticleTypeListCondition(conditiontype)
  664. if err != nil {
  665. br.Msg = "获取信息失败"
  666. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  667. return
  668. }
  669. for _, v := range listType {
  670. articleTypeIds += strconv.Itoa(v.ArticleTypeId) + ","
  671. }
  672. articleTypeIds = strings.TrimRight(articleTypeIds, ",")
  673. condition += ` AND a.article_type_id IN (` + articleTypeIds + `) `
  674. total, err := models.GetArticleResearchCount(condition, pars)
  675. if err != nil {
  676. br.Msg = "获取信息失败"
  677. br.ErrMsg = "GetArticleResearchCount,Err:" + err.Error()
  678. return
  679. }
  680. list, err := models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId)
  681. if err != nil {
  682. br.Msg = "获取信息失败"
  683. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  684. return
  685. }
  686. var articleIds []int
  687. for k, v := range list {
  688. if v.MyCollectNum > 0 {
  689. list[k].IsCollect = true
  690. }
  691. articleIds = append(articleIds, v.ArticleId)
  692. }
  693. //处理关联的产业
  694. industrialMap, err := services.GetArticleIndustrialByArticleId(articleIds)
  695. if err != nil {
  696. br.Msg = "获取信息失败"
  697. br.ErrMsg = "获取关联的产业信息失败,GetArticleIndustrialByArticleId Err:" + err.Error()
  698. return
  699. }
  700. for k, v := range list {
  701. if len(industrialMap[v.ArticleId]) > 0 {
  702. list[k].List = industrialMap[v.ArticleId]
  703. } else {
  704. list[k].List = make([]*models.IndustrialManagementResp, 0)
  705. }
  706. }
  707. //处理对应的文章类型标签按钮
  708. nameMap, styleMap, err := services.GetArticleTypeMap()
  709. if err != nil {
  710. br.Msg = "获取信息失败"
  711. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  712. return
  713. }
  714. page := paging.GetPaging(currentIndex, pageSize, total)
  715. resp := new(models.ArticleResearchListResp)
  716. for _, v := range list {
  717. item := models.ArticleResearchResp{
  718. ArticleId: v.ArticleId,
  719. Title: v.Title,
  720. PublishDate: v.PublishDate,
  721. DepartmentId: v.DepartmentId,
  722. NickName: v.NickName,
  723. IsCollect: v.IsCollect,
  724. Pv: v.Pv,
  725. CollectNum: v.CollectNum,
  726. ArticleTypeName: nameMap[v.ArticleTypeId],
  727. ButtonStyle: styleMap[v.ArticleTypeId],
  728. List: v.List,
  729. }
  730. resp.List = append(resp.List, &item)
  731. }
  732. resp.Paging = page
  733. br.Ret = 200
  734. br.Success = true
  735. br.Msg = "获取成功"
  736. br.Data = resp
  737. }