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.

28 lines
925 B

  1. package datas
  2. import (
  3. "github.com/gookit/color"
  4. "time"
  5. "gin-vue-admin/model"
  6. "gorm.io/gorm"
  7. )
  8. var Authorities = []model.SysAuthority{
  9. {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "888", AuthorityName: "普通用户", ParentId: "0"},
  10. {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "8881", AuthorityName: "普通用户子角色", ParentId: "888"},
  11. {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "9528", AuthorityName: "测试角色", ParentId: "0"},
  12. }
  13. func InitSysAuthority(db *gorm.DB) (err error) {
  14. return db.Transaction(func(tx *gorm.DB) error {
  15. if tx.Where("authority_id IN ? ", []string{"888", "9528"}).Find(&[]model.SysAuthority{}).RowsAffected == 2 {
  16. color.Danger.Println("sys_authorities表的初始数据已存在!")
  17. return nil
  18. }
  19. if err := tx.Create(&Authorities).Error; err != nil { // 遇到错误时回滚事务
  20. return err
  21. }
  22. return nil
  23. })
  24. }