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.

96 lines
3.0 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 AuthoritiesMenus = new(authoritiesMenus)
  11. type authoritiesMenus struct{}
  12. func (a *authoritiesMenus) TableName() string {
  13. var entity AuthorityMenus
  14. return entity.TableName()
  15. }
  16. func (a *authoritiesMenus) Initialize() error {
  17. entities := []AuthorityMenus{
  18. {BaseMenuId: 1, AuthorityId: "888"},
  19. {BaseMenuId: 2, AuthorityId: "888"},
  20. {BaseMenuId: 3, AuthorityId: "888"},
  21. {BaseMenuId: 4, AuthorityId: "888"},
  22. {BaseMenuId: 5, AuthorityId: "888"},
  23. {BaseMenuId: 6, AuthorityId: "888"},
  24. {BaseMenuId: 7, AuthorityId: "888"},
  25. {BaseMenuId: 8, AuthorityId: "888"},
  26. {BaseMenuId: 9, AuthorityId: "888"},
  27. {BaseMenuId: 10, AuthorityId: "888"},
  28. {BaseMenuId: 11, AuthorityId: "888"},
  29. {BaseMenuId: 12, AuthorityId: "888"},
  30. {BaseMenuId: 13, AuthorityId: "888"},
  31. {BaseMenuId: 14, AuthorityId: "888"},
  32. {BaseMenuId: 15, AuthorityId: "888"},
  33. {BaseMenuId: 16, AuthorityId: "888"},
  34. {BaseMenuId: 17, AuthorityId: "888"},
  35. {BaseMenuId: 18, AuthorityId: "888"},
  36. {BaseMenuId: 19, AuthorityId: "888"},
  37. {BaseMenuId: 20, AuthorityId: "888"},
  38. {BaseMenuId: 22, AuthorityId: "888"},
  39. {BaseMenuId: 23, AuthorityId: "888"},
  40. {BaseMenuId: 24, AuthorityId: "888"},
  41. {BaseMenuId: 25, AuthorityId: "888"},
  42. {BaseMenuId: 1, AuthorityId: "8881"},
  43. {BaseMenuId: 2, AuthorityId: "8881"},
  44. {BaseMenuId: 8, AuthorityId: "8881"},
  45. {BaseMenuId: 1, AuthorityId: "9528"},
  46. {BaseMenuId: 2, AuthorityId: "9528"},
  47. {BaseMenuId: 3, AuthorityId: "9528"},
  48. {BaseMenuId: 4, AuthorityId: "9528"},
  49. {BaseMenuId: 5, AuthorityId: "9528"},
  50. {BaseMenuId: 6, AuthorityId: "9528"},
  51. {BaseMenuId: 7, AuthorityId: "9528"},
  52. {BaseMenuId: 8, AuthorityId: "9528"},
  53. {BaseMenuId: 9, AuthorityId: "9528"},
  54. {BaseMenuId: 10, AuthorityId: "9528"},
  55. {BaseMenuId: 11, AuthorityId: "9528"},
  56. {BaseMenuId: 12, AuthorityId: "9528"},
  57. {BaseMenuId: 14, AuthorityId: "9528"},
  58. {BaseMenuId: 15, AuthorityId: "9528"},
  59. {BaseMenuId: 16, AuthorityId: "9528"},
  60. {BaseMenuId: 17, AuthorityId: "9528"},
  61. }
  62. if err := global.GVA_DB.Create(&entities).Error; err != nil {
  63. return errors.Wrap(err, a.TableName()+"表数据初始化失败!")
  64. }
  65. return nil
  66. }
  67. func (a *authoritiesMenus) CheckDataExist() bool {
  68. if errors.Is(global.GVA_DB.Where("sys_base_menu_id = ? AND sys_authority_authority_id = ?", 17, "9528").First(&AuthorityMenus{}).Error, gorm.ErrRecordNotFound) { // 判断是否存在数据
  69. return false
  70. }
  71. return true
  72. }
  73. type AuthorityMenus struct {
  74. AuthorityId string `gorm:"column:sys_authority_authority_id"`
  75. BaseMenuId uint `gorm:"column:sys_base_menu_id"`
  76. }
  77. func (a *AuthorityMenus) TableName() string {
  78. var entity system.SysAuthority
  79. types := reflect.TypeOf(entity)
  80. if s, o := types.FieldByName("SysBaseMenus"); o {
  81. m1 := schema.ParseTagSetting(s.Tag.Get("gorm"), ";")
  82. return m1["MANY2MANY"]
  83. }
  84. return ""
  85. }