date_statia.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package charge
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/library/log"
  6. )
  7. const (
  8. _inStatisTableSQL = "INSERT INTO %s(avs, money_section, money_tips, charge, category_id, cdate) VALUES %s ON DUPLICATE KEY UPDATE avs=VALUES(avs),charge=VALUES(charge),cdate=VALUES(cdate)"
  9. _delStatisTableSQL = "DELETE FROM %s WHERE cdate = ?"
  10. )
  11. // InsertStatisTable add archive_charge_date_statis batch
  12. func (d *Dao) InsertStatisTable(c context.Context, table, vals string) (rows int64, err error) {
  13. if table == "" {
  14. err = fmt.Errorf("InsertStatisTable table(%s) val(%s) error", table, vals)
  15. return
  16. }
  17. if vals == "" {
  18. return
  19. }
  20. res, err := d.db.Exec(c, fmt.Sprintf(_inStatisTableSQL, table, vals))
  21. if err != nil {
  22. log.Error("InsertStatisTable d.db.Exec error(%v)", err)
  23. return
  24. }
  25. return res.RowsAffected()
  26. }
  27. // DelStatisTable delete av_charge_statis
  28. func (d *Dao) DelStatisTable(c context.Context, table, date string) (rows int64, err error) {
  29. if table == "" || date == "" {
  30. err = fmt.Errorf("DelStatisTable table(%s) date(%s) error", table, date)
  31. return
  32. }
  33. res, err := d.db.Exec(c, fmt.Sprintf(_delStatisTableSQL, table), date)
  34. if err != nil {
  35. log.Error("DelStatisTable d.db.Exec error(%v)", err)
  36. return
  37. }
  38. return res.RowsAffected()
  39. }