message.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package controllers
  2. import (
  3. "eta/eta_mini_crm_ht/models"
  4. "eta/eta_mini_crm_ht/models/response"
  5. "eta/eta_mini_crm_ht/utils"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "strings"
  8. )
  9. type MessageController struct {
  10. BaseAuthController
  11. }
  12. // ReportList
  13. // @Title 研报列表
  14. // @Description pdf研报列表
  15. // @Param PageSize query int true "每页数据条数"
  16. // @Param CurrentIndex query int true "当前页页码,从1开始"
  17. // @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
  18. // @Param KeyWord query string true "报告标题/创建人"
  19. // @Param SortType query string true "排序方式"
  20. // @Success 200 {object} models.ReportAuthorResp
  21. // @router /reportList [get]
  22. func (this *MessageController) ReportList() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. pageSize, _ := this.GetInt("PageSize")
  29. currentIndex, _ := this.GetInt("CurrentIndex")
  30. permissionIds := this.GetString("PermissionIds")
  31. analystNames := this.GetString("AnalystNames")
  32. sortType := this.GetString("SortType")
  33. var condition string
  34. var pars []interface{}
  35. if pageSize <= 0 {
  36. pageSize = utils.PageSize20
  37. }
  38. if currentIndex <= 0 {
  39. currentIndex = 1
  40. }
  41. if permissionIds != "" {
  42. permissionArr := strings.Split(permissionIds, ",")
  43. condition += " AND permission_id in (" + utils.GetOrmReplaceHolder(len(permissionArr)) + ")"
  44. pars = append(pars, permissionArr)
  45. }
  46. if analystNames != "" {
  47. analystNameArr := strings.Split(analystNames, ",")
  48. condition += " AND author in (" + utils.GetOrmReplaceHolder(len(analystNameArr)) + ")"
  49. pars = append(pars, analystNameArr)
  50. }
  51. sortCondition := " ORDER BY published_time "
  52. if sortType == "" {
  53. sortType = "DESC"
  54. }
  55. sortCondition = sortCondition + sortType
  56. total, err := models.GetReportCountByCondition(condition, pars)
  57. if err != nil {
  58. br.Msg = "获取研报列表失败"
  59. br.ErrMsg = "获取研报列表统计失败,Err:" + err.Error()
  60. return
  61. }
  62. startSize := utils.StartIndex(currentIndex, pageSize)
  63. reportList, err := models.GetReportByCondition(condition, sortCondition, pars, startSize, pageSize)
  64. if err != nil {
  65. br.Msg = "获取研报列表失败"
  66. br.ErrMsg = "获取研报列表失败,Err:" + err.Error()
  67. return
  68. }
  69. var reportViewList []*models.ReportView
  70. for _, report := range reportList {
  71. reportView := report.ToView()
  72. reportViewList = append(reportViewList, reportView)
  73. }
  74. page := paging.GetPaging(currentIndex, pageSize, total)
  75. resp := new(response.ReportListResp)
  76. resp.List = reportViewList
  77. resp.Paging = page
  78. br.Ret = 200
  79. br.Success = true
  80. br.Data = resp
  81. br.Msg = "获取成功"
  82. }
  83. // AudioList
  84. // @Title 研报列表
  85. // @Description pdf研报列表
  86. // @Param PageSize query int true "每页数据条数"
  87. // @Param CurrentIndex query int true "当前页页码,从1开始"
  88. // @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
  89. // @Param KeyWord query string true "报告标题/创建人"
  90. // @Param SortType query string true "排序方式"
  91. // @Success 200 {object} models.ReportAuthorResp
  92. // @router /audioList [get]
  93. func (this *MessageController) AudioList() {
  94. br := new(models.BaseResponse).Init()
  95. defer func() {
  96. this.Data["json"] = br
  97. this.ServeJSON()
  98. }()
  99. pageSize, _ := this.GetInt("PageSize")
  100. currentIndex, _ := this.GetInt("CurrentIndex")
  101. permissionIds := this.GetString("PermissionIds")
  102. analystNames := this.GetString("AnalystNames")
  103. sortType := this.GetString("SortType")
  104. var condition string
  105. var pars []interface{}
  106. if pageSize <= 0 {
  107. pageSize = utils.PageSize20
  108. }
  109. if currentIndex <= 0 {
  110. currentIndex = 1
  111. }
  112. if permissionIds != "" {
  113. permissionArr := strings.Split(permissionIds, ",")
  114. condition += " AND permission_id in (" + utils.GetOrmReplaceHolder(len(permissionArr)) + ")"
  115. pars = append(pars, permissionArr)
  116. }
  117. if analystNames != "" {
  118. analystNameArr := strings.Split(analystNames, ",")
  119. condition += " AND author in (" + utils.GetOrmReplaceHolder(len(analystNameArr)) + ")"
  120. pars = append(pars, analystNameArr)
  121. }
  122. sortCondition := " ORDER BY published_time "
  123. if sortType == "" {
  124. sortType = "DESC"
  125. }
  126. sortCondition = sortCondition + sortType
  127. total, err := models.GetReportCountByCondition(condition, pars)
  128. if err != nil {
  129. br.Msg = "获取研报列表失败"
  130. br.ErrMsg = "获取研报列表统计失败,Err:" + err.Error()
  131. return
  132. }
  133. startSize := utils.StartIndex(currentIndex, pageSize)
  134. reportList, err := models.GetReportByCondition(condition, sortCondition, pars, startSize, pageSize)
  135. if err != nil {
  136. br.Msg = "获取研报列表失败"
  137. br.ErrMsg = "获取研报列表失败,Err:" + err.Error()
  138. return
  139. }
  140. var reportViewList []*models.ReportView
  141. for _, report := range reportList {
  142. reportView := report.ToView()
  143. reportViewList = append(reportViewList, reportView)
  144. }
  145. page := paging.GetPaging(currentIndex, pageSize, total)
  146. resp := new(response.ReportListResp)
  147. resp.List = reportViewList
  148. resp.Paging = page
  149. br.Ret = 200
  150. br.Success = true
  151. br.Data = resp
  152. br.Msg = "获取成功"
  153. }