research.go 25 KB

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