video.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type VideoTagsItems struct {
  7. TagsId int `description:"标签id"`
  8. TagsName string `description:"标签名称"`
  9. }
  10. type VideoTagsListResp struct {
  11. List []*VideoTagsItems
  12. }
  13. func GetVideoTagsList() (items []*VideoTagsItems, err error) {
  14. o := orm.NewOrmUsingDB("rddp")
  15. sql := `SELECT * FROM tags WHERE tags_type=1 ORDER BY sort ASC `
  16. _, err = o.Raw(sql).QueryRows(&items)
  17. return
  18. }
  19. type VideoList struct {
  20. VideoId int `description:"视频id"`
  21. Title string `description:"视频标题"`
  22. VideoUrl string `description:"视频地址"`
  23. VideoCoverUrl string `description:"视频封面地址"`
  24. Status int `description:"视频状态:0:未发布,1:已发布"`
  25. PublishTime string `description:"视频发布时间"`
  26. PlaySeconds uint32 `description:"视频播放时长"`
  27. CreateTime time.Time `description:"视频创建时间"`
  28. ModifyTime time.Time `description:"视频修改时间"`
  29. TagsName string `description:"标签名称"`
  30. }
  31. func GetVideoIdByKeyWord(tagName string) (video_id string, err error) {
  32. o := orm.NewOrmUsingDB("rddp")
  33. sql := ` SELECT GROUP_CONCAT(DISTINCT a.video_id) AS video_id FROM video_tags AS a
  34. INNER JOIN tags AS b ON a.tags_id=b.tags_id
  35. WHERE b.tags_name=? `
  36. err = o.Raw(sql, tagName).QueryRow(&video_id)
  37. return
  38. }
  39. func GetVideoListCount(condition string, pars []interface{}) (count int, err error) {
  40. o := orm.NewOrmUsingDB("rddp")
  41. sql := `SELECT COUNT(DISTINCT a.video_id) AS count
  42. FROM video AS a WHERE 1=1 `
  43. if condition != "" {
  44. sql += condition
  45. }
  46. err = o.Raw(sql, pars).QueryRow(&count)
  47. return
  48. }
  49. func GetVideoList(condition string, pars []interface{}, startSize, pageSize int) (items []*VideoList, err error) {
  50. o := orm.NewOrmUsingDB("rddp")
  51. sql := `SELECT a.*,GROUP_CONCAT(c.tags_name SEPARATOR '/') AS tags_name FROM video AS a
  52. INNER JOIN video_tags AS b ON a.video_id=b.video_id
  53. INNER JOIN tags AS c ON b.tags_id=c.tags_id
  54. WHERE 1=1 AND status=1 `
  55. if condition != "" {
  56. sql += condition
  57. }
  58. sql += ` GROUP BY a.video_id ORDER BY a.modify_time DESC LIMIT ?,? `
  59. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  60. return
  61. }
  62. type VideoListResp struct {
  63. List []*VideoList
  64. Status int `description:"权限状态:0:有权限,1:无权限"`
  65. }