column_income_stat.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package income
  2. import (
  3. "context"
  4. "fmt"
  5. model "go-common/app/job/main/growup/model/income"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _columnIncomeStatSQL = "SELECT id,aid,mid,upload_time,total_income,title FROM column_income_statis WHERE id > ? ORDER BY id LIMIT ?"
  10. _inColumnIncomeStatSQL = "INSERT INTO column_income_statis(aid,title,mid,tag_id,upload_time,total_income) VALUES %s ON DUPLICATE KEY UPDATE aid=VALUES(aid),title=VALUES(title),mid=VALUES(mid),upload_time=VALUES(upload_time),total_income=VALUES(total_income)"
  11. )
  12. // ColumnIncomeStat key: av_id
  13. func (d *Dao) ColumnIncomeStat(c context.Context, id int64, limit int64) (m map[int64]*model.ColumnIncomeStat, last int64, err error) {
  14. rows, err := d.db.Query(c, _columnIncomeStatSQL, id, limit)
  15. if err != nil {
  16. log.Error("d.db.Query AvIncomeStat error(%v)", err)
  17. return
  18. }
  19. defer rows.Close()
  20. m = make(map[int64]*model.ColumnIncomeStat)
  21. for rows.Next() {
  22. c := &model.ColumnIncomeStat{}
  23. err = rows.Scan(&last, &c.ArticleID, &c.MID, &c.UploadTime, &c.TotalIncome, &c.Title)
  24. if err != nil {
  25. log.Error("rows scan error(%v)", err)
  26. return
  27. }
  28. m[c.ArticleID] = c
  29. }
  30. return
  31. }
  32. // InsertColumnIncomeStat batch insert column income stat
  33. func (d *Dao) InsertColumnIncomeStat(c context.Context, values string) (rows int64, err error) {
  34. res, err := d.db.Exec(c, fmt.Sprintf(_inColumnIncomeStatSQL, values))
  35. if err != nil {
  36. log.Error("d.db.Exec InsertColumnIncomeStat error(%v)", err)
  37. return
  38. }
  39. return res.RowsAffected()
  40. }