research.go 25 KB

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