research.go 26 KB

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