av_income_stat.go 1.5 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. _avIncomeStatSQL = "SELECT id,av_id,mid,tag_id,is_original,upload_time,total_income,ctime FROM av_income_statis WHERE id > ? ORDER BY id LIMIT ?"
  10. _inAvIncomeStatSQL = "INSERT INTO av_income_statis(av_id,mid,tag_id,is_original,upload_time,total_income) VALUES %s ON DUPLICATE KEY UPDATE av_id=VALUES(av_id),mid=VALUES(mid),tag_id=VALUES(tag_id),is_original=VALUES(is_original),upload_time=VALUES(upload_time),total_income=VALUES(total_income)"
  11. )
  12. // AvIncomeStat key: av_id
  13. func (d *Dao) AvIncomeStat(c context.Context, id int64, limit int64) (m map[int64]*model.AvIncomeStat, last int64, err error) {
  14. rows, err := d.db.Query(c, _avIncomeStatSQL, id, limit)
  15. if err != nil {
  16. log.Error("d.db.Query AvIncomeStat error(%v)", err)
  17. return
  18. }
  19. defer rows.Close()
  20. m = make(map[int64]*model.AvIncomeStat)
  21. for rows.Next() {
  22. a := &model.AvIncomeStat{}
  23. err = rows.Scan(&last, &a.AvID, &a.MID, &a.TagID, &a.IsOriginal, &a.UploadTime, &a.TotalIncome, &a.CTime)
  24. if err != nil {
  25. log.Error("rows scan error(%v)", err)
  26. return
  27. }
  28. m[a.AvID] = a
  29. }
  30. return
  31. }
  32. // InsertAvIncomeStat batch insert av income stat
  33. func (d *Dao) InsertAvIncomeStat(c context.Context, values string) (rows int64, err error) {
  34. res, err := d.db.Exec(c, fmt.Sprintf(_inAvIncomeStatSQL, values))
  35. if err != nil {
  36. log.Error("d.db.Exec InsertAvIncomeStat error(%v)", err)
  37. return
  38. }
  39. return res.RowsAffected()
  40. }