archive_oper.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package archive
  2. import (
  3. "context"
  4. "database/sql"
  5. "go-common/app/job/main/videoup-report/model/archive"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _operLastRoundSQL = "SELECT id,aid,uid,typeid,state,round,attribute,last_id,ctime,mtime FROM archive_oper WHERE aid = ? AND round = ? ORDER BY id DESC LIMIT 1"
  10. _operNextRoundSQL = "SELECT id,aid,uid,typeid,state,round,attribute,last_id,ctime,mtime FROM archive_oper WHERE id > ? AND aid = ? AND round != ? ORDER BY id ASC LIMIT 1"
  11. _operInsertSQL = "INSERT INTO archive_oper(aid,uid,typeid,state,content,round,attribute,last_id,remark) VALUES(?,399,?,?,?,?,?,?,?)"
  12. _lastArcOperSQL = "SELECT aid,uid,typeid,content,round,attribute,last_id,remark FROM archive_oper WHERE aid=? AND uid!=399 ORDER BY mtime DESC LIMIT 1"
  13. _lastVideoOperUIDSQL = "SELECT uid FROM archive_video_oper WHERE vid=? AND uid != 399 ORDER BY mtime DESC LIMIT 1;"
  14. _lastVideoOperSQL = "SELECT aid, uid, vid, status, content, attribute, last_id, remark FROM archive_video_oper WHERE vid=? AND uid != 399 ORDER BY mtime DESC LIMIT 1;"
  15. )
  16. // LastRoundOper get last archive round record.
  17. func (d *Dao) LastRoundOper(c context.Context, aid int64, round int8) (oper *archive.Oper, err error) {
  18. row := d.db.QueryRow(c, _operLastRoundSQL, aid, round)
  19. oper = &archive.Oper{}
  20. if err = row.Scan(&oper.ID, &oper.AID, &oper.UID, &oper.TypeID, &oper.State, &oper.Round, &oper.Attribute, &oper.LastID, &oper.CTime, &oper.MTime); err != nil {
  21. log.Error("row.Scan error(%v)", err)
  22. return
  23. }
  24. return
  25. }
  26. // NextRoundOper get next archive round record.
  27. func (d *Dao) NextRoundOper(c context.Context, id int64, aid int64, round int8) (oper *archive.Oper, err error) {
  28. row := d.db.QueryRow(c, _operNextRoundSQL, id, aid, round)
  29. oper = &archive.Oper{}
  30. if err = row.Scan(&oper.ID, &oper.AID, &oper.UID, &oper.TypeID, &oper.State, &oper.Round, &oper.Attribute, &oper.LastID, &oper.CTime, &oper.MTime); err != nil {
  31. log.Error("row.Scan error(%v)", err)
  32. return
  33. }
  34. return
  35. }
  36. // AddArchiveOper add archive operate log
  37. func (d *Dao) AddArchiveOper(c context.Context, aid int64, attribute int32, typeid int16, state int, round int8, lastID int64, content, remark string) (id int64, err error) {
  38. var (
  39. res sql.Result
  40. )
  41. if res, err = d.db.Exec(c, _operInsertSQL, aid, typeid, state, content, round, attribute, lastID, remark); err != nil {
  42. log.Error("AddArchiveOper(%d,%d,%d,%d,%s,%d,%d,%d,%s) error(%v)", aid, typeid, state, content, round, attribute, lastID, remark, err)
  43. return
  44. }
  45. id, err = res.LastInsertId()
  46. return
  47. }
  48. //LastVideoOperUID get the last manual-operate operator id by vid
  49. func (d *Dao) LastVideoOperUID(c context.Context, vid int64) (uid int64, err error) {
  50. if err = d.db.QueryRow(c, _lastVideoOperUIDSQL, vid).Scan(&uid); err != nil {
  51. log.Error("LastVideoOperUID db.row.Scan error(%v) vid(%d)", err, vid)
  52. }
  53. return
  54. }
  55. //LastVideoOper get the last manual-operate record by vid
  56. func (d *Dao) LastVideoOper(c context.Context, vid int64) (oper *archive.VideoOper, err error) {
  57. oper = &archive.VideoOper{}
  58. if err = d.db.QueryRow(c, _lastVideoOperSQL, vid).Scan(&oper.AID, &oper.UID, &oper.VID, &oper.Status, &oper.Content, &oper.Attribute, &oper.LastID, &oper.Remark); err != nil {
  59. log.Error("LastVideoOper db.row.Scan error(%v), vid(%d)", err, vid)
  60. }
  61. return
  62. }
  63. // LastArcOper get a archive last history.
  64. func (d *Dao) LastArcOper(c context.Context, aid int64) (re *archive.Oper, err error) {
  65. re = &archive.Oper{}
  66. if err = d.db.QueryRow(c, _lastArcOperSQL, aid).Scan(&re.AID, &re.UID, &re.TypeID, &re.Content, &re.Round, &re.Attribute, &re.LastID, &re.Remark); err != nil {
  67. log.Error(" LastArcOper db.row.Scan error(%v) aid(%d)", err, aid)
  68. }
  69. return
  70. }