forbid.go 2.2 KB

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