road_video.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. // RoadVideo 线上路演(路演视频)
  8. type RoadVideo struct {
  9. RoadVideoId int `orm:"column(road_video_id);pk;auto" description:"问题ID"`
  10. Title string `description:"视频标题"`
  11. ChartPermissionIds string `description:"品种权限ID,用英文逗号分隔"`
  12. CoverImgUrl string `description:"封面图地址"`
  13. VideoUrl string `description:"视频地址"`
  14. VideoSeconds string `description:"视频时长,单位秒"`
  15. PublishState int `description:"发布状态:0-待发布 1-已发布"`
  16. SendThsState int `description:"客群消息推送状态:0-待推送 1-已推送"`
  17. SendTemplateState int `description:"模板消息推送状态:0-待推送 1-已推送"`
  18. IsDeleted int `description:"是否已删除 0-否 1-是"`
  19. AdminId int `description:"上传视频的管理员账号"`
  20. AdminRealName string `description:"上传视频的管理员姓名"`
  21. PublishTime time.Time `description:"发布时间"`
  22. SendThsTime time.Time `description:"推送客群时间"`
  23. SendTemplateTime time.Time `description:"推送模板消息时间"`
  24. CreateTime time.Time `description:"提问时间"`
  25. ModifyTime time.Time `description:"修改时间"`
  26. DeleteTime time.Time `description:"删除时间"`
  27. ReportId int `description:"关联的报告ID"`
  28. }
  29. type RoadVideoMore struct {
  30. RoadVideo
  31. ClickNum int `description:"点击量"`
  32. }
  33. func (item *RoadVideo) TableName() string {
  34. return "yb_road_video"
  35. }
  36. func (item *RoadVideo) Add() (err error) {
  37. o := orm.NewOrm()
  38. _, err = o.Insert(item)
  39. return
  40. }
  41. func (item *RoadVideo) Update(cols []string) (err error) {
  42. o := orm.NewOrm()
  43. _, err = o.Update(item, cols...)
  44. return
  45. }
  46. // GetRoadVideoById 主键获取视频
  47. func GetRoadVideoById(videoId int) (item *RoadVideo, err error) {
  48. o := orm.NewOrm()
  49. sql := `SELECT * FROM yb_road_video WHERE road_video_id = ? AND is_deleted = 0 LIMIT 1`
  50. err = o.Raw(sql, videoId).QueryRow(&item)
  51. return
  52. }
  53. // GetRoadVideoList 获取视频列表
  54. func GetRoadVideoList(condition string, pars []interface{}, order string, startSize, pageSize int) (total int, list []*RoadVideoMore, err error) {
  55. o := orm.NewOrm()
  56. sql := `SELECT
  57. v.*,
  58. l.click_num
  59. FROM
  60. yb_road_video v
  61. LEFT JOIN ( SELECT count( * ) AS click_num, community_video_id FROM yb_community_video_play_log WHERE type=2 GROUP BY community_video_id ) AS l ON v.road_video_id = l.community_video_id
  62. WHERE
  63. v.is_deleted = 0 `
  64. sql += condition
  65. if order != "" {
  66. sql += order
  67. } else {
  68. sql += ` ORDER BY v.modify_time DESC`
  69. }
  70. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  71. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  72. return
  73. }
  74. sql += ` LIMIT ?,?`
  75. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  76. return
  77. }
  78. // DeleteRoadVideo 删除视频
  79. func DeleteRoadVideo(videoId int) (err error) {
  80. o := orm.NewOrm()
  81. sql := `UPDATE yb_road_video SET is_deleted = 1, delete_time = NOW() WHERE road_video_id = ? LIMIT 1`
  82. _, err = o.Raw(sql, videoId).Exec()
  83. return
  84. }
  85. // GetRoadVideoListByIds 根据IDs获取视频列表
  86. func GetRoadVideoListByIds(videoIds []int) (list []*RoadVideo, err error) {
  87. arrLen := len(videoIds)
  88. if arrLen == 0 {
  89. return
  90. }
  91. o := orm.NewOrm()
  92. sql := `SELECT * FROM yb_road_video WHERE road_video_id IN (` + utils.GetOrmInReplace(arrLen) + `) AND is_deleted = 0`
  93. _, err = o.Raw(sql, videoIds).QueryRows(&list)
  94. return
  95. }
  96. // GetRoadVideoListByReportIds 根据报告IDs获取视频列表
  97. func GetRoadVideoListByReportIds(reportIds []int) (list []*RoadVideo, err error) {
  98. arrLen := len(reportIds)
  99. if arrLen == 0 {
  100. return
  101. }
  102. o := orm.NewOrm()
  103. sql := `SELECT * FROM yb_road_video WHERE report_id IN (` + utils.GetOrmInReplace(arrLen) + `) AND is_deleted = 0`
  104. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  105. return
  106. }