feat: rbac迁移完成,并已部署至dev服务器

This commit is contained in:
Blizzard
2026-05-01 01:19:50 +08:00
parent f80a3dc064
commit 8b11068fef
250 changed files with 6314 additions and 13072 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ Host: 0.0.0.0
Port: 9003
Auth:
AccessSecret: sundynix-jwt-secret-2024
AccessSecret: 9149f2eb-d517-4a50-a03a-231dbcf0d872
AccessExpire: 604800
SystemRpc:
+47 -9
View File
@@ -11,6 +11,7 @@ import (
menu "sundynix-micro-go/app/system/api/internal/handler/menu"
operationRecord "sundynix-micro-go/app/system/api/internal/handler/operationRecord"
role "sundynix-micro-go/app/system/api/internal/handler/role"
user "sundynix-micro-go/app/system/api/internal/handler/user"
"sundynix-micro-go/app/system/api/internal/svc"
"github.com/zeromicro/go-zero/rest"
@@ -27,7 +28,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
// 删除客户端
Method: http.MethodDelete,
Method: http.MethodPost,
Path: "/client/delete",
Handler: client.DeleteClientHandler(serverCtx),
},
@@ -39,7 +40,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
// 更新客户端
Method: http.MethodPut,
Method: http.MethodPost,
Path: "/client/update",
Handler: client.UpdateClientHandler(serverCtx),
},
@@ -58,7 +59,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
// 删除字典
Method: http.MethodDelete,
Method: http.MethodPost,
Path: "/dict/delete",
Handler: dict.DeleteDictHandler(serverCtx),
},
@@ -70,7 +71,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
// 更新字典
Method: http.MethodPut,
Method: http.MethodPost,
Path: "/dict/update",
Handler: dict.UpdateDictHandler(serverCtx),
},
@@ -95,7 +96,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
// 删除菜单
Method: http.MethodDelete,
Method: http.MethodPost,
Path: "/menu/delete",
Handler: menu.DeleteMenuHandler(serverCtx),
},
@@ -107,7 +108,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
// 更新菜单
Method: http.MethodPut,
Method: http.MethodPost,
Path: "/menu/update",
Handler: menu.UpdateMenuHandler(serverCtx),
},
@@ -120,7 +121,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
// 删除操作日志
Method: http.MethodDelete,
Method: http.MethodPost,
Path: "/log/delete",
Handler: operationRecord.DeleteOperationRecordHandler(serverCtx),
},
@@ -145,7 +146,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
// 删除角色
Method: http.MethodDelete,
Method: http.MethodPost,
Path: "/role/delete",
Handler: role.DeleteRoleHandler(serverCtx),
},
@@ -157,7 +158,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
// 更新角色
Method: http.MethodPut,
Method: http.MethodPost,
Path: "/role/update",
Handler: role.UpdateRoleHandler(serverCtx),
},
@@ -165,4 +166,41 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
rest.WithPrefix("/api/sys"),
)
server.AddRoutes(
[]rest.Route{
{
// 创建用户
Method: http.MethodPost,
Path: "/user/create",
Handler: user.CreateUserHandler(serverCtx),
},
{
// 删除用户
Method: http.MethodPost,
Path: "/user/delete",
Handler: user.DeleteUserHandler(serverCtx),
},
{
// 用户列表
Method: http.MethodPost,
Path: "/user/list",
Handler: user.GetUserListHandler(serverCtx),
},
{
// 重置密码
Method: http.MethodPost,
Path: "/user/resetPassword",
Handler: user.ResetPasswordHandler(serverCtx),
},
{
// 更新用户
Method: http.MethodPost,
Path: "/user/update",
Handler: user.UpdateUserHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
rest.WithPrefix("/api/sys"),
)
}
@@ -0,0 +1,27 @@
package user
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"sundynix-micro-go/app/system/api/internal/logic/user"
"sundynix-micro-go/app/system/api/internal/svc"
"sundynix-micro-go/app/system/api/internal/types"
"sundynix-micro-go/common/response"
)
func CreateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UserCreateReq
if err := httpx.Parse(r, &req); err != nil {
response.Fail(w, err.Error())
return
}
l := user.NewCreateUserLogic(r.Context(), svcCtx)
if err := l.CreateUser(&req); err != nil {
response.Fail(w, err.Error())
} else {
response.Ok(w)
}
}
}
@@ -0,0 +1,27 @@
package user
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"sundynix-micro-go/app/system/api/internal/logic/user"
"sundynix-micro-go/app/system/api/internal/svc"
"sundynix-micro-go/app/system/api/internal/types"
"sundynix-micro-go/common/response"
)
func DeleteUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.IdsReq
if err := httpx.Parse(r, &req); err != nil {
response.Fail(w, err.Error())
return
}
l := user.NewDeleteUserLogic(r.Context(), svcCtx)
if err := l.DeleteUser(&req); err != nil {
response.Fail(w, err.Error())
} else {
response.Ok(w)
}
}
}
@@ -0,0 +1,28 @@
package user
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"sundynix-micro-go/app/system/api/internal/logic/user"
"sundynix-micro-go/app/system/api/internal/svc"
"sundynix-micro-go/app/system/api/internal/types"
"sundynix-micro-go/common/response"
)
func GetUserListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UserListReq
if err := httpx.Parse(r, &req); err != nil {
response.Fail(w, err.Error())
return
}
l := user.NewGetUserListLogic(r.Context(), svcCtx)
resp, err := l.GetUserList(&req)
if err != nil {
response.Fail(w, err.Error())
} else {
response.OkWithData(w, resp)
}
}
}
@@ -0,0 +1,27 @@
package user
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"sundynix-micro-go/app/system/api/internal/logic/user"
"sundynix-micro-go/app/system/api/internal/svc"
"sundynix-micro-go/app/system/api/internal/types"
"sundynix-micro-go/common/response"
)
func ResetPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ResetPasswordReq
if err := httpx.Parse(r, &req); err != nil {
response.Fail(w, err.Error())
return
}
l := user.NewResetPasswordLogic(r.Context(), svcCtx)
if err := l.ResetPassword(&req); err != nil {
response.Fail(w, err.Error())
} else {
response.Ok(w)
}
}
}
@@ -0,0 +1,27 @@
package user
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"sundynix-micro-go/app/system/api/internal/logic/user"
"sundynix-micro-go/app/system/api/internal/svc"
"sundynix-micro-go/app/system/api/internal/types"
"sundynix-micro-go/common/response"
)
func UpdateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UserUpdateReq
if err := httpx.Parse(r, &req); err != nil {
response.Fail(w, err.Error())
return
}
l := user.NewUpdateUserLogic(r.Context(), svcCtx)
if err := l.UpdateUser(&req); err != nil {
response.Fail(w, err.Error())
} else {
response.Ok(w)
}
}
}
@@ -0,0 +1,31 @@
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 CreateUserLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCreateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateUserLogic {
return &CreateUserLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
}
func (l *CreateUserLogic) CreateUser(req *types.UserCreateReq) error {
_, err := l.svcCtx.SystemRpc.CreateUser(l.ctx, &system.CreateUserReq{
Name: req.Name,
Account: req.Account,
Password: req.Password,
Phone: req.Phone,
})
return err
}
@@ -0,0 +1,26 @@
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 DeleteUserLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteUserLogic {
return &DeleteUserLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
}
func (l *DeleteUserLogic) DeleteUser(req *types.IdsReq) error {
_, err := l.svcCtx.SystemRpc.DeleteUser(l.ctx, &system.DeleteUserReq{Ids: req.Ids})
return err
}
@@ -0,0 +1,46 @@
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 GetUserListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserListLogic {
return &GetUserListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
}
func (l *GetUserListLogic) GetUserList(req *types.UserListReq) (resp interface{}, err error) {
rpcResp, err := l.svcCtx.SystemRpc.GetUserList(l.ctx, &system.GetUserListReq{
Current: int32(req.Current),
PageSize: int32(req.PageSize),
Name: req.Name,
Account: req.Account,
})
if err != nil {
return nil, err
}
var list []map[string]interface{}
for _, u := range rpcResp.List {
list = append(list, map[string]interface{}{
"id": u.Id,
"name": u.Name,
"account": u.Account,
"nickName": u.NickName,
"phone": u.Phone,
"gender": u.Gender,
"createdAt": u.CreatedAt,
})
}
return map[string]interface{}{"list": list, "total": rpcResp.Total}, nil
}
@@ -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 ResetPasswordLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResetPasswordLogic {
return &ResetPasswordLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
}
func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordReq) error {
_, err := l.svcCtx.SystemRpc.ResetPassword(l.ctx, &system.ResetPasswordReq{
Id: req.Id,
Password: req.Password,
})
return err
}
@@ -0,0 +1,32 @@
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 UpdateUserLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUpdateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserLogic {
return &UpdateUserLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
}
func (l *UpdateUserLogic) UpdateUser(req *types.UserUpdateReq) error {
_, err := l.svcCtx.SystemRpc.UpdateUser(l.ctx, &system.UpdateUserReq{
Id: req.Id,
Name: req.Name,
Account: req.Account,
Phone: req.Phone,
NickName: req.NickName,
})
return err
}
@@ -1,6 +1,3 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1
package svc
import (
+30
View File
@@ -98,6 +98,11 @@ type PageReq struct {
Keyword string `json:"keyword,optional"`
}
type ResetPasswordReq struct {
Id string `json:"id"`
Password string `json:"password"`
}
type RoleListReq struct {
Current int `json:"current,optional"`
PageSize int `json:"pageSize,optional"`
@@ -118,3 +123,28 @@ type RoleUpdateReq struct {
Sort int `json:"sort,optional"`
MenuIds []string `json:"menuIds,optional"`
}
type UserCreateReq struct {
Name string `json:"name"`
Account string `json:"account"`
Password string `json:"password"`
Phone string `json:"phone,optional"`
NickName string `json:"nickName,optional"`
RoleIds []string `json:"roleIds,optional"`
}
type UserListReq struct {
Current int `json:"current,optional"`
PageSize int `json:"pageSize,optional"`
Name string `json:"name,optional"`
Account string `json:"account,optional"`
}
type UserUpdateReq struct {
Id string `json:"id"`
Name string `json:"name,optional"`
Account string `json:"account,optional"`
Phone string `json:"phone,optional"`
NickName string `json:"nickName,optional"`
RoleIds []string `json:"roleIds,optional"`
}
+63 -9
View File
@@ -115,6 +115,33 @@ type (
PageSize int `json:"pageSize,optional"`
Type string `json:"type,optional"`
}
// ---------- 用户管理 ----------
UserCreateReq {
Name string `json:"name"`
Account string `json:"account"`
Password string `json:"password"`
Phone string `json:"phone,optional"`
NickName string `json:"nickName,optional"`
RoleIds []string `json:"roleIds,optional"`
}
UserUpdateReq {
Id string `json:"id"`
Name string `json:"name,optional"`
Account string `json:"account,optional"`
Phone string `json:"phone,optional"`
NickName string `json:"nickName,optional"`
RoleIds []string `json:"roleIds,optional"`
}
UserListReq {
Current int `json:"current,optional"`
PageSize int `json:"pageSize,optional"`
Name string `json:"name,optional"`
Account string `json:"account,optional"`
}
ResetPasswordReq {
Id string `json:"id"`
Password string `json:"password"`
}
)
// ========== 需要鉴权的接口 ==========
@@ -130,11 +157,11 @@ service system-api {
@doc "更新客户端"
@handler UpdateClient
put /client/update (ClientUpdateReq)
post /client/update (ClientUpdateReq)
@doc "删除客户端"
@handler DeleteClient
delete /client/delete (IdsReq)
post /client/delete (IdsReq)
@doc "客户端列表"
@handler GetClientList
@@ -153,11 +180,11 @@ service system-api {
@doc "更新角色"
@handler UpdateRole
put /role/update (RoleUpdateReq)
post /role/update (RoleUpdateReq)
@doc "删除角色"
@handler DeleteRole
delete /role/delete (IdsReq)
post /role/delete (IdsReq)
@doc "角色列表"
@handler GetRoleList
@@ -176,11 +203,11 @@ service system-api {
@doc "更新菜单"
@handler UpdateMenu
put /menu/update (MenuUpdateReq)
post /menu/update (MenuUpdateReq)
@doc "删除菜单"
@handler DeleteMenu
delete /menu/delete (IdsReq)
post /menu/delete (IdsReq)
@doc "菜单列表(树形)"
@handler GetMenuList
@@ -203,7 +230,7 @@ service system-api {
@doc "删除操作日志"
@handler DeleteOperationRecord
delete /log/delete (IdsReq)
post /log/delete (IdsReq)
}
@server (
@@ -218,14 +245,41 @@ service system-api {
@doc "更新字典"
@handler UpdateDict
put /dict/update (DictUpdateReq)
post /dict/update (DictUpdateReq)
@doc "删除字典"
@handler DeleteDict
delete /dict/delete (IdsReq)
post /dict/delete (IdsReq)
@doc "字典列表"
@handler GetDictList
post /dict/list (DictListReq)
}
@server (
prefix: /api/sys
group: user
jwt: Auth
)
service system-api {
@doc "用户列表"
@handler GetUserList
post /user/list (UserListReq)
@doc "创建用户"
@handler CreateUser
post /user/create (UserCreateReq)
@doc "更新用户"
@handler UpdateUser
post /user/update (UserUpdateReq)
@doc "删除用户"
@handler DeleteUser
post /user/delete (IdsReq)
@doc "重置密码"
@handler ResetPassword
post /user/resetPassword (ResetPasswordReq)
}
+2
View File
@@ -12,6 +12,7 @@ import (
"sundynix-micro-go/app/system/api/internal/svc"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/stat"
"github.com/zeromicro/go-zero/rest"
)
@@ -19,6 +20,7 @@ var configFile = flag.String("f", "etc/system-api.yaml", "the config file")
func main() {
flag.Parse()
stat.DisableLog()
var c config.Config
conf.MustLoad(*configFile, &c)