feat: rbac完善,file接入完成
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AssignRoleMenusLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAssignRoleMenusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AssignRoleMenusLogic {
|
||||
return &AssignRoleMenusLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *AssignRoleMenusLogic) AssignRoleMenus(req *types.AssignRoleMenusReq) error {
|
||||
_, err := l.svcCtx.SystemRpc.AssignRoleMenus(l.ctx, &system.AssignRoleMenusReq{
|
||||
RoleId: req.RoleId,
|
||||
MenuIds: req.MenuIds,
|
||||
})
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetRoleDetailLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 角色详情(含已授权菜单)
|
||||
func NewGetRoleDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRoleDetailLogic {
|
||||
return &GetRoleDetailLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetRoleDetailLogic) GetRoleDetail(req *types.IdQueryReq) (resp *types.RoleDetailResp, err error) {
|
||||
rpcResp, err := l.svcCtx.SystemRpc.GetRoleDetail(l.ctx, &system.GetRoleDetailReq{
|
||||
Id: req.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.RoleDetailResp{
|
||||
Id: rpcResp.Id,
|
||||
Name: rpcResp.Name,
|
||||
Code: rpcResp.Code,
|
||||
Sort: int(rpcResp.Sort),
|
||||
MenuIds: rpcResp.MenuIds,
|
||||
}, nil
|
||||
}
|
||||
@@ -20,7 +20,7 @@ func NewUpdateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Update
|
||||
|
||||
func (l *UpdateRoleLogic) UpdateRole(req *types.RoleUpdateReq) error {
|
||||
_, err := l.svcCtx.SystemRpc.UpdateRole(l.ctx, &system.RoleUpdateReq{
|
||||
Id: req.Id, Name: req.Name, Code: req.Code, Sort: int32(req.Sort), MenuIds: req.MenuIds,
|
||||
Id: req.Id, Name: req.Name, Code: req.Code, Sort: int32(req.Sort),
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AssignUserRolesLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAssignUserRolesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AssignUserRolesLogic {
|
||||
return &AssignUserRolesLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *AssignUserRolesLogic) AssignUserRoles(req *types.AssignUserRolesReq) error {
|
||||
_, err := l.svcCtx.SystemRpc.AssignUserRoles(l.ctx, &system.AssignUserRolesReq{
|
||||
UserId: req.UserId,
|
||||
RoleIds: req.RoleIds,
|
||||
})
|
||||
return err
|
||||
}
|
||||
@@ -21,11 +21,21 @@ func NewCreateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Create
|
||||
}
|
||||
|
||||
func (l *CreateUserLogic) CreateUser(req *types.UserCreateReq) error {
|
||||
_, err := l.svcCtx.SystemRpc.CreateUser(l.ctx, &system.CreateUserReq{
|
||||
resp, err := l.svcCtx.SystemRpc.CreateUser(l.ctx, &system.CreateUserReq{
|
||||
Name: req.Name,
|
||||
Account: req.Account,
|
||||
Password: req.Password,
|
||||
Phone: req.Phone,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 创建完成后立即绑定角色
|
||||
if len(req.RoleIds) > 0 && resp != nil {
|
||||
_, err = l.svcCtx.SystemRpc.AssignUserRoles(l.ctx, &system.AssignUserRolesReq{
|
||||
UserId: resp.User.Id,
|
||||
RoleIds: req.RoleIds,
|
||||
})
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetUserDetailLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 用户详情(含角色信息)
|
||||
func NewGetUserDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserDetailLogic {
|
||||
return &GetUserDetailLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetUserDetailLogic) GetUserDetail(req *types.IdQueryReq) (resp *types.UserDetailResp, err error) {
|
||||
rpcResp, err := l.svcCtx.SystemRpc.GetUserDetail(l.ctx, &system.GetUserDetailReq{
|
||||
Id: req.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.UserDetailResp{
|
||||
Id: rpcResp.Id,
|
||||
Name: rpcResp.Name,
|
||||
Account: rpcResp.Account,
|
||||
NickName: rpcResp.NickName,
|
||||
Phone: rpcResp.Phone,
|
||||
RoleIds: rpcResp.RoleIds,
|
||||
}, nil
|
||||
}
|
||||
@@ -32,6 +32,15 @@ func (l *GetUserListLogic) GetUserList(req *types.UserListReq) (resp interface{}
|
||||
}
|
||||
var list []map[string]interface{}
|
||||
for _, u := range rpcResp.List {
|
||||
var roles []map[string]interface{}
|
||||
for _, r := range u.Roles {
|
||||
roles = append(roles, map[string]interface{}{
|
||||
"id": r.Id,
|
||||
"name": r.Name,
|
||||
"code": r.Code,
|
||||
})
|
||||
}
|
||||
|
||||
list = append(list, map[string]interface{}{
|
||||
"id": u.Id,
|
||||
"name": u.Name,
|
||||
@@ -40,6 +49,7 @@ func (l *GetUserListLogic) GetUserList(req *types.UserListReq) (resp interface{}
|
||||
"phone": u.Phone,
|
||||
"gender": u.Gender,
|
||||
"createdAt": u.CreatedAt,
|
||||
"roles": roles,
|
||||
})
|
||||
}
|
||||
return map[string]interface{}{"list": list, "total": rpcResp.Total}, nil
|
||||
|
||||
Reference in New Issue
Block a user