model.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package yb_community_video
  2. import (
  3. "errors"
  4. "hongze/hongze_yb/global"
  5. "hongze/hongze_yb/utils"
  6. )
  7. func (item *YbCommunityVideo) Create() (err error) {
  8. err = global.DEFAULT_MYSQL.Create(item).Error
  9. return
  10. }
  11. func (item *YbCommunityVideo) Update(updateCols []string) (err error) {
  12. err = global.DEFAULT_MYSQL.Model(item).Select(updateCols).Updates(*item).Error
  13. return
  14. }
  15. // GetPageListByCondition 分页获取视频列表
  16. func GetPageListByCondition(where map[string]interface{}, pageIndex, pageSize int) (list []*YbCommunityVideo, err error) {
  17. cond, vals, e := utils.WhereBuild(where)
  18. if e != nil {
  19. err = errors.New("系统异常,生成查询语句失败")
  20. return
  21. }
  22. offset := (pageIndex - 1) * pageSize
  23. err = global.DEFAULT_MYSQL.Model(YbCommunityVideo{}).
  24. Where(cond, vals...).
  25. Where("is_deleted = 0 AND publish_state = 1").
  26. Offset(offset).Limit(pageSize).
  27. Order("publish_time DESC").Scan(&list).Error
  28. return
  29. }
  30. // GetItemById 主键获取已发布的视频
  31. func GetItemById(videoId int) (item *YbCommunityVideo, err error) {
  32. err = global.DEFAULT_MYSQL.Model(YbCommunityVideo{}).
  33. Where("community_video_id = ? AND is_deleted = 0 AND publish_state = 1", videoId).
  34. First(&item).Error
  35. return
  36. }
  37. // GetListByVideoIds 根据视频IDs获取列表
  38. func GetListByVideoIds(videoIds []int) (list []*YbCommunityVideo, err error) {
  39. var where string
  40. where = `publish_state = 1 AND is_deleted = 0`
  41. if len(videoIds) > 0 {
  42. where += ` AND community_video_id IN (?)`
  43. }
  44. err = global.DEFAULT_MYSQL.Model(YbCommunityVideo{}).
  45. Where(where, videoIds).
  46. Order("community_video_id asc").
  47. Scan(&list).Error
  48. return
  49. }