From 57dc7850d4ad699eb5a0269c25df93abe979c3a7 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Mon, 23 Oct 2023 13:41:58 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=9D=83=E9=99=90=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E7=9A=84=E9=83=A8=E5=88=86=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/auth.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/service/auth.go b/service/auth.go index eab2257..ed5298e 100644 --- a/service/auth.go +++ b/service/auth.go @@ -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()