message.go 9.9 KB

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