mango_recom.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package thirdp
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/tv/model"
  6. tpMdl "go-common/app/interface/main/tv/model/thirdp"
  7. arcwar "go-common/app/service/main/archive/api"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. )
  11. const (
  12. _rtypePGC = 1
  13. _rtypeUGC = 2
  14. )
  15. func (s *Service) mangoR() (err error) {
  16. var (
  17. ctx = context.Background()
  18. rids []int64
  19. recoms []*tpMdl.MangoRecom
  20. params []*tpMdl.MangoParams
  21. catInfo *arcwar.Tp
  22. )
  23. if rids, err = s.dao.MangoOrder(ctx); err != nil { // pick mango recoms' order
  24. log.Error("mango MangoOrder Error %v", err)
  25. return
  26. }
  27. if len(rids) == 0 {
  28. log.Error("mango MangoOrder Empty")
  29. return
  30. }
  31. if recoms, err = s.dao.MangoRecom(ctx, rids); err != nil { // pick mango recom data
  32. log.Error("mango MangoRecom Rids [%v], Err %v", rids, err)
  33. return
  34. }
  35. for _, recom := range recoms {
  36. if recom.Rtype == _rtypePGC {
  37. var sn *model.SeasonCMS
  38. if sn, err = s.cmsDao.LoadSnCMS(context.Background(), recom.RID); err != nil {
  39. return err
  40. }
  41. param := recom.ToParam()
  42. param.Category = tpMdl.PgcCat(recom.Category)
  43. param.Role = sn.Role
  44. param.PlayTime = sn.Playtime.Time().Format("2006-01-02")
  45. params = append(params, param)
  46. } else if recom.Rtype == _rtypeUGC {
  47. var arc *model.ArcCMS
  48. if arc, err = s.cmsDao.LoadArcMeta(context.Background(), recom.RID); err != nil {
  49. return err
  50. }
  51. param := recom.ToParam()
  52. if catInfo, err = s.arcDao.TypeInfo(int32(recom.Category)); err != nil { // pick ugc category name
  53. log.Warn("MangoRecom Recom RID %d, Cat %d", recom.RID, recom.Category)
  54. } else {
  55. param.Category = catInfo.Name
  56. }
  57. param.PlayTime = arc.Pubtime.Time().Format("2006-01-02")
  58. params = append(params, param)
  59. } else {
  60. return ecode.TvDangbeiWrongType
  61. }
  62. }
  63. if len(params) > 0 {
  64. s.mangoRecom = params
  65. }
  66. return
  67. }
  68. func (s *Service) mangorproc() {
  69. for {
  70. time.Sleep(time.Duration(s.conf.Cfg.PageReload))
  71. if err := s.mangoR(); err != nil {
  72. log.Error("mango Error %v", err)
  73. }
  74. }
  75. }
  76. // MangoRecom returns the mango recom data
  77. func (s *Service) MangoRecom() (data []*tpMdl.MangoParams) {
  78. if len(s.mangoRecom) == 0 {
  79. data = make([]*tpMdl.MangoParams, 0)
  80. return
  81. }
  82. data = s.mangoRecom
  83. return
  84. }