research.go 24 KB

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