model.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package yb_road_video
  2. import (
  3. "hongze/hongze_yb/global"
  4. )
  5. func (r *YbRoadVideo) Create() (err error) {
  6. err = global.DEFAULT_MYSQL.Create(r).Error
  7. return
  8. }
  9. func (r *YbRoadVideo) Update(updateCols []string) (err error) {
  10. err = global.DEFAULT_MYSQL.Model(r).Select(updateCols).Updates(*r).Error
  11. return
  12. }
  13. // GetPageListByCondition 分页获取视频列表
  14. func GetPageListByCondition(where string, par []interface{}, pageIndex, pageSize int) (list []*YbRoadVideo, total int64, err error) {
  15. offset := (pageIndex - 1) * pageSize
  16. err = global.DEFAULT_MYSQL.Model(YbRoadVideo{}).
  17. Where(where, par...).Count(&total).Error
  18. if err != nil {
  19. return
  20. }
  21. err = global.DEFAULT_MYSQL.Model(YbRoadVideo{}).
  22. Where(where, par...).
  23. Offset(offset).Limit(pageSize).
  24. Order("publish_time DESC").Scan(&list).Error
  25. return
  26. }
  27. // GetItemById 主键获取已发布的视频
  28. func GetItemById(videoId int) (item *YbRoadVideo, err error) {
  29. err = global.DEFAULT_MYSQL.Model(YbRoadVideo{}).
  30. Where("road_video_id = ? AND is_deleted = 0 AND publish_state = 1", videoId).
  31. First(&item).Error
  32. return
  33. }
  34. // GetListByVideoIds 根据视频IDs获取列表
  35. func GetListByVideoIds(videoIds []int) (list []*YbRoadVideo, err error) {
  36. var where string
  37. where = `publish_state = 1 AND is_deleted = 0`
  38. if len(videoIds) > 0 {
  39. where += ` AND road_video_id IN (?)`
  40. }
  41. err = global.DEFAULT_MYSQL.Model(YbRoadVideo{}).
  42. Where(where, videoIds).
  43. Order("road_video_id asc").
  44. Scan(&list).Error
  45. return
  46. }
  47. // GetItemByReportId 报告ID获取已绑定的路演视频
  48. func GetItemByReportId(reportId int) (item *YbRoadVideo, err error) {
  49. err = global.DEFAULT_MYSQL.Model(YbRoadVideo{}).
  50. Where("report_id = ? AND is_deleted = 0 AND publish_state = 1", reportId).
  51. First(&item).Error
  52. return
  53. }