research.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  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. followTypeMap := services.GetCygxIndustryFllowListTypeMapByMobile(user.Mobile) // 关注的对应状态
  356. listSubjcet, err := models.GetThemeHeatSubjectList(condition)
  357. if err != nil {
  358. br.Msg = "获取信息失败"
  359. br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
  360. return
  361. }
  362. mapHot := make(map[int]bool)
  363. mapNew, err := services.GetYanXuanIndustrialManagementIdNewMap(articleTypeIds)
  364. if err != nil {
  365. br.Msg = "获取信息失败"
  366. br.ErrMsg = "GetYanXuanIndustrialManagementIdNewMap,Err:" + err.Error()
  367. return
  368. }
  369. //if themeType == 2 {
  370. mapHot, err = services.GetYanXuanIndustrialManagementIdHotMap(articleTypeIds)
  371. if err != nil {
  372. br.Msg = "获取信息失败"
  373. br.ErrMsg = "GetYanXuanIndustrialManagementIdNewMap,Err:" + err.Error()
  374. return
  375. }
  376. //}
  377. for k, v := range list {
  378. list[k].IsNew = mapNew[v.IndustrialManagementId]
  379. list[k].IsHot = mapHot[v.IndustrialManagementId]
  380. list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  381. if v.FllowNum > 0 {
  382. list[k].IsFollow = true
  383. }
  384. list[k].FollowType = followTypeMap[v.IndustrialManagementId]
  385. for _, v2 := range listSubjcet {
  386. if v2.IndustrialManagementId == v.IndustrialManagementId {
  387. list[k].IndustrialSubjectList = append(list[k].IndustrialSubjectList, v2)
  388. }
  389. }
  390. }
  391. page := paging.GetPaging(currentIndex, pageSize, total)
  392. resp := new(models.IndustrialManagementHotListResp)
  393. resp.Paging = page
  394. resp.List = list
  395. br.Ret = 200
  396. br.Success = true
  397. br.Msg = "获取成功"
  398. br.Data = resp
  399. }
  400. // @Title 主题详情
  401. // @Description 主题详情接口
  402. // @Param IndustrialManagementId query int true "分类ID"
  403. // @Success 200 {object} models.GetThemeDetailResp
  404. // @router /theme/detail [get]
  405. func (this *MobileResearchController) ThemeDetail() {
  406. br := new(models.BaseResponse).Init()
  407. defer func() {
  408. this.Data["json"] = br
  409. this.ServeJSON()
  410. }()
  411. user := this.User
  412. if user == nil {
  413. br.Msg = "请重新登录"
  414. br.Ret = 408
  415. return
  416. }
  417. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  418. if industrialManagementId < 1 {
  419. br.Msg = "请输入产业ID"
  420. return
  421. }
  422. detailIndustrial, err := models.GetIndustrialManagementDetail(industrialManagementId)
  423. if err != nil {
  424. br.Msg = "获取信息失败"
  425. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  426. return
  427. }
  428. var condition string
  429. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  430. if err != nil {
  431. br.Msg = "获取信息失败"
  432. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  433. return
  434. }
  435. if articleTypeIds != "" {
  436. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  437. } else {
  438. br.Msg = "获取信息失败"
  439. br.ErrMsg = "研选分类ID不能为空"
  440. return
  441. }
  442. resp := new(models.GetThemeDetailResp)
  443. list, err := models.GetThemeDetail(user.UserId, industrialManagementId, condition)
  444. if err != nil {
  445. br.Msg = "获取信息失败"
  446. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  447. return
  448. }
  449. list, err = services.HandleArticleCategoryImg(list, user)
  450. if err != nil {
  451. br.Msg = "获取信息失败"
  452. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  453. return
  454. }
  455. //处理对应的文章类型标签按钮
  456. nameMap, styleMap, err := services.GetArticleTypeMap()
  457. if err != nil {
  458. br.Msg = "获取信息失败"
  459. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  460. return
  461. }
  462. var articleIds []int
  463. for _, v := range list {
  464. item := models.ArticleResearchResp{
  465. ArticleId: v.ArticleId,
  466. ArticleTypeId: v.ArticleTypeId,
  467. Title: v.Title,
  468. PublishDate: v.PublishDate,
  469. DepartmentId: v.DepartmentId,
  470. NickName: v.NickName,
  471. IsCollect: v.IsCollect,
  472. Pv: v.Pv,
  473. CollectNum: v.CollectNum,
  474. Abstract: v.Abstract,
  475. Annotation: v.Annotation,
  476. ImgUrlPc: v.ImgUrlPc,
  477. ArticleTypeName: nameMap[v.ArticleTypeId],
  478. ButtonStyle: styleMap[v.ArticleTypeId],
  479. List: v.List,
  480. }
  481. if item.ArticleTypeName == "纪要" || item.ArticleTypeName == "沙龙" || item.ArticleTypeName == "专家访谈" {
  482. item.Annotation = "核心结论:" + item.Annotation
  483. } else {
  484. item.Annotation = "核心观点:" + item.Annotation
  485. }
  486. resp.List = append(resp.List, &item)
  487. articleIds = append(articleIds, v.ArticleId)
  488. }
  489. //处理用户数是否关注该产业
  490. userFollowIndustrialMap, err := services.GetUserFollowIndustrialMap(user)
  491. if err != nil {
  492. br.Msg = "获取信息失败"
  493. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  494. return
  495. }
  496. if _, ok := userFollowIndustrialMap[industrialManagementId]; ok {
  497. resp.IsFollow = true
  498. }
  499. listSub, err := models.GetcygxIndustrialSubject(industrialManagementId)
  500. if err != nil {
  501. br.Msg = "获取信息失败"
  502. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  503. return
  504. }
  505. //处理文章关联的标的
  506. articleGroupSubjectMap, subjectMap, err := services.GetArticleGroupSubjectMap(articleIds)
  507. if err != nil {
  508. br.Msg = "获取信息失败"
  509. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  510. return
  511. }
  512. if len(articleGroupSubjectMap) > 0 {
  513. for k, v := range resp.List {
  514. resp.List[k].ListSubject = articleGroupSubjectMap[v.ArticleId]
  515. }
  516. }
  517. for _, v := range listSub {
  518. itemSubJect := new(models.IndustrialSubject)
  519. itemSubJect.SubjectName = v.SubjectName
  520. itemSubJect.IndustrialSubjectId = v.IndustrialSubjectId
  521. if subjectMap[v.IndustrialSubjectId] != "" {
  522. resp.ListSubject = append(resp.ListSubject, itemSubJect)
  523. }
  524. }
  525. resp.IndustryName = detailIndustrial.IndustryName
  526. resp.IndustrialManagementId = detailIndustrial.IndustrialManagementId
  527. br.Ret = 200
  528. br.Success = true
  529. br.Msg = "获取成功"
  530. br.Data = resp
  531. }
  532. // @Title 研选作者详情
  533. // @Description 研选作者详情接口
  534. // @Param DepartmentId query int true "作者ID"
  535. // @Success 200 {object} models.DepartmentDetailResp
  536. // @router /departmentId/detail [get]
  537. func (this *MobileResearchController) DepartmentIdDetail() {
  538. br := new(models.BaseResponse).Init()
  539. defer func() {
  540. this.Data["json"] = br
  541. this.ServeJSON()
  542. }()
  543. user := this.User
  544. if user == nil {
  545. br.Msg = "请重新登录"
  546. br.Ret = 408
  547. return
  548. }
  549. pageSize, _ := this.GetInt("PageSize")
  550. currentIndex, _ := this.GetInt("CurrentIndex")
  551. var startSize int
  552. if pageSize <= 0 {
  553. pageSize = utils.PageSize20
  554. }
  555. if currentIndex <= 0 {
  556. currentIndex = 1
  557. }
  558. startSize = paging.StartIndex(currentIndex, pageSize)
  559. departmentId, _ := this.GetInt("DepartmentId")
  560. if departmentId < 1 {
  561. br.Msg = "请输入作者ID"
  562. return
  563. }
  564. var condition string
  565. var pars []interface{}
  566. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  567. if err != nil {
  568. br.Msg = "获取信息失败"
  569. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  570. return
  571. }
  572. needYanxuanSpecial := true
  573. if articleTypeIds != "" && !strings.Contains(articleTypeIds, "999") {
  574. needYanxuanSpecial = false
  575. }
  576. //只勾选了研选专栏时去掉文章的统计
  577. if articleTypeIds == "999" {
  578. condition += ` AND 1<0 `
  579. }
  580. if articleTypeIds != "" {
  581. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  582. } else {
  583. br.Msg = "获取信息失败"
  584. br.ErrMsg = "研选分类ID不能为空"
  585. return
  586. }
  587. resp := new(models.DepartmentDetailResp)
  588. detail, err := models.GetDepartmentDetail(user.UserId, departmentId, condition)
  589. if err != nil {
  590. br.Msg = "获取信息失败"
  591. br.ErrMsg = "获取作者信息失败,Err:" + err.Error()
  592. return
  593. }
  594. resp.DepartmentId = detail.DepartmentId
  595. resp.NickName = detail.NickName
  596. resp.ImgUrl = detail.ImgUrl
  597. resp.FllowNum = detail.FllowNum
  598. resp.ArticleNum = detail.ArticleNum
  599. resp.CollectNum = detail.CollectNum
  600. if detail.MyFllowNum > 0 {
  601. resp.IsFollow = true
  602. }
  603. condition += ` AND a.department_id = ` + strconv.Itoa(departmentId)
  604. total, err := models.GetArticleResearchCount(condition, pars, needYanxuanSpecial)
  605. if err != nil {
  606. br.Msg = "获取信息失败"
  607. br.ErrMsg = "GetArticleResearchCount,Err:" + err.Error()
  608. return
  609. }
  610. list, err := models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId, needYanxuanSpecial)
  611. if err != nil {
  612. br.Msg = "获取信息失败"
  613. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  614. return
  615. }
  616. list, err = services.HandleArticleCategoryImg(list, user)
  617. if err != nil {
  618. br.Msg = "获取信息失败"
  619. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  620. return
  621. }
  622. //处理对应的文章类型标签按钮
  623. nameMap, styleMap, err := services.GetArticleTypeMap()
  624. if err != nil {
  625. br.Msg = "获取信息失败"
  626. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  627. return
  628. }
  629. //resp := new(models.ArticleResearchListResp)
  630. for _, v := range list {
  631. item := models.ArticleResearchResp{
  632. ArticleId: v.ArticleId,
  633. ArticleTypeId: v.ArticleTypeId,
  634. Title: v.Title,
  635. PublishDate: v.PublishDate,
  636. DepartmentId: v.DepartmentId,
  637. NickName: v.NickName,
  638. IsCollect: v.IsCollect,
  639. Pv: v.Pv,
  640. CollectNum: v.CollectNum,
  641. Abstract: v.Abstract,
  642. Annotation: v.Annotation,
  643. ImgUrlPc: v.ImgUrlPc,
  644. ArticleTypeName: nameMap[v.ArticleTypeId],
  645. ButtonStyle: styleMap[v.ArticleTypeId],
  646. List: v.List,
  647. }
  648. if item.ArticleTypeName == "纪要" || item.ArticleTypeName == "沙龙" || item.ArticleTypeName == "专家访谈" {
  649. item.Annotation = "核心结论:" + item.Annotation
  650. } else {
  651. item.Annotation = "核心观点:" + item.Annotation
  652. }
  653. resp.List = append(resp.List, &item)
  654. }
  655. condition = ` AND a.department_id = ` + strconv.Itoa(departmentId)
  656. listIndustrial, err := models.GetIndustrialManagementNewList(condition)
  657. if err != nil {
  658. br.Msg = "获取信息失败"
  659. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  660. return
  661. }
  662. page := paging.GetPaging(currentIndex, pageSize, total)
  663. resp.ListIndustrial = listIndustrial
  664. resp.Paging = page
  665. br.Ret = 200
  666. br.Success = true
  667. br.Msg = "获取成功"
  668. br.Data = resp
  669. }
  670. // @Title 关注作者/取消关注作者
  671. // @Description 关注作者/取消关注作者 接口
  672. // @Param request body models.CygxArticleDepartmentId true "type json string"
  673. // @Success 200
  674. // @router /fllowDepartment [post]
  675. func (this *MobileResearchController) FllowDepartment() {
  676. br := new(models.BaseResponse).Init()
  677. defer func() {
  678. this.Data["json"] = br
  679. this.ServeJSON()
  680. }()
  681. user := this.User
  682. if user == nil {
  683. br.Msg = "请重新登录"
  684. br.Ret = 408
  685. return
  686. }
  687. uid := user.UserId
  688. var req models.CygxArticleDepartmentId
  689. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  690. if err != nil {
  691. br.Msg = "参数解析异常!"
  692. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  693. return
  694. }
  695. departmentId := req.DepartmentId
  696. var condition string
  697. countDepartment, err := models.GetDepartmentCount(departmentId)
  698. if err != nil {
  699. br.Msg = "获取数据失败!"
  700. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  701. return
  702. }
  703. if countDepartment == 0 {
  704. br.Msg = "作者不存在!"
  705. br.ErrMsg = "作者ID不存在:" + strconv.Itoa(departmentId)
  706. return
  707. }
  708. countUser, err := models.GetArticleDepartmentFollowByUid(uid)
  709. count, err := models.GetArticleDepartmentFollow(uid, departmentId, condition)
  710. if err != nil {
  711. br.Msg = "获取数据失败!"
  712. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  713. return
  714. }
  715. resp := new(models.CygxArticleDepartmentFollowResp)
  716. if countUser == 0 {
  717. resp.GoFollow = true
  718. }
  719. if count == 0 {
  720. item := new(models.CygxArticleDepartmentFollow)
  721. item.DepartmentId = departmentId
  722. item.UserId = uid
  723. item.Email = user.Email
  724. item.Mobile = user.Mobile
  725. item.RealName = user.RealName
  726. item.CompanyId = user.CompanyId
  727. item.CompanyName = user.CompanyName
  728. item.Type = 1
  729. item.CreateTime = time.Now()
  730. item.ModifyTime = time.Now()
  731. _, err = models.AddArticleDepartmentFollow(item)
  732. if err != nil {
  733. br.Msg = "操作失败"
  734. br.ErrMsg = "操作失败,Err:" + err.Error()
  735. return
  736. }
  737. resp.Status = 1
  738. } else {
  739. var doType int
  740. condition = ` AND type = 1`
  741. count, err = models.GetArticleDepartmentFollow(uid, departmentId, condition)
  742. if err != nil {
  743. br.Msg = "操作失败!"
  744. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  745. return
  746. }
  747. if count == 1 {
  748. resp.Status = 2
  749. doType = 2
  750. } else {
  751. resp.Status = 1
  752. doType = 1
  753. }
  754. err = models.RemoveArticleDepartmentFollow(uid, departmentId, doType)
  755. if err != nil {
  756. br.Msg = "操作失败"
  757. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  758. return
  759. }
  760. }
  761. br.Msg = "操作成功"
  762. br.Ret = 200
  763. br.Success = true
  764. br.Data = resp
  765. }
  766. // @Title 研选月度收藏榜
  767. // @Description 研选月度收藏榜接口
  768. // @Param PageSize query int true "每页数据条数"
  769. // @Success 200 {object} models.ReportBillboardListResp
  770. // @router /article/billboard [get]
  771. func (this *MobileResearchController) Billboard() {
  772. br := new(models.BaseResponse).Init()
  773. defer func() {
  774. this.Data["json"] = br
  775. this.ServeJSON()
  776. }()
  777. user := this.User
  778. if user == nil {
  779. br.Msg = "请重新登录"
  780. br.Ret = 408
  781. return
  782. }
  783. pageSize, _ := this.GetInt("PageSize", 15)
  784. var condition string
  785. var pars []interface{}
  786. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  787. if err != nil {
  788. br.Msg = "获取信息失败"
  789. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  790. return
  791. }
  792. if articleTypeIds != "" {
  793. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  794. } else {
  795. br.Msg = "获取信息失败"
  796. br.ErrMsg = "研选分类ID不能为空"
  797. return
  798. }
  799. // 根据关注时间一个月前至昨日的增量数据排序
  800. nowTime := time.Now().Local()
  801. startTime := nowTime.AddDate(0, -1, 0)
  802. endTime := nowTime.AddDate(0, 0, -1)
  803. condition += ` AND ac.create_time BETWEEN ? AND ?`
  804. pars = append(pars, startTime, endTime)
  805. list, err := models.GetReportCollectionBillboardListYx(pageSize, pars, condition)
  806. if err != nil {
  807. br.Msg = "获取失败"
  808. br.ErrMsg = "获取报告阅读增量排行榜失败, Err:" + err.Error()
  809. return
  810. }
  811. list, err = services.HandleArticleCategoryImg(list, user)
  812. if err != nil {
  813. br.Msg = "获取信息失败"
  814. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  815. return
  816. }
  817. //处理对应的文章类型标签按钮
  818. nameMap, styleMap, err := services.GetArticleTypeMap()
  819. if err != nil {
  820. br.Msg = "获取信息失败"
  821. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  822. return
  823. }
  824. resp := new(models.ArticleResearchListResp)
  825. for _, v := range list {
  826. item := models.ArticleResearchResp{
  827. ArticleId: v.ArticleId,
  828. ArticleTypeId: v.ArticleTypeId,
  829. Title: v.Title,
  830. PublishDate: v.PublishDate,
  831. DepartmentId: v.DepartmentId,
  832. NickName: v.NickName,
  833. IsCollect: v.IsCollect,
  834. Pv: v.Pv,
  835. CollectNum: v.CollectNum,
  836. Abstract: v.Abstract,
  837. Annotation: v.Annotation,
  838. ImgUrlPc: v.ImgUrlPc,
  839. ArticleTypeName: nameMap[v.ArticleTypeId],
  840. ButtonStyle: styleMap[v.ArticleTypeId],
  841. List: v.List,
  842. }
  843. resp.List = append(resp.List, &item)
  844. }
  845. br.Ret = 200
  846. br.Success = true
  847. br.Msg = "获取成功"
  848. br.Data = resp
  849. }