research.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package controllers
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/services"
  6. "hongze/hongze_clpt/utils"
  7. "strconv"
  8. "strings"
  9. )
  10. type MobileResearchController struct {
  11. BaseAuthMobileController
  12. }
  13. // @Title 研选文章类型列表
  14. // @Description 研选文章类型列表接口
  15. // @Success 200 {object} models.CygxArticleTypeListResp
  16. // @router /article/typeList [get]
  17. func (this *MobileResearchController) ArticleType() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. this.Data["json"] = br
  21. this.ServeJSON()
  22. }()
  23. user := this.User
  24. if user == nil {
  25. br.Msg = "请重新登录"
  26. br.Ret = 408
  27. return
  28. }
  29. var condition string
  30. condition = " AND is_show_yanx = 1 "
  31. list, err := models.GetCygxArticleTypeListCondition(condition)
  32. if err != nil {
  33. br.Msg = "获取信息失败"
  34. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  35. return
  36. }
  37. resp := new(models.CygxArticleTypeListResp)
  38. for _, v := range list {
  39. item := models.CygxArticleTypeResp{
  40. ArticleTypeId: v.ArticleTypeId,
  41. ArticleTypeName: v.ArticleTypeName,
  42. ButtonStyle: v.ButtonStyle,
  43. }
  44. resp.List = append(resp.List, &item)
  45. }
  46. br.Ret = 200
  47. br.Success = true
  48. br.Msg = "获取成功"
  49. br.Data = resp
  50. }
  51. // @Title 研选最新报告列表
  52. // @Description 研选最新报告列表接口
  53. // @Param PageSize query int true "每页数据条数"
  54. // @Param CurrentIndex query int true "当前页页码,从1开始"
  55. // @Param ArticleTypeIds query array true "文章类型ID多个用 , 隔开"
  56. // @Success 200 {object} models.IndustrialManagementNewList
  57. // @router /article/newList [get]
  58. func (this *MobileResearchController) ArticleNewList() {
  59. br := new(models.BaseResponse).Init()
  60. defer func() {
  61. this.Data["json"] = br
  62. this.ServeJSON()
  63. }()
  64. user := this.User
  65. if user == nil {
  66. br.Msg = "请重新登录"
  67. br.Ret = 408
  68. return
  69. }
  70. pageSize, _ := this.GetInt("PageSize")
  71. currentIndex, _ := this.GetInt("CurrentIndex")
  72. articleTypeIds := this.GetString("ArticleTypeIds")
  73. var startSize int
  74. if pageSize <= 0 {
  75. pageSize = utils.PageSize20
  76. }
  77. if currentIndex <= 0 {
  78. currentIndex = 1
  79. }
  80. startSize = paging.StartIndex(currentIndex, pageSize)
  81. var condition string
  82. var pars []interface{}
  83. condition = ` AND publish_status = 1 `
  84. if articleTypeIds == "" {
  85. var conditiontype string
  86. conditiontype = " AND is_show_yanx = 1 "
  87. listType, err := models.GetCygxArticleTypeListCondition(conditiontype)
  88. if err != nil {
  89. br.Msg = "获取信息失败"
  90. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  91. return
  92. }
  93. for _, v := range listType {
  94. articleTypeIds += strconv.Itoa(v.ArticleTypeId) + ","
  95. }
  96. articleTypeIds = strings.TrimRight(articleTypeIds, ",")
  97. }
  98. condition += ` AND a.article_type_id IN (` + articleTypeIds + `) `
  99. total, err := models.GetArticleResearchCount(condition, pars)
  100. if err != nil {
  101. br.Msg = "获取信息失败"
  102. br.ErrMsg = "GetArticleResearchCount,Err:" + err.Error()
  103. return
  104. }
  105. list, err := models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId)
  106. if err != nil {
  107. br.Msg = "获取信息失败"
  108. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  109. return
  110. }
  111. list, err = services.HandleArticleCategoryImg(list)
  112. if err != nil {
  113. br.Msg = "获取信息失败"
  114. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  115. return
  116. }
  117. //处理对应的文章类型标签按钮
  118. nameMap, styleMap, err := services.GetArticleTypeMap()
  119. if err != nil {
  120. br.Msg = "获取信息失败"
  121. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  122. return
  123. }
  124. page := paging.GetPaging(currentIndex, pageSize, total)
  125. resp := new(models.ArticleResearchListResp)
  126. for _, v := range list {
  127. item := models.ArticleResearchResp{
  128. ArticleId: v.ArticleId,
  129. ArticleTypeId: v.ArticleTypeId,
  130. Title: v.Title,
  131. PublishDate: v.PublishDate,
  132. DepartmentId: v.DepartmentId,
  133. NickName: v.NickName,
  134. IsCollect: v.IsCollect,
  135. Pv: v.Pv,
  136. CollectNum: v.CollectNum,
  137. Abstract: v.Abstract,
  138. Annotation: v.Annotation,
  139. ImgUrlPc: v.ImgUrlPc,
  140. ArticleTypeName: nameMap[v.ArticleTypeId],
  141. ButtonStyle: styleMap[v.ArticleTypeId],
  142. List: v.List,
  143. }
  144. resp.List = append(resp.List, &item)
  145. }
  146. resp.Paging = page
  147. br.Ret = 200
  148. br.Success = true
  149. br.Msg = "获取成功"
  150. br.Data = resp
  151. }