research.go 21 KB

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