tab2.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. package feed
  2. import (
  3. "context"
  4. "strconv"
  5. "time"
  6. cdm "go-common/app/interface/main/app-card/model"
  7. "go-common/app/interface/main/app-card/model/bplus"
  8. "go-common/app/interface/main/app-card/model/card"
  9. "go-common/app/interface/main/app-card/model/card/bangumi"
  10. "go-common/app/interface/main/app-card/model/card/live"
  11. "go-common/app/interface/main/app-card/model/card/operate"
  12. "go-common/app/interface/main/app-feed/model"
  13. tag "go-common/app/interface/main/tag/model"
  14. article "go-common/app/interface/openplatform/article/model"
  15. "go-common/app/service/main/archive/model/archive"
  16. "go-common/library/log"
  17. "go-common/library/sync/errgroup"
  18. )
  19. // Actives2 return actives
  20. func (s *Service) Actives2(c context.Context, id, mid int64, mobiApp string, plat int8, build, forceHost int, now time.Time) (items []card.Handler, cover string, isBnj bool, bnjDays int, err error) {
  21. if id == s.c.Bnj.TabID {
  22. isBnj = true
  23. nt := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
  24. bt, _ := time.Parse("2006-01-02", s.c.Bnj.BeginTime)
  25. bnjDays = int(bt.Sub(nt).Hours() / 24)
  26. if bnjDays < 0 {
  27. bnjDays = 0
  28. }
  29. }
  30. rs := s.tabCache[id]
  31. if items, err = s.dealTab2(c, rs, mid, mobiApp, plat, build, forceHost, now); err != nil {
  32. log.Error("s.dealTab(%v) error(%v)", rs, err)
  33. return
  34. }
  35. cover = s.coverCache[id]
  36. return
  37. }
  38. func (s *Service) dealTab2(c context.Context, rs []*operate.Active, mid int64, mobiApp string, plat int8, build, forceHost int, now time.Time) (is []card.Handler, err error) {
  39. if len(rs) == 0 {
  40. is = []card.Handler{}
  41. return
  42. }
  43. var (
  44. paids, aids, tids, roomIDs, sids, metaIDs, picIDs []int64
  45. pam, am map[int64]*archive.ArchiveWithPlayer
  46. rm map[int64]*live.Room
  47. sm map[int64]*bangumi.Season
  48. metam map[int64]*article.Meta
  49. tagm map[int64]*tag.Tag
  50. picm map[int64]*bplus.Picture
  51. )
  52. convergem := map[int64]*operate.Card{}
  53. specialm := map[int64]*operate.Card{}
  54. downloadm := map[int64]*operate.Download{}
  55. for _, r := range rs {
  56. switch r.Type {
  57. case model.GotoPlayer:
  58. if r.Pid != 0 {
  59. paids = append(paids, r.Pid)
  60. }
  61. case model.GotoPlayerLive:
  62. if r.Pid != 0 {
  63. roomIDs = append(roomIDs, r.Pid)
  64. }
  65. case model.GotoTabTagRcmd:
  66. if r.Pid != 0 {
  67. var taids []int64
  68. if taids, err = s.rcmd.TagTop(c, mid, r.Pid, r.Limit); err != nil {
  69. log.Error("%+v", err)
  70. err = nil
  71. continue
  72. }
  73. tids = append(tids, r.Pid)
  74. r.Items = make([]*operate.Active, 0, len(taids))
  75. for _, aid := range taids {
  76. item := &operate.Active{Pid: aid, Goto: model.GotoAv, Param: strconv.FormatInt(aid, 10)}
  77. r.Items = append(r.Items, item)
  78. aids = append(aids, aid)
  79. }
  80. }
  81. case model.GotoConverge:
  82. cardm, aid, roomID, metaID := s.convergeCard(c, 3, r.Pid)
  83. for id, card := range cardm {
  84. convergem[id] = card
  85. }
  86. aids = append(aids, aid...)
  87. roomIDs = append(roomIDs, roomID...)
  88. metaIDs = append(metaIDs, metaID...)
  89. case model.GotoTabContentRcmd:
  90. for _, item := range r.Items {
  91. if item.Pid == 0 {
  92. continue
  93. }
  94. switch item.Goto {
  95. case cdm.GotoAv:
  96. aids = append(aids, item.Pid)
  97. case cdm.GotoLive:
  98. roomIDs = append(roomIDs, item.Pid)
  99. case cdm.GotoBangumi:
  100. sids = append(sids, item.Pid)
  101. case cdm.GotoGame:
  102. if card, ok := s.downloadCache[item.Pid]; ok {
  103. downloadm[item.Pid] = card
  104. }
  105. case cdm.GotoArticle:
  106. metaIDs = append(metaIDs, item.Pid)
  107. case cdm.GotoSpecial:
  108. cardm := s.specialCard(c, item.Pid)
  109. for id, card := range cardm {
  110. specialm[id] = card
  111. }
  112. case cdm.GotoPicture:
  113. // 版本过滤5.37为新卡片
  114. if (plat == model.PlatIPhone && build > 8300) || (plat == model.PlatAndroid && build > 5365000) {
  115. picIDs = append(picIDs, item.Pid)
  116. }
  117. }
  118. }
  119. case model.GotoSpecial:
  120. cardm := s.specialCard(c, r.Pid)
  121. for id, card := range cardm {
  122. specialm[id] = card
  123. }
  124. }
  125. }
  126. g, ctx := errgroup.WithContext(c)
  127. if len(tids) != 0 {
  128. g.Go(func() (err error) {
  129. if tagm, err = s.tg.InfoByIDs(c, 0, tids); err != nil {
  130. log.Error("%+v", err)
  131. err = nil
  132. }
  133. return
  134. })
  135. }
  136. if len(aids) != 0 {
  137. g.Go(func() (err error) {
  138. if am, err = s.ArchivesWithPlayer(ctx, aids, 0, "", 0, 0, 0, 0); err != nil {
  139. log.Error("%+v", err)
  140. err = nil
  141. }
  142. return
  143. })
  144. }
  145. if len(paids) != 0 {
  146. g.Go(func() (err error) {
  147. if pam, err = s.ArchivesWithPlayer(ctx, paids, 32, mobiApp, 0, 0, forceHost, build); err != nil {
  148. log.Error("%+v", err)
  149. err = nil
  150. }
  151. return
  152. })
  153. }
  154. if len(roomIDs) != 0 {
  155. g.Go(func() (err error) {
  156. if rm, err = s.lv.AppMRoom(ctx, roomIDs); err != nil {
  157. log.Error("%+v", err)
  158. err = nil
  159. }
  160. return
  161. })
  162. }
  163. if len(sids) != 0 {
  164. g.Go(func() (err error) {
  165. if sm, err = s.bgm.Seasons(ctx, sids, now); err != nil {
  166. log.Error("%+v", err)
  167. err = nil
  168. }
  169. return
  170. })
  171. }
  172. if len(metaIDs) != 0 {
  173. g.Go(func() (err error) {
  174. if metam, err = s.art.Articles(ctx, metaIDs); err != nil {
  175. log.Error("%+v", err)
  176. err = nil
  177. }
  178. return
  179. })
  180. }
  181. if len(picIDs) != 0 {
  182. g.Go(func() (err error) {
  183. if picm, err = s.bplus.DynamicDetail(ctx, picIDs...); err != nil {
  184. log.Error("%+v", err)
  185. err = nil
  186. }
  187. return
  188. })
  189. }
  190. if err = g.Wait(); err != nil {
  191. log.Error("%+v", err)
  192. return
  193. }
  194. is = make([]card.Handler, 0, len(rs))
  195. for _, r := range rs {
  196. var main interface{}
  197. cardGoto := cdm.CardGt(r.Type)
  198. op := &operate.Card{}
  199. op.From(cardGoto, r.Pid, 0, plat, build)
  200. // 版本过滤
  201. hasThreePoint := (plat == model.PlatIPhone && build >= 8240) || (plat == model.PlatAndroid && build > 5341000)
  202. if hasThreePoint {
  203. op.FromSwitch(cdm.SwitchFeedIndexTabThreePoint)
  204. }
  205. h := card.Handle(plat, cardGoto, "", cdm.ColumnSvrDouble, nil, tagm, nil, nil, nil)
  206. if h == nil {
  207. continue
  208. }
  209. switch r.Type {
  210. case model.GotoPlayer:
  211. main = pam
  212. case model.GotoPlayerLive:
  213. main = rm
  214. case model.GotoSpecial:
  215. op = specialm[r.Pid]
  216. case model.GotoConverge:
  217. main = map[cdm.Gt]interface{}{cdm.GotoAv: am, cdm.GotoLive: rm, cdm.GotoArticle: metam}
  218. op = convergem[r.Pid]
  219. case model.GotoBanner:
  220. op.FromActiveBanner(r.Items, "")
  221. case model.GotoTabNews:
  222. op.FromActive(r)
  223. case model.GotoTabContentRcmd:
  224. main = map[cdm.Gt]interface{}{cdm.GotoAv: am, cdm.GotoGame: downloadm, cdm.GotoBangumi: sm, cdm.GotoLive: rm, cdm.GotoArticle: metam, cdm.GotoSpecial: specialm, cdm.GotoPicture: picm}
  225. op.FromActive(r)
  226. case model.GotoTabEntrance:
  227. op.FromActive(r)
  228. case model.GotoTabTagRcmd:
  229. main = map[cdm.Gt]interface{}{cdm.GotoAv: am}
  230. op.FromActive(r)
  231. op.Items = make([]*operate.Card, 0, len(r.Items))
  232. for _, item := range r.Items {
  233. if item != nil {
  234. op.Items = append(op.Items, &operate.Card{ID: item.Pid, Goto: item.Goto})
  235. }
  236. }
  237. }
  238. h.From(main, op)
  239. if !h.Get().Right {
  240. continue
  241. }
  242. if hasThreePoint {
  243. h.Get().TabThreePointWatchLater()
  244. }
  245. is = append(is, h)
  246. }
  247. return
  248. }