forbid.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package archive
  2. // const Forbid Enum Values
  3. const (
  4. // Forbid style
  5. ForbidRank = "rank"
  6. ForbidDynamic = "dynamic"
  7. ForbidRecommend = "recommend"
  8. ForbidShow = "show"
  9. // ForbidRank style
  10. ForbidRankMain = 0
  11. ForbidRankRecentArc = 1
  12. ForbidRankAllArc = 2
  13. // ForbidDynamic style
  14. ForbidDynamicMain = 0
  15. // ForbidRecommend style
  16. ForbidRecommendMain = 0
  17. // ForbidShow style
  18. ForbidShowMain = 0
  19. ForbidShowMobile = 1
  20. ForbidShowWeb = 2
  21. ForbidShowOversea = 3
  22. ForbidShowOnline = 4
  23. )
  24. // ForbidAttr forbid attribute
  25. type ForbidAttr struct {
  26. Aid int64 `json:"aid"`
  27. RankV int32 `json:"rank_attr"`
  28. DynamicV int32 `json:"dynamic_attr"`
  29. RecommendV int32 `json:"recommend_attr"`
  30. ShowV int32 `json:"show_attr"`
  31. SearchV int32 `json:"search"`
  32. PushBlogV int32 `json:"push_blog"`
  33. // specific
  34. Rank struct {
  35. Main int32 `json:"main"`
  36. RecentArc int32 `json:"recent_arc"`
  37. AllArc int32 `json:"all_arc"`
  38. } `json:"_"`
  39. Dynamic struct {
  40. Main int32 `json:"main"`
  41. } `json:"-"`
  42. Recommend struct {
  43. Main int32 `json:"main"`
  44. } `json:"-"`
  45. Show struct {
  46. Main int32 `json:"main"`
  47. Mobile int32 `json:"mobile"`
  48. Web int32 `json:"web"`
  49. Oversea int32 `json:"oversea"`
  50. Online int32 `json:"online"`
  51. } `json:"-"`
  52. }
  53. // Convert convert db value into attr.
  54. func (f *ForbidAttr) Convert() {
  55. // rank
  56. f.Rank.Main = f.RankV & 1
  57. f.Rank.RecentArc = (f.RankV >> 1) & 1
  58. f.Rank.AllArc = (f.RankV >> 2) & 1
  59. // dynamic
  60. f.Dynamic.Main = f.DynamicV & 1
  61. // recommend
  62. f.Recommend.Main = f.RecommendV & 1
  63. // show
  64. f.Show.Main = f.ShowV & 1
  65. f.Show.Mobile = (f.ShowV >> 1) & 1
  66. f.Show.Web = (f.ShowV >> 2) & 1
  67. f.Show.Oversea = (f.ShowV >> 3) & 1
  68. f.Show.Online = (f.ShowV >> 4) & 1
  69. }
  70. // Reverse reverse attr into db value.
  71. func (f *ForbidAttr) Reverse() {
  72. // rank
  73. f.RankV = (f.Rank.AllArc << 2) | (f.Rank.RecentArc << 1) | f.Rank.Main
  74. // dynamic
  75. f.DynamicV = f.Dynamic.Main
  76. // recommend
  77. f.RecommendV = f.Recommend.Main
  78. // show
  79. f.ShowV = (f.Show.Online << 4) | (f.Show.Oversea << 3) | (f.Show.Web << 2) | (f.Show.Mobile << 1) | f.Show.Main
  80. }
  81. // SetAttr set forbid attr.
  82. func (f *ForbidAttr) SetAttr(name string, v int32, bit uint) (change bool) {
  83. if name == ForbidRank {
  84. old := f.RankV
  85. f.RankV = f.RankV&(^(1 << bit)) | (v << bit)
  86. change = old == f.RankV
  87. } else if name == ForbidDynamic {
  88. old := f.DynamicV
  89. f.DynamicV = f.DynamicV&(^(1 << bit)) | (v << bit)
  90. change = old == f.DynamicV
  91. } else if name == ForbidRecommend {
  92. old := f.RecommendV
  93. f.RecommendV = f.RecommendV&(^(1 << bit)) | (v << bit)
  94. change = old == f.RecommendV
  95. } else if name == ForbidShow {
  96. old := f.ShowV
  97. f.ShowV = f.ShowV&(^(1 << bit)) | (v << bit)
  98. change = old == f.ShowV
  99. }
  100. return
  101. }