research.go 24 KB

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