history.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package archive
  2. import (
  3. "context"
  4. "go-common/app/admin/main/videoup/model/archive"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. "time"
  8. )
  9. const (
  10. _archistoryByAIDSQL = "SELECT `id`, `aid`, `title`, `tag`, `content`, `cover`, `mid`, `ctime` FROM `archive_edit_history` WHERE `aid`=? AND `ctime`>? ORDER BY `id` DESC;"
  11. _archistoryByIDSQL = "SELECT `id`, `aid`, `title`, `tag`, `content`, `cover`, `mid`, `ctime` FROM `archive_edit_history` WHERE `id`=? LIMIT 1"
  12. )
  13. //HistoryByAID 根据aid获取稿件的用户编辑历史
  14. func (d *Dao) HistoryByAID(c context.Context, aid int64, stime time.Time) (hs []*archive.ArcHistory, err error) {
  15. hs = []*archive.ArcHistory{}
  16. rows, err := d.db.Query(c, _archistoryByAIDSQL, aid, stime)
  17. if err != nil {
  18. log.Error("HistoryByAID d.db.Query(aid(%d)) error(%v)", aid, err)
  19. return
  20. }
  21. defer rows.Close()
  22. for rows.Next() {
  23. h := &archive.ArcHistory{}
  24. if err = rows.Scan(&h.ID, &h.AID, &h.Title, &h.Tag, &h.Content, &h.Cover, &h.MID, &h.CTime); err != nil {
  25. log.Error("HistoryByAID rows.Scan(aid(%d)) error(%v)", aid, err)
  26. return
  27. }
  28. hs = append(hs, h)
  29. }
  30. return
  31. }
  32. //HistoryByID 根据id获取一条稿件的用户编辑历史
  33. func (d *Dao) HistoryByID(c context.Context, id int64) (h *archive.ArcHistory, err error) {
  34. h = &archive.ArcHistory{}
  35. row := d.db.QueryRow(c, _archistoryByIDSQL, id)
  36. if err = row.Scan(&h.ID, &h.AID, &h.Title, &h.Tag, &h.Content, &h.Cover, &h.MID, &h.CTime); err != nil {
  37. if err == sql.ErrNoRows {
  38. return nil, nil
  39. }
  40. log.Error("HistoryByID row.Scan(id(%d)) error(%v)", id, err)
  41. }
  42. return
  43. }