|
@@ -49,20 +49,20 @@ func (r *Role) List(ctx context.Context, req entity.RoleListReq) (*entity.RoleRe
|
|
|
findOptions := options.Find().SetSkip(int64((req.Page - 1) * req.Size)).SetLimit(int64(req.Size))
|
|
|
countDocuments, err := rolesCollection.CountDocuments(ctx, filter)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("List CountDocuments error:", err)
|
|
|
+ mhayaLogger.Warnf("List CountDocuments error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
|
// 防御性编程
|
|
|
tableName := roles.TableName()
|
|
|
if tableName == "" {
|
|
|
- mhayaLogger.Warnf("List tableName is nil, tableName:", tableName)
|
|
|
+ mhayaLogger.Warnf("List tableName is nil, tableName:%v", tableName)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
|
cursor, err := rolesCollection.Find(ctx, filter, findOptions)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("List Find error:", err)
|
|
|
+ mhayaLogger.Warnf("List Find error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
defer func() {
|
|
@@ -75,14 +75,14 @@ func (r *Role) List(ctx context.Context, req entity.RoleListReq) (*entity.RoleRe
|
|
|
for cursor.Next(ctx) {
|
|
|
var role *entity.RoleDetail
|
|
|
if err := cursor.Decode(&role); err != nil {
|
|
|
- mhayaLogger.Warnf("List Decode error:", err)
|
|
|
+ mhayaLogger.Warnf("List Decode error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
details = append(details, role)
|
|
|
}
|
|
|
|
|
|
if err := cursor.Err(); err != nil {
|
|
|
- mhayaLogger.Warnf("List cursor error:", err)
|
|
|
+ mhayaLogger.Warnf("List cursor error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -101,7 +101,7 @@ func (r *Role) Add(ctx context.Context, req entity.RoleAddReq) *code.Result {
|
|
|
|
|
|
// 检查上下文是否有效
|
|
|
if ctx.Err() != nil {
|
|
|
- mhayaLogger.Warnf("Add ctx error:", ctx.Err())
|
|
|
+ mhayaLogger.Warnf("Add ctx error:%v", ctx.Err())
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -116,7 +116,7 @@ func (r *Role) Add(ctx context.Context, req entity.RoleAddReq) *code.Result {
|
|
|
collection := mdb.MDB.Collection(roles.TableName())
|
|
|
_, insertErr := collection.InsertOne(ctx, req)
|
|
|
if insertErr != nil {
|
|
|
- mhayaLogger.Warnf("Add InsertOne error:", insertErr)
|
|
|
+ mhayaLogger.Warnf("Add InsertOne error:%v", insertErr)
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -128,7 +128,7 @@ func (r *Role) Update(ctx context.Context, req entity.RoleUpdateReq) *code.Resul
|
|
|
// 更新条件
|
|
|
objID, err := primitive.ObjectIDFromHex(req.Id)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("Update req.Id error:", req.Id)
|
|
|
+ mhayaLogger.Warnf("Update req.Id error:%v", req.Id)
|
|
|
return common.NewResult(code.ParamError)
|
|
|
}
|
|
|
|
|
@@ -148,7 +148,7 @@ func (r *Role) Update(ctx context.Context, req entity.RoleUpdateReq) *code.Resul
|
|
|
// 执行更新操作
|
|
|
_, err = collection.UpdateOne(context.TODO(), updateCondition, updateContent, updateOptions)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("Update UpdateOne error:", err)
|
|
|
+ mhayaLogger.Warnf("Update UpdateOne error:%v", err)
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -187,7 +187,7 @@ func (r *Role) Del(ctx context.Context, req entity.RoleDelReq) *code.Result {
|
|
|
id, _ := primitive.ObjectIDFromHex(req.Id)
|
|
|
_, err := collection.DeleteOne(ctx, bson.M{"_id": id})
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("Del DeleteOne error:", err)
|
|
|
+ mhayaLogger.Warnf("Del DeleteOne error:%v", err)
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -198,7 +198,7 @@ func (r *Role) Del(ctx context.Context, req entity.RoleDelReq) *code.Result {
|
|
|
func (r *Role) AddRoleAccess(ctx context.Context, req entity.RoleAccessAddReq) *code.Result {
|
|
|
// 检查上下文是否有效
|
|
|
if ctx.Err() != nil {
|
|
|
- mhayaLogger.Warnf("AddRoleAccess ctx error:", ctx.Err())
|
|
|
+ mhayaLogger.Warnf("AddRoleAccess ctx error:%v", ctx.Err())
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -231,7 +231,7 @@ func (r *Role) AddRoleAccess(ctx context.Context, req entity.RoleAccessAddReq) *
|
|
|
collection = mdb.MDB.Collection(roleAccess.TableName())
|
|
|
_, insertErr := collection.UpdateOne(ctx, bson.M{"role_id": req.RoleId}, bson.M{"$addToSet": bson.M{"access_id": bson.M{"$each": req.AccessId}}}, options.Update().SetUpsert(true))
|
|
|
if insertErr != nil {
|
|
|
- mhayaLogger.Warnf("AddRoleAccess UpdateOne error:", insertErr)
|
|
|
+ mhayaLogger.Warnf("AddRoleAccess UpdateOne error:%v", insertErr)
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
return nil
|
|
@@ -242,14 +242,14 @@ func (r *Role) UpdateRoleAccess(ctx context.Context, req entity.RoleAccessUpdate
|
|
|
// 验证请求数据的有效性
|
|
|
err := validateConcurrently(ctx, req)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("UpdateRoleAccess validateConcurrently error:", err)
|
|
|
+ mhayaLogger.Warnf("UpdateRoleAccess validateConcurrently error:%v", err)
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
|
// 更新角色权限
|
|
|
err = r.updateAccessInDatabase(ctx, req)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("UpdateRoleAccess updateAccessInDatabase error:", err)
|
|
|
+ mhayaLogger.Warnf("UpdateRoleAccess updateAccessInDatabase error:%v", err)
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -264,7 +264,7 @@ func (r *Role) DelRoleAccess(ctx context.Context, req entity.RoleAccessDelReq) *
|
|
|
filter := bson.M{"role_id": req.RoleId}
|
|
|
_, err := collection.DeleteOne(ctx, filter)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("DelRoleAccess DeleteOne error:", err)
|
|
|
+ mhayaLogger.Warnf("DelRoleAccess DeleteOne error:%v", err)
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -280,7 +280,7 @@ func (r *Role) GetRoleAccessList(ctx context.Context, req entity.RoleAccessListR
|
|
|
cursor, err := collection.Find(ctx, filter)
|
|
|
defer cursor.Close(ctx)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("GetRoleAccessList Find error:", err)
|
|
|
+ mhayaLogger.Warnf("GetRoleAccessList Find error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -288,7 +288,7 @@ func (r *Role) GetRoleAccessList(ctx context.Context, req entity.RoleAccessListR
|
|
|
for cursor.Next(ctx) {
|
|
|
var roleAccess models.RoleAccess
|
|
|
if err := cursor.Decode(&roleAccess); err != nil {
|
|
|
- mhayaLogger.Warnf("GetRoleAccessList Decode error:", err)
|
|
|
+ mhayaLogger.Warnf("GetRoleAccessList Decode error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -311,14 +311,14 @@ func (r *Role) GetRoleAccessList(ctx context.Context, req entity.RoleAccessListR
|
|
|
cursor, err = collection.Find(ctx, accessFilter)
|
|
|
defer cursor.Close(ctx)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("GetRoleAccessList sub Find error:", err)
|
|
|
+ mhayaLogger.Warnf("GetRoleAccessList sub Find error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
var accessList []*entity.AccessDetail
|
|
|
for cursor.Next(ctx) {
|
|
|
var accesss *models.Access
|
|
|
if err := cursor.Decode(&accesss); err != nil {
|
|
|
- mhayaLogger.Warnf("GetRoleAccessList sub Decode error:", err)
|
|
|
+ mhayaLogger.Warnf("GetRoleAccessList sub Decode error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
accessList = append(accessList, &entity.AccessDetail{
|
|
@@ -367,7 +367,7 @@ func formatAccessData(accessData []*entity.AccessDetail) []*entity.AccessDetail
|
|
|
func (r *Role) AddAccess(ctx context.Context, req entity.AccessAddReq) *code.Result {
|
|
|
// 检查上下文是否有效
|
|
|
if ctx.Err() != nil {
|
|
|
- mhayaLogger.Warnf("AddAccess ctx error:", ctx.Err())
|
|
|
+ mhayaLogger.Warnf("AddAccess ctx error:%v", ctx.Err())
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -382,7 +382,7 @@ func (r *Role) AddAccess(ctx context.Context, req entity.AccessAddReq) *code.Res
|
|
|
// 插入新角色权限记录
|
|
|
_, err := collection.InsertOne(ctx, req)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("AddAccess InsertOne error:", err)
|
|
|
+ mhayaLogger.Warnf("AddAccess InsertOne error:%v", err)
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -405,7 +405,7 @@ func (r *Role) DelAccess(ctx context.Context, req entity.AccessDelReq) *code.Res
|
|
|
objID, _ = primitive.ObjectIDFromHex(req.Id)
|
|
|
_, err := mdb.MDB.Collection(access.TableName()).DeleteOne(ctx, bson.M{"_id": objID})
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("DelAccess DeleteOne error:", err)
|
|
|
+ mhayaLogger.Warnf("DelAccess DeleteOne error:%v", err)
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -441,7 +441,7 @@ func (r *Role) UpdateAccess(ctx context.Context, req entity.AccessUpdateReq) *co
|
|
|
|
|
|
_, err = collection.UpdateByID(ctx, objID, bson.M{"$set": updateFields})
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("UpdateAccess UpdateByID error:", err)
|
|
|
+ mhayaLogger.Warnf("UpdateAccess UpdateByID error:%v", err)
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -482,14 +482,14 @@ func (r *Role) ListAccess(ctx context.Context, req entity.AccessListReq) (*entit
|
|
|
findOptions.SetSort(bson.M{"add_time": -1})
|
|
|
countDocuments, err := collection.CountDocuments(ctx, filter)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("ListAccess CountDocuments error:", err)
|
|
|
+ mhayaLogger.Warnf("ListAccess CountDocuments error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
|
cursor, err := collection.Find(ctx, filter, findOptions)
|
|
|
defer cursor.Close(ctx)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("ListAccess Find error:", err)
|
|
|
+ mhayaLogger.Warnf("ListAccess Find error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -497,7 +497,7 @@ func (r *Role) ListAccess(ctx context.Context, req entity.AccessListReq) (*entit
|
|
|
for cursor.Next(ctx) {
|
|
|
var accesss *models.Access
|
|
|
if err := cursor.Decode(&accesss); err != nil {
|
|
|
- mhayaLogger.Warnf("ListAccess Decode error:", err)
|
|
|
+ mhayaLogger.Warnf("ListAccess Decode error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -546,7 +546,7 @@ func (r *Role) AdminBindRole(ctx context.Context, req entity.AdminBindRoleReq) *
|
|
|
filter := bson.M{"_id": roleId, "status": 1}
|
|
|
// 判断你是否存在
|
|
|
if err := collection.FindOne(ctx, filter).Err(); err != nil {
|
|
|
- mhayaLogger.Warnf("AdminBindRole Find error:", err)
|
|
|
+ mhayaLogger.Warnf("AdminBindRole Find error:%v", err)
|
|
|
return common.NewResult(code.RoleNotExistOrDisabledUserError)
|
|
|
}
|
|
|
|
|
@@ -578,7 +578,7 @@ func (r *Role) AdminBindRole(ctx context.Context, req entity.AdminBindRoleReq) *
|
|
|
// 更新管理员数据
|
|
|
_, err = collection.UpdateByID(ctx, objID, bson.M{"$set": bson.M{"role_id": req.RoleId}})
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("AdminBindRole UpdateByID error:", err)
|
|
|
+ mhayaLogger.Warnf("AdminBindRole UpdateByID error:%v", err)
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -610,7 +610,7 @@ func (r *Role) AdminUnBindRole(ctx context.Context, req entity.AdminBindRoleReq)
|
|
|
// 更新管理员数据
|
|
|
_, err = collection.UpdateByID(ctx, objID, bson.M{"$set": bson.M{"role_id": ""}})
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("AdminUnBindRole UpdateByID error:", err)
|
|
|
+ mhayaLogger.Warnf("AdminUnBindRole UpdateByID error:%v", err)
|
|
|
return common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -678,7 +678,7 @@ func (r *Role) GetAdminRole(ctx context.Context, req entity.AdminBindRoleReq) (*
|
|
|
cursor, err := collection.Find(ctx, filter)
|
|
|
defer cursor.Close(ctx)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("GetAdminRole Find error:", err)
|
|
|
+ mhayaLogger.Warnf("GetAdminRole Find error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -687,7 +687,7 @@ func (r *Role) GetAdminRole(ctx context.Context, req entity.AdminBindRoleReq) (*
|
|
|
var accesss *models.Access
|
|
|
err := cursor.Decode(&accesss)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("GetAdminRole Decode error:", err)
|
|
|
+ mhayaLogger.Warnf("GetAdminRole Decode error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
accessList = append(accessList, &entity.AccessDetail{
|
|
@@ -715,13 +715,13 @@ func (r *Role) GetAdminRole(ctx context.Context, req entity.AdminBindRoleReq) (*
|
|
|
|
|
|
role, err := getRole(ctx, req.RoleId)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("GetAdminRole getRole error:", err)
|
|
|
+ mhayaLogger.Warnf("GetAdminRole getRole error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
|
roleAccess, err := getRoleAccess(ctx, req.RoleId)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("GetAdminRole getRoleAccess error:", err)
|
|
|
+ mhayaLogger.Warnf("GetAdminRole getRoleAccess error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -738,7 +738,7 @@ func (r *Role) GetAdminRole(ctx context.Context, req entity.AdminBindRoleReq) (*
|
|
|
|
|
|
if len(AccessIds) == 0 {
|
|
|
if len(invalidAccessIds) > 0 {
|
|
|
- mhayaLogger.Warnf("GetAdminRole 无效的权限ID:", strings.Join(invalidAccessIds, ", "))
|
|
|
+ mhayaLogger.Warnf("GetAdminRole 无效的权限ID:%v", strings.Join(invalidAccessIds, ", "))
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -752,7 +752,7 @@ func (r *Role) GetAdminRole(ctx context.Context, req entity.AdminBindRoleReq) (*
|
|
|
cursor, err := collection.Find(ctx, filter)
|
|
|
defer cursor.Close(ctx)
|
|
|
if err != nil {
|
|
|
- mhayaLogger.Warnf("GetAdminRole Find error:", err)
|
|
|
+ mhayaLogger.Warnf("GetAdminRole Find error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
|
|
@@ -760,7 +760,7 @@ func (r *Role) GetAdminRole(ctx context.Context, req entity.AdminBindRoleReq) (*
|
|
|
for cursor.Next(ctx) {
|
|
|
var accesss *models.Access
|
|
|
if err := cursor.Decode(&accesss); err != nil {
|
|
|
- mhayaLogger.Warnf("GetAdminRole Decode error:", err)
|
|
|
+ mhayaLogger.Warnf("GetAdminRole Decode error:%v", err)
|
|
|
return nil, common.NewResult(code.InternalError)
|
|
|
}
|
|
|
accessList = append(accessList, &entity.AccessDetail{
|