archive.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package archive
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/service/main/up/model"
  6. "go-common/library/database/sql"
  7. "go-common/library/time"
  8. "go-common/library/xstr"
  9. )
  10. const (
  11. _arcsAidsSQL = "SELECT aid,pubtime,copyright FROM archive WHERE aid IN (%s) AND state>=0 ORDER BY pubtime DESC"
  12. )
  13. // ArcsAids get archives by aids.
  14. func (d *Dao) ArcsAids(c context.Context, ids []int64) (aids []int64, ptimes []time.Time, copyrights []int8, aptm map[int64]*model.AidPubTime, err error) {
  15. d.infoProm.Incr("ArcAids")
  16. rows, err := d.resultDB.Query(c, fmt.Sprintf(_arcsAidsSQL, xstr.JoinInts(ids)))
  17. if err != nil {
  18. return
  19. }
  20. defer rows.Close()
  21. aptm = make(map[int64]*model.AidPubTime, len(ids))
  22. for rows.Next() {
  23. var (
  24. aid int64
  25. ptime time.Time
  26. copyright int8
  27. )
  28. if err = rows.Scan(&aid, &ptime, &copyright); err != nil {
  29. if err == sql.ErrNoRows {
  30. err = nil
  31. return
  32. }
  33. return
  34. }
  35. aptm[aid] = &model.AidPubTime{Aid: aid, PubDate: ptime, Copyright: copyright}
  36. aids = append(aids, aid)
  37. ptimes = append(ptimes, ptime)
  38. copyrights = append(copyrights, copyright)
  39. }
  40. return
  41. }