tab.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. package channel
  2. import (
  3. "context"
  4. "time"
  5. cdm "go-common/app/interface/main/app-card/model"
  6. cardm "go-common/app/interface/main/app-card/model/card"
  7. "go-common/app/interface/main/app-card/model/card/live"
  8. "go-common/app/interface/main/app-card/model/card/operate"
  9. shopping "go-common/app/interface/main/app-card/model/card/show"
  10. "go-common/app/interface/main/app-channel/model"
  11. "go-common/app/interface/main/app-channel/model/card"
  12. "go-common/app/interface/main/app-channel/model/feed"
  13. article "go-common/app/interface/openplatform/article/model"
  14. account "go-common/app/service/main/account/model"
  15. relation "go-common/app/service/main/relation/model"
  16. seasongrpc "go-common/app/service/openplatform/pgc-season/api/grpc/season/v1"
  17. "go-common/library/log"
  18. "go-common/library/sync/errgroup"
  19. )
  20. func (s *Service) TabList(c context.Context, channelID, mid int64, channelName, mobiApp string, displayID, build, from int, plat int8, now time.Time) (res *feed.Tab, err error) {
  21. var (
  22. cards []*card.Card
  23. // requestCnt = 10
  24. isIpad = plat == model.PlatIPad
  25. item []cardm.Handler
  26. )
  27. if isIpad {
  28. // requestCnt = 20
  29. }
  30. if channelID > 0 {
  31. channelName = ""
  32. }
  33. item, err = s.dealTab2(c, plat, build, mobiApp, mid, cards, now)
  34. res = &feed.Tab{
  35. Items: item,
  36. }
  37. return
  38. }
  39. func (s *Service) dealTab2(c context.Context, plat int8, build int, mobiApp string, mid int64, cards []*card.Card, now time.Time) (is []cardm.Handler, err error) {
  40. if len(cards) == 0 {
  41. is = []cardm.Handler{}
  42. return
  43. }
  44. var (
  45. shopIDs, roomIDs, metaIDs []int64
  46. rmUpIDs, mtUpIDs, upIDs []int64
  47. seasonIDs []int32
  48. rm map[int64]*live.Room
  49. metam map[int64]*article.Meta
  50. shopm map[int64]*shopping.Shopping
  51. seasonm map[int32]*seasongrpc.CardInfoProto
  52. ac map[int64]*account.Card
  53. statm map[int64]*relation.Stat
  54. isAtten map[int64]int8
  55. )
  56. for _, card := range cards {
  57. switch card.Type {
  58. case model.GotoPGC:
  59. if card.Value != 0 {
  60. seasonIDs = append(seasonIDs, int32(card.Value))
  61. }
  62. case model.GotoLive:
  63. if card.Value != 0 {
  64. roomIDs = append(roomIDs, card.Value)
  65. }
  66. case model.GotoArticle:
  67. if card.Value != 0 {
  68. metaIDs = append(metaIDs, card.Value)
  69. }
  70. case model.GotoShoppingS:
  71. if card.Value != 0 {
  72. shopIDs = append(shopIDs, card.Value)
  73. }
  74. }
  75. }
  76. g, ctx := errgroup.WithContext(c)
  77. if len(roomIDs) != 0 {
  78. g.Go(func() (err error) {
  79. if rm, err = s.lv.AppMRoom(ctx, roomIDs); err != nil {
  80. log.Error("%+v", err)
  81. err = nil
  82. }
  83. for _, r := range rm {
  84. rmUpIDs = append(rmUpIDs, r.UID)
  85. }
  86. return
  87. })
  88. }
  89. if len(seasonIDs) != 0 {
  90. g.Go(func() (err error) {
  91. if seasonm, err = s.bgm.CardsInfoReply(ctx, seasonIDs); err != nil {
  92. log.Error("%+v", err)
  93. err = nil
  94. }
  95. return
  96. })
  97. }
  98. if len(metaIDs) != 0 {
  99. g.Go(func() (err error) {
  100. if metam, err = s.art.Articles(ctx, metaIDs); err != nil {
  101. log.Error("%+v", err)
  102. err = nil
  103. }
  104. for _, meta := range metam {
  105. if meta.Author != nil {
  106. mtUpIDs = append(mtUpIDs, meta.Author.Mid)
  107. }
  108. }
  109. return
  110. })
  111. }
  112. if len(shopIDs) != 0 {
  113. g.Go(func() (err error) {
  114. if shopm, err = s.sp.Card(ctx, shopIDs); err != nil {
  115. log.Error("%+v", err)
  116. err = nil
  117. }
  118. return
  119. })
  120. }
  121. if err = g.Wait(); err != nil {
  122. log.Error("%+v", err)
  123. return
  124. }
  125. upIDs = append(upIDs, rmUpIDs...)
  126. upIDs = append(upIDs, mtUpIDs...)
  127. g, ctx = errgroup.WithContext(c)
  128. if len(upIDs) != 0 {
  129. g.Go(func() (err error) {
  130. if ac, err = s.acc.Cards3(ctx, upIDs); err != nil {
  131. log.Error("%+v", err)
  132. err = nil
  133. }
  134. return
  135. })
  136. g.Go(func() (err error) {
  137. if statm, err = s.rel.Stats(ctx, upIDs); err != nil {
  138. log.Error("%+v", err)
  139. err = nil
  140. }
  141. return
  142. })
  143. if mid != 0 {
  144. g.Go(func() error {
  145. isAtten = s.acc.IsAttention(ctx, upIDs, mid)
  146. return nil
  147. })
  148. }
  149. }
  150. if err = g.Wait(); err != nil {
  151. log.Error("%+v", err)
  152. return
  153. }
  154. for _, card := range cards {
  155. var (
  156. r = card.CardToAiChange()
  157. main interface{}
  158. )
  159. h := cardm.Handle(plat, cdm.CardGt(r.Goto), "", cdm.ColumnSvrSingle, r, nil, isAtten, statm, ac)
  160. if h == nil {
  161. continue
  162. }
  163. op := &operate.Card{}
  164. op.From(cdm.CardGt(r.Goto), r.ID, 0, plat, build)
  165. switch r.Goto {
  166. case model.GotoLive:
  167. main = rm
  168. case model.GotoPGC:
  169. main = seasonm
  170. case model.GotoArticle:
  171. main = metam
  172. case model.GotoShoppingS:
  173. main = shopm
  174. }
  175. h.From(main, op)
  176. if h.Get() == nil {
  177. continue
  178. }
  179. if h.Get().Right {
  180. is = append(is, h)
  181. }
  182. }
  183. if rl := len(is); rl == 0 {
  184. is = []cardm.Handler{}
  185. return
  186. }
  187. return
  188. }