research.go 26 KB

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