statistics.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _inRaingStatisticsSQL = "INSERT INTO up_rating_statistics(ups,section,tips,total_score,creativity_score,influence_score,credit_score,fans,avs,coin,play,tag_id,ctype,cdate) VALUES %s"
  10. _inAscSQL = "INSERT INTO up_rating_trend_%s(mid,tag_id,creativity_score,creativity_diff,influence_score,influence_diff,credit_score,credit_diff,magnetic_score,magnetic_diff,date,ctype,section,tips) VALUES %s ON DUPLICATE KEY UPDATE tag_id=VALUES(tag_id),creativity_score=VALUES(creativity_score),influence_score=VALUES(influence_score),credit_score=VALUES(credit_score)"
  11. _inRatingTopSQL = "INSERT INTO up_rating_top(mid,ctype,tag_id,score,fans,play,cdate) VALUES %s"
  12. _delTrendSQL = "DELETE FROM up_rating_trend_%s LIMIT ?"
  13. _delRatingComSQL = "DELETE FROM %s WHERE cdate='%s' LIMIT ?"
  14. )
  15. // DelTrend del trend limit x
  16. func (d *Dao) DelTrend(c context.Context, table string, limit int) (rows int64, err error) {
  17. res, err := d.db.Exec(c, fmt.Sprintf(_delTrendSQL, table), limit)
  18. if err != nil {
  19. log.Error("d.db.Exec(%s) error(%v)", fmt.Sprintf(_delTrendSQL, table), err)
  20. return
  21. }
  22. return res.RowsAffected()
  23. }
  24. // InsertRatingStatis batch insert rating statistics
  25. func (d *Dao) InsertRatingStatis(c context.Context, values string) (rows int64, err error) {
  26. if values == "" {
  27. return
  28. }
  29. res, err := d.db.Exec(c, fmt.Sprintf(_inRaingStatisticsSQL, values))
  30. if err != nil {
  31. log.Error("d.db.Exec(%s) error(%v)", fmt.Sprintf(_inRaingStatisticsSQL, values), err)
  32. return
  33. }
  34. return res.RowsAffected()
  35. }
  36. // InsertTrend insert asc values
  37. func (d *Dao) InsertTrend(c context.Context, table string, values string) (rows int64, err error) {
  38. if values == "" {
  39. return
  40. }
  41. res, err := d.db.Exec(c, fmt.Sprintf(_inAscSQL, table, values))
  42. if err != nil {
  43. log.Error("d.db.Exec(%s) error(%v)", fmt.Sprintf(_inAscSQL, table, values), err)
  44. return
  45. }
  46. return res.RowsAffected()
  47. }
  48. // InsertTopRating insert rating top
  49. func (d *Dao) InsertTopRating(c context.Context, values string) (rows int64, err error) {
  50. if values == "" {
  51. return
  52. }
  53. res, err := d.db.Exec(c, fmt.Sprintf(_inRatingTopSQL, values))
  54. if err != nil {
  55. log.Error("d.db.Exec(%s) error(%v)", fmt.Sprintf(_inRatingTopSQL, values), err)
  56. return
  57. }
  58. return res.RowsAffected()
  59. }
  60. // DelRatingCom del rating common by date
  61. func (d *Dao) DelRatingCom(c context.Context, table string, date time.Time, limit int) (rows int64, err error) {
  62. res, err := d.db.Exec(c, fmt.Sprintf(_delRatingComSQL, table, date.Format(_layout)), limit)
  63. if err != nil {
  64. return
  65. }
  66. return res.RowsAffected()
  67. }