community_video_cover.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // CommunityVideoCover 视频社区封面库
  7. type CommunityVideoCover struct {
  8. CommunityVideoCoverId int `orm:"column(community_video_cover_id);pk" description:"封面ID"`
  9. CoverName string `description:"封面名称"`
  10. CoverUrl string `description:"封面图地址"`
  11. IsDeleted int `description:"是否已删除 0-否 1-是"`
  12. CreateTime time.Time `description:"创建时间"`
  13. ModifyTime time.Time `description:"修改时间"`
  14. DeleteTime time.Time `description:"删除时间"`
  15. Type int8 `description:"封面类型(1 视频社区,2 路演视频)"`
  16. }
  17. func (item *CommunityVideoCover) TableName() string {
  18. return "yb_community_video_cover"
  19. }
  20. func (item *CommunityVideoCover) Add() (lastId int64, err error) {
  21. o := orm.NewOrm()
  22. lastId, err = o.Insert(item)
  23. if err != nil {
  24. return
  25. }
  26. item.CommunityVideoCoverId = int(lastId)
  27. return
  28. }
  29. func (item *CommunityVideoCover) Update(cols []string) (err error) {
  30. o := orm.NewOrm()
  31. _, err = o.Update(item, cols...)
  32. return
  33. }
  34. // GetCommunityVideoCoverById 主键获取封面
  35. func GetCommunityVideoCoverById(coverId int) (item *CommunityVideoCover, err error) {
  36. o := orm.NewOrm()
  37. sql := `SELECT * FROM yb_community_video_cover WHERE community_video_cover_id = ? AND is_deleted = 0 LIMIT 1`
  38. err = o.Raw(sql, coverId).QueryRow(&item)
  39. return
  40. }
  41. // GetCommunityVideoCoverPageList 获取封面库分页列表
  42. func GetCommunityVideoCoverPageList(condition string, pars []interface{}, orderRule string, startSize, pageSize int) (total int, list []*CommunityVideoCover, err error) {
  43. o := orm.NewOrm()
  44. sql := `SELECT * FROM yb_community_video_cover WHERE is_deleted = 0 `
  45. sql += condition
  46. if orderRule == "" {
  47. orderRule = ` ORDER BY modify_time DESC`
  48. }
  49. sql += orderRule
  50. totalSQL := `SELECT COUNT(1) total FROM (` + sql + `) z`
  51. if err = o.Raw(totalSQL, pars).QueryRow(&total); err != nil {
  52. return
  53. }
  54. sql += ` LIMIT ?,?`
  55. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  56. return
  57. }
  58. // DeleteVideoCover 删除封面
  59. func DeleteVideoCover(coverId int) (err error) {
  60. o := orm.NewOrm()
  61. sql := `UPDATE yb_community_video_cover SET is_deleted = 1, delete_time = NOW() WHERE community_video_cover_id = ? LIMIT 1`
  62. _, err = o.Raw(sql, coverId).Exec()
  63. return
  64. }