forbid.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. )
  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. _upFlowIDSQL = "INSERT INTO archive_forbid (aid,on_flow_id) VALUES (?,?) ON DUPLICATE KEY UPDATE on_flow_id=?"
  12. _forbidSQL = `SELECT aid,rank_attr,recommend_attr,dynamic_attr,show_attr,on_flow_id FROM archive_forbid WHERE aid=?`
  13. )
  14. // TxUpForbid insert archive forbid.
  15. func (d *Dao) TxUpForbid(tx *sql.Tx, af *archive.ForbidAttr) (rows int64, err error) {
  16. res, err := tx.Exec(_inForbidSQL, af.Aid, af.RankV, af.RecommendV, af.DynamicV, af.ShowV, af.RankV, af.RecommendV, af.DynamicV, af.ShowV)
  17. if err != nil {
  18. log.Error("d.inForbid.Exec error(%v)", err)
  19. return
  20. }
  21. rows, err = res.RowsAffected()
  22. return
  23. }
  24. // TxUpFlowID insert archive flowid.
  25. func (d *Dao) TxUpFlowID(tx *sql.Tx, aid, onFlowID int64) (rows int64, err error) {
  26. res, err := tx.Exec(_upFlowIDSQL, aid, onFlowID, onFlowID)
  27. if err != nil {
  28. log.Error("d.upFlowID.Exec error(%v)", err)
  29. return
  30. }
  31. rows, err = res.RowsAffected()
  32. return
  33. }
  34. // Forbid get a archive forbid.
  35. func (d *Dao) Forbid(c context.Context, aid int64) (af *archive.ForbidAttr, err error) {
  36. row := d.rddb.QueryRow(c, _forbidSQL, aid)
  37. af = &archive.ForbidAttr{Aid: aid}
  38. if err = row.Scan(&af.Aid, &af.RankV, &af.DynamicV, &af.RecommendV, &af.ShowV, &af.OnFlowID); err != nil {
  39. if err == sql.ErrNoRows {
  40. // af = nil // NOTE: for init
  41. err = nil
  42. } else {
  43. log.Error("row.Scan error(%v)", err)
  44. }
  45. return
  46. }
  47. af.Convert()
  48. return
  49. }