delay.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package archive
  2. import (
  3. "context"
  4. "database/sql"
  5. "go-common/app/admin/main/videoup/model/archive"
  6. xsql "go-common/library/database/sql"
  7. "go-common/library/log"
  8. xtime "go-common/library/time"
  9. "time"
  10. )
  11. const (
  12. _upDelaySQL = "INSERT INTO archive_delay (aid,type,mid,state,dtime) VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE mid=?,state=?,dtime=?,deleted_at='0000-00-00 00:00:00'"
  13. _upDelStateSQL = "UPDATE archive_delay SET state=? WHERE aid=? AND type=?"
  14. _upDelayDtimeSQL = "UPDATE archive_delay SET dtime=? WHERE aid=? AND type=?"
  15. _delDelaySQL = "UPDATE archive_delay SET deleted_at = ? WHERE aid=? AND type=?"
  16. _DelaySQL = "SELECT aid,dtime,state,mid FROM archive_delay WHERE aid=? AND type=? AND deleted_at = 0"
  17. )
  18. // TxUpDelay update delay
  19. func (d *Dao) TxUpDelay(tx *xsql.Tx, mid, aid int64, state, tp int8, dTime xtime.Time) (rows int64, err error) {
  20. res, err := tx.Exec(_upDelaySQL, aid, tp, mid, state, dTime, mid, state, dTime)
  21. if err != nil {
  22. log.Error("d.TxUpDelay.Exec() error(%v)", err)
  23. return
  24. }
  25. rows, err = res.RowsAffected()
  26. return
  27. }
  28. // TxUpDelState update delay state
  29. func (d *Dao) TxUpDelState(tx *xsql.Tx, aid int64, state, tp int8) (rows int64, err error) {
  30. res, err := tx.Exec(_upDelStateSQL, state, aid, tp)
  31. if err != nil {
  32. log.Error("d.TxUpDelState.Exec() error(%v)", err)
  33. return
  34. }
  35. rows, err = res.RowsAffected()
  36. return
  37. }
  38. // TxUpDelayDtime update archive delaytime by aid.
  39. func (d *Dao) TxUpDelayDtime(tx *xsql.Tx, aid int64, tp int8, dtime xtime.Time) (rows int64, err error) {
  40. res, err := tx.Exec(_upDelayDtimeSQL, dtime, aid, tp)
  41. if err != nil {
  42. log.Error("d.TxUpDelayDtime.Exec() error(%v)", err)
  43. return
  44. }
  45. rows, err = res.RowsAffected()
  46. return
  47. }
  48. // TxDelDelay delete delay
  49. func (d *Dao) TxDelDelay(tx *xsql.Tx, aid int64, tp int8) (rows int64, err error) {
  50. res, err := tx.Exec(_delDelaySQL, time.Now(), aid, tp)
  51. if err != nil {
  52. log.Error("d.TxDelDelay.Exec() error(%v)", err)
  53. return
  54. }
  55. rows, err = res.RowsAffected()
  56. return
  57. }
  58. // Delay get a delay time by avid.
  59. func (d *Dao) Delay(c context.Context, aid int64, tp int8) (dl *archive.Delay, err error) {
  60. row := d.rddb.QueryRow(c, _DelaySQL, aid, tp)
  61. dl = &archive.Delay{}
  62. if err = row.Scan(&dl.Aid, &dl.DTime, &dl.State, &dl.Mid); err != nil {
  63. if err == sql.ErrNoRows {
  64. dl = nil
  65. err = nil
  66. } else {
  67. log.Error("row.Scan error(%v)", err)
  68. }
  69. return
  70. }
  71. return
  72. }