region.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package region
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/app-feed/model"
  6. "go-common/app/interface/main/app-feed/model/tag"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. )
  10. var (
  11. _emptyHotTags = []*tag.Hot{}
  12. _emptyTags = []*tag.Tag{}
  13. _banRegion = map[int16]struct{}{
  14. // bangumi
  15. 33: struct{}{},
  16. 32: struct{}{},
  17. 153: struct{}{},
  18. 51: struct{}{},
  19. 152: struct{}{},
  20. // music
  21. 29: struct{}{},
  22. 54: struct{}{},
  23. 130: struct{}{},
  24. // tech
  25. 37: struct{}{},
  26. 96: struct{}{},
  27. // movie
  28. 145: struct{}{},
  29. 146: struct{}{},
  30. 147: struct{}{},
  31. // TV series
  32. 15: struct{}{},
  33. 34: struct{}{},
  34. 86: struct{}{},
  35. // entertainment
  36. 71: struct{}{},
  37. 137: struct{}{},
  38. 131: struct{}{},
  39. }
  40. )
  41. // HotTags get hot tags of region id.
  42. func (s *Service) HotTags(c context.Context, mid int64, rid int16, ver string, plat int8, now time.Time) (hs []*tag.Hot, version string, err error) {
  43. if hs, err = s.tg.Hots(c, mid, rid, now); err != nil {
  44. log.Error("tg.HotTags(%d) error(%v)", rid, err)
  45. return
  46. }
  47. if model.IsOverseas(plat) {
  48. for _, hot := range hs {
  49. if _, ok := _banRegion[hot.Rid]; ok {
  50. hot.Tags = _emptyTags
  51. }
  52. }
  53. }
  54. if len(hs) == 0 {
  55. hs = _emptyHotTags
  56. return
  57. }
  58. version = s.md5(hs)
  59. if ver == version {
  60. err = ecode.NotModified
  61. }
  62. return
  63. }
  64. func (s *Service) SubTags(c context.Context, mid int64, pn, ps int) (t *tag.SubTag) {
  65. t = &tag.SubTag{}
  66. sub, err := s.tg.SubTags(c, mid, 0, pn, ps)
  67. if err != nil {
  68. log.Error("s.tg.SubTags(%d,%d,%d) error(%v)", mid, pn, ps, err)
  69. return
  70. }
  71. subTags := make([]*tag.Tag, 0, len(sub.Tags))
  72. for _, st := range sub.Tags {
  73. subTag := &tag.Tag{ID: st.ID, Name: st.Name, IsAtten: st.IsAtten}
  74. subTags = append(subTags, subTag)
  75. }
  76. if len(subTags) != 0 {
  77. t.SubTags = subTags
  78. } else {
  79. t.SubTags = _emptyTags
  80. }
  81. t.Count = sub.Total
  82. return
  83. }
  84. func (s *Service) AddTag(c context.Context, mid, tid int64, now time.Time) (err error) {
  85. if err = s.tg.Add(c, mid, tid, now); err != nil {
  86. log.Error("s.tg.Add(%d, %d) error(%v)", mid, tid, err)
  87. }
  88. return
  89. }
  90. func (s *Service) CancelTag(c context.Context, mid, tid int64, now time.Time) (err error) {
  91. if err = s.tg.Cancel(c, mid, tid, now); err != nil {
  92. log.Error("s.tg.Cancel(%d, %d) error(%v)", mid, tid, err)
  93. }
  94. return
  95. }