research.go 25 KB

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