enum_accoutCheck.go 950 B

123456789101112131415161718192021222324252627282930313233
  1. package enum
  2. var (
  3. notAccountCheck = NewEnum(0, "不需要校验账户状态") //0 -> 00000000
  4. needUserAccount = NewEnum(1, "需要用户账户状态") //1 -> 00000001
  5. needEntAccount = NewEnum(1<<1, "需要企业账户状态") //2 -> 00000010
  6. )
  7. type AccountCheck struct {
  8. *Enum
  9. }
  10. // NewAccountCheck 初始化账户状态校验对象
  11. func NewAccountCheck(code int64, desc ...string) *AccountCheck {
  12. return &AccountCheck{
  13. NewEnum(code, desc...),
  14. }
  15. }
  16. // NeedCheck 是否需要进行账户状态校验
  17. func (ac *AccountCheck) NeedCheck() bool {
  18. return ac.GetCode() != notAccountCheck.code
  19. }
  20. // CheckUserAccount 校验是否需要用户Status
  21. func (ac *AccountCheck) CheckUserAccount() bool {
  22. return needUserAccount.code == (ac.GetCode() & needUserAccount.code)
  23. }
  24. // CheckEntAccount 校验是否需要企业Status
  25. func (ac *AccountCheck) CheckEntAccount() bool {
  26. return needEntAccount.code == (ac.GetCode() & needEntAccount.code)
  27. }