archive.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package dao
  2. import (
  3. "context"
  4. "database/sql"
  5. "go-common/app/admin/main/videoup-task/model"
  6. xsql "go-common/library/database/sql"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _arcSQL = "SELECT id,mid,title,access,attribute,reject_reason,tag,forward,round,state,copyright,cover,content,typeid,pubtime,ctime,mtime FROM archive WHERE id=?"
  11. _archiveParamSQL = `SELECT a.typeid,addit.up_from FROM archive AS a LEFT JOIN archive_addit AS addit ON a.id=addit.aid WHERE a.id=?`
  12. )
  13. // Archive get archive by aid
  14. func (d *Dao) Archive(c context.Context, aid int64) (a *model.Archive, err error) {
  15. var (
  16. row = d.arcDB.QueryRow(c, _arcSQL, aid)
  17. reason, tag sql.NullString
  18. )
  19. a = &model.Archive{}
  20. if err = row.Scan(&a.Aid, &a.Mid, &a.Title, &a.Access, &a.Attribute, &reason, &tag, &a.Forward, &a.Round, &a.State,
  21. &a.Copyright, &a.Cover, &a.Desc, &a.TypeID, &a.PTime, &a.CTime, &a.MTime); err != nil {
  22. if err == xsql.ErrNoRows {
  23. a = nil
  24. err = nil
  25. } else {
  26. log.Error("row.Scan error(%v)", err)
  27. }
  28. return
  29. }
  30. a.RejectReason = reason.String
  31. a.Tag = tag.String
  32. return
  33. }
  34. // ArchiveParam .
  35. func (d *Dao) ArchiveParam(c context.Context, aid int64) (typeid int16, upfrom int8, err error) {
  36. if err = d.arcDB.QueryRow(c, _archiveParamSQL, aid).Scan(&typeid, &upfrom); err != nil {
  37. log.Error("ArchiveParam error(%v)", err)
  38. }
  39. return
  40. }