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.

36 lines
1.3 KiB

3 years ago
3 years ago
3 years ago
  1. package source
  2. import (
  3. "gin-vue-admin/global"
  4. "gin-vue-admin/model/system"
  5. "github.com/gookit/color"
  6. "time"
  7. "gorm.io/gorm"
  8. )
  9. var Authority = new(authority)
  10. type authority struct{}
  11. var authorities = []system.SysAuthority{
  12. {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "888", AuthorityName: "普通用户", ParentId: "0", DefaultRouter: "dashboard"},
  13. {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "8881", AuthorityName: "普通用户子角色", ParentId: "888", DefaultRouter: "dashboard"},
  14. {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "9528", AuthorityName: "测试角色", ParentId: "0", DefaultRouter: "dashboard"},
  15. }
  16. //@author: [SliverHorn](https://github.com/SliverHorn)
  17. //@description: sys_authorities 表数据初始化
  18. func (a *authority) Init() error {
  19. return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
  20. if tx.Where("authority_id IN ? ", []string{"888", "9528"}).Find(&[]system.SysAuthority{}).RowsAffected == 2 {
  21. color.Danger.Println("\n[Mysql] --> sys_authorities 表的初始数据已存在!")
  22. return nil
  23. }
  24. if err := tx.Create(&authorities).Error; err != nil { // 遇到错误时回滚事务
  25. return err
  26. }
  27. color.Info.Println("\n[Mysql] --> sys_authorities 表初始数据成功!")
  28. return nil
  29. })
  30. }