user_authority.go.go 950 B

12345678910111213141516171819202122232425262728293031323334
  1. package source
  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/gookit/color"
  6. "gorm.io/gorm"
  7. )
  8. var UserAuthority = new(userAuthority)
  9. type userAuthority struct{}
  10. var userAuthorityModel = []system.SysUseAuthority{
  11. {1, "888"},
  12. {1, "8881"},
  13. {1, "9528"},
  14. {2, "888"},
  15. }
  16. //@description: user_authority 数据初始化
  17. func (a *userAuthority) Init() error {
  18. return global.GVA_DB.Model(&system.SysUseAuthority{}).Transaction(func(tx *gorm.DB) error {
  19. if tx.Where("sys_user_id IN (1, 2)").Find(&[]AuthorityMenus{}).RowsAffected == 4 {
  20. color.Danger.Println("\n[Mysql] --> sys_user_authority 表的初始数据已存在!")
  21. return nil
  22. }
  23. if err := tx.Create(&userAuthorityModel).Error; err != nil { // 遇到错误时回滚事务
  24. return err
  25. }
  26. color.Info.Println("\n[Mysql] --> sys_user_authority 表初始数据成功!")
  27. return nil
  28. })
  29. }