av_charge_statis.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package charge
  2. import (
  3. "context"
  4. "fmt"
  5. model "go-common/app/job/main/growup/model/charge"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _avChargeStatisSQL = "SELECT id,av_id,mid,total_charge,upload_time FROM av_charge_statis WHERE id > ? ORDER BY id LIMIT ?"
  10. _inAvChargeStatisSQL = "INSERT INTO av_charge_statis(av_id,mid,tag_id,is_original,total_charge,upload_time) VALUES %s ON DUPLICATE KEY UPDATE total_charge=VALUES(total_charge)"
  11. )
  12. // AvChargeStatis get av_charge_statis
  13. func (d *Dao) AvChargeStatis(c context.Context, id int64, limit int) (data []*model.AvChargeStatis, err error) {
  14. rows, err := d.db.Query(c, _avChargeStatisSQL, id, limit)
  15. if err != nil {
  16. log.Error("d.Query av_charge_statis error(%v)", err)
  17. return
  18. }
  19. defer rows.Close()
  20. for rows.Next() {
  21. ads := &model.AvChargeStatis{}
  22. err = rows.Scan(&ads.ID, &ads.AvID, &ads.MID, &ads.TotalCharge, &ads.UploadTime)
  23. if err != nil {
  24. log.Error("rows scan error(%v)", err)
  25. return
  26. }
  27. data = append(data, ads)
  28. }
  29. return
  30. }
  31. // InsertAvChargeStatisBatch add av charge statis batch
  32. func (d *Dao) InsertAvChargeStatisBatch(c context.Context, vals string) (count int64, err error) {
  33. if vals == "" {
  34. return
  35. }
  36. res, err := d.db.Exec(c, fmt.Sprintf(_inAvChargeStatisSQL, vals))
  37. if err != nil {
  38. log.Error("InsertAvChargeStatisBatch d.db.Exec error(%v)", err)
  39. return
  40. }
  41. return res.RowsAffected()
  42. }