charge_ratio.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package income
  2. import (
  3. "context"
  4. model "go-common/app/job/main/growup/model/income"
  5. "go-common/library/log"
  6. )
  7. const (
  8. _avChargeRatioSQL = "SELECT id,av_id,ratio,adjust_type,ctype FROM av_charge_ratio WHERE id > ? ORDER BY id LIMIT ?"
  9. _upChargeRatioSQL = "SELECT id,mid,ratio,adjust_type,ctype FROM up_charge_ratio WHERE id > ? ORDER BY id LIMIT ?"
  10. )
  11. // ArchiveChargeRatio map[ctype]map[archive_id]*archiveChargeRatio
  12. func (d *Dao) ArchiveChargeRatio(c context.Context, id int64, limit int64) (m map[int]map[int64]*model.ArchiveChargeRatio, last int64, err error) {
  13. rows, err := d.db.Query(c, _avChargeRatioSQL, id, limit)
  14. if err != nil {
  15. log.Error("d.db.Query AvChargeRatio error(%v)", err)
  16. return
  17. }
  18. m = make(map[int]map[int64]*model.ArchiveChargeRatio)
  19. defer rows.Close()
  20. for rows.Next() {
  21. ratio := &model.ArchiveChargeRatio{}
  22. err = rows.Scan(&last, &ratio.ArchiveID, &ratio.Ratio, &ratio.AdjustType, &ratio.CType)
  23. if err != nil {
  24. log.Error("AvChargeRatio scan error(%v)", err)
  25. return
  26. }
  27. if ac, ok := m[ratio.CType]; ok {
  28. ac[ratio.ArchiveID] = ratio
  29. } else {
  30. m[ratio.CType] = map[int64]*model.ArchiveChargeRatio{
  31. ratio.ArchiveID: ratio,
  32. }
  33. }
  34. }
  35. return
  36. }
  37. // UpChargeRatio get every day up charge ratio
  38. func (d *Dao) UpChargeRatio(c context.Context, id int64, limit int64) (m map[int]map[int64]*model.UpChargeRatio, last int64, err error) {
  39. rows, err := d.db.Query(c, _upChargeRatioSQL, id, limit)
  40. if err != nil {
  41. log.Error("d.db.Query UpChargeRatio error(%v)", err)
  42. return
  43. }
  44. m = make(map[int]map[int64]*model.UpChargeRatio)
  45. defer rows.Close()
  46. for rows.Next() {
  47. ratio := &model.UpChargeRatio{}
  48. err = rows.Scan(&last, &ratio.MID, &ratio.Ratio, &ratio.AdjustType, &ratio.CType)
  49. if err != nil {
  50. log.Error("UpChargeRatio scan error(%v)", err)
  51. return
  52. }
  53. if ur, ok := m[ratio.CType]; ok {
  54. ur[ratio.MID] = ratio
  55. } else {
  56. m[ratio.CType] = map[int64]*model.UpChargeRatio{
  57. ratio.MID: ratio,
  58. }
  59. }
  60. }
  61. return
  62. }