porder.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. _inPorderSQL = `INSERT INTO archive_porder (aid,industry_id,brand_id,brand_name,official,show_type,show_front,advertiser,agent,state) VALUES (?,?,?,?,?,?,?,?,?,1) ON DUPLICATE KEY UPDATE
  10. industry_id=?,brand_id=?,brand_name=?,official=?,show_type=?,show_front=?,advertiser=?,agent=?`
  11. _selPorderSQL = `select industry_id,brand_id,brand_name,official,show_type,advertiser,agent,state from archive_porder where aid=?`
  12. _selPorderConfigSQL = `select id,name,rank,type,state from porder_config`
  13. )
  14. // TxUpPorder archive_porder
  15. func (d *Dao) TxUpPorder(tx *sql.Tx, aid int64, ap *archive.ArcParam) (rows int64, err error) {
  16. res, err := tx.Exec(_inPorderSQL, aid, ap.IndustryID, ap.BrandID, ap.BrandName, ap.Official, ap.ShowType, ap.ShowFront, ap.Advertiser, ap.Agent, ap.IndustryID, ap.BrandID, ap.BrandName, ap.Official, ap.ShowType, ap.ShowFront, ap.Advertiser, ap.Agent)
  17. if err != nil {
  18. log.Error("d.TxUpPorder.Exec error(%v)", err)
  19. return
  20. }
  21. rows, err = res.RowsAffected()
  22. return
  23. }
  24. // Porder get archive Proder
  25. func (d *Dao) Porder(c context.Context, aid int64) (p *archive.Porder, err error) {
  26. row := d.rddb.QueryRow(c, _selPorderSQL, aid)
  27. p = &archive.Porder{}
  28. if err = row.Scan(&p.IndustryID, &p.BrandID, &p.BrandName, &p.Official, &p.ShowType, &p.Advertiser, &p.Agent, &p.State); err != nil {
  29. if err != sql.ErrNoRows {
  30. log.Error("row.Scan error(%v)", err)
  31. return
  32. }
  33. err = nil
  34. }
  35. return
  36. }
  37. // PorderConfig get archive ProderConfigs
  38. func (d *Dao) PorderConfig(c context.Context) (pc map[int64]*archive.PorderConfig, err error) {
  39. rows, err := d.rddb.Query(c, _selPorderConfigSQL)
  40. if err != nil {
  41. log.Error("d.db.Query(%s) error(%v)", err)
  42. return
  43. }
  44. defer rows.Close()
  45. pc = make(map[int64]*archive.PorderConfig)
  46. for rows.Next() {
  47. ap := &archive.PorderConfig{}
  48. if err = rows.Scan(&ap.ID, &ap.Name, &ap.Rank, &ap.Type, &ap.State); err != nil {
  49. log.Error("rows.Scan error(%v)", err)
  50. return
  51. }
  52. pc[ap.ID] = ap
  53. }
  54. return
  55. }