refactor:
- source 初始化数据 new 实现 - service mysql 与 pgsql 分开实现 - 代码备注优化
This commit is contained in:
35
server/source/system/authority.go
Normal file
35
server/source/system/authority.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var Authority = new(authority)
|
||||
|
||||
type authority struct{}
|
||||
|
||||
func (a *authority) TableName() string {
|
||||
return "sys_authorities"
|
||||
}
|
||||
|
||||
func (a *authority) Initialize() error {
|
||||
entities := []system.SysAuthority{
|
||||
{AuthorityId: "888", AuthorityName: "普通用户", ParentId: "0", DefaultRouter: "dashboard"},
|
||||
{AuthorityId: "9528", AuthorityName: "测试角色", ParentId: "0", DefaultRouter: "dashboard"},
|
||||
{AuthorityId: "8881", AuthorityName: "普通用户子角色", ParentId: "888", DefaultRouter: "dashboard"},
|
||||
}
|
||||
if err := global.GVA_DB.Create(&entities).Error; err != nil {
|
||||
return errors.Wrapf(err, "%s表数据初始化失败!", a.TableName())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *authority) CheckDataExist() bool {
|
||||
if errors.Is(global.GVA_DB.Where("authority_id = ?", "8881").First(&system.SysAuthority{}).Error, gorm.ErrRecordNotFound) { // 判断是否存在数据
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user