forbid.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package archive
  2. const (
  3. // ForbidRank 禁止排行
  4. ForbidRank = "rank"
  5. // ForbidDynamic 动态禁止
  6. ForbidDynamic = "dynamic"
  7. // ForbidRecommend 禁止推荐
  8. ForbidRecommend = "recommend"
  9. // ForbidShow 禁止展示
  10. ForbidShow = "show"
  11. // ForbidRankMain forbid rank main
  12. ForbidRankMain = 0
  13. // ForbidRankRecentArc forbid rank recent archive
  14. ForbidRankRecentArc = 1
  15. // ForbidRankAllArc forbid rank all archive
  16. ForbidRankAllArc = 2
  17. // ForbidDynamicMain forbid dynamic main
  18. ForbidDynamicMain = 0
  19. // ForbidRecommendMain forbid recomment main
  20. ForbidRecommendMain = 0
  21. // ForbidShowMain forbid show main
  22. ForbidShowMain = 0
  23. // ForbidShowMobile forbid show mobile
  24. ForbidShowMobile = 1
  25. // ForbidShowWeb forbid show web
  26. ForbidShowWeb = 2
  27. // ForbidShowOversea forbid show oversea
  28. ForbidShowOversea = 3
  29. // ForbidShowOnline forbid show online
  30. ForbidShowOnline = 4
  31. //ForbidAttrChannel forbid channel
  32. ForbidAttrChannel = 101
  33. //ForbidAttrHot forbid hot
  34. ForbidAttrHot = 102
  35. )
  36. var (
  37. _forbidBits = map[string]map[uint]string{
  38. ForbidRank: map[uint]string{
  39. ForbidRankMain: "所有排行禁止",
  40. ForbidRankRecentArc: "近期稿件排行禁止",
  41. ForbidRankAllArc: "全部稿件排行禁止",
  42. },
  43. ForbidDynamic: map[uint]string{
  44. ForbidDynamicMain: "所有动态禁止",
  45. },
  46. ForbidRecommend: map[uint]string{
  47. ForbidRecommendMain: "所有推荐禁止",
  48. },
  49. ForbidShow: map[uint]string{
  50. ForbidShowMain: "移动端最新/网页端最新/热度/在线等禁止",
  51. ForbidShowMobile: "移动端最新禁止",
  52. ForbidShowWeb: "网页端最新禁止",
  53. ForbidShowOversea: "海外禁止",
  54. ForbidShowOnline: "在线列表禁止",
  55. },
  56. }
  57. )
  58. // ForbidAttr forbid attribute
  59. type ForbidAttr struct {
  60. Aid int64 `json:"aid"`
  61. OnFlowID int64 `json:"on_flow_id"`
  62. RankV int32 `json:"-"`
  63. DynamicV int32 `json:"-"`
  64. RecommendV int32 `json:"-"`
  65. ShowV int32 `json:"-"`
  66. // specific
  67. Rank struct {
  68. Main int32 `json:"main"`
  69. RecentArc int32 `json:"recent_arc"`
  70. AllArc int32 `json:"all_arc"`
  71. } `json:"rank_attr"`
  72. Dynamic struct {
  73. Main int32 `json:"main"`
  74. } `json:"dynamic_attr"`
  75. Recommend struct {
  76. Main int32 `json:"main"`
  77. } `json:"recommend_attr"`
  78. Show struct {
  79. Main int32 `json:"main"`
  80. Mobile int32 `json:"mobile"`
  81. Web int32 `json:"web"`
  82. Oversea int32 `json:"oversea"`
  83. Online int32 `json:"online"`
  84. } `json:"show_attr"`
  85. }
  86. // Convert convert db value into attr.
  87. func (f *ForbidAttr) Convert() {
  88. // rank
  89. f.Rank.Main = f.RankV & 1
  90. f.Rank.RecentArc = (f.RankV >> 1) & 1
  91. f.Rank.AllArc = (f.RankV >> 2) & 1
  92. // dynamic
  93. f.Dynamic.Main = f.DynamicV & 1
  94. // recommend
  95. f.Recommend.Main = f.RecommendV & 1
  96. // show
  97. f.Show.Main = f.ShowV & 1
  98. f.Show.Mobile = (f.ShowV >> 1) & 1
  99. f.Show.Web = (f.ShowV >> 2) & 1
  100. f.Show.Oversea = (f.ShowV >> 3) & 1
  101. f.Show.Online = (f.ShowV >> 4) & 1
  102. }
  103. // Reverse reverse attr into db value.
  104. // func (f *ForbidAttr) Reverse() {
  105. // // rank
  106. // f.RankV = (f.Rank.AllArc << 2) | (f.Rank.RecentArc << 1) | f.Rank.Main
  107. // // dynamic
  108. // f.DynamicV = f.Dynamic.Main
  109. // // recommend
  110. // f.RecommendV = f.Recommend.Main
  111. // // show
  112. // f.ShowV = (f.Show.Online << 4) | (f.Show.Oversea << 3) | (f.Show.Web << 2) | (f.Show.Mobile << 1) | f.Show.Main
  113. // }
  114. // SetAttr set forbid attr.
  115. func (f *ForbidAttr) SetAttr(name string, v int32, bit uint) (change bool) {
  116. if name == ForbidRank {
  117. old := f.RankV
  118. f.RankV = f.RankV&(^(1 << bit)) | (v << bit)
  119. change = old == f.RankV
  120. } else if name == ForbidDynamic {
  121. old := f.DynamicV
  122. f.DynamicV = f.DynamicV&(^(1 << bit)) | (v << bit)
  123. change = old == f.DynamicV
  124. } else if name == ForbidRecommend {
  125. old := f.RecommendV
  126. f.RecommendV = f.RecommendV&(^(1 << bit)) | (v << bit)
  127. change = old == f.RecommendV
  128. } else if name == ForbidShow {
  129. old := f.ShowV
  130. f.ShowV = f.ShowV&(^(1 << bit)) | (v << bit)
  131. change = old == f.ShowV
  132. }
  133. return
  134. }
  135. // ForbidBitDesc return bit desc.
  136. func ForbidBitDesc(name string, bit uint) (desc string) {
  137. return _forbidBits[name][bit]
  138. }