video.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package controllers
  2. import (
  3. "hongze/hongze_api/models"
  4. "hongze/hongze_api/utils"
  5. "rdluck_tools/paging"
  6. "time"
  7. )
  8. //视频
  9. type VideoController struct {
  10. BaseAuthController
  11. }
  12. // @Title 获取视频标签列表
  13. // @Description 获取视频标签列表接口
  14. // @Success 200 {object} video.VideoTagsListResp
  15. // @router /tags/list [get]
  16. func (this *VideoController) TagsList() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. user := this.User
  23. if user == nil {
  24. br.Msg = "请登录"
  25. br.ErrMsg = "请登录,用户信息为空"
  26. br.Ret = 408
  27. return
  28. }
  29. list, err := models.GetVideoTagsList()
  30. if err != nil {
  31. br.Msg = "获取失败"
  32. br.ErrMsg = "获取失败,Err:" + err.Error()
  33. return
  34. }
  35. resp := new(models.VideoTagsListResp)
  36. resp.List = list
  37. br.Ret = 200
  38. br.Success = true
  39. br.Msg = "获取成功"
  40. br.Data = resp
  41. }
  42. // @Title 视频列表
  43. // @Description 视频列表接口
  44. // @Param PageSize query int true "每页数据条数"
  45. // @Param CurrentIndex query int true "当前页页码,从1开始"
  46. // @Param KeyWord query string true "搜索关键词"
  47. // @Param Tags query string true "标签名称"
  48. // @Param DateType query string true "时间筛选组合:1:近一个月,2:近三个月,3:近半年,4:全部"
  49. // @Success 200 {object} video.VideoListResp
  50. // @router /list [get]
  51. func (this *VideoController) List() {
  52. br := new(models.BaseResponse).Init()
  53. defer func() {
  54. this.Data["json"] = br
  55. this.ServeJSON()
  56. }()
  57. user := this.User
  58. if user == nil {
  59. br.Msg = "请登录"
  60. br.ErrMsg = "请登录,用户信息为空"
  61. br.Ret = 408
  62. return
  63. }
  64. status := 0
  65. company, err := models.GetCompanyById(user.CompanyId)
  66. if err != nil {
  67. if err.Error() != utils.ErrNoRow() {
  68. br.Msg = "获取报告详情失败"
  69. br.ErrMsg = "获取用户管理企业信息失败,Err:" + err.Error()
  70. return
  71. } else {
  72. status = 1
  73. }
  74. }
  75. if company == nil {
  76. status = 1
  77. } else {
  78. if company.CompanyType == 3 || company.CompanyType == 4 {
  79. status = 1
  80. }
  81. }
  82. pageSize, _ := this.GetInt("PageSize")
  83. currentIndex, _ := this.GetInt("CurrentIndex")
  84. keyWord := this.GetString("KeyWord")
  85. tags := this.GetString("Tags")
  86. dateType, _ := this.GetInt("DateType")
  87. var startSize int
  88. if pageSize <= 0 {
  89. pageSize = utils.PageSize20
  90. }
  91. if currentIndex <= 0 {
  92. currentIndex = 1
  93. }
  94. startSize = paging.StartIndex(currentIndex, pageSize)
  95. var condition string
  96. var pars []interface{}
  97. if tags != "" {
  98. videoIdStr, err := models.GetVideoIdByKeyWord(keyWord)
  99. if err != nil {
  100. br.Msg = "获取失败"
  101. br.ErrMsg = "获取失败,Err:" + err.Error()
  102. return
  103. }
  104. if videoIdStr != "" {
  105. condition += ` AND a.video_id IN (` + videoIdStr + `) `
  106. }
  107. }
  108. if keyWord != "" {
  109. condition += ` AND (a.title LIKE '%` + keyWord + `%' ) `
  110. }
  111. publishDate := ""
  112. if dateType == 1 {
  113. publishDate = time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
  114. } else if dateType == 2 {
  115. publishDate = time.Now().AddDate(0, -3, 0).Format(utils.FormatDate)
  116. } else if dateType == 3 {
  117. publishDate = time.Now().AddDate(0, -6, 0).Format(utils.FormatDate)
  118. } else if dateType == 4 {
  119. publishDate = time.Now().AddDate(-100, 0, 0).Format(utils.FormatDate)
  120. }
  121. if publishDate != "" {
  122. condition += ` AND a.publish_time >=? `
  123. pars = append(pars, publishDate)
  124. }
  125. total := 0
  126. resp := new(models.VideoListResp)
  127. if status == 0 {
  128. total, err = models.GetVideoListCount(condition, pars)
  129. if err != nil {
  130. br.Msg = "获取失败"
  131. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  132. return
  133. }
  134. list, err := models.GetVideoList(condition, pars, startSize, pageSize)
  135. if err != nil {
  136. br.Msg = "获取失败"
  137. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  138. return
  139. }
  140. resp.List = list
  141. } else {
  142. list := make([]*models.VideoList, 0)
  143. resp.List = list
  144. }
  145. page := paging.GetPaging(currentIndex, pageSize, total)
  146. resp.Paging = page
  147. resp.Status = status
  148. br.Ret = 200
  149. br.Success = true
  150. br.Msg = "获取成功"
  151. br.Data = resp
  152. }