|
@@ -19,8 +19,7 @@ import (
|
|
|
|
|
|
func CreateAuthority(auth model.SysAuthority) (err error, authority model.SysAuthority) {
|
|
|
var authorityBox model.SysAuthority
|
|
|
- notHas := errors.Is(global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&authorityBox).Error, gorm.ErrRecordNotFound)
|
|
|
- if !notHas {
|
|
|
+ if !errors.Is(global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&authorityBox).Error, gorm.ErrRecordNotFound) {
|
|
|
return errors.New("存在相同角色id"), auth
|
|
|
}
|
|
|
err = global.GVA_DB.Create(&auth).Error
|
|
@@ -36,8 +35,7 @@ func CreateAuthority(auth model.SysAuthority) (err error, authority model.SysAut
|
|
|
|
|
|
func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, authority model.SysAuthority) {
|
|
|
var authorityBox model.SysAuthority
|
|
|
- notHas := errors.Is(global.GVA_DB.Where("authority_id = ?", copyInfo.Authority.AuthorityId).First(&authorityBox).Error, gorm.ErrRecordNotFound)
|
|
|
- if !notHas {
|
|
|
+ if !errors.Is(global.GVA_DB.Where("authority_id = ?", copyInfo.Authority.AuthorityId).First(&authorityBox).Error, gorm.ErrRecordNotFound) {
|
|
|
return errors.New("存在相同角色id"), authority
|
|
|
}
|
|
|
copyInfo.Authority.Children = []model.SysAuthority{}
|
|
@@ -79,12 +77,10 @@ func UpdateAuthority(auth model.SysAuthority) (err error, authority model.SysAut
|
|
|
|
|
|
|
|
|
func DeleteAuthority(auth *model.SysAuthority) (err error) {
|
|
|
- notHas := errors.Is(global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&model.SysUser{}).Error, gorm.ErrRecordNotFound)
|
|
|
- if !notHas {
|
|
|
+ if !errors.Is(global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&model.SysUser{}).Error, gorm.ErrRecordNotFound) {
|
|
|
return errors.New("此角色有用户正在使用禁止删除")
|
|
|
}
|
|
|
- notHas = errors.Is(global.GVA_DB.Where("parent_id = ?", auth.AuthorityId).First(&model.SysAuthority{}).Error, gorm.ErrRecordNotFound)
|
|
|
- if !notHas {
|
|
|
+ if !errors.Is(global.GVA_DB.Where("parent_id = ?", auth.AuthorityId).First(&model.SysAuthority{}).Error, gorm.ErrRecordNotFound) {
|
|
|
return errors.New("此角色存在子角色不允许删除")
|
|
|
}
|
|
|
db := global.GVA_DB.Preload("SysBaseMenus").Where("authority_id = ?", auth.AuthorityId).First(auth)
|