archive.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package income
  2. import (
  3. "context"
  4. "fmt"
  5. model "go-common/app/job/main/growup/model/income"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _getArchiveByDateSQL = "SELECT id, %s, mid, tag_id, income, date FROM %s WHERE id > ? AND date = ? ORDER BY id LIMIT ?"
  10. _getBgmIncomeByDateSQL = "SELECT id, sid, mid, income, date FROM bgm_income WHERE id > ? AND date = ? ORDER BY id LIMIT ?"
  11. )
  12. // GetArchiveByDate get archive by date
  13. func (d *Dao) GetArchiveByDate(c context.Context, aid, table, date string, id int64, limit int) (archives []*model.ArchiveIncome, err error) {
  14. archives = make([]*model.ArchiveIncome, 0)
  15. rows, err := d.db.Query(c, fmt.Sprintf(_getArchiveByDateSQL, aid, table), id, date, limit)
  16. if err != nil {
  17. log.Error("GetArchiveByDate d.db.Query error(%v)", err)
  18. return
  19. }
  20. defer rows.Close()
  21. for rows.Next() {
  22. archive := &model.ArchiveIncome{}
  23. err = rows.Scan(&archive.ID, &archive.AID, &archive.MID, &archive.TagID, &archive.Income, &archive.Date)
  24. if err != nil {
  25. log.Error("GetArchiveByDate rows.Scan error(%v)", err)
  26. return
  27. }
  28. archives = append(archives, archive)
  29. }
  30. return
  31. }
  32. // GetBgmIncomeByDate get bgm income by date
  33. func (d *Dao) GetBgmIncomeByDate(c context.Context, date string, id int64, limit int) (archives []*model.ArchiveIncome, err error) {
  34. archives = make([]*model.ArchiveIncome, 0)
  35. rows, err := d.db.Query(c, _getBgmIncomeByDateSQL, id, date, limit)
  36. if err != nil {
  37. log.Error("GetArchiveByDate d.db.Query error(%v)", err)
  38. return
  39. }
  40. defer rows.Close()
  41. for rows.Next() {
  42. archive := &model.ArchiveIncome{}
  43. err = rows.Scan(&archive.ID, &archive.AID, &archive.MID, &archive.Income, &archive.Date)
  44. if err != nil {
  45. log.Error("GetArchiveByDate rows.Scan error(%v)", err)
  46. return
  47. }
  48. archives = append(archives, archive)
  49. }
  50. return
  51. }