video.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. package dao
  2. import (
  3. "context"
  4. "database/sql"
  5. "fmt"
  6. "strconv"
  7. "strings"
  8. xtime "time"
  9. "go-common/app/job/bbq/video/model"
  10. "go-common/app/service/bbq/search/api/grpc/v1"
  11. "go-common/library/cache/redis"
  12. xsql "go-common/library/database/sql"
  13. "go-common/library/log"
  14. "go-common/library/time"
  15. jsoniter "github.com/json-iterator/go"
  16. )
  17. const (
  18. _limitSize = 2000
  19. // MaxSyncESNum 限制每次更新到es的数量
  20. MaxSyncESNum = 100
  21. // QueryVideoByMtime 根据mtime获取视频基础信息
  22. QueryVideoByMtime = "select `svid`,`mtime` from video where mtime >= ? order by mtime asc"
  23. // QueryVideoStatisticsByMtime 根据mtime获取视频相关播放信息
  24. QueryVideoStatisticsByMtime = "select `svid`,`mtime` from video_statistics where mtime >= ? order by mtime asc"
  25. // QueryVideoStatisticsHiveByMtime 根据mtime获取视频主站信息
  26. QueryVideoStatisticsHiveByMtime = "select `svid`,`mtime` from video_statistics_hive where mtime >= ? order by mtime asc"
  27. // QueryVideoTagByMtime 根据mtime获取视频tag信息
  28. QueryVideoTagByMtime = "select `svid`,`mtime` from video_tag where mtime >= ? order by mtime asc"
  29. _recRecallOpVideoKey = "job:bbq:rec:op"
  30. _syncOperVideoTagKey = "job:bbq:video:syncvideotagkey"
  31. _syncOperVideoTimeKey = "job:bbq:video:syncvideotimekey"
  32. _selectVideoInfo = "select `svid`,`title`,`content`,`mid`,`cid`,`pubtime`,`ctime`,`mtime`,`duration`,`original`,`state`,`is_full_screen`,`ver_id`,`ver`,`from`,`avid`,`tid`,`sub_tid`,`score` from video where id > ? order by id asc limit 100"
  33. _selectVideoInfoByIDs = "select `svid`,`title`,`content`,`mid`,`cid`,`pubtime`,`ctime`,`mtime`,`duration`,`original`,`state`,`is_full_screen`,`ver_id`,`ver`,`from`,`avid`,`tid`,`sub_tid`,`score` from video where svid in (%s)"
  34. _selectVideoStatisticsHiveInfo = "select `svid`,`play`,`fav`,`coin`,`subtitles`,`likes`,`share`,`report`,`duration_daily`,`duration_all`,`reply`,`share_daily`,`play_daily`,`subtitles_daily`,`likes_daily`,`fav_daily`,`access`,`reply_daily` from video_statistics_hive where svid in (%s)"
  35. _selectVideoStatisticsInfo = "select `svid`,`play`,`subtitles`,`like`,`share`,`report` from video_statistics where svid in (%s)"
  36. _selectVideoTagsInfo = "select v.svid,t.id,t.name,t.type from video_tag v inner join tag t on v.tag_id = t.id where v.svid in (%s)"
  37. _queryCheckTask = "select `task_id`,`task_name`,`last_check` from check_task where `task_name` = ?"
  38. _updateTaskLastCheck = "update check_task set last_check = ? where `task_name` = ?"
  39. _queryTagByMtime = "select `id`,`mtime` from tag where mtime > ? order by mtime asc limit 10"
  40. _queryVideoTagByTagID = "select `id`,`svid` from video_tag where tag_id in (%s) and id > ? order by id asc limit 100"
  41. _queryVideoBySVIDs = "select `svid`,`title` from video where svid in (%s)"
  42. _queryIDs = "select `id`,`svid` from video where id > %d order by id asc limit %d"
  43. _queryOutPutVideos = "select id,svid,title,pubtime from video where id > ? and state in (%s) order by id ASC limit ?"
  44. _updateUVSt = "update user_statistics set %s = %s+1 where mid = %d"
  45. _updateUVStDel = "update user_statistics set %s = %s-1 where mid = %d and %s >0"
  46. _updateSVTotal = "update user_statistics set av_total = av_total + 1 where mid = ?"
  47. _getSvidByCid = "select svid from video where cid = ?"
  48. _updateSVID = "update video_repository set svid = ? where id = ?"
  49. _updateSyncStatus = "update video_repository set sync_status = sync_status|? where svid = ?"
  50. _queryCMSOne = "select `home_img_url`,`home_img_width`,`home_img_height`,`from`,`sync_status`, `tag`, `avid`, `cid`, `svid`, `title`, `mid`, `content`, `pubtime`,`duration`,`original`,`is_full_screen`,`tid`,`sub_tid`,`cover_url`,`cover_width`,`cover_height` from video_repository where svid = ?"
  51. _queryCMSOneByID = "select `tag`, `avid`, `cid`, `svid`, `title`, `mid`, `content`, `pubtime`,`duration`,`original`,`is_full_screen`,`tid`,`sub_tid`,`cover_url`,`cover_width`,`cover_height` from video_repository where id = ?"
  52. _queryBbqVideo = "select title,mid,cid,state,tid,sub_tid,svid from video where svid in (%s)"
  53. )
  54. // RawVideo 从数据库获取视频信息
  55. func (d *Dao) RawVideo(ctx context.Context, SVID int64) (res *model.VideoRepRaw, err error) {
  56. res = new(model.VideoRepRaw)
  57. err = d.dbCms.QueryRow(ctx, _queryCMSOne, SVID).Scan(&res.HomeImgURL, &res.CoverWidth, &res.HomeImgHeight, &res.From, &res.SyncStatus, &res.Tag, &res.AVID, &res.CID, &res.SVID, &res.Title, &res.MID, &res.Content, &res.Pubtime, &res.Duration, &res.Original, &res.IsFull, &res.TID, &res.SubTID, &res.CoverURL, &res.CoverWidth, &res.CoverHeight)
  58. if err != nil {
  59. log.Error("RawVideo error(%v),svid:%d", err, SVID)
  60. }
  61. return
  62. }
  63. //RawBbqVideo ..
  64. func (d *Dao) RawBbqVideo(ctx context.Context, SVID []int64) (res *model.VideoRaw, err error) {
  65. res = new(model.VideoRaw)
  66. svids := strings.Trim(strings.Join(strings.Split(fmt.Sprint(SVID), " "), ","), "[]")
  67. err = d.db.QueryRow(ctx, fmt.Sprintf(_queryBbqVideo, svids)).Scan(&res.Title, &res.MID, &res.CID, &res.State, &res.TID, &res.SubTID, &res.SVID)
  68. if err != nil {
  69. log.Errorw(ctx, "event", "RawBbqVideo queryrow scan err:[%v],SVID :[%v]", err, SVID)
  70. }
  71. return
  72. }
  73. //RawVideoByID ...get video info by id
  74. func (d *Dao) RawVideoByID(ctx context.Context, ID int64) (res *model.VideoRepRaw, err error) {
  75. res = new(model.VideoRepRaw)
  76. err = d.dbCms.QueryRow(ctx, _queryCMSOneByID, ID).Scan(&res.Tag, &res.AVID, &res.CID, &res.SVID, &res.Title, &res.MID, &res.Content, &res.Pubtime, &res.Duration, &res.Original, &res.IsFull, &res.TID, &res.SubTID, &res.CoverURL, &res.CoverWidth, &res.CoverHeight)
  77. if err != nil {
  78. log.Error("RawVideoByID error(%v),id:%d", err, ID)
  79. }
  80. return
  81. }
  82. //UpdateSyncStatus update video_repository sync_status
  83. func (d *Dao) UpdateSyncStatus(ctx context.Context, SVID int64, st int64) (err error) {
  84. if _, err = d.dbCms.Exec(ctx, _updateSyncStatus, st, SVID); err != nil {
  85. log.Error("UpdateSyncStatus err :%v,svid :", err, SVID)
  86. }
  87. return
  88. }
  89. //UpdateVideoUploadProcessStatus ...
  90. func (d *Dao) UpdateVideoUploadProcessStatus(ctx context.Context, SVID int64, st int64) (err error) {
  91. if _, err = d.db.Exec(ctx, "update video_upload_process set status = ? where svid = ?", st, SVID); err != nil {
  92. log.Errorw(ctx, "errmsg", "UpdateVideoUploadProcessStatus update failed", "err", err)
  93. }
  94. return
  95. }
  96. //UpdateSvid ...
  97. func (d *Dao) UpdateSvid(c context.Context, id int64, svid int64) (err error) {
  98. if _, err = d.dbCms.Exec(c, _updateSVID, svid, id); err != nil {
  99. log.Error("distribution svid err:%v,svid:%d", err, svid)
  100. }
  101. return
  102. }
  103. //AddSVTotal ...
  104. func (d *Dao) AddSVTotal(mid int64) (err error) {
  105. _, err = d.db.Exec(context.Background(), _updateSVTotal, mid)
  106. if err != nil {
  107. log.Error("AddSVTotal ,mid:%s,err:%v", mid, err)
  108. }
  109. return
  110. }
  111. //UpdateUVSt 更新用户视频统计信息
  112. func (d *Dao) UpdateUVSt(mid int64, field string) (err error) {
  113. _, err = d.db.Exec(context.Background(), fmt.Sprintf(_updateUVSt, field, field, mid))
  114. if err != nil {
  115. log.Error("UpdateUVSt ,mid:%s,field:%s,op:%d,err:%v", mid, field, err)
  116. }
  117. return
  118. }
  119. //UpdateUVStDel ...
  120. func (d *Dao) UpdateUVStDel(mid int64, field string) (err error) {
  121. _, err = d.db.Exec(context.Background(), fmt.Sprintf(_updateUVStDel, field, field, mid, field))
  122. if err != nil {
  123. log.Error("UpdateUVStDel ,mid:%s,field:%s,op:%d,err:%v", mid, field, err)
  124. }
  125. return
  126. }
  127. //VideoList 获取视频基础信息
  128. func (d *Dao) VideoList(c context.Context, id int64) (ids string, res []*v1.VideoESInfo, err error) {
  129. var rows *xsql.Rows
  130. if rows, err = d.db.Query(c, _selectVideoInfo, id); err != nil {
  131. log.Error("select videos err(%v)", err)
  132. return
  133. }
  134. defer rows.Close()
  135. var (
  136. pubtime time.Time
  137. ctime time.Time
  138. mtime time.Time
  139. idstring []string
  140. )
  141. for rows.Next() {
  142. tmp := new(v1.VideoESInfo)
  143. if err = rows.Scan(&tmp.SVID, &tmp.Title, &tmp.Content, &tmp.MID, &tmp.CID, &pubtime, &ctime, &mtime, &tmp.Duration, &tmp.Original, &tmp.State, &tmp.ISFullScreen, &tmp.VerID, &tmp.Ver, &tmp.From, &tmp.AVID, &tmp.Tid, &tmp.SubTid, &tmp.Score); err != nil {
  144. if err == sql.ErrNoRows {
  145. err = nil
  146. }
  147. return
  148. }
  149. tmp.Pubtime = int64(pubtime)
  150. tmp.Ctime = int64(ctime)
  151. tmp.Mtime = int64(mtime)
  152. idstring = append(idstring, strconv.FormatInt(tmp.SVID, 10))
  153. res = append(res, tmp)
  154. }
  155. ids = strings.Join(idstring, ",")
  156. return
  157. }
  158. //VideoListByIDs 根据视频id获取视频基础信息
  159. func (d *Dao) VideoListByIDs(c context.Context, ids string) (res []*v1.VideoESInfo, err error) {
  160. var rows *xsql.Rows
  161. if rows, err = d.db.Query(c, fmt.Sprintf(_selectVideoInfoByIDs, ids)); err != nil {
  162. log.Error("select videos by ids err(%v)", err)
  163. return
  164. }
  165. defer rows.Close()
  166. var (
  167. pubtime time.Time
  168. ctime time.Time
  169. mtime time.Time
  170. )
  171. for rows.Next() {
  172. tmp := new(v1.VideoESInfo)
  173. if err = rows.Scan(&tmp.SVID, &tmp.Title, &tmp.Content, &tmp.MID, &tmp.CID, &pubtime, &ctime, &mtime, &tmp.Duration, &tmp.Original, &tmp.State, &tmp.ISFullScreen, &tmp.VerID, &tmp.Ver, &tmp.From, &tmp.AVID, &tmp.Tid, &tmp.SubTid, &tmp.Score); err != nil {
  174. log.Error("select videos scan err(%v)", err)
  175. return
  176. }
  177. tmp.Pubtime = int64(pubtime)
  178. tmp.Ctime = int64(ctime)
  179. tmp.Mtime = int64(mtime)
  180. res = append(res, tmp)
  181. }
  182. return
  183. }
  184. //VideoStatisticsHiveList 获取视频互动信息,hive表
  185. func (d *Dao) VideoStatisticsHiveList(c context.Context, ids string) (res map[int64]*v1.VideoESInfo, err error) {
  186. var rows *xsql.Rows
  187. if rows, err = d.db.Query(c, fmt.Sprintf(_selectVideoStatisticsHiveInfo, ids)); err != nil {
  188. log.Error("select video statistics hive err(%v)", err)
  189. return
  190. }
  191. defer rows.Close()
  192. res = make(map[int64]*v1.VideoESInfo)
  193. for rows.Next() {
  194. tmp := new(v1.VideoESInfo)
  195. if err = rows.Scan(&tmp.SVID, &tmp.PlayHive, &tmp.FavHive, &tmp.CoinHive, &tmp.SubtitlesHive, &tmp.LikesHive, &tmp.ShareHive, &tmp.ReportHive, &tmp.DurationDailyHive, &tmp.DurationAllHive, &tmp.ReplyHive, &tmp.ShareDailyHive, &tmp.PlayDailyHive, &tmp.SubtitlesDailyHive, &tmp.LikesDailyHive, &tmp.FavDailyHive, &tmp.AccessHive, &tmp.ReplyDailyHive); err != nil {
  196. log.Error("select video statistics hive scan err(%v)", err)
  197. return
  198. }
  199. res[tmp.SVID] = tmp
  200. }
  201. return
  202. }
  203. //VideoStatisticsList 获取视频互动信息
  204. func (d *Dao) VideoStatisticsList(c context.Context, ids string) (res map[int64]*v1.VideoESInfo, err error) {
  205. var rows *xsql.Rows
  206. if rows, err = d.db.Query(c, fmt.Sprintf(_selectVideoStatisticsInfo, ids)); err != nil {
  207. log.Error("select video statistics err(%v)", err)
  208. return
  209. }
  210. defer rows.Close()
  211. res = make(map[int64]*v1.VideoESInfo)
  212. for rows.Next() {
  213. tmp := new(v1.VideoESInfo)
  214. if err = rows.Scan(&tmp.SVID, &tmp.Play, &tmp.SubtitlesHive, &tmp.Like, &tmp.Share, &tmp.Report); err != nil {
  215. log.Error("select video statistics scan err(%v)", err)
  216. return
  217. }
  218. res[tmp.SVID] = tmp
  219. }
  220. return
  221. }
  222. //VideoTagsList 获取视频tags
  223. func (d *Dao) VideoTagsList(c context.Context, ids string) (res map[int64][]*v1.VideoESTags, err error) {
  224. var rows *xsql.Rows
  225. if rows, err = d.db.Query(c, fmt.Sprintf(_selectVideoTagsInfo, ids)); err != nil {
  226. fmt.Println(rows)
  227. log.Error("select video statistics err(%v)", err)
  228. return
  229. }
  230. defer rows.Close()
  231. var svid int64
  232. res = make(map[int64][]*v1.VideoESTags)
  233. for rows.Next() {
  234. tmp := new(v1.VideoESTags)
  235. if err = rows.Scan(&svid, &tmp.ID, &tmp.Name, &tmp.Type); err != nil {
  236. log.Error("select video statistics scan err(%v)", err)
  237. return
  238. }
  239. res[svid] = append(res[svid], tmp)
  240. }
  241. return
  242. }
  243. //RawCheckTask 查询脚本任务
  244. func (d *Dao) RawCheckTask(c context.Context, taskName string) (res *model.CheckTask, err error) {
  245. res = new(model.CheckTask)
  246. raw := d.db.QueryRow(c, _queryCheckTask, taskName)
  247. if err = raw.Scan(&res.TaskID, &res.TaskName, &res.LastCheck); err != nil {
  248. log.Error("query check task name(%s) err(%v)", taskName, err)
  249. }
  250. return
  251. }
  252. //UpdateTaskLastCheck 更新上次执行时间
  253. func (d *Dao) UpdateTaskLastCheck(c context.Context, taskName string, lastCheck int64) (num int64, err error) {
  254. res, err := d.db.Exec(c, _updateTaskLastCheck, lastCheck, taskName)
  255. if err != nil {
  256. log.Error("update task last check name(%s)(%d) err(%v)", taskName, lastCheck, err)
  257. return
  258. }
  259. return res.RowsAffected()
  260. }
  261. // RawGetIDByMtime 获取最近更新的那些svid,该函数可以用于多个表的查询,只需传入不同表的查询语句即可
  262. func (d *Dao) RawGetIDByMtime(baseTableQuery string, mtime int64) (ids []int64, lastMtime int64, err error) {
  263. mtimeStr := xtime.Unix(mtime, 0).Format("2006-01-02 15:04:05")
  264. var rows *xsql.Rows
  265. if rows, err = d.db.Query(context.Background(), baseTableQuery, mtimeStr); err != nil {
  266. log.Error("select ids fail: err=%v, mtime=%s, sql=%s", err, mtimeStr, baseTableQuery)
  267. return
  268. }
  269. defer rows.Close()
  270. var (
  271. temp time.Time
  272. svid int64
  273. )
  274. for rows.Next() {
  275. if err = rows.Scan(&svid, &temp); err != nil {
  276. if err == sql.ErrNoRows {
  277. err = nil
  278. }
  279. log.Error("select videos by mtime scan fail: err=%v, mtime=%s, sql=%s", err, mtimeStr, baseTableQuery)
  280. return
  281. }
  282. lastMtime = int64(temp)
  283. ids = append(ids, svid)
  284. }
  285. return
  286. }
  287. //RawTagByMtime 根据mtime获取tag信息
  288. func (d *Dao) RawTagByMtime(c context.Context, mtime int64) (ids string, res int64, err error) {
  289. str := xtime.Unix(mtime, 0).Format("2006-01-02 15:04:05")
  290. var rows *xsql.Rows
  291. if rows, err = d.db.Query(c, _queryTagByMtime, str); err != nil {
  292. log.Error("select tag err(%v)", err)
  293. return
  294. }
  295. defer rows.Close()
  296. var (
  297. temp time.Time
  298. id int64
  299. idstring []string
  300. )
  301. for rows.Next() {
  302. if err = rows.Scan(&id, &temp); err != nil {
  303. if err == sql.ErrNoRows {
  304. err = nil
  305. }
  306. log.Error("select tag by mtime scan err(%v)", err)
  307. return
  308. }
  309. res = int64(temp)
  310. idstring = append(idstring, strconv.FormatInt(id, 10))
  311. }
  312. ids = strings.Join(idstring, ",")
  313. return
  314. }
  315. //RawVideoTagByIDs .
  316. func (d *Dao) RawVideoTagByIDs(c context.Context, ids string, id int64) (svids string, res int64, err error) {
  317. var rows *xsql.Rows
  318. if rows, err = d.db.Query(c, fmt.Sprintf(_queryVideoTagByTagID, ids), id); err != nil {
  319. log.Error("select video tag err(%v)", err)
  320. return
  321. }
  322. defer rows.Close()
  323. var (
  324. temp int64
  325. svid int64
  326. idstring []string
  327. )
  328. for rows.Next() {
  329. if err = rows.Scan(&temp, &svid); err != nil {
  330. if err == sql.ErrNoRows {
  331. err = nil
  332. } else {
  333. log.Error("select video tag by id scan err(%v)", err)
  334. }
  335. return
  336. }
  337. res = int64(temp)
  338. idstring = append(idstring, strconv.FormatInt(svid, 10))
  339. }
  340. svids = strings.Join(idstring, ",")
  341. return
  342. }
  343. //GetSyncOperVideoFlag 获取同步信号灯
  344. func (d *Dao) GetSyncOperVideoFlag(c context.Context) (tag int64, err error) {
  345. conn := d.redis.Get(c)
  346. defer conn.Close()
  347. val, err := conn.Do("get", _syncOperVideoTagKey)
  348. if err != nil {
  349. log.Error("cache sync oper video tag get err(%v)", err)
  350. return
  351. }
  352. if val == nil {
  353. if err = d.SetSyncOperVideoFlag(c, model.DenySyncOperVideoTag); err != nil {
  354. log.Error("set sync oper video flag faild")
  355. return
  356. }
  357. tag = model.DenySyncOperVideoTag
  358. } else {
  359. tag, err = redis.Int64(val, err)
  360. }
  361. return
  362. }
  363. //SetSyncOperVideoFlag 设置同步信号灯
  364. func (d *Dao) SetSyncOperVideoFlag(c context.Context, v int64) (err error) {
  365. conn := d.redis.Get(c)
  366. defer conn.Close()
  367. if _, err = conn.Do("set", _syncOperVideoTagKey, v); err != nil {
  368. log.Error("cache sync oper video tag set err(%v)", err)
  369. return
  370. }
  371. return
  372. }
  373. //GetSyncOperVideoExportTime ...
  374. func (d *Dao) GetSyncOperVideoExportTime(c context.Context) (t string, err error) {
  375. conn := d.redis.Get(c)
  376. defer conn.Close()
  377. val, err := conn.Do("get", _syncOperVideoTimeKey)
  378. if err == nil {
  379. if val == nil {
  380. conn.Do("set", _syncOperVideoTimeKey, "")
  381. }
  382. t, err = redis.String(val, err)
  383. } else {
  384. log.Error("get sync oper video export time err,errinfo:%v", err)
  385. }
  386. return
  387. }
  388. //RawVideoBySVIDS 根据svids获取视频
  389. func (d *Dao) RawVideoBySVIDS(c context.Context, svids []string) (res map[int64]string, err error) {
  390. res = make(map[int64]string)
  391. str := strings.Join(svids, ",")
  392. var rows *xsql.Rows
  393. if rows, err = d.db.Query(c, fmt.Sprintf(_queryVideoBySVIDs, str)); err != nil {
  394. log.Error("select videos by svids err(%v)", err)
  395. return
  396. }
  397. defer rows.Close()
  398. var (
  399. svid int64
  400. title string
  401. )
  402. for rows.Next() {
  403. if err = rows.Scan(&svid, &title); err != nil {
  404. if err == sql.ErrNoRows {
  405. err = nil
  406. }
  407. log.Error("select videos by svids scan err(%v)", err)
  408. return
  409. }
  410. res[svid] = title
  411. }
  412. return
  413. }
  414. //GetVideoByLastID 获取所有SVID
  415. func (d *Dao) GetVideoByLastID(c context.Context, last int64) (IDs []int64, lastRet int64, err error) {
  416. length := 1000 //分批大小
  417. var rows *xsql.Rows
  418. rows, err = d.db.Query(c, fmt.Sprintf(_queryIDs, last, length))
  419. if err != nil {
  420. log.Error("db _queryIDs err(%v)", err)
  421. return
  422. }
  423. for rows.Next() {
  424. var svid int64
  425. if err = rows.Scan(&lastRet, &svid); err != nil {
  426. log.Error("scan err(%v)", err)
  427. continue
  428. }
  429. IDs = append(IDs, svid)
  430. }
  431. return
  432. }
  433. //GetRecallOpVideo 获取精选视频
  434. func (d *Dao) GetRecallOpVideo(c context.Context) (ids []int64, err error) {
  435. conn := d.redis.Get(c)
  436. defer conn.Close()
  437. val, err := redis.Bytes(conn.Do("GET", _recRecallOpVideoKey))
  438. if err != nil {
  439. if err == redis.ErrNil {
  440. err = nil
  441. } else {
  442. log.Error("cache rec recall op video get redis err (%v)", err)
  443. }
  444. return ids, err
  445. }
  446. if err = jsoniter.Unmarshal(val, &ids); err != nil {
  447. log.Error("rec recall op video unmarshal err (%v)", err)
  448. }
  449. return
  450. }
  451. //SetRecallOpVideo 写入精选视频
  452. func (d *Dao) SetRecallOpVideo(c context.Context, ids []int64) (err error) {
  453. conn := d.redis.Get(c)
  454. defer conn.Close()
  455. bytes, _ := jsoniter.Marshal(ids)
  456. _, err = conn.Do("SET", _recRecallOpVideoKey, bytes)
  457. if err != nil {
  458. log.Error("rec recall op video set redis error(%v) ", err)
  459. }
  460. return
  461. }
  462. //VideosByLast 使用lastid批量获取视屏
  463. func (d *Dao) VideosByLast(c context.Context, lastid int64) (svinfo []*model.VideoDB, err error) {
  464. var rows *xsql.Rows
  465. query := fmt.Sprintf(_queryOutPutVideos, model.VideoStateOutPut)
  466. rows, err = d.db.Query(c, query, lastid, _limitSize)
  467. if err != nil {
  468. log.Error("db _queryVideos err(%v)", err)
  469. return
  470. }
  471. for rows.Next() {
  472. video := new(model.VideoDB)
  473. if err = rows.Scan(&video.AutoID, &video.ID, &video.Title, &video.Pubtime); err != nil {
  474. log.Error("scan err(%v)", err)
  475. continue
  476. }
  477. svinfo = append(svinfo, video)
  478. }
  479. return
  480. }
  481. // GetSvidByCid 根据cid获取svid
  482. func (d *Dao) GetSvidByCid(c context.Context, cid int64) (svid int64, err error) {
  483. err = d.db.QueryRow(c, _getSvidByCid, cid).Scan(&svid)
  484. if err != nil {
  485. log.Warn("db _getSvidByCid err(%v)", err)
  486. return
  487. }
  488. return
  489. }