oper.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package dao
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/admin/main/videoup-task/model"
  6. "go-common/library/database/sql"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _inVideoOperSQL = "INSERT INTO archive_video_oper (aid,uid,vid,status,content,attribute,last_id,remark) VALUES (?,?,?,?,?,?,?,?)"
  11. _videoOperSQL = "SELECT id,aid,uid,vid,status,content,attribute,last_id,remark,ctime FROM archive_video_oper WHERE vid = ? ORDER BY ctime DESC"
  12. _upVideoOperSQL = "UPDATE archive_video_oper SET last_id=? WHERE id=?"
  13. )
  14. // AddVideoOper insert archive_video_oper.
  15. func (d *Dao) AddVideoOper(c context.Context, aid, adminID, vid int64, attribute int32, status int16, lastID int64, content, remark string) (id int64, err error) {
  16. res, err := d.arcDB.Exec(c, _inVideoOperSQL, aid, adminID, vid, status, content, attribute, lastID, remark)
  17. if err != nil {
  18. log.Error("d.inVideoOper.Exec error(%v)", err)
  19. return
  20. }
  21. id, err = res.LastInsertId()
  22. return
  23. }
  24. //VideoOpers get video oper history list
  25. func (d *Dao) VideoOpers(c context.Context, vid int64) (op []*model.VOper, uids []int64, err error) {
  26. var (
  27. rows *sql.Rows
  28. ctime time.Time
  29. )
  30. op = []*model.VOper{}
  31. uids = []int64{}
  32. if rows, err = d.arcReadDB.Query(c, _videoOperSQL, vid); err != nil {
  33. log.Error("d.arcReadDB.Query error(%v)", err)
  34. return
  35. }
  36. defer rows.Close()
  37. for rows.Next() {
  38. p := &model.VOper{}
  39. if err = rows.Scan(&p.ID, &p.AID, &p.UID, &p.VID, &p.Status, &p.Content, &p.Attribute, &p.LastID, &p.Remark, &ctime); err != nil {
  40. log.Error("rows.Scan error(%v)", err)
  41. return
  42. }
  43. p.CTime = ctime.Format("2006-01-02 15:04:05")
  44. op = append(op, p)
  45. uids = append(uids, p.UID)
  46. }
  47. return
  48. }
  49. // UpVideoOper update archive_video_oper last_id by id.
  50. func (d *Dao) UpVideoOper(c context.Context, lastID, id int64) (rows int64, err error) {
  51. res, err := d.arcDB.Exec(c, _upVideoOperSQL, lastID, id)
  52. if err != nil {
  53. log.Error("d.upVideoOper.Exec error(%v)", err)
  54. return
  55. }
  56. rows, err = res.RowsAffected()
  57. return
  58. }