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.

34 lines
950 B

  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. }