oper.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package archive
  2. import (
  3. "context"
  4. "database/sql"
  5. "go-common/app/admin/main/videoup/model/archive"
  6. "go-common/library/log"
  7. "go-common/library/time"
  8. )
  9. const (
  10. _inArcOperSQL = "INSERT INTO archive_oper (aid,uid,typeid,state,content,round,attribute,last_id,remark) VALUES (?,?,?,?,?,?,?,?,?)"
  11. _inVideoOperSQL = "INSERT INTO archive_video_oper (aid,uid,vid,status,content,attribute,last_id,remark) VALUES (?,?,?,?,?,?,?,?)"
  12. _upVideoOperSQL = "UPDATE archive_video_oper SET last_id=? WHERE id=?"
  13. _arcOperSQL = "SELECT id,aid,uid,typeid,state,content,round,attribute,last_id,remark FROM archive_oper WHERE aid = ? ORDER BY ctime DESC"
  14. _arcPassedOperSQL = "SELECT id FROM archive_oper WHERE aid=? AND state>=? LIMIT 1"
  15. _videoOperSQL = "SELECT id,aid,uid,vid,status,content,attribute,last_id,remark,ctime FROM archive_video_oper WHERE vid = ? ORDER BY ctime DESC"
  16. _operAttrSQL = "SELECT attribute, ctime FROM archive_video_oper WHERE vid=? ORDER BY ctime DESC;"
  17. )
  18. // AddArcOper insert archive_oper.
  19. func (d *Dao) AddArcOper(c context.Context, aid, adminID int64, attribute int32, typeID, state int16, round int8, lastID int64, content, remark string) (rows int64, err error) {
  20. res, err := d.db.Exec(c, _inArcOperSQL, aid, adminID, typeID, state, content, round, attribute, lastID, remark)
  21. if err != nil {
  22. log.Error("d.inArcOper.Exec error(%v)", err)
  23. return
  24. }
  25. rows, err = res.RowsAffected()
  26. return
  27. }
  28. // AddVideoOper insert archive_video_oper.
  29. func (d *Dao) AddVideoOper(c context.Context, aid, adminID, vid int64, attribute int32, status int16, lastID int64, content, remark string) (id int64, err error) {
  30. res, err := d.db.Exec(c, _inVideoOperSQL, aid, adminID, vid, status, content, attribute, lastID, remark)
  31. if err != nil {
  32. log.Error("d.inVideoOper.Exec error(%v)", err)
  33. return
  34. }
  35. id, err = res.LastInsertId()
  36. return
  37. }
  38. // UpVideoOper update archive_video_oper last_id by id.
  39. func (d *Dao) UpVideoOper(c context.Context, lastID, id int64) (rows int64, err error) {
  40. res, err := d.db.Exec(c, _upVideoOperSQL, lastID, id)
  41. if err != nil {
  42. log.Error("d.upVideoOper.Exec error(%v)", err)
  43. return
  44. }
  45. rows, err = res.RowsAffected()
  46. return
  47. }
  48. // ArchiveOper select archive_oper.
  49. func (d *Dao) ArchiveOper(c context.Context, aid int64) (oper *archive.ArcOper, err error) {
  50. row := d.rddb.QueryRow(c, _arcOperSQL, aid)
  51. oper = &archive.ArcOper{}
  52. if err = row.Scan(&oper.ID, &oper.Aid, &oper.UID, &oper.TypeID, &oper.State, &oper.Content, &oper.Round, &oper.Attribute, &oper.LastID, &oper.Remark); err != nil {
  53. if err == sql.ErrNoRows {
  54. err = nil
  55. } else {
  56. log.Error("row.Scan error(%v)", err)
  57. }
  58. }
  59. return
  60. }
  61. // VideoOper select archive_video_oper.
  62. func (d *Dao) VideoOper(c context.Context, vid int64) (oper *archive.VideoOper, err error) {
  63. row := d.rddb.QueryRow(c, _videoOperSQL, vid)
  64. oper = &archive.VideoOper{}
  65. if err = row.Scan(&oper.ID, &oper.AID, &oper.UID, &oper.VID, &oper.Status, &oper.Content, &oper.Attribute, &oper.LastID, &oper.Remark, &oper.CTime); err != nil {
  66. if err == sql.ErrNoRows {
  67. err = nil
  68. } else {
  69. log.Error("row.Scan error(%v)", err)
  70. }
  71. }
  72. return
  73. }
  74. // PassedOper check archive passed
  75. func (d *Dao) PassedOper(c context.Context, aid int64) (id int64, err error) {
  76. row := d.rddb.QueryRow(c, _arcPassedOperSQL, aid, archive.StateOpen)
  77. if err = row.Scan(&id); err != nil {
  78. if err == sql.ErrNoRows {
  79. err = nil
  80. } else {
  81. log.Error("row.Scan error(%v)", err)
  82. }
  83. }
  84. return
  85. }
  86. //VideoOperAttrsCtimes 获取vid的审核属性记录,按照ctime排序
  87. func (d *Dao) VideoOperAttrsCtimes(c context.Context, vid int64) (attrs []int32, ctimes []int64, err error) {
  88. rows, err := d.rddb.Query(c, _operAttrSQL, vid)
  89. if err != nil {
  90. log.Error("VideoOperAttrsCtimes d.rddb.Query error(%v)", err)
  91. return
  92. }
  93. defer rows.Close()
  94. for rows.Next() {
  95. var (
  96. ctime time.Time
  97. attr int32
  98. )
  99. if err = rows.Scan(&attr, &ctime); err != nil {
  100. log.Error("VideoOperAttrsCtimes rows.Scan error(%v)", err)
  101. return
  102. }
  103. attrs = append(attrs, attr)
  104. ctimes = append(ctimes, int64(ctime))
  105. }
  106. return
  107. }