research.go 25 KB

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