recommend.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package dao
  2. import (
  3. "context"
  4. "database/sql"
  5. "time"
  6. "go-common/app/job/main/mcn/model"
  7. xsql "go-common/library/database/sql"
  8. )
  9. const (
  10. _inMcnUpRecommendPoolSQL = `INSERT INTO mcn_up_recommend_pool (up_mid, fans_count, fans_count_increase_month, archive_count, play_count_accumulate, play_count_average, active_tid, last_archive_time, generate_time) VALUES (?,?,?,?,?,?,?,?,?)
  11. ON DUPLICATE KEY UPDATE fans_count=?, fans_count_increase_month=?, archive_count=?, play_count_accumulate=?, play_count_average=?, active_tid=?, last_archive_time=?, generate_time=?`
  12. _delMcnUpRecommendPoolSQL = "UPDATE mcn_up_recommend_pool SET state = 100 WHERE generate_time < ? AND state IN (1,2) AND source = 1"
  13. _delMcnUpRecommendSourceSQL = "DELETE FROM mcn_up_recommend_source WHERE id = ?"
  14. _selMcnUpRecommendSourcesSQL = "SELECT id,up_mid,fans_count,fans_count_increase_month,archive_count,play_count_accumulate,play_count_average,active_tid,last_archive_time,ctime,mtime FROM mcn_up_recommend_source LIMIT ?"
  15. )
  16. // AddMcnUpRecommend .
  17. func (d *Dao) AddMcnUpRecommend(c context.Context, arg *model.McnUpRecommendPool) (rows int64, err error) {
  18. var res sql.Result
  19. if res, err = d.db.Exec(c, _inMcnUpRecommendPoolSQL, arg.UpMid, arg.FansCount, arg.FansCountIncreaseMonth, arg.ArchiveCount, arg.PlayCountAccumulate, arg.PlayCountAverage, arg.ActiveTid, arg.LastArchiveTime, arg.GenerateTime,
  20. arg.FansCount, arg.FansCountIncreaseMonth, arg.ArchiveCount, arg.PlayCountAccumulate, arg.PlayCountAverage, arg.ActiveTid, arg.LastArchiveTime, arg.GenerateTime); err != nil {
  21. return rows, err
  22. }
  23. return res.RowsAffected()
  24. }
  25. // DelMcnUpRecommendPool .
  26. func (d *Dao) DelMcnUpRecommendPool(c context.Context) (rows int64, err error) {
  27. var res sql.Result
  28. if res, err = d.db.Exec(c, _delMcnUpRecommendPoolSQL, time.Now().AddDate(0, 0, -3)); err != nil {
  29. return rows, err
  30. }
  31. return res.RowsAffected()
  32. }
  33. // DelMcnUpRecommendSource .
  34. func (d *Dao) DelMcnUpRecommendSource(c context.Context, id int64) (rows int64, err error) {
  35. var res sql.Result
  36. if res, err = d.db.Exec(c, _delMcnUpRecommendSourceSQL, id); err != nil {
  37. return rows, err
  38. }
  39. return res.RowsAffected()
  40. }
  41. // McnUpRecommendSources .
  42. func (d *Dao) McnUpRecommendSources(c context.Context, limit int) (rps []*model.McnUpRecommendPool, err error) {
  43. var rows *xsql.Rows
  44. if rows, err = d.db.Query(c, _selMcnUpRecommendSourcesSQL, limit); err != nil {
  45. return
  46. }
  47. defer rows.Close()
  48. for rows.Next() {
  49. rp := new(model.McnUpRecommendPool)
  50. if err = rows.Scan(&rp.ID, &rp.UpMid, &rp.FansCount, &rp.FansCountIncreaseMonth, &rp.ArchiveCount, &rp.PlayCountAccumulate, &rp.PlayCountAverage, &rp.ActiveTid, &rp.LastArchiveTime, &rp.Ctime, &rp.Mtime); err != nil {
  51. if err == xsql.ErrNoRows {
  52. err = nil
  53. return
  54. }
  55. return
  56. }
  57. rps = append(rps, rp)
  58. }
  59. err = rows.Err()
  60. return
  61. }