bgm_income_stat.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. _bgmIncomeStatSQL = "SELECT id,sid,total_income FROM bgm_income_statis WHERE id > ? ORDER BY id LIMIT ?"
  10. _inBgmIncomeStatSQL = "INSERT INTO bgm_income_statis(sid,total_income) VALUES %s ON DUPLICATE KEY UPDATE sid=VALUES(sid),total_income=VALUES(total_income)"
  11. )
  12. // BgmIncomeStat key: sid
  13. func (d *Dao) BgmIncomeStat(c context.Context, id int64, limit int64) (m map[int64]*model.BgmIncomeStat, last int64, err error) {
  14. rows, err := d.db.Query(c, _bgmIncomeStatSQL, id, limit)
  15. if err != nil {
  16. log.Error("d.db.Query BgmIncomeStat error(%v)", err)
  17. return
  18. }
  19. defer rows.Close()
  20. m = make(map[int64]*model.BgmIncomeStat)
  21. for rows.Next() {
  22. b := &model.BgmIncomeStat{}
  23. err = rows.Scan(&last, &b.SID, &b.TotalIncome)
  24. if err != nil {
  25. log.Error("rows scan error(%v)", err)
  26. return
  27. }
  28. m[b.SID] = b
  29. }
  30. return
  31. }
  32. // InsertBgmIncomeStat batch insert bgm income stat
  33. func (d *Dao) InsertBgmIncomeStat(c context.Context, values string) (rows int64, err error) {
  34. res, err := d.db.Exec(c, fmt.Sprintf(_inBgmIncomeStatSQL, values))
  35. if err != nil {
  36. log.Error("d.db.Exec InsertBgmIncomeStat error(%v)", err)
  37. return
  38. }
  39. return res.RowsAffected()
  40. }