forbid.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package archive
  2. import (
  3. "context"
  4. "go-common/app/job/main/videoup/model/archive"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _inForbidSQL = `INSERT INTO archive_forbid (aid,rank_attr,recommend_attr,dynamic_attr,show_attr) VALUES (?,?,?,?,?) ON DUPLICATE KEY UPDATE
  10. rank_attr=?,recommend_attr=?,dynamic_attr=?,show_attr=?`
  11. _forbidSQL = `SELECT aid,rank_attr,recommend_attr,dynamic_attr,show_attr,on_flow_id FROM archive_forbid WHERE aid=?`
  12. )
  13. // TxUpForbid insert archive_oper.
  14. func (d *Dao) TxUpForbid(tx *sql.Tx, af *archive.ForbidAttr) (rows int64, err error) {
  15. res, err := tx.Exec(_inForbidSQL, af.Aid, af.RankV, af.RecommendV, af.DynamicV, af.ShowV, af.RankV, af.RecommendV, af.DynamicV, af.ShowV)
  16. if err != nil {
  17. log.Error("d.inForbid.Exec error(%v)", err)
  18. return
  19. }
  20. rows, err = res.RowsAffected()
  21. return
  22. }
  23. // Forbid get a archive forbid.
  24. func (d *Dao) Forbid(c context.Context, aid int64) (af *archive.ForbidAttr, err error) {
  25. row := d.db.QueryRow(c, _forbidSQL, aid)
  26. af = &archive.ForbidAttr{Aid: aid}
  27. if err = row.Scan(&af.Aid, &af.RankV, &af.RecommendV, &af.DynamicV, &af.ShowV, &af.OnFlowID); err != nil {
  28. if err == sql.ErrNoRows {
  29. // af = nil // NOTE: for init
  30. err = nil
  31. } else {
  32. log.Error("row.Scan error(%v)", err)
  33. }
  34. return
  35. }
  36. return
  37. }