新增部门角色

This commit is contained in:
momo
2023-11-14 11:45:25 +08:00
parent 3bde233e8a
commit 8542091977
23 changed files with 791 additions and 15 deletions

View File

@@ -1,6 +1,10 @@
package config
import "github.com/zeromicro/go-zero/rest"
import (
"fusenapi/server/ldap-admin/internal/types"
"github.com/zeromicro/go-zero/rest"
)
type Config struct {
rest.RestConf

View 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 AddDepartmentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AddDepartmentReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewAddDepartmentLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.AddDepartment(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View 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 AddMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AddMenuHandler
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewAddMenuLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.AddMenu(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View 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 DeleteDepartmentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteDepartmentReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewDeleteDepartmentLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.DeleteDepartment(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View 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 EditDepartmentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.EditDepartmentReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewEditDepartmentLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.EditDepartment(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View 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 EditMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.EditMenuHandler
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewEditMenuLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.EditMenu(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View 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 GetMenusTreeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetMenusTreeReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewGetMenusTreeLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.GetMenusTree(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@@ -17,6 +17,36 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/api/ldap-admin/get_departments",
Handler: GetDepartmentsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/add_department",
Handler: AddDepartmentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/edit_department",
Handler: EditDepartmentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/delete_department",
Handler: DeleteDepartmentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/get_menus_tree",
Handler: GetMenusTreeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/add_menu",
Handler: AddMenuHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/edit_menu",
Handler: EditMenuHandler(serverCtx),
},
},
)
}

View File

@@ -0,0 +1,62 @@
package logic
import (
"errors"
"fusenapi/model/gmodel"
"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"
"gorm.io/gorm"
)
type AddDepartmentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAddDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddDepartmentLogic {
return &AddDepartmentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *AddDepartmentLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *AddDepartmentLogic) AddDepartment(req *types.AddDepartmentReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
if req.ParentId > 0 {
_, err := l.svcCtx.AllModels.LdapDepartment.GetOneById(l.ctx, req.ParentId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
basic.CodeServiceErr.Message = "查询不到上级"
} else {
basic.CodeServiceErr.Message = "系统出错"
}
return resp.SetStatus(basic.CodeServiceErr)
}
}
err := l.svcCtx.AllModels.LdapDepartment.InsertOne(l.ctx, gmodel.LdapDepartment{
Name: &req.Name,
})
if err != nil {
return resp.SetStatus(basic.CodeServiceErr)
}
return resp.SetStatus(basic.CodeOK)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *AddDepartmentLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View 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 AddMenuLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAddMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddMenuLogic {
return &AddMenuLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *AddMenuLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *AddMenuLogic) AddMenu(req *types.AddMenuHandler, 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 *AddMenuLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View 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 DeleteDepartmentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDepartmentLogic {
return &DeleteDepartmentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *DeleteDepartmentLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *DeleteDepartmentLogic) DeleteDepartment(req *types.DeleteDepartmentReq, 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 *DeleteDepartmentLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View 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 EditDepartmentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewEditDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditDepartmentLogic {
return &EditDepartmentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *EditDepartmentLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *EditDepartmentLogic) EditDepartment(req *types.EditDepartmentReq, 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 *EditDepartmentLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View 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 EditMenuLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewEditMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditMenuLogic {
return &EditMenuLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *EditMenuLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *EditMenuLogic) EditMenu(req *types.EditMenuHandler, 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 *EditMenuLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@@ -4,6 +4,7 @@ import (
"fusenapi/constants"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"math"
"context"
@@ -32,18 +33,34 @@ func NewGetDepartmentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
// }
func (l *GetDepartmentsLogic) GetDepartments(req *types.GetDepartmentsReq, userinfo *auth.UserInfo) (resp *basic.Response) {
if req.CurrentPage <= 0{
if req.CurrentPage <= 0 {
req.CurrentPage = constants.DEFAULT_PAGE
}
if req.PageSize <= 0{
if req.PageSize <= 0 {
req.PageSize = constants.DEFAULT_PAGE_SIZE
}
/*departList,total,err := l.svcCtx.AllModels.LdapDepartment.GetList(l.ctx,req.CurrentPage,req.PageSize,"")
if err != nil{
resList, resTotal, err := l.svcCtx.AllModels.LdapDepartment.GetList(l.ctx, req.CurrentPage, req.PageSize, "")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"获取部门列表失败")
}*/
return resp.SetStatus(basic.CodeOK)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "获取部门列表失败")
}
var pageCount int64 = 1
if resTotal > int64(req.PageSize) {
var float64Count = float64(resTotal)
var float64PerPage = float64(req.PageSize)
pageCountFloat := math.Ceil(float64Count / float64PerPage)
pageCount = int64(pageCountFloat)
}
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
"list": resList,
"meta": map[string]int64{
"total_count": resTotal,
"page_count": pageCount,
"current_page": int64(req.CurrentPage),
"per_page": int64(req.PageSize),
},
})
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理

View 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 GetMenusTreeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetMenusTreeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenusTreeLogic {
return &GetMenusTreeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *GetMenusTreeLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *GetMenusTreeLogic) GetMenusTree(req *types.GetMenusTreeReq, 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 *GetMenusTreeLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@@ -5,6 +5,57 @@ import (
"fusenapi/utils/basic"
)
type EditMenuHandler 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"`
Status int64 `json:"status"`
ParentId int64 `json:"parent_id"`
Creator string `json:"creator"`
}
type AddMenuHandler struct {
Name string `json:"name"`
Title string `json:"title"`
Icon string `json:"icon"`
Path string `json:"path"`
Sort int64 `json:"sort"`
Status int64 `json:"status"`
ParentId int64 `json:"parent_id"`
Creator string `json:"creator"`
}
type GetMenusTreeReq struct {
}
type AddDepartmentReq struct {
Name string `json:"name"`
Remark string `json:"remark"`
Creator string `json:"creator"`
Type string `json:"type"`
ParentId int64 `json:"parent_id"`
Dn string `json:"dn"`
SyncState int64 `json:"sync_state"`
}
type EditDepartmentReq struct {
Id int64 `json:"id"`
Name string `json:"name"`
Remark string `json:"remark"`
Creator string `json:"creator"`
Type string `json:"type"`
ParentId int64 `json:"parent_id"`
Dn string `json:"dn"`
SyncState int64 `json:"sync_state"`
}
type DeleteDepartmentReq struct {
Id int64 `json:"id"`
}
type GetDepartmentsReq struct {
CurrentPage int `form:"current_page"`
PageSize int `form:"page_size"`