research.go 21 KB

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