rating.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/interface/main/up-rating/model"
  6. "go-common/library/database/sql"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _upScoreSQL = "SELECT mid, creativity_score, influence_score, credit_score, cdate FROM up_rating_%02d WHERE mid=? AND cdate=? AND is_deleted=0"
  11. _taskStatusSQL = "SELECT status FROM task_status WHERE date=? "
  12. _whitelistSQL = "SELECT count(*) FROM up_white_list WHERE mid=? AND is_deleted=0"
  13. )
  14. // White will del later
  15. func (d *Dao) White(c context.Context, mid int64) (count int64, err error) {
  16. err = d.rddb.QueryRow(c, _whitelistSQL, mid).Scan(&count)
  17. if err != nil {
  18. if err == sql.ErrNoRows {
  19. err = nil
  20. } else {
  21. log.Error("UpScore row scan error(%v)", err)
  22. }
  23. }
  24. return
  25. }
  26. // TaskStatus ...
  27. func (d *Dao) TaskStatus(c context.Context, date string) (status int, err error) {
  28. err = d.rddb.QueryRow(c, _taskStatusSQL, date).Scan(&status)
  29. if err != nil {
  30. if err == sql.ErrNoRows {
  31. err = nil
  32. } else {
  33. log.Error("UpScore row scan error(%v)", err)
  34. }
  35. }
  36. return
  37. }
  38. // UpScore gets score data of UP
  39. func (d *Dao) UpScore(c context.Context, mon int, mid int64, date string) (score *model.Score, err error) {
  40. score = new(model.Score)
  41. row := d.rddb.QueryRow(c, fmt.Sprintf(_upScoreSQL, mon), mid, date)
  42. err = row.Scan(&score.MID, &score.Creative, &score.Influence, &score.Credit, &score.CDate)
  43. if err != nil {
  44. if err == sql.ErrNoRows {
  45. score, err = nil, nil
  46. } else {
  47. log.Error("UpScore row scan error(%v)", err)
  48. }
  49. }
  50. return
  51. }