income_date_statis.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package income
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/library/log"
  6. )
  7. const (
  8. _inIncomeStatisTableSQL = "INSERT INTO %s(avs, money_section, money_tips, income, category_id, cdate) VALUES %s ON DUPLICATE KEY UPDATE avs=VALUES(avs),income=VALUES(income),cdate=VALUES(cdate)"
  9. _delIncomeStatisTableSQL = "DELETE FROM %s WHERE cdate = ?"
  10. _inUpIncomeDailyStatisSQL = "INSERT INTO %s(ups, money_section, money_tips, income, cdate) VALUES %s ON DUPLICATE KEY UPDATE ups=VALUES(ups),income=VALUES(income),cdate=VALUES(cdate)"
  11. )
  12. // InsertIncomeStatisTable add av_income_date_statis batch
  13. func (d *Dao) InsertIncomeStatisTable(c context.Context, table, vals string) (rows int64, err error) {
  14. if table == "" {
  15. err = fmt.Errorf("InsertIncomeStatisTable table(%s) val(%s) error", table, vals)
  16. return
  17. }
  18. if vals == "" {
  19. return
  20. }
  21. res, err := d.db.Exec(c, fmt.Sprintf(_inIncomeStatisTableSQL, table, vals))
  22. if err != nil {
  23. log.Error("incomeStatisTableBatch d.db.Exec error(%v)", err)
  24. return
  25. }
  26. return res.RowsAffected()
  27. }
  28. // InsertUpIncomeDailyStatis add up_income_daily_statis batch
  29. func (d *Dao) InsertUpIncomeDailyStatis(c context.Context, table string, vals string) (rows int64, err error) {
  30. if vals == "" {
  31. return
  32. }
  33. res, err := d.db.Exec(c, fmt.Sprintf(_inUpIncomeDailyStatisSQL, table, vals))
  34. if err != nil {
  35. log.Error("InsertUpIncomeDailyStatis d.db.Exec error(%v)", err)
  36. return
  37. }
  38. return res.RowsAffected()
  39. }
  40. // DelIncomeStatisTable del income statis by table
  41. func (d *Dao) DelIncomeStatisTable(c context.Context, table, date string) (rows int64, err error) {
  42. if table == "" || date == "" {
  43. err = fmt.Errorf("DelIncomeStatisTable table(%s) date(%s) error", table, date)
  44. return
  45. }
  46. res, err := d.db.Exec(c, fmt.Sprintf(_delIncomeStatisTableSQL, table), date)
  47. if err != nil {
  48. log.Error("DelIncomeStatisTable d.db.Exec error(%v)", err)
  49. return
  50. }
  51. return res.RowsAffected()
  52. }