audit.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package feed
  2. import (
  3. "context"
  4. "time"
  5. cdm "go-common/app/interface/main/app-card/model"
  6. "go-common/app/interface/main/app-card/model/card"
  7. "go-common/app/interface/main/app-card/model/card/banner"
  8. "go-common/app/interface/main/app-card/model/card/operate"
  9. "go-common/app/interface/main/app-feed/model"
  10. "go-common/app/interface/main/app-feed/model/feed"
  11. "go-common/app/service/main/archive/model/archive"
  12. "go-common/library/log"
  13. )
  14. var (
  15. _auditBanners = []*banner.Banner{
  16. &banner.Banner{
  17. Title: "充电",
  18. Image: "http://i0.hdslb.com/bfs/archive/9ce8f6cdf76e6cbd50ce7db76262d5a35e594c79.png",
  19. Hash: "3c4990d06c46de0080e3821fca6bedca",
  20. URI: "bilibili://video/813060",
  21. },
  22. }
  23. // av2314237 已经删除,后续看情况处理
  24. // 已删除失效id已更换新的稿件id
  25. _aids = []int64{308040, 2431658, 2432648, 2427553, 539600, 1968681, 850424, 887861, 1960912, 1935680, 1406019,
  26. 1985297, 1977493, 2312184, 2316891, 864845, 1986932, 880857, 875624, 744299}
  27. )
  28. // Audit check audit plat then return audit data.
  29. func (s *Service) Audit(c context.Context, mobiApp string, plat int8, build int) (is []*feed.Item, ok bool) {
  30. if plats, ok := s.auditCache[mobiApp]; ok {
  31. if _, ok = plats[build]; ok {
  32. return s.auditData(c), true
  33. }
  34. }
  35. return
  36. }
  37. // Audit2 check audit plat and ip, then return audit data.
  38. func (s *Service) Audit2(c context.Context, mobiApp string, plat int8, build int, column cdm.ColumnStatus) (is []card.Handler, ok bool) {
  39. if plats, ok := s.auditCache[mobiApp]; ok {
  40. if _, ok = plats[build]; ok {
  41. return s.auditData2(c, plat, column), true
  42. }
  43. }
  44. return
  45. }
  46. // auditData some data for audit.
  47. func (s *Service) auditData(c context.Context) (is []*feed.Item) {
  48. i := &feed.Item{}
  49. i.FromBanner(_auditBanners, "")
  50. is = append(is, i)
  51. am, err := s.ArchivesWithPlayer(c, _aids, 0, "", 0, 0, 0, 0)
  52. if err != nil {
  53. log.Error("%+v", err)
  54. return
  55. }
  56. for _, aid := range _aids {
  57. if a, ok := am[aid]; ok {
  58. i := &feed.Item{}
  59. i.FromAv(a)
  60. is = append(is, i)
  61. }
  62. }
  63. return
  64. }
  65. // auditData2 some data for audit.
  66. func (s *Service) auditData2(c context.Context, plat int8, column cdm.ColumnStatus) (is []card.Handler) {
  67. i := card.Handle(plat, model.GotoBanner, "", column, nil, nil, nil, nil, nil)
  68. if i != nil {
  69. op := &operate.Card{}
  70. op.FromBanner(_auditBanners, "")
  71. i.From(nil, op)
  72. is = append(is, i)
  73. }
  74. am, err := s.arc.Archives(c, _aids)
  75. if err != nil {
  76. log.Error("%+v", err)
  77. }
  78. var main interface{}
  79. for _, aid := range _aids {
  80. if a, ok := am[aid]; ok {
  81. i := card.Handle(plat, model.GotoAv, "", column, nil, nil, nil, nil, nil)
  82. if i == nil {
  83. continue
  84. }
  85. op := &operate.Card{}
  86. op.From(cdm.CardGotoAv, aid, 0, 0, 0)
  87. main = map[int64]*archive.ArchiveWithPlayer{a.Aid: &archive.ArchiveWithPlayer{Archive3: archive.BuildArchive3(a)}}
  88. i.From(main, op)
  89. if !i.Get().Right {
  90. continue
  91. }
  92. if model.IsIPad(plat) {
  93. // ipad卡片不展示标签
  94. i.Get().DescButton = nil
  95. }
  96. is = append(is, i)
  97. }
  98. }
  99. return
  100. }
  101. func (s *Service) loadAuditCache() {
  102. as, err := s.adt.Audits(context.Background())
  103. if err != nil {
  104. log.Error("s.adt.Audits error(%v)", err)
  105. return
  106. }
  107. s.auditCache = as
  108. }
  109. // auditproc load audit cache.
  110. func (s *Service) auditproc() {
  111. for {
  112. time.Sleep(s.tick)
  113. s.loadAuditCache()
  114. }
  115. }