authorities_menus.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package source
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/gookit/color"
  5. "gorm.io/gorm"
  6. )
  7. var AuthoritiesMenus = new(authoritiesMenus)
  8. type authoritiesMenus struct{}
  9. type AuthorityMenus struct {
  10. AuthorityId string `gorm:"column:sys_authority_authority_id"`
  11. BaseMenuId uint `gorm:"column:sys_base_menu_id"`
  12. }
  13. var authorityMenus = []AuthorityMenus{
  14. {"888", 1},
  15. {"888", 2},
  16. {"888", 3},
  17. {"888", 4},
  18. {"888", 5},
  19. {"888", 6},
  20. {"888", 7},
  21. {"888", 8},
  22. {"888", 9},
  23. {"888", 10},
  24. {"888", 11},
  25. {"888", 12},
  26. {"888", 13},
  27. {"888", 14},
  28. {"888", 15},
  29. {"888", 16},
  30. {"888", 17},
  31. {"888", 18},
  32. {"888", 19},
  33. {"888", 20},
  34. {"888", 22},
  35. {"888", 23},
  36. {"888", 24},
  37. {"888", 25},
  38. {"8881", 1},
  39. {"8881", 2},
  40. {"8881", 8},
  41. {"9528", 1},
  42. {"9528", 2},
  43. {"9528", 3},
  44. {"9528", 4},
  45. {"9528", 5},
  46. {"9528", 6},
  47. {"9528", 7},
  48. {"9528", 8},
  49. {"9528", 9},
  50. {"9528", 10},
  51. {"9528", 11},
  52. {"9528", 12},
  53. {"9528", 14},
  54. {"9528", 15},
  55. {"9528", 16},
  56. {"9528", 17},
  57. }
  58. //@author: [SliverHorn](https://github.com/SliverHorn)
  59. //@description: sys_authority_menus 表数据初始化
  60. func (a *authoritiesMenus) Init() error {
  61. return global.GVA_DB.Table("sys_authority_menus").Transaction(func(tx *gorm.DB) error {
  62. if tx.Where("sys_authority_authority_id IN ('888', '8881', '9528')").Find(&[]AuthorityMenus{}).RowsAffected == 48 {
  63. color.Danger.Println("\n[Mysql] --> sys_authority_menus 表的初始数据已存在!")
  64. return nil
  65. }
  66. if err := tx.Create(&authorityMenus).Error; err != nil { // 遇到错误时回滚事务
  67. return err
  68. }
  69. color.Info.Println("\n[Mysql] --> sys_authority_menus 表初始数据成功!")
  70. return nil
  71. })
  72. }