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.1 KiB
36 lines
1.1 KiB
9 months ago
|
package source
|
||
|
|
||
|
import (
|
||
|
"pure-admin/global"
|
||
|
"pure-admin/model"
|
||
|
|
||
|
"github.com/gookit/color"
|
||
|
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
var Authority = new(authority)
|
||
|
|
||
|
type authority struct{}
|
||
|
|
||
|
var authorities = []model.SysAuthority{
|
||
|
{AuthorityId: 888, AuthorityName: "普通用户", ParentId: "0", DefaultRouter: "dashboard"},
|
||
|
{AuthorityId: 8881, AuthorityName: "普通用户子角色", ParentId: "888", DefaultRouter: "dashboard"},
|
||
|
{AuthorityId: 9528, AuthorityName: "测试角色", ParentId: "0", DefaultRouter: "dashboard"},
|
||
|
}
|
||
|
|
||
|
// @description: sys_authorities 表数据初始化
|
||
|
func (a *authority) Init() error {
|
||
|
return global.MG_DB.Transaction(func(tx *gorm.DB) error {
|
||
|
if tx.Where("authority_id in (?) ", []string{"888", "9528"}).Find(&[]model.SysAuthority{}).RowsAffected == 2 {
|
||
|
color.Danger.Println("\n[Mysql] --> sys_authorities 表的初始数据已存在!")
|
||
|
return nil
|
||
|
}
|
||
|
if err := tx.Create(&authorities).Error; err != nil { // 遇到错误时回滚事务
|
||
|
return err
|
||
|
}
|
||
|
color.Info.Println("\n[Mysql] --> sys_authorities 表初始数据成功!")
|
||
|
return nil
|
||
|
})
|
||
|
}
|