wild.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. package search
  2. import (
  3. "context"
  4. mdlSearch "go-common/app/interface/main/tv/model/search"
  5. v1 "go-common/app/service/main/archive/api"
  6. "go-common/library/log"
  7. "go-common/library/sync/errgroup"
  8. )
  9. const (
  10. _showHide = 0
  11. season = "番剧"
  12. upper = "用户"
  13. movie = "影视"
  14. _searchType = "all"
  15. _mobiAPP = "app"
  16. _bangumiType = 1
  17. _biliUserType = 2
  18. _filmType = 3
  19. _mediaBangumiType = 7
  20. _mediaFtType = 8
  21. )
  22. // UserSearch search user .
  23. func (s *Service) UserSearch(ctx context.Context, arg *mdlSearch.UserSearch) (res []*mdlSearch.User, err error) {
  24. if res, err = s.dao.UserSearch(ctx, arg); err != nil {
  25. log.Error("s.dao.UserSearch error(%v)", err)
  26. }
  27. if len(res) == 0 {
  28. res = make([]*mdlSearch.User, 0)
  29. }
  30. return
  31. }
  32. // SearchAll search all .
  33. func (s *Service) SearchAll(ctx context.Context, arg *mdlSearch.UserSearch) (res *mdlSearch.ResultAll, err error) {
  34. var (
  35. user = &mdlSearch.Search{}
  36. avm map[int64]*v1.Arc
  37. avids []int64
  38. items []*mdlSearch.Item
  39. wildCfg = s.conf.Wild.WildSearch
  40. )
  41. arg.SeasonNum = wildCfg.SeasonNum
  42. arg.MovieNum = wildCfg.MovieNum
  43. arg.SearchType = _searchType
  44. arg.MobiAPP = _mobiAPP
  45. if user, err = s.dao.SearchAllWild(ctx, arg); err != nil {
  46. log.Error(" s.dao.SearchAllWild error(%v)", err)
  47. }
  48. res = &mdlSearch.ResultAll{}
  49. if user == nil {
  50. return
  51. }
  52. res.Trackid = user.Trackid
  53. res.Page = user.Page
  54. res.Attribute = user.Attribute
  55. nis := make([]*mdlSearch.NavInfo, 0, 4)
  56. // season
  57. if user.PageInfo.Bangumi != nil {
  58. var nav = &mdlSearch.NavInfo{
  59. Name: season,
  60. Total: user.PageInfo.Bangumi.NumResult,
  61. Pages: user.PageInfo.Bangumi.Pages,
  62. Type: _bangumiType,
  63. }
  64. if user.PageInfo.Bangumi.NumResult > wildCfg.SeasonNum {
  65. nav.Show = wildCfg.SeasonMore
  66. } else {
  67. nav.Show = _showHide
  68. }
  69. nis = append(nis, nav)
  70. }
  71. // media season
  72. if user.PageInfo.MediaBangumi != nil {
  73. var nav = &mdlSearch.NavInfo{
  74. Name: season,
  75. Total: user.PageInfo.MediaBangumi.NumResult,
  76. Pages: user.PageInfo.MediaBangumi.Pages,
  77. Type: _mediaBangumiType,
  78. }
  79. if user.PageInfo.MediaBangumi.NumResult > wildCfg.SeasonNum {
  80. nav.Show = wildCfg.SeasonMore
  81. } else {
  82. nav.Show = _showHide
  83. }
  84. nis = append(nis, nav)
  85. }
  86. // upper
  87. if user.PageInfo.BiliUser != nil {
  88. var nav = &mdlSearch.NavInfo{
  89. Name: upper,
  90. Total: user.PageInfo.BiliUser.NumResult,
  91. Pages: user.PageInfo.BiliUser.Pages,
  92. Type: _biliUserType,
  93. }
  94. nis = append(nis, nav)
  95. }
  96. // movie
  97. if user.PageInfo.Film != nil {
  98. var nav = &mdlSearch.NavInfo{
  99. Name: movie,
  100. Total: user.PageInfo.Film.NumResult,
  101. Pages: user.PageInfo.Film.Pages,
  102. Type: _filmType,
  103. }
  104. if user.PageInfo.Movie != nil && user.PageInfo.Movie.NumResult > wildCfg.MovieNum {
  105. nav.Show = wildCfg.MovieMore
  106. } else {
  107. nav.Show = _showHide
  108. }
  109. nis = append(nis, nav)
  110. }
  111. // media movie
  112. if user.PageInfo.MediaFt != nil {
  113. var nav = &mdlSearch.NavInfo{
  114. Name: movie,
  115. Total: user.PageInfo.MediaFt.NumResult,
  116. Pages: user.PageInfo.MediaFt.Pages,
  117. Type: _mediaFtType,
  118. }
  119. if user.PageInfo.MediaFt.NumResult > wildCfg.MovieNum {
  120. nav.Show = wildCfg.MovieMore
  121. } else {
  122. nav.Show = _showHide
  123. }
  124. nis = append(nis, nav)
  125. }
  126. res.NavInfo = nis
  127. // archive
  128. for _, v := range user.Result.Video {
  129. avids = append(avids, v.ID)
  130. }
  131. for _, v := range user.Result.Movie {
  132. if v.Type == "movie" {
  133. avids = append(avids, v.Aid)
  134. }
  135. }
  136. if arg.Page == 1 {
  137. for _, v := range user.Result.User {
  138. for _, vr := range v.Res {
  139. avids = append(avids, vr.Aid)
  140. }
  141. }
  142. for _, v := range user.Result.BiliUser {
  143. for _, vr := range v.Res {
  144. avids = append(avids, vr.Aid)
  145. }
  146. }
  147. }
  148. group := new(errgroup.Group)
  149. if len(avids) != 0 {
  150. group.Go(func() (err error) {
  151. if avm, err = s.arcDao.Archives(ctx, avids); err != nil {
  152. log.Error("%+v", err)
  153. err = nil
  154. }
  155. return
  156. })
  157. }
  158. if err = group.Wait(); err != nil {
  159. return
  160. }
  161. // item add data .
  162. var promptBangumi, promptFt string
  163. // season
  164. bangumi := user.Result.Bangumi
  165. items = make([]*mdlSearch.Item, 0, len(bangumi))
  166. for _, v := range bangumi {
  167. si := &mdlSearch.Item{}
  168. si.FromSeason(v, mdlSearch.GotoBangumiWeb)
  169. items = append(items, si)
  170. }
  171. if len(res.Items.Season) > 5 && arg.RID == 0 {
  172. res.Items.Season = res.Items.Season[:5]
  173. res.Items.Season = items
  174. } else {
  175. res.Items.Season = items
  176. }
  177. // movie
  178. movie := user.Result.Movie
  179. items = make([]*mdlSearch.Item, 0, len(movie))
  180. for _, v := range movie {
  181. si := &mdlSearch.Item{}
  182. si.FromMovie(v, avm)
  183. items = append(items, si)
  184. }
  185. res.Items.Movie = items
  186. // season2
  187. mb := user.Result.MediaBangumi
  188. // movie2
  189. mf := user.Result.MediaFt
  190. items = make([]*mdlSearch.Item, 0, len(mb)+len(mf))
  191. for _, v := range mb {
  192. si := &mdlSearch.Item{}
  193. si.FromMedia(v, promptBangumi, mdlSearch.GotoBangumi, nil)
  194. items = append(items, si)
  195. }
  196. for _, v := range mf {
  197. si := &mdlSearch.Item{}
  198. si.FromMedia(v, promptFt, mdlSearch.GotoMovie, nil)
  199. si.Goto = mdlSearch.GotoAv
  200. items = append(items, si)
  201. }
  202. if len(res.Items.Season2) > 5 && arg.RID == 0 {
  203. res.Items.Season2 = res.Items.Season2[:5]
  204. res.Items.Season2 = items
  205. } else {
  206. res.Items.Season2 = items
  207. }
  208. items = make([]*mdlSearch.Item, 0, len(user.Result.Video))
  209. for _, v := range user.Result.Video {
  210. si := &mdlSearch.Item{}
  211. si.FromVideo(v, avm[v.ID])
  212. items = append(items, si)
  213. }
  214. res.Items.Archive = items
  215. return
  216. }
  217. // PgcSearch search .
  218. func (s *Service) PgcSearch(ctx context.Context, arg *mdlSearch.UserSearch) (res *mdlSearch.TypeSearch, err error) {
  219. var (
  220. wildCfg = s.conf.Wild.WildSearch
  221. )
  222. arg.SeasonNum = wildCfg.SeasonNum
  223. arg.MovieNum = wildCfg.MovieNum
  224. arg.SearchType = _searchType
  225. arg.MobiAPP = _mobiAPP
  226. if res, err = s.dao.PgcSearch(ctx, arg); err != nil {
  227. log.Error("[wild.PgcSearch] s.dao.PgcSearch error(%v)", err)
  228. return
  229. }
  230. if len(res.Items) <= 0 {
  231. res.Items = make([]*mdlSearch.Item, 0)
  232. }
  233. return
  234. }