research.go 25 KB

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