charge_ratio.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/main/growup/model"
  5. "go-common/library/log"
  6. )
  7. const (
  8. _avDailyIncChargeSQL = "SELECT inc_charge, tag_id FROM av_daily_charge_06 WHERE av_id = ? AND date = '2018-06-24' AND upload_time >= '2018-06-24'"
  9. _avChargeRatioSQL = "SELECT id,av_id,ratio,adjust_type FROM av_charge_ratio WHERE id > ? ORDER BY id LIMIT ?"
  10. )
  11. // AvDailyIncCharge get av_daily_charge inc_charge
  12. func (d *Dao) AvDailyIncCharge(c context.Context, avID int64) (incCharge, tagID int64, err error) {
  13. err = d.db.QueryRow(c, _avDailyIncChargeSQL, avID).Scan(&incCharge, &tagID)
  14. return
  15. }
  16. // AvChargeRatio get av_charge_ratio
  17. func (d *Dao) AvChargeRatio(c context.Context, id int64, limit int64) (m map[int64]*model.AvChargeRatio, last int64, err error) {
  18. rows, err := d.db.Query(c, _avChargeRatioSQL, id, limit)
  19. if err != nil {
  20. log.Error("d.db.Query AvChargeRatio error(%v)", err)
  21. return
  22. }
  23. m = make(map[int64]*model.AvChargeRatio)
  24. defer rows.Close()
  25. for rows.Next() {
  26. ratio := &model.AvChargeRatio{}
  27. err = rows.Scan(&last, &ratio.AvID, &ratio.Ratio, &ratio.AdjustType)
  28. if err != nil {
  29. log.Error("AvChargeRatio scan error(%v)", err)
  30. return
  31. }
  32. m[ratio.AvID] = ratio
  33. }
  34. return
  35. }