archive.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package archive
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. "go-common/app/job/main/videoup-report/model/archive"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _archiveByAidSQL = "SELECT id,mid,typeid,copyright,author,title,cover,content,duration,round,attribute,access,state,tag,pubtime,ctime,mtime FROM archive WHERE id=? "
  11. _arcNoteSQL = "SELECT coalesce(note,'') from archive where id=?"
  12. _upOriginalAids = "SELECT " +
  13. "a.id,a.mid,a.typeid,a.copyright,a.author,a.title,a.cover,a.content,a.duration,a.round,a.attribute,a.access,a.state,a.tag,a.pubtime,a.ctime,a.mtime " +
  14. "FROM archive AS a LEFT JOIN archive_delay as delay ON delay.aid = a.id " +
  15. "WHERE a.mid=? AND a.copyright=? AND a.ctime>=? AND a.ctime<? AND (a.state >= 0 OR delay.state >= 0)"
  16. _upArcTagSQL = "UPDATE archive SET tag=? WHERE id=?"
  17. )
  18. // ArchiveByAid get archive by aid
  19. func (d *Dao) ArchiveByAid(c context.Context, aid int64) (arc *archive.Archive, err error) {
  20. row := d.db.QueryRow(c, _archiveByAidSQL, aid)
  21. arc = &archive.Archive{}
  22. if err = row.Scan(&arc.ID, &arc.Mid, &arc.TypeID, &arc.Copyright, &arc.Author, &arc.Title, &arc.Cover, &arc.Desc, &arc.Duration,
  23. &arc.Round, &arc.Attribute, &arc.Access, &arc.State, &arc.Tag, &arc.PTime, &arc.CTime, &arc.MTime); err != nil {
  24. log.Error("row.Scan error(%v)", err)
  25. }
  26. return
  27. }
  28. //ArchiveNote 稿件审核的备注字段,可能为NIL
  29. func (d *Dao) ArchiveNote(c context.Context, aid int64) (note string, err error) {
  30. if err = d.db.QueryRow(c, _arcNoteSQL, aid).Scan(&note); err != nil {
  31. log.Error("ArchiveNote db.row.Scan error(%v), aid(%d)", err, aid)
  32. }
  33. return
  34. }
  35. // ExcitationArchivesByTime 获取Up主过审的自制稿件
  36. func (d *Dao) ExcitationArchivesByTime(c context.Context, mid int64, bt, et time.Time) (archives []*archive.Archive, err error) {
  37. archives = []*archive.Archive{}
  38. if mid < 1 {
  39. err = fmt.Errorf("wrong mid(%d)", mid)
  40. return
  41. }
  42. rows, err := d.db.Query(c, _upOriginalAids, mid, archive.CopyrightOriginal, bt, et)
  43. if err != nil {
  44. log.Error("d.db.Query(%s,%d,%d,%v,%v) error(%v)", _upOriginalAids, mid, archive.CopyrightOriginal, bt, et)
  45. return
  46. }
  47. defer rows.Close()
  48. for rows.Next() {
  49. arc := &archive.Archive{}
  50. if err = rows.Scan(&arc.ID, &arc.Mid, &arc.TypeID, &arc.Copyright, &arc.Author, &arc.Title, &arc.Cover, &arc.Desc, &arc.Duration,
  51. &arc.Round, &arc.Attribute, &arc.Access, &arc.State, &arc.Tag, &arc.PTime, &arc.CTime, &arc.MTime); err != nil {
  52. log.Error("rows.Scan() error(%v)", err)
  53. return
  54. }
  55. archives = append(archives, arc)
  56. }
  57. return
  58. }
  59. //UpTag update archive tag
  60. func (d *Dao) UpTag(c context.Context, aid int64, tags string) (rows int64, err error) {
  61. res, err := d.db.Exec(c, _upArcTagSQL, tags, aid)
  62. if err != nil {
  63. log.Error("d.UpTag.Exec() error(%v)", err)
  64. return
  65. }
  66. rows, err = res.RowsAffected()
  67. return
  68. }