research.go 26 KB

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