addit.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package archive
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/job/main/videoup-report/model/archive"
  6. "go-common/library/database/sql"
  7. "go-common/library/log"
  8. "go-common/library/xstr"
  9. )
  10. const (
  11. _additSQL = "SELECT id,aid,source,redirect_url,mission_id,up_from,order_id,dynamic FROM archive_addit WHERE aid=?"
  12. _additsSQL = "SELECT id,aid,source,redirect_url,mission_id,up_from,order_id,dynamic FROM archive_addit WHERE aid IN (%s)"
  13. )
  14. // Addit get archive addit.
  15. func (d *Dao) Addit(c context.Context, aid int64) (addit *archive.Addit, err error) {
  16. row := d.db.QueryRow(c, _additSQL, aid)
  17. addit = &archive.Addit{}
  18. if err = row.Scan(&addit.ID, &addit.Aid, &addit.Source, &addit.RedirectURL, &addit.MissionID, &addit.UpFrom, &addit.OrderID, &addit.Dynamic); err != nil {
  19. if err == sql.ErrNoRows {
  20. addit = nil
  21. err = nil
  22. } else {
  23. log.Error("row.Scan error(%v)", err)
  24. }
  25. }
  26. return
  27. }
  28. // Addits batch get archive addit.
  29. func (d *Dao) Addits(c context.Context, aids []int64) (addits map[int64]*archive.Addit, err error) {
  30. addits = make(map[int64]*archive.Addit)
  31. if len(aids) < 1 {
  32. return
  33. }
  34. rows, err := d.db.Query(c, fmt.Sprintf(_additsSQL, xstr.JoinInts(aids)))
  35. if err != nil {
  36. log.Error("d.db.Query(%s) error(%v)", fmt.Sprintf(_additsSQL, xstr.JoinInts(aids)), err)
  37. return
  38. }
  39. defer rows.Close()
  40. for rows.Next() {
  41. addit := &archive.Addit{}
  42. if err = rows.Scan(&addit.ID, &addit.Aid, &addit.Source, &addit.RedirectURL, &addit.MissionID, &addit.UpFrom, &addit.OrderID, &addit.Dynamic); err != nil {
  43. log.Error("row.Scan error(%v)", err)
  44. return
  45. }
  46. addits[addit.Aid] = addit
  47. }
  48. return
  49. }