research.go 26 KB

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