video.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. package controllers
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hongze_api/models"
  5. "hongze/hongze_api/utils"
  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 DateType query string true "时间筛选组合:1:近一个月,2:近三个月,3:近半年,4:全部"
  48. // @Param Tags query string true "标签名称"
  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. companyProduct, 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 len(companyProduct) == 0 {
  76. status = 1
  77. } else {
  78. status = 1
  79. for _, v := range companyProduct {
  80. if v.Status == utils.COMPANY_STATUS_TRY_OUT ||
  81. v.Status == utils.COMPANY_STATUS_FORMAL ||
  82. v.Status == utils.COMPANY_STATUS_FOREVER {
  83. status = 0
  84. break
  85. }
  86. }
  87. for _, v := range companyProduct {
  88. //如果产品类型是 ficc ,且当前产品状态是禁用状态, 且是当前产品状态是禁用的,那么是没有权限访问的
  89. if v.ProductId == 1 && v.IsSuspend > 0 && v.Status == utils.COMPANY_STATUS_TRY_OUT {
  90. status = 1
  91. break
  92. }
  93. }
  94. }
  95. pageSize, _ := this.GetInt("PageSize")
  96. currentIndex, _ := this.GetInt("CurrentIndex")
  97. keyWord := this.GetString("KeyWord")
  98. dateType, _ := this.GetInt("DateType")
  99. tags := this.GetString("Tags")
  100. var startSize int
  101. if pageSize <= 0 {
  102. pageSize = utils.PageSize20
  103. }
  104. if currentIndex <= 0 {
  105. currentIndex = 1
  106. }
  107. startSize = paging.StartIndex(currentIndex, pageSize)
  108. resp := new(models.VideoListResp)
  109. var condition string
  110. var pars []interface{}
  111. if keyWord != "" {
  112. videoIdStr, err := models.GetVideoIdByKeyWord(keyWord)
  113. if err != nil {
  114. br.Msg = "获取失败"
  115. br.ErrMsg = "获取失败,Err:" + err.Error()
  116. return
  117. }
  118. if videoIdStr != "" {
  119. condition += ` AND (a.video_id IN (` + videoIdStr + `) OR a.title LIKE '%` + keyWord + `%' ) `
  120. } else {
  121. condition += ` AND (a.title LIKE '%` + keyWord + `%' ) `
  122. }
  123. }
  124. if tags != "" {
  125. videoIdStr, err := models.GetVideoIdByKeyWord(tags)
  126. if err != nil {
  127. br.Msg = "获取失败"
  128. br.ErrMsg = "获取失败,Err:" + err.Error()
  129. return
  130. }
  131. if videoIdStr != "" {
  132. condition += ` AND a.video_id IN (` + videoIdStr + `) `
  133. } else {
  134. list := make([]*models.VideoList, 0)
  135. resp.List = list
  136. resp.Status = status
  137. br.Ret = 200
  138. br.Success = true
  139. br.Msg = "获取成功"
  140. br.Data = resp
  141. return
  142. }
  143. }
  144. publishDate := ""
  145. if dateType == 1 {
  146. publishDate = time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
  147. } else if dateType == 2 {
  148. publishDate = time.Now().AddDate(0, -3, 0).Format(utils.FormatDate)
  149. } else if dateType == 3 {
  150. publishDate = time.Now().AddDate(0, -6, 0).Format(utils.FormatDate)
  151. } else if dateType == 4 {
  152. publishDate = time.Now().AddDate(-100, 0, 0).Format(utils.FormatDate)
  153. }
  154. if publishDate != "" {
  155. condition += ` AND a.publish_time >=? `
  156. pars = append(pars, publishDate)
  157. }
  158. if status == 0 {
  159. list, err := models.GetVideoList(condition, pars, startSize, pageSize)
  160. if err != nil {
  161. br.Msg = "获取失败"
  162. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  163. return
  164. }
  165. if len(list) <= 0 {
  166. list := make([]*models.VideoList, 0)
  167. resp.List = list
  168. } else {
  169. resp.List = list
  170. }
  171. } else {
  172. list := make([]*models.VideoList, 0)
  173. resp.List = list
  174. }
  175. resp.Status = status
  176. br.Ret = 200
  177. br.Success = true
  178. br.Msg = "获取成功"
  179. br.Data = resp
  180. }