oper.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package archive
  2. import (
  3. "context"
  4. "go-common/app/job/main/videoup/model/archive"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _inArchiveOperSQL = "INSERT INTO archive_oper(aid,uid,typeid,state,round,attribute,last_id,content) VALUES(?,399,?,?,?,?,?,?)"
  10. _arcPassedOperSQL = "SELECT id FROM archive_oper WHERE aid=? AND state>=? LIMIT 1"
  11. )
  12. // TxArchiveOper add archive oper log
  13. func (d *Dao) TxArchiveOper(tx *sql.Tx, aid int64, typeID int16, state int8, round int8, attr int32, lastID int64, content string) (rows int64, err error) {
  14. res, err := tx.Exec(_inArchiveOperSQL, aid, typeID, state, round, attr, lastID, content)
  15. if err != nil {
  16. log.Error("tx.Exec error(%v)", err)
  17. return
  18. }
  19. rows, err = res.RowsAffected()
  20. return
  21. }
  22. // ArchiveOper add archive oper log
  23. func (d *Dao) ArchiveOper(c context.Context, aid int64, typeID int16, state int8, round int8, attr int32, lastID int64, content string) (rows int64, err error) {
  24. res, err := d.db.Exec(c, _inArchiveOperSQL, aid, typeID, state, round, attr, lastID, content)
  25. if err != nil {
  26. log.Error("tx.Exec error(%v)", err)
  27. return
  28. }
  29. rows, err = res.RowsAffected()
  30. return
  31. }
  32. // PassedOper check archive passed
  33. func (d *Dao) PassedOper(c context.Context, aid int64) (id int64, err error) {
  34. row := d.db.QueryRow(c, _arcPassedOperSQL, aid, archive.StateOpen)
  35. if err = row.Scan(&id); err != nil {
  36. if err == sql.ErrNoRows {
  37. err = nil
  38. } else {
  39. log.Error("row.Scan error(%v)", err)
  40. }
  41. }
  42. return
  43. }