video.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/admin/main/videoup-task/model"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _videoVID = `SELECT vr.id FROM archive_video_relation vr LEFT JOIN video v ON vr.cid=v.id
  10. LEFT JOIN archive a ON vr.aid=a.id
  11. WHERE vr.aid=? AND vr.cid=? AND vr.state != -100 AND v.status != -100 AND a.state != -100`
  12. _video = `SELECT vr.id, vr.aid, vr.cid, ar.mid, ar.copyright, ar.typeid, v.status, v.attribute, v.xcode_state, vr.title, vr.description, v.filename,
  13. coalesce(ad.tid, 0) tid, coalesce(ad.reason, '') reason, coalesce(ao.remark, '') note
  14. FROM archive_video_relation vr LEFT JOIN video v ON vr.cid=v.id
  15. LEFT JOIN archive ar ON vr.aid=ar.id
  16. LEFT JOIN archive_video_audit ad ON vr.id = ad.vid
  17. LEFT JOIN archive_video_oper ao ON vr.id = ao.vid
  18. WHERE vr.aid=? AND vr.cid=? AND ao.content NOT LIKE '%一审任务质检TAG: [%'
  19. ORDER BY ao.id DESC LIMIT 0,1`
  20. _videoByCid = `SELECT vr.id,vr.aid,vr.title AS eptitle,vr.description,v.filename,v.src_type,vr.cid,v.duration,v.filesize,
  21. v.resolutions,vr.index_order,vr.ctime,vr.mtime,v.status,v.playurl,v.attribute,v.failcode AS failinfo,v.xcode_state,v.weblink
  22. FROM archive_video_relation AS vr LEFT JOIN video AS v ON vr.cid = v.id WHERE vr.cid = ?`
  23. _newVideoIDSQL = `SELECT avr.id,v.filename,avr.cid,avr.aid,avr.title,avr.description,v.src_type,v.duration,v.filesize,v.resolutions,v.playurl,v.failcode,
  24. avr.index_order,v.attribute,v.xcode_state,avr.state,avr.ctime,avr.mtime FROM archive_video_relation avr JOIN video v on avr.cid = v.id
  25. WHERE avr.id=? LIMIT 1`
  26. _videoAttributeSQL = `SELECT attribute FROM video WHERE id = ?`
  27. )
  28. // VideoAttribute get attr
  29. func (d *Dao) VideoAttribute(ctx context.Context, cid int64) (attr int32, err error) {
  30. if err = d.arcDB.QueryRow(ctx, _videoAttributeSQL, cid).Scan(&attr); err != nil {
  31. if err == sql.ErrNoRows {
  32. attr = 0
  33. err = nil
  34. } else {
  35. PromeErr("arcdb: scan", "GetVVideoAttributeID row.Scan error(%v), cid(%d)", err, cid)
  36. }
  37. }
  38. return
  39. }
  40. //GetVID get vid
  41. func (d *Dao) GetVID(ctx context.Context, aid int64, cid int64) (vid int64, err error) {
  42. if err = d.arcReadDB.QueryRow(ctx, _videoVID, aid, cid).Scan(&vid); err != nil {
  43. if err == sql.ErrNoRows {
  44. vid = 0
  45. err = nil
  46. } else {
  47. PromeErr("arcReaddb: scan", "GetVID row.Scan error(%v) aid(%d), cid(%d)", err, aid, cid)
  48. }
  49. }
  50. return
  51. }
  52. //Video get video by aid & cid
  53. func (d *Dao) Video(ctx context.Context, aid int64, cid int64) (v *model.Video, err error) {
  54. v = &model.Video{}
  55. if err = d.arcReadDB.QueryRow(ctx, _video, aid, cid).Scan(&v.ID, &v.AID, &v.CID, &v.MID, &v.Copyright, &v.TypeID, &v.Status,
  56. &v.Attribute, &v.XcodeState, &v.Title, &v.Description, &v.Filename,
  57. &v.TagID, &v.Reason, &v.Note); err != nil {
  58. if err == sql.ErrNoRows {
  59. err = nil
  60. v = nil
  61. } else {
  62. PromeErr("arcReaddb: scan", "Video row.Scan error(%v) aid(%d), cid(%d)", err, aid, cid)
  63. }
  64. }
  65. return
  66. }
  67. // ArcVideoByCID get video by cid
  68. func (d *Dao) ArcVideoByCID(c context.Context, cid int64) (v *model.ArcVideo, err error) {
  69. row := d.arcDB.QueryRow(c, _videoByCid, cid)
  70. v = &model.ArcVideo{}
  71. if err = row.Scan(&v.ID, &v.Aid, &v.Title, &v.Desc, &v.Filename, &v.SrcType, &v.Cid, &v.Duration, &v.Filesize, &v.Resolutions, &v.Index, &v.CTime, &v.MTime, &v.Status, &v.Playurl, &v.Attribute, &v.FailCode, &v.XcodeState, &v.WebLink); err != nil {
  72. if err == sql.ErrNoRows {
  73. v = nil
  74. err = nil
  75. } else {
  76. log.Error("row.Scan error(%v)", err)
  77. }
  78. }
  79. return
  80. }
  81. // NewVideoByID .
  82. func (d *Dao) NewVideoByID(c context.Context, id int64) (v *model.ArcVideo, err error) {
  83. row := d.arcDB.QueryRow(c, _newVideoIDSQL, id)
  84. v = &model.ArcVideo{}
  85. if err = row.Scan(&v.ID, &v.Filename, &v.Cid, &v.Aid, &v.Title, &v.Desc, &v.SrcType, &v.Duration, &v.Filesize, &v.Resolutions,
  86. &v.Playurl, &v.FailCode, &v.Index, &v.Attribute, &v.XcodeState, &v.Status, &v.CTime, &v.MTime); err != nil {
  87. if err == sql.ErrNoRows {
  88. v = nil
  89. err = nil
  90. } else {
  91. log.Error("row.Scan error(%v)", err)
  92. }
  93. }
  94. return
  95. }