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.

57 lines
1.6 KiB

3 years ago
  1. package system
  2. import (
  3. "reflect"
  4. "github.com/flipped-aurora/gin-vue-admin/server/global"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/system"
  6. "github.com/pkg/errors"
  7. "gorm.io/gorm"
  8. "gorm.io/gorm/schema"
  9. )
  10. var DataAuthorities = new(dataAuthorities)
  11. type dataAuthorities struct{}
  12. func (a *dataAuthorities) TableName() string {
  13. var entity AuthoritiesResources
  14. return entity.TableName()
  15. }
  16. func (a *dataAuthorities) Initialize() error {
  17. entities := []AuthoritiesResources{
  18. {AuthorityId: "888", ResourcesId: "888"},
  19. {AuthorityId: "888", ResourcesId: "8881"},
  20. {AuthorityId: "888", ResourcesId: "9528"},
  21. {AuthorityId: "9528", ResourcesId: "8881"},
  22. {AuthorityId: "9528", ResourcesId: "9528"},
  23. }
  24. if err := global.GVA_DB.Create(&entities).Error; err != nil {
  25. return errors.Wrap(err, a.TableName()+"表数据初始化失败!")
  26. }
  27. return nil
  28. }
  29. func (a *dataAuthorities) CheckDataExist() bool {
  30. if errors.Is(global.GVA_DB.Where("sys_authority_authority_id = ? AND data_authority_id_authority_id = ?", "9528", "9528").First(&AuthoritiesResources{}).Error, gorm.ErrRecordNotFound) { // 判断是否存在数据
  31. return false
  32. }
  33. return true
  34. }
  35. // AuthoritiesResources 角色资源表
  36. type AuthoritiesResources struct {
  37. AuthorityId string `gorm:"column:sys_authority_authority_id"`
  38. ResourcesId string `gorm:"column:data_authority_id_authority_id"`
  39. }
  40. func (a *AuthoritiesResources) TableName() string {
  41. var entity system.SysAuthority
  42. types := reflect.TypeOf(entity)
  43. if s, o := types.FieldByName("DataAuthorityId"); o {
  44. m1 := schema.ParseTagSetting(s.Tag.Get("gorm"), ";")
  45. return m1["MANY2MANY"]
  46. }
  47. return ""
  48. }