You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.1 KiB

  1. package system
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/system"
  5. "github.com/pkg/errors"
  6. "gorm.io/gorm"
  7. )
  8. var UserAuthority = new(userAuthority)
  9. type userAuthority struct{}
  10. func (a *userAuthority) TableName() string {
  11. var entity system.SysUseAuthority
  12. return entity.TableName()
  13. }
  14. func (a *userAuthority) Initialize() error {
  15. entities := []system.SysUseAuthority{
  16. {SysUserId: 1, SysAuthorityAuthorityId: "888"},
  17. {SysUserId: 1, SysAuthorityAuthorityId: "8881"},
  18. {SysUserId: 1, SysAuthorityAuthorityId: "9528"},
  19. {SysUserId: 2, SysAuthorityAuthorityId: "888"},
  20. }
  21. if err := global.GVA_DB.Create(&entities).Error; err != nil {
  22. return errors.Wrap(err, a.TableName()+"表数据初始化失败!")
  23. }
  24. return nil
  25. }
  26. func (a *userAuthority) CheckDataExist() bool {
  27. if errors.Is(global.GVA_DB.Where("sys_user_id = ? AND sys_authority_authority_id = ?", 2, "888").First(&system.SysUseAuthority{}).Error, gorm.ErrRecordNotFound) { // 判断是否存在数据
  28. return false
  29. }
  30. return true
  31. }