research.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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. // @Success 200 {object} models.DepartmentListResp
  233. // @router /kolList [get]
  234. func (this *ResearchController) KolList() {
  235. br := new(models.BaseResponse).Init()
  236. defer func() {
  237. this.Data["json"] = br
  238. this.ServeJSON()
  239. }()
  240. user := this.User
  241. if user == nil {
  242. br.Msg = "请重新登录"
  243. br.Ret = 408
  244. return
  245. }
  246. //chartPermissionId, _ := this.GetInt("ChartPermissionId")
  247. //if chartPermissionId < 1 {
  248. // br.Msg = "请输入分类ID"
  249. // return
  250. //}
  251. list, err := models.GetDepartmentList(user.UserId)
  252. if err != nil {
  253. br.Msg = "获取信息失败"
  254. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  255. return
  256. }
  257. listIndustrial, err := models.GetIndustrialDepartmentList()
  258. if err != nil {
  259. br.Msg = "获取信息失败"
  260. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  261. return
  262. }
  263. departmentMap := make(map[string]string)
  264. for k, v := range list {
  265. if v.FllowNum > 0 {
  266. list[k].IsFollw = true
  267. }
  268. for _, v2 := range listIndustrial {
  269. if v2.DepartmentId == v.DepartmentId {
  270. if departmentMap["D"+strconv.Itoa(v2.DepartmentId)+"In"+strconv.Itoa(v2.IndustrialManagementId)] == "" && len(list[k].List) < 4 {
  271. list[k].List = append(list[k].List, v2)
  272. departmentMap["D"+strconv.Itoa(v2.DepartmentId)+"In"+strconv.Itoa(v2.IndustrialManagementId)] = v.NickName
  273. }
  274. }
  275. }
  276. }
  277. resp := new(models.DepartmentListResp)
  278. resp.List = list
  279. br.Ret = 200
  280. br.Success = true
  281. br.Msg = "获取成功"
  282. br.Data = resp
  283. }
  284. // @Title 主题详情
  285. // @Description 主题详情接口
  286. // @Param IndustrialManagementId query int true "分类ID"
  287. // @Param Source query int true "来源 1:研选,2:报告 默认1"
  288. // @Success 200 {object} models.GetThemeDetailResp
  289. // @router /theme/detail [get]
  290. func (this *ResearchController) ThemeDetail() {
  291. br := new(models.BaseResponse).Init()
  292. defer func() {
  293. this.Data["json"] = br
  294. this.ServeJSON()
  295. }()
  296. user := this.User
  297. if user == nil {
  298. br.Msg = "请重新登录"
  299. br.Ret = 408
  300. return
  301. }
  302. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  303. if industrialManagementId < 1 {
  304. br.Msg = "请输入产业ID"
  305. return
  306. }
  307. source, _ := this.GetInt("Source")
  308. if source != 2 {
  309. source = 1
  310. }
  311. var condition string
  312. if source == 1 {
  313. condition = ` AND a.category_name LIKE '%研选%' `
  314. } else {
  315. condition = ` AND a.category_name NOT LIKE '%研选%' `
  316. }
  317. resp := new(models.GetThemeDetailResp)
  318. list, err := models.GetThemeDetail(user.UserId, industrialManagementId, condition)
  319. if err != nil {
  320. br.Msg = "获取信息失败"
  321. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  322. return
  323. }
  324. var itemsNull []*models.GetThemeAericleListResp
  325. subjectMap := make(map[string]string)
  326. articleMap := make(map[int]int)
  327. for _, v := range list {
  328. resp.IndustryName = v.IndustryName
  329. resp.IndustrialManagementId = v.IndustrialManagementId
  330. itemSubJect := new(models.IndustrialSubject)
  331. itemSubJect.SubjectName = v.SubjectName
  332. itemSubJect.IndustrialSubjectId = v.IndustrialSubjectId
  333. if subjectMap[v.SubjectName] == "" && v.SubjectName != "" {
  334. resp.ListSubject = append(resp.ListSubject, itemSubJect)
  335. }
  336. subjectMap[v.SubjectName] = v.IndustryName
  337. if v.FllowNum > 0 {
  338. resp.IsFollw = true
  339. }
  340. if v.SubjectName == "" {
  341. item := new(models.GetThemeAericleListResp)
  342. item.ArticleId = v.ArticleId
  343. item.Title = v.Title
  344. item.PublishDate = v.PublishDate
  345. item.SubjectName = v.SubjectName
  346. item.DepartmentId = v.DepartmentId
  347. item.NickName = v.NickName
  348. item.Pv = v.Pv
  349. item.CollectNum = v.CollectNum
  350. itemsNull = append(itemsNull, item)
  351. }
  352. }
  353. for _, v := range resp.ListSubject {
  354. subjetcGroup := new(models.GetThemeAericleListBuSubjectResp)
  355. for _, v2 := range list {
  356. if v2.IndustrialSubjectId == v.IndustrialSubjectId && articleMap[v2.ArticleId] == 0 {
  357. item := new(models.GetThemeAericleListResp)
  358. item.ArticleId = v2.ArticleId
  359. item.Title = v2.Title
  360. item.PublishDate = v2.PublishDate
  361. item.SubjectName = v2.SubjectName
  362. item.IndustrialSubjectId = v2.IndustrialSubjectId
  363. for _, v3 := range list {
  364. if v3.ArticleId == v2.ArticleId && v3.SubjectName != v2.SubjectName && v3.SubjectName != "" {
  365. item.SubjectName += "/" + v3.SubjectName
  366. }
  367. }
  368. item.DepartmentId = v2.DepartmentId
  369. item.NickName = v2.NickName
  370. item.Pv = v2.Pv
  371. item.CollectNum = v2.CollectNum
  372. item.MyCollectNum = v2.MyCollectNum
  373. if v2.MyCollectNum > 0 {
  374. item.IsCollect = true
  375. }
  376. resp.List = append(resp.List, item)
  377. articleMap[v2.ArticleId] = v2.ArticleId
  378. //subjetcGroup.List = append(subjetcGroup.List, item)
  379. }
  380. subjetcGroup.SubjectName = v.SubjectName
  381. }
  382. }
  383. //当标的为空时进行合并
  384. if len(itemsNull) > 0 {
  385. for _, v := range itemsNull {
  386. resp.List = append(resp.List, v)
  387. }
  388. }
  389. br.Ret = 200
  390. br.Success = true
  391. br.Msg = "获取成功"
  392. br.Data = resp
  393. }
  394. // @Title 研选作者详情
  395. // @Description 研选作者详情接口
  396. // @Param DepartmentId query int true "作者ID"
  397. // @Success 200 {object} models.DepartmentDetailResp
  398. // @router /departmentId/detail [get]
  399. func (this *ResearchController) DepartmentIdDetail() {
  400. br := new(models.BaseResponse).Init()
  401. defer func() {
  402. this.Data["json"] = br
  403. this.ServeJSON()
  404. }()
  405. user := this.User
  406. if user == nil {
  407. br.Msg = "请重新登录"
  408. br.Ret = 408
  409. return
  410. }
  411. departmentId, _ := this.GetInt("DepartmentId")
  412. if departmentId < 1 {
  413. br.Msg = "请输入作者ID"
  414. return
  415. }
  416. resp := new(models.DepartmentDetailResp)
  417. detail, err := models.GetDepartmentDetail(user.UserId, departmentId)
  418. if err != nil {
  419. br.Msg = "获取信息失败"
  420. br.ErrMsg = "获取作者信息失败,Err:" + err.Error()
  421. return
  422. }
  423. resp.DepartmentId = detail.DepartmentId
  424. resp.NickName = detail.NickName
  425. resp.ImgUrl = detail.ImgUrl
  426. resp.FllowNum = detail.FllowNum
  427. resp.ArticleNum = detail.ArticleNum
  428. resp.CollectNum = detail.CollectNum
  429. if detail.MyFllowNum > 0 {
  430. resp.IsFllow = true
  431. }
  432. var condition string
  433. condition = ` AND a.department_id = ` + strconv.Itoa(departmentId) + ` ORDER BY a.publish_date DESC `
  434. list, err := models.GetArticleCollectionList(condition, user.UserId)
  435. if err != nil {
  436. br.Msg = "获取信息失败"
  437. br.ErrMsg = "获取文章列表失败,Err:" + err.Error()
  438. return
  439. }
  440. for k, v := range list {
  441. if v.MyCollectNum > 0 {
  442. list[k].IsCollect = true
  443. }
  444. }
  445. condition = ` AND a.department_id = ` + strconv.Itoa(departmentId)
  446. listIndustrial, err := models.GetIndustrialManagementNewList(condition)
  447. if err != nil {
  448. br.Msg = "获取信息失败"
  449. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  450. return
  451. }
  452. resp.List = list
  453. resp.ListIndustrial = listIndustrial
  454. br.Ret = 200
  455. br.Success = true
  456. br.Msg = "获取成功"
  457. br.Data = resp
  458. }
  459. // @Title 文章相关热门收藏
  460. // @Description 文章相关热门收藏接口
  461. // @Param ArticleId query int true "文章ID"
  462. // @Success 200 {object} models.ArticleCollectionLIstResp
  463. // @router /article/hotList [get]
  464. func (this *ResearchController) ArticleHotList() {
  465. br := new(models.BaseResponse).Init()
  466. defer func() {
  467. this.Data["json"] = br
  468. this.ServeJSON()
  469. }()
  470. user := this.User
  471. if user == nil {
  472. br.Msg = "请重新登录"
  473. br.Ret = 408
  474. return
  475. }
  476. articleId, _ := this.GetInt("ArticleId")
  477. if articleId < 1 {
  478. br.Msg = "请输入分类ID"
  479. return
  480. }
  481. var condition string
  482. 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 `
  483. list, err := models.GetArticleCollectionList(condition, user.UserId)
  484. if err != nil {
  485. br.Msg = "获取信息失败"
  486. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  487. return
  488. }
  489. for k, v := range list {
  490. if v.MyCollectNum > 0 {
  491. list[k].IsCollect = true
  492. }
  493. }
  494. resp := new(models.ArticleCollectionLIstResp)
  495. resp.List = list
  496. br.Ret = 200
  497. br.Success = true
  498. br.Msg = "获取成功"
  499. br.Data = resp
  500. }
  501. // @Title 热搜关键词
  502. // @Description 热搜关键词接口
  503. // @Success 200 {object} models.UserSearchKeyWordListResp
  504. // @router /hotKeyWord [get]
  505. func (this *ResearchController) HotKeyWord() {
  506. br := new(models.BaseResponse).Init()
  507. defer func() {
  508. this.Data["json"] = br
  509. this.ServeJSON()
  510. }()
  511. user := this.User
  512. if user == nil {
  513. br.Msg = "请重新登录"
  514. br.Ret = 408
  515. return
  516. }
  517. //本来应该放在config控制器下,与未上线的代码冲突,所以放在这里
  518. list, err := models.GetUserSearchKeyWord()
  519. if err != nil {
  520. br.Msg = "获取信息失败"
  521. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  522. return
  523. }
  524. resp := new(models.UserSearchKeyWordListResp)
  525. resp.List = list
  526. br.Ret = 200
  527. br.Success = true
  528. br.Msg = "获取成功"
  529. br.Data = resp
  530. }
  531. // @Title 研选文章类型列表
  532. // @Description 研选文章类型列表接口
  533. // @Success 200 {object} models.CygxArticleTypeListResp
  534. // @router /article/typeList [get]
  535. func (this *ResearchController) ArticleType() {
  536. br := new(models.BaseResponse).Init()
  537. defer func() {
  538. this.Data["json"] = br
  539. this.ServeJSON()
  540. }()
  541. user := this.User
  542. if user == nil {
  543. br.Msg = "请重新登录"
  544. br.Ret = 408
  545. return
  546. }
  547. var condition string
  548. condition = " AND is_show_yanx = 1 "
  549. list, err := models.GetCygxArticleTypeListCondition(condition)
  550. if err != nil {
  551. br.Msg = "获取信息失败"
  552. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  553. return
  554. }
  555. resp := new(models.CygxArticleTypeListResp)
  556. for _, v := range list {
  557. item := models.CygxArticleTypeResp{
  558. ArticleTypeId: v.ArticleTypeId,
  559. ArticleTypeName: v.ArticleTypeName,
  560. ButtonStyle: v.ButtonStyle,
  561. }
  562. resp.List = append(resp.List, &item)
  563. }
  564. br.Ret = 200
  565. br.Success = true
  566. br.Msg = "获取成功"
  567. br.Data = resp
  568. }
  569. // @Title 研选最新报告列表
  570. // @Description 研选最新报告列表接口
  571. // @Param PageSize query int true "每页数据条数"
  572. // @Param CurrentIndex query int true "当前页页码,从1开始"
  573. // @Param ArticleTypeIds query array true "文章类型ID多个用 , 隔开"
  574. // @Success 200 {object} models.IndustrialManagementNewList
  575. // @router /article/newList [get]
  576. func (this *ResearchController) ArticleNewList() {
  577. br := new(models.BaseResponse).Init()
  578. defer func() {
  579. this.Data["json"] = br
  580. this.ServeJSON()
  581. }()
  582. user := this.User
  583. if user == nil {
  584. br.Msg = "请重新登录"
  585. br.Ret = 408
  586. return
  587. }
  588. pageSize, _ := this.GetInt("PageSize")
  589. currentIndex, _ := this.GetInt("CurrentIndex")
  590. articleTypeIds := this.GetString("ArticleTypeIds")
  591. var startSize int
  592. if pageSize <= 0 {
  593. pageSize = utils.PageSize20
  594. }
  595. if currentIndex <= 0 {
  596. currentIndex = 1
  597. }
  598. startSize = paging.StartIndex(currentIndex, pageSize)
  599. var condition string
  600. var pars []interface{}
  601. condition = ` AND publish_status = 1 `
  602. if articleTypeIds == "" {
  603. var conditiontype string
  604. conditiontype = " AND is_show_yanx = 1 "
  605. listType, err := models.GetCygxArticleTypeListCondition(conditiontype)
  606. if err != nil {
  607. br.Msg = "获取信息失败"
  608. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  609. return
  610. }
  611. for _, v := range listType {
  612. articleTypeIds += strconv.Itoa(v.ArticleTypeId) + ","
  613. }
  614. articleTypeIds = strings.TrimRight(articleTypeIds, ",")
  615. }
  616. condition += ` AND a.article_type_id IN (` + articleTypeIds + `) `
  617. total, err := models.GetArticleResearchCount(condition, pars)
  618. if err != nil {
  619. br.Msg = "获取信息失败"
  620. br.ErrMsg = "GetArticleResearchCount,Err:" + err.Error()
  621. return
  622. }
  623. list, err := models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId)
  624. if err != nil {
  625. br.Msg = "获取信息失败"
  626. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  627. return
  628. }
  629. var articleIds []int
  630. for k, v := range list {
  631. if v.MyCollectNum > 0 {
  632. list[k].IsCollect = true
  633. }
  634. articleIds = append(articleIds, v.ArticleId)
  635. }
  636. //处理关联的产业
  637. industrialMap, err := services.GetArticleIndustrialByArticleId(articleIds)
  638. if err != nil {
  639. br.Msg = "获取信息失败"
  640. br.ErrMsg = "获取关联的产业信息失败,GetArticleIndustrialByArticleId Err:" + err.Error()
  641. return
  642. }
  643. for k, v := range list {
  644. if len(industrialMap[v.ArticleId]) > 0 {
  645. list[k].List = industrialMap[v.ArticleId]
  646. } else {
  647. list[k].List = make([]*models.IndustrialManagementResp, 0)
  648. }
  649. }
  650. //处理对应的文章类型标签按钮
  651. nameMap, styleMap, err := services.GetArticleTypeMap()
  652. if err != nil {
  653. br.Msg = "获取信息失败"
  654. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  655. return
  656. }
  657. page := paging.GetPaging(currentIndex, pageSize, total)
  658. resp := new(models.ArticleResearchListResp)
  659. for _, v := range list {
  660. item := models.ArticleResearchResp{
  661. ArticleId: v.ArticleId,
  662. Title: v.Title,
  663. PublishDate: v.PublishDate,
  664. DepartmentId: v.DepartmentId,
  665. NickName: v.NickName,
  666. IsCollect: v.IsCollect,
  667. Pv: v.Pv,
  668. CollectNum: v.CollectNum,
  669. ArticleTypeName: nameMap[v.ArticleTypeId],
  670. ButtonStyle: styleMap[v.ArticleTypeId],
  671. List: v.List,
  672. }
  673. resp.List = append(resp.List, &item)
  674. }
  675. resp.Paging = page
  676. br.Ret = 200
  677. br.Success = true
  678. br.Msg = "获取成功"
  679. br.Data = resp
  680. }