research.go 25 KB

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