package yb import ( "github.com/beego/beego/v2/client/orm" "hongze/hz_crm_api/utils" "time" ) // RoadVideo 线上路演(路演视频) type RoadVideo struct { RoadVideoId int `orm:"column(road_video_id);pk;auto" description:"问题ID"` Title string `description:"视频标题"` ChartPermissionIds string `description:"品种权限ID,用英文逗号分隔"` CoverImgUrl string `description:"封面图地址"` VideoUrl string `description:"视频地址"` VideoSeconds string `description:"视频时长,单位秒"` PublishState int `description:"发布状态:0-待发布 1-已发布"` SendThsState int `description:"客群消息推送状态:0-待推送 1-已推送"` SendTemplateState int `description:"模板消息推送状态:0-待推送 1-已推送"` IsDeleted int `description:"是否已删除 0-否 1-是"` AdminId int `description:"上传视频的管理员账号"` AdminRealName string `description:"上传视频的管理员姓名"` PublishTime time.Time `description:"发布时间"` SendThsTime time.Time `description:"推送客群时间"` SendTemplateTime time.Time `description:"推送模板消息时间"` CreateTime time.Time `description:"提问时间"` ModifyTime time.Time `description:"修改时间"` DeleteTime time.Time `description:"删除时间"` ReportId int `description:"关联的报告ID"` } type RoadVideoMore struct { RoadVideo ClickNum int `description:"点击量"` } func (item *RoadVideo) TableName() string { return "yb_road_video" } func (item *RoadVideo) Add() (err error) { o := orm.NewOrm() _, err = o.Insert(item) return } func (item *RoadVideo) Update(cols []string) (err error) { o := orm.NewOrm() _, err = o.Update(item, cols...) return } // GetRoadVideoById 主键获取视频 func GetRoadVideoById(videoId int) (item *RoadVideo, err error) { o := orm.NewOrm() sql := `SELECT * FROM yb_road_video WHERE road_video_id = ? AND is_deleted = 0 LIMIT 1` err = o.Raw(sql, videoId).QueryRow(&item) return } // GetRoadVideoList 获取视频列表 func GetRoadVideoList(condition string, pars []interface{}, order string, startSize, pageSize int) (total int, list []*RoadVideoMore, err error) { o := orm.NewOrm() sql := `SELECT v.*, l.click_num FROM yb_road_video v 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 WHERE v.is_deleted = 0 ` sql += condition if order != "" { sql += order } else { sql += ` ORDER BY v.modify_time DESC` } totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z` if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil { return } sql += ` LIMIT ?,?` _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list) return } // DeleteRoadVideo 删除视频 func DeleteRoadVideo(videoId int) (err error) { o := orm.NewOrm() sql := `UPDATE yb_road_video SET is_deleted = 1, delete_time = NOW() WHERE road_video_id = ? LIMIT 1` _, err = o.Raw(sql, videoId).Exec() return } // GetRoadVideoListByIds 根据IDs获取视频列表 func GetRoadVideoListByIds(videoIds []int) (list []*RoadVideo, err error) { arrLen := len(videoIds) if arrLen == 0 { return } o := orm.NewOrm() sql := `SELECT * FROM yb_road_video WHERE road_video_id IN (` + utils.GetOrmInReplace(arrLen) + `) AND is_deleted = 0` _, err = o.Raw(sql, videoIds).QueryRows(&list) return } // GetRoadVideoListByReportIds 根据报告IDs获取视频列表 func GetRoadVideoListByReportIds(reportIds []int) (list []*RoadVideo, err error) { arrLen := len(reportIds) if arrLen == 0 { return } o := orm.NewOrm() sql := `SELECT * FROM yb_road_video WHERE report_id IN (` + utils.GetOrmInReplace(arrLen) + `) AND is_deleted = 0` _, err = o.Raw(sql, reportIds).QueryRows(&list) return }