fix
This commit is contained in:
parent
d457c5391f
commit
6d7a88ef29
|
@ -1,2 +1,20 @@
|
|||
package gmodel
|
||||
|
||||
import "context"
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
func (m *LdapMenusModel) Create(ctx context.Context, data *LdapMenus) error {
|
||||
return m.db.WithContext(ctx).Model(&LdapMenus{}).Create(&data).Error
|
||||
}
|
||||
func (m *LdapMenusModel) FindOne(ctx context.Context, id int64) (resp *LdapMenus, err error) {
|
||||
err = m.db.WithContext(ctx).Model(&LdapMenus{}).Where("id= ? and status = ?", id, 1).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (m *LdapMenusModel) FindByPath(ctx context.Context, path string) (resp *LdapMenus, err error) {
|
||||
err = m.db.WithContext(ctx).Model(&LdapMenus{}).Where("path= ? and status = ?", path, 1).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (m *LdapMenusModel) Update(ctx context.Context, id int64, data *LdapMenus) error {
|
||||
return m.db.WithContext(ctx).Model(&LdapMenus{}).Where("id = ?", id).Updates(&data).Error
|
||||
}
|
||||
|
|
35
server/ldap-admin/internal/handler/deletemenuhandler.go
Normal file
35
server/ldap-admin/internal/handler/deletemenuhandler.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/ldap-admin/internal/logic"
|
||||
"fusenapi/server/ldap-admin/internal/svc"
|
||||
"fusenapi/server/ldap-admin/internal/types"
|
||||
)
|
||||
|
||||
func DeleteMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.DeleteMenuReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewDeleteMenuLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.DeleteMenu(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
35
server/ldap-admin/internal/handler/getmenudetailhandler.go
Normal file
35
server/ldap-admin/internal/handler/getmenudetailhandler.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/ldap-admin/internal/logic"
|
||||
"fusenapi/server/ldap-admin/internal/svc"
|
||||
"fusenapi/server/ldap-admin/internal/types"
|
||||
)
|
||||
|
||||
func GetMenuDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.GetMenuDetailReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewGetMenuDetailLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.GetMenuDetail(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
35
server/ldap-admin/internal/handler/getmenushandler.go
Normal file
35
server/ldap-admin/internal/handler/getmenushandler.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/ldap-admin/internal/logic"
|
||||
"fusenapi/server/ldap-admin/internal/svc"
|
||||
"fusenapi/server/ldap-admin/internal/types"
|
||||
)
|
||||
|
||||
func GetMenusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.GetMenusReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewGetMenusLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.GetMenus(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,6 +32,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/ldap-admin/save_menu",
|
||||
Handler: SaveMenuHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/ldap-admin/delete_menu",
|
||||
Handler: DeleteMenuHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/ldap-admin/get_menu_detail",
|
||||
Handler: GetMenuDetailHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/ldap-admin/get_menus",
|
||||
Handler: GetMenusHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
43
server/ldap-admin/internal/logic/deletemenulogic.go
Normal file
43
server/ldap-admin/internal/logic/deletemenulogic.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/ldap-admin/internal/svc"
|
||||
"fusenapi/server/ldap-admin/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteMenuLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteMenuLogic {
|
||||
return &DeleteMenuLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *DeleteMenuLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *DeleteMenuLogic) DeleteMenu(req *types.DeleteMenuReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *DeleteMenuLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
43
server/ldap-admin/internal/logic/getmenudetaillogic.go
Normal file
43
server/ldap-admin/internal/logic/getmenudetaillogic.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/ldap-admin/internal/svc"
|
||||
"fusenapi/server/ldap-admin/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetMenuDetailLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetMenuDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuDetailLogic {
|
||||
return &GetMenuDetailLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *GetMenuDetailLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *GetMenuDetailLogic) GetMenuDetail(req *types.GetMenuDetailReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *GetMenuDetailLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
43
server/ldap-admin/internal/logic/getmenuslogic.go
Normal file
43
server/ldap-admin/internal/logic/getmenuslogic.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/ldap-admin/internal/svc"
|
||||
"fusenapi/server/ldap-admin/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetMenusLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetMenusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenusLogic {
|
||||
return &GetMenusLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *GetMenusLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *GetMenusLogic) GetMenus(req *types.GetMenusReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *GetMenusLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
|
@ -1,8 +1,13 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
|
@ -31,10 +36,58 @@ func NewSaveMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveMenu
|
|||
// }
|
||||
|
||||
func (l *SaveMenuLogic) SaveMenu(req *types.SaveMenuReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
req.Path = strings.Trim(req.Path, " ")
|
||||
req.Name = strings.Trim(req.Name, " ")
|
||||
req.Title = strings.Trim(req.Title, " ")
|
||||
if req.Path == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数path不能为空")
|
||||
}
|
||||
if req.Name == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数name不能为空")
|
||||
}
|
||||
if req.Title == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数title不能为空")
|
||||
}
|
||||
now := time.Now().UTC()
|
||||
data := &gmodel.LdapMenus{
|
||||
Name: &req.Name,
|
||||
Title: &req.Title,
|
||||
Icon: &req.Icon,
|
||||
Path: &req.Path,
|
||||
Sort: &req.Sort,
|
||||
Status: &req.Status,
|
||||
ParentId: &req.ParentId,
|
||||
Utime: &now,
|
||||
}
|
||||
//查询重复
|
||||
info, err := l.svcCtx.AllModels.LdapMenus.FindByPath(l.ctx, req.Path)
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "获取检查重复路径失败")
|
||||
}
|
||||
//没有
|
||||
} else { //有
|
||||
//是新增/或者是更新但是id不等
|
||||
if req.Id == 0 || (info.Id != req.Id) {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "该路径已经存在")
|
||||
}
|
||||
}
|
||||
if req.Id > 0 { //更新
|
||||
//更新
|
||||
if err = l.svcCtx.AllModels.LdapMenus.Update(l.ctx, req.Id, data); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "更新失败")
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "更新成功")
|
||||
}
|
||||
//添加
|
||||
data.Ctime = &now
|
||||
if err = l.svcCtx.AllModels.LdapMenus.Create(l.ctx, data); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "添加失败")
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "添加成功")
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
|
|
|
@ -45,6 +45,49 @@ type Member struct {
|
|||
}
|
||||
|
||||
type SaveMenuReq struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Title string `json:"title"`
|
||||
Icon string `json:"icon"`
|
||||
Path string `json:"path"`
|
||||
Sort int64 `json:"sort"`
|
||||
ParentId int64 `json:"parent_id"`
|
||||
Status int64 `json:"status,options=0|1"`
|
||||
}
|
||||
|
||||
type DeleteMenuReq struct {
|
||||
Id int64 `json:"id"`
|
||||
}
|
||||
|
||||
type GetMenuDetailReq struct {
|
||||
Id int64 `form:"id"`
|
||||
}
|
||||
|
||||
type GetMenuDetailRsp struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Title string `json:"title"`
|
||||
Icon string `json:"icon"`
|
||||
Path string `json:"path"`
|
||||
Sort int64 `json:"sort"`
|
||||
ParentId int64 `json:"parent_id"`
|
||||
Status int64 `json:"status"`
|
||||
}
|
||||
|
||||
type GetMenusReq struct {
|
||||
CurrentPage int64 `form:"current_page"`
|
||||
Name string `form:"name"`
|
||||
Title string `form:"title"`
|
||||
Path string `form:"path"`
|
||||
ParentId int64 `form:"parent_id"`
|
||||
}
|
||||
|
||||
type GetMenusRsp struct {
|
||||
List []MenuItem `json:"list"`
|
||||
Meta Meta `json:"meta"`
|
||||
}
|
||||
|
||||
type MenuItem struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Title string `json:"title"`
|
||||
|
|
|
@ -24,6 +24,15 @@ service ldap-admin {
|
|||
//保存菜单
|
||||
@handler SaveMenuHandler
|
||||
post /api/ldap-admin/save_menu(SaveMenuReq) returns (response);
|
||||
//删除菜单
|
||||
@handler DeleteMenuHandler
|
||||
post /api/ldap-admin/delete_menu(DeleteMenuReq) returns (response);
|
||||
//获取菜单详情
|
||||
@handler GetMenuDetailHandler
|
||||
get /api/ldap-admin/get_menu_detail(GetMenuDetailReq) returns (response);
|
||||
//获取菜单列表
|
||||
@handler GetMenusHandler
|
||||
get /api/ldap-admin/get_menus(GetMenusReq) returns (response);
|
||||
}
|
||||
|
||||
type GetApisReq {
|
||||
|
@ -65,6 +74,46 @@ type Member {
|
|||
}
|
||||
//保存菜单
|
||||
type SaveMenuReq {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Title string `json:"title"`
|
||||
Icon string `json:"icon"`
|
||||
Path string `json:"path"`
|
||||
Sort int64 `json:"sort"`
|
||||
ParentId int64 `json:"parent_id"`
|
||||
Status int64 `json:"status,options=0|1"`
|
||||
}
|
||||
//删除菜单
|
||||
type DeleteMenuReq {
|
||||
Id int64 `json:"id"`
|
||||
}
|
||||
//获取菜单详情
|
||||
type GetMenuDetailReq {
|
||||
Id int64 `form:"id"`
|
||||
}
|
||||
type GetMenuDetailRsp {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Title string `json:"title"`
|
||||
Icon string `json:"icon"`
|
||||
Path string `json:"path"`
|
||||
Sort int64 `json:"sort"`
|
||||
ParentId int64 `json:"parent_id"`
|
||||
Status int64 `json:"status"`
|
||||
}
|
||||
//获取菜单列表
|
||||
type GetMenusReq {
|
||||
CurrentPage int64 `form:"current_page"`
|
||||
Name string `form:"name"`
|
||||
Title string `form:"title"`
|
||||
Path string `form:"path"`
|
||||
ParentId int64 `form:"parent_id"`
|
||||
}
|
||||
type GetMenusRsp {
|
||||
List []MenuItem `json:"list"`
|
||||
Meta Meta `json:"meta"`
|
||||
}
|
||||
type MenuItem {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Title string `json:"title"`
|
||||
|
|
Loading…
Reference in New Issue
Block a user