message.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. "strconv"
  8. "strings"
  9. )
  10. type MessageController struct {
  11. BaseAuthController
  12. }
  13. // ReportList
  14. // @Title 研报列表
  15. // @Description pdf研报列表
  16. // @Param PageSize query int true "每页数据条数"
  17. // @Param CurrentIndex query int true "当前页页码,从1开始"
  18. // @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
  19. // @Param KeyWord query string true "报告标题/创建人"
  20. // @Param SortType query string true "排序方式"
  21. // @Success 200 {object} models.ReportAuthorResp
  22. // @router /reportList [get]
  23. func (this *MessageController) ReportList() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. pageSize, _ := this.GetInt("PageSize")
  30. currentIndex, _ := this.GetInt("CurrentIndex")
  31. permissionIds := this.GetString("PermissionIds")
  32. analystNames := this.GetString("AnalystNames")
  33. sortType := this.GetString("SortType")
  34. var permissionCondition string
  35. var condition string
  36. var pars []interface{}
  37. if pageSize <= 0 {
  38. pageSize = utils.PageSize20
  39. }
  40. if currentIndex <= 0 {
  41. currentIndex = 1
  42. }
  43. if permissionIds != "" {
  44. permissionArr := strings.Split(permissionIds, ",")
  45. permissionCondition += "permission_id in (" + utils.GetOrmReplaceHolder(len(permissionArr)) + ")"
  46. pars = append(pars, permissionArr)
  47. }
  48. if analystNames != "" {
  49. analystNameArr := strings.Split(analystNames, ",")
  50. condition += " AND author in (" + utils.GetOrmReplaceHolder(len(analystNameArr)) + ")"
  51. pars = append(pars, analystNameArr)
  52. }
  53. sortCondition := " ORDER BY published_time "
  54. if sortType == "" {
  55. sortType = "DESC"
  56. }
  57. sortCondition = sortCondition + sortType
  58. total, err := models.GetReportCountByCondition(condition, pars)
  59. if err != nil {
  60. br.Msg = "获取音频列表失败"
  61. br.ErrMsg = "获取音频列表统计失败,Err:" + err.Error()
  62. return
  63. }
  64. startSize := utils.StartIndex(currentIndex, pageSize)
  65. reportList, err := models.GetReportByCondition(condition, sortCondition, pars, startSize, pageSize)
  66. if err != nil {
  67. br.Msg = "获取研报列表失败"
  68. br.ErrMsg = "获取研报列表失败,Err:" + err.Error()
  69. return
  70. }
  71. var reportViewList []*models.ReportView
  72. for _, report := range reportList {
  73. reportView := report.ToView()
  74. reportViewList = append(reportViewList, reportView)
  75. }
  76. page := paging.GetPaging(currentIndex, pageSize, total)
  77. resp := new(response.ReportListResp)
  78. resp.List = reportViewList
  79. resp.Paging = page
  80. br.Ret = 200
  81. br.Success = true
  82. br.Data = resp
  83. br.Msg = "获取成功"
  84. }
  85. // AudioList
  86. // @Title 研报列表
  87. // @Description pdf研报列表
  88. // @Param PageSize query int true "每页数据条数"
  89. // @Param CurrentIndex query int true "当前页页码,从1开始"
  90. // @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
  91. // @Param KeyWord query string true "报告标题/创建人"
  92. // @Param SortType query string true "排序方式"
  93. // @Success 200 {object} models.ReportAuthorResp
  94. // @router /audioList [get]
  95. func (this *MessageController) AudioList() {
  96. br := new(models.BaseResponse).Init()
  97. defer func() {
  98. this.Data["json"] = br
  99. this.ServeJSON()
  100. }()
  101. pageSize, _ := this.GetInt("PageSize")
  102. currentIndex, _ := this.GetInt("CurrentIndex")
  103. permissionIds := this.GetString("PermissionIds")
  104. analystIds := this.GetString("AnalystIds")
  105. sortType := this.GetString("SortType")
  106. var permissionCondition string
  107. var condition string
  108. var pars []interface{}
  109. if pageSize <= 0 {
  110. pageSize = utils.PageSize20
  111. }
  112. if currentIndex <= 0 {
  113. currentIndex = 1
  114. }
  115. var permissionPars []interface{}
  116. if permissionIds != "" {
  117. permissionArr := strings.Split(permissionIds, ",")
  118. for _, permissionId := range permissionArr {
  119. perId, _ := strconv.Atoi(permissionId)
  120. permissionPars = append(permissionPars, perId)
  121. }
  122. permissionCondition += " AND permission_id in (" + utils.GetOrmReplaceHolder(len(permissionPars)) + ")"
  123. ids, err := models.GetMappingsByCondition(permissionCondition, permissionPars)
  124. if err != nil {
  125. condition += " AND id in (" + utils.GetOrmReplaceHolder(len(ids)) + ")"
  126. pars = append(pars, ids)
  127. }
  128. }
  129. if analystIds != "" {
  130. analystIdArr := strings.Split(analystIds, ",")
  131. var authorIds []int
  132. for _, analystId := range analystIdArr {
  133. id, _ := strconv.Atoi(analystId)
  134. authorIds = append(authorIds, id)
  135. }
  136. condition += " AND author_id in (" + utils.GetOrmReplaceHolder(len(authorIds)) + ")"
  137. pars = append(pars, authorIds)
  138. }
  139. sortCondition := " ORDER BY published_time "
  140. if sortType == "" {
  141. sortType = "DESC"
  142. }
  143. sortCondition = sortCondition + sortType
  144. total, err := models.GetMediaCountByCondition(models.Audio, condition, pars)
  145. if err != nil {
  146. br.Msg = "获取研报列表失败"
  147. br.ErrMsg = "获取研报列表统计失败,Err:" + err.Error()
  148. return
  149. }
  150. startSize := utils.StartIndex(currentIndex, pageSize)
  151. reportList, err := models.GetMediaByCondition(models.Audio, condition, sortCondition, pars, startSize, pageSize)
  152. if err != nil {
  153. br.Msg = "获取研报列表失败"
  154. br.ErrMsg = "获取研报列表失败,Err:" + err.Error()
  155. return
  156. }
  157. var reportViewList []*models.ESMedia
  158. for _, report := range reportList {
  159. reportView := report.ToView()
  160. reportViewList = append(reportViewList, reportView)
  161. }
  162. page := paging.GetPaging(currentIndex, pageSize, total)
  163. resp := new(response.MediaListResp)
  164. resp.List = reportViewList
  165. resp.Paging = page
  166. br.Ret = 200
  167. br.Success = true
  168. br.Data = resp
  169. br.Msg = "获取成功"
  170. }
  171. // VideoList
  172. // @Title 研报列表
  173. // @Description pdf研报列表
  174. // @Param PageSize query int true "每页数据条数"
  175. // @Param CurrentIndex query int true "当前页页码,从1开始"
  176. // @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
  177. // @Param KeyWord query string true "报告标题/创建人"
  178. // @Param SortType query string true "排序方式"
  179. // @Success 200 {object} models.ReportAuthorResp
  180. // @router /videoList [get]
  181. func (this *MessageController) VideoList() {
  182. br := new(models.BaseResponse).Init()
  183. defer func() {
  184. this.Data["json"] = br
  185. this.ServeJSON()
  186. }()
  187. pageSize, _ := this.GetInt("PageSize")
  188. currentIndex, _ := this.GetInt("CurrentIndex")
  189. permissionIds := this.GetString("PermissionIds")
  190. analystIds := this.GetString("AnalystIds")
  191. sortType := this.GetString("SortType")
  192. var permissionCondition string
  193. var condition string
  194. var pars []interface{}
  195. if pageSize <= 0 {
  196. pageSize = utils.PageSize20
  197. }
  198. if currentIndex <= 0 {
  199. currentIndex = 1
  200. }
  201. var permissionPars []interface{}
  202. if permissionIds != "" {
  203. permissionArr := strings.Split(permissionIds, ",")
  204. for _, permissionId := range permissionArr {
  205. perId, _ := strconv.Atoi(permissionId)
  206. permissionPars = append(permissionPars, perId)
  207. }
  208. permissionCondition += " AND permission_id in (" + utils.GetOrmReplaceHolder(len(permissionPars)) + ")"
  209. ids, err := models.GetMappingsByCondition(permissionCondition, permissionPars)
  210. if err != nil {
  211. condition += " AND id in (" + utils.GetOrmReplaceHolder(len(ids)) + ")"
  212. pars = append(pars, ids)
  213. }
  214. }
  215. if analystIds != "" {
  216. analystIdArr := strings.Split(analystIds, ",")
  217. var authorIds []int
  218. for _, analystId := range analystIdArr {
  219. id, _ := strconv.Atoi(analystId)
  220. authorIds = append(authorIds, id)
  221. }
  222. condition += " AND author_id in (" + utils.GetOrmReplaceHolder(len(authorIds)) + ")"
  223. pars = append(pars, authorIds)
  224. }
  225. sortCondition := " ORDER BY published_time "
  226. if sortType == "" {
  227. sortType = "DESC"
  228. }
  229. sortCondition = sortCondition + sortType
  230. total, err := models.GetMediaCountByCondition(models.Video, condition, pars)
  231. if err != nil {
  232. br.Msg = "获取研报列表失败"
  233. br.ErrMsg = "获取研报列表统计失败,Err:" + err.Error()
  234. return
  235. }
  236. startSize := utils.StartIndex(currentIndex, pageSize)
  237. List, err := models.GetMediaByCondition(models.Video, condition, sortCondition, pars, startSize, pageSize)
  238. if err != nil {
  239. br.Msg = "获取研报列表失败"
  240. br.ErrMsg = "获取研报列表失败,Err:" + err.Error()
  241. return
  242. }
  243. var reportViewList []*models.ESMedia
  244. for _, report := range List {
  245. reportView := report.ToView()
  246. reportViewList = append(reportViewList, reportView)
  247. }
  248. page := paging.GetPaging(currentIndex, pageSize, total)
  249. resp := new(response.MediaListResp)
  250. resp.List = reportViewList
  251. resp.Paging = page
  252. br.Ret = 200
  253. br.Success = true
  254. br.Data = resp
  255. br.Msg = "获取成功"
  256. }