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.

35 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 Authority = new(authority)
  9. type authority struct{}
  10. func (a *authority) TableName() string {
  11. return "sys_authorities"
  12. }
  13. func (a *authority) Initialize() error {
  14. entities := []system.SysAuthority{
  15. {AuthorityId: "888", AuthorityName: "普通用户", ParentId: "0", DefaultRouter: "dashboard"},
  16. {AuthorityId: "9528", AuthorityName: "测试角色", ParentId: "0", DefaultRouter: "dashboard"},
  17. {AuthorityId: "8881", AuthorityName: "普通用户子角色", ParentId: "888", DefaultRouter: "dashboard"},
  18. }
  19. if err := global.GVA_DB.Create(&entities).Error; err != nil {
  20. return errors.Wrapf(err, "%s表数据初始化失败!", a.TableName())
  21. }
  22. return nil
  23. }
  24. func (a *authority) CheckDataExist() bool {
  25. if errors.Is(global.GVA_DB.Where("authority_id = ?", "8881").First(&system.SysAuthority{}).Error, gorm.ErrRecordNotFound) { // 判断是否存在数据
  26. return false
  27. }
  28. return true
  29. }