【权限数据操作的部分报错说明】
This commit is contained in:
parent
e84db3a9bf
commit
57dc7850d4
@ -7,6 +7,7 @@ import (
|
||||
"joylink.club/bj-rtsts-server/db/dbquery"
|
||||
"joylink.club/bj-rtsts-server/db/model"
|
||||
"joylink.club/bj-rtsts-server/dto"
|
||||
"joylink.club/bj-rtsts-server/sys_error"
|
||||
)
|
||||
|
||||
// 查询权限角色信息列表
|
||||
@ -14,7 +15,7 @@ func PageAuthRoleQuery(query *dto.PageQueryDto) *dto.PageDto {
|
||||
d := dbquery.AuthRole
|
||||
records, total, err := d.Debug().Select(d.ID, d.Name).Order(d.CreateTime).FindByPage(query.Offset(), query.Size)
|
||||
if err != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
|
||||
panic(sys_error.New("查询权限数据库出错,请联系维护人员", err))
|
||||
}
|
||||
return &dto.PageDto{Total: int(total), PageQueryDto: *query, Records: dto.ConvertFromAuthRole(records)}
|
||||
}
|
||||
@ -24,7 +25,7 @@ func ListAuthRoleQuery() []*dto.AuthRoleRspDto {
|
||||
d := dbquery.AuthRole
|
||||
records, err := d.Debug().Select(d.ID, d.Name).Order(d.CreateTime).Find()
|
||||
if err != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
|
||||
panic(sys_error.New("查询权限数据库出错,请联系维护人员", err))
|
||||
}
|
||||
return dto.ConvertFromAuthRole(records)
|
||||
}
|
||||
@ -35,11 +36,11 @@ func CreateAuthRole(a *dto.AuthRoleReqDto) bool {
|
||||
aq := dbquery.AuthRole
|
||||
err := aq.Save(&d)
|
||||
if err != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
|
||||
panic(sys_error.New("保存权限数据库出错,请联系维护人员", err))
|
||||
}
|
||||
n := len(a.AddPaths)
|
||||
if n == 0 {
|
||||
return false
|
||||
return true
|
||||
}
|
||||
// 查询刚插入的角色
|
||||
newAuthRole, _ := aq.Where(aq.Name.Eq(a.Name)).Order(aq.CreateTime).Last()
|
||||
@ -56,7 +57,7 @@ func QueryAuthRole(rid int32) *dto.AuthRoleDetailRspDto {
|
||||
// 查询用户角色信息
|
||||
role, err := dbquery.AuthRole.Where(dbquery.AuthRole.ID.Eq(rid)).First()
|
||||
if err != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
|
||||
panic(sys_error.New("查询角色数据库出错,请联系维护人员", err))
|
||||
}
|
||||
rsp := &dto.AuthRoleDetailRspDto{
|
||||
Id: role.ID,
|
||||
@ -71,7 +72,7 @@ func QueryAuthRoleByUid(uid int32) []*model.AuthRole {
|
||||
aru := dbquery.AuthRoleUser
|
||||
arus, err1 := aru.Distinct(aru.Rid).Select(aru.Rid).Where(aru.UID.Eq(uid)).Find()
|
||||
if err1 != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: err1.Error()})
|
||||
panic(sys_error.New("查询角色数据库出错,请联系维护人员", err1))
|
||||
}
|
||||
if len(arus) == 0 {
|
||||
return nil
|
||||
@ -82,7 +83,7 @@ func QueryAuthRoleByUid(uid int32) []*model.AuthRole {
|
||||
}
|
||||
roles, err2 := dbquery.AuthRole.Where(dbquery.AuthRole.ID.In(rids...)).Find()
|
||||
if err2 != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: err2.Error()})
|
||||
panic(sys_error.New("查询角色数据库发生错误,请联系维护人员", err2))
|
||||
}
|
||||
return roles
|
||||
}
|
||||
@ -92,7 +93,7 @@ func UpdateAuthRole(rid int32, info *dto.AuthRoleReqDto) bool {
|
||||
// 查询用户角色信息
|
||||
role, err := dbquery.AuthRole.Where(dbquery.AuthRole.ID.Eq(rid)).First()
|
||||
if err != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
|
||||
panic(sys_error.New("更新角色数据库发生错误,不存在此用户", err))
|
||||
}
|
||||
role.Name = info.Name // 更新名称
|
||||
dbquery.AuthRole.Updates(role)
|
||||
@ -119,18 +120,18 @@ func UpdateAuthRole(rid int32, info *dto.AuthRoleReqDto) bool {
|
||||
func DeleteAuthRole(rid int32) bool {
|
||||
oldD, err1 := dbquery.AuthRole.Where(dbquery.AuthRole.ID.Eq(rid)).First()
|
||||
if err1 != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err1.Error()})
|
||||
panic(sys_error.New("删除权限角色数据库发生错误", err1))
|
||||
}
|
||||
if dto.IsSystemRole(oldD.ID) {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: "系统角色不可删除"})
|
||||
panic(sys_error.New("系统角色不可删除", err1))
|
||||
}
|
||||
// 如果有用户关联则不删除
|
||||
count, err2 := dbquery.AuthRoleUser.Where(dbquery.AuthRoleUser.Rid.Eq(rid)).Count()
|
||||
if err2 != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err2.Error()})
|
||||
panic(sys_error.New("删除失败,还存在用户关联", err2))
|
||||
}
|
||||
if count > 0 {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: "有用户关联该角色"})
|
||||
panic(sys_error.New("删除失败,有用户关联该角色"))
|
||||
}
|
||||
// 删除用户关联关系
|
||||
dbquery.AuthRoleUser.Where(dbquery.AuthRoleUser.Rid.Eq(rid)).Delete()
|
||||
|
Loading…
Reference in New Issue
Block a user