combine.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package history
  2. import (
  3. "context"
  4. hismdl "go-common/app/interface/main/history/model"
  5. "go-common/app/interface/main/tv/model"
  6. "go-common/app/interface/main/tv/model/history"
  7. "go-common/library/log"
  8. )
  9. func (s *Service) pgcHisRes(ctx context.Context, res []*hismdl.Resource) (resMap map[int64]*history.HisRes, err error) {
  10. var (
  11. snMetas map[int64]*model.SeasonCMS
  12. epMetas map[int64]*model.EpCMS
  13. pickSids []int64
  14. pickEpids []int64
  15. )
  16. resMap = make(map[int64]*history.HisRes)
  17. for _, v := range res {
  18. pickSids = append(pickSids, v.Sid)
  19. pickEpids = append(pickEpids, v.Epid)
  20. }
  21. if snMetas, err = s.cmsDao.LoadSnsCMSMap(ctx, pickSids); err != nil {
  22. log.Error("LoadSnsCMS Sids %v, Err %v", pickSids, err)
  23. return
  24. }
  25. if epMetas, err = s.cmsDao.LoadEpsCMS(ctx, pickEpids); err != nil {
  26. log.Warn("LoadEpsCMS Epids %v, Err %v", pickEpids, err)
  27. err = nil
  28. }
  29. for _, v := range res {
  30. his := hisTrans(v)
  31. his.Type = _typePGC
  32. his.Page = nil
  33. // season info
  34. snMeta, okS := snMetas[v.Sid]
  35. if !okS {
  36. log.Error("pgcHisRes Missing Info Sid %d", v.Sid)
  37. continue
  38. }
  39. his.Title = snMeta.Title
  40. his.Cover = snMeta.Cover
  41. if snMeta.NeedVip() { // add vip corner mark
  42. his.CornerMark = &(*s.conf.Cfg.SnVipCorner)
  43. }
  44. // ep info
  45. epMeta, okE := epMetas[v.Epid]
  46. if !okE {
  47. log.Warn("pgcHisRes Missing Info Epid %d", v.Epid)
  48. } else {
  49. his.EPMeta = &history.HisEP{
  50. EPID: epMeta.EPID,
  51. Cover: epMeta.Cover,
  52. Title: epMeta.Subtitle,
  53. LongTitle: epMeta.Title,
  54. }
  55. }
  56. resMap[v.Sid] = his
  57. }
  58. return
  59. }
  60. func (s *Service) ugcHisRes(ctx context.Context, res []*hismdl.Resource) (resMap map[int64]*history.HisRes, err error) {
  61. var (
  62. arcMetas map[int64]*model.ArcCMS
  63. videoMetas map[int64]*model.VideoCMS
  64. pickAids []int64
  65. pickCids []int64
  66. )
  67. resMap = make(map[int64]*history.HisRes)
  68. for _, v := range res {
  69. pickAids = append(pickAids, v.Oid)
  70. pickCids = append(pickCids, v.Cid)
  71. }
  72. if arcMetas, err = s.cmsDao.LoadArcsMediaMap(ctx, pickAids); err != nil {
  73. log.Error("LoadArcsMediaMap Sids %v, Err %v", pickAids, err)
  74. return
  75. }
  76. if videoMetas, err = s.cmsDao.LoadVideosMeta(ctx, pickCids); err != nil {
  77. log.Warn("LoadVideosMeta Epids %v, Err %v", pickCids, err)
  78. err = nil
  79. }
  80. for _, v := range res {
  81. his := hisTrans(v)
  82. his.Type = _typeUGC
  83. his.Page = nil
  84. // season info
  85. arcMeta, okS := arcMetas[v.Oid]
  86. if !okS {
  87. log.Error("ugcHisRes Missing Info Aid %d", v.Oid)
  88. continue
  89. }
  90. his.Title = arcMeta.Title
  91. his.Cover = arcMeta.Cover
  92. // ep info
  93. video, okE := videoMetas[v.Cid]
  94. if !okE {
  95. log.Warn("ugcHisRes Missing Info Cid %d", v.Cid)
  96. } else {
  97. his.Page = &history.HisPage{
  98. CID: video.CID,
  99. Part: video.Title,
  100. Page: video.IndexOrder,
  101. }
  102. }
  103. resMap[v.Oid] = his
  104. }
  105. return
  106. }
  107. func hisTrans(res *hismdl.Resource) *history.HisRes {
  108. return &history.HisRes{
  109. Mid: res.Mid,
  110. Oid: res.Oid,
  111. Sid: res.Sid,
  112. Epid: res.Epid,
  113. Cid: res.Cid,
  114. Business: res.Business,
  115. DT: res.DT,
  116. Pro: res.Pro,
  117. Unix: res.Unix,
  118. Type: _typePGC,
  119. }
  120. }
  121. func (s *Service) getDuration(ctx context.Context, res []*hismdl.Resource) (durs map[int64]int64) {
  122. var (
  123. aids []int64
  124. )
  125. durs = make(map[int64]int64)
  126. for _, v := range res {
  127. aids = append(aids, v.Oid)
  128. }
  129. resMeta := s.arcDao.LoadViews(ctx, aids)
  130. for _, v := range res {
  131. if view, ok := resMeta[v.Oid]; ok && len(view.Pages) > 0 {
  132. for _, vp := range view.Pages {
  133. if v.Cid == vp.Cid {
  134. durs[v.Oid] = vp.Duration
  135. break
  136. }
  137. }
  138. }
  139. }
  140. return
  141. }