增加添加部门接口

This commit is contained in:
laodaming 2023-11-16 14:15:45 +08:00
parent def6990eba
commit 6fb16aa12c
5 changed files with 19 additions and 59 deletions

View File

@ -11,7 +11,7 @@ import (
"fusenapi/server/ldap-admin/internal/types"
)
func GetDepartmentsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
func GetOrganizationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
@ -21,12 +21,12 @@ func GetDepartmentsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
// 创建一个业务逻辑层实例
l := logic.NewGetDepartmentsLogic(r.Context(), svcCtx)
l := logic.NewGetOrganizationsLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.GetDepartments(&req, userinfo)
resp := l.GetOrganizations(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)

View File

@ -44,8 +44,8 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodGet,
Path: "/api/ldap-admin/get_departments",
Handler: GetDepartmentsHandler(serverCtx),
Path: "/api/ldap-admin/get_organizations",
Handler: GetOrganizationsHandler(serverCtx),
},
{
Method: http.MethodPost,

View File

@ -1,27 +1,28 @@
package logic
import (
"context"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/ldap_lib"
"sort"
"strings"
"context"
"fusenapi/server/ldap-admin/internal/svc"
"fusenapi/server/ldap-admin/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetDepartmentsLogic struct {
type GetOrganizationsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetDepartmentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDepartmentsLogic {
return &GetDepartmentsLogic{
func NewGetOrganizationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrganizationsLogic {
return &GetOrganizationsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
@ -29,7 +30,7 @@ func NewGetDepartmentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
}
// 处理进入前逻辑w,r
// func (l *GetDepartmentsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// func (l *GetOrganizationsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
type DNItem struct {
Attribute map[string]interface{} `json:"attribute"`
@ -39,7 +40,7 @@ type DNItem struct {
Child []*DNItem `json:"child"`
}
func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
func (l *GetOrganizationsLogic) GetOrganizations(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
//从ldap获取组织架构数据
rootCn := strings.Split(l.svcCtx.Config.Ldap.RootDN, ",")
if len(rootCn) == 0 {
@ -112,3 +113,8 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.
}
return resp.SetStatusWithMessage(basic.CodeOK, "", list)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *GetOrganizationsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -19,30 +19,6 @@ type SaveApiReq struct {
Remark string `json:"remark"`
}
type GetDepartmentsRsp struct {
List []*DepartmentsItem `json:"list"`
}
type DepartmentsItem struct {
Id int64 `json:"id"`
Name string `json:"name"`
Remark string `json:"remark"`
Type string `json:"type"`
ParentId int64 `json:"parent_id"`
Dn string `json:"dn"`
SyncState int64 `json:"sync_state"`
Sort int64 `json:"sort"`
Child []*DepartmentsItem `json:"child"`
Members []Member `json:"members"`
}
type Member struct {
Id int64 `json:"id"`
Name string `json:"name"`
Nickname string `json:"nickname"`
Email string `json:"email"`
}
type SaveMenuReq struct {
Id int64 `json:"id"`
Name string `json:"name"`

View File

@ -31,8 +31,8 @@ service ldap-admin {
@handler GetMenusHandler
get /api/ldap-admin/get_menus(GetMenusReq) returns (response);
//获取ldap组织列表
@handler GetDepartmentsHandler
get /api/ldap-admin/get_departments(request) returns (response);
@handler GetOrganizationsHandler
get /api/ldap-admin/get_organizations(request) returns (response);
//增加ldap组织
@handler CreateLdapOrganizationHandler
post /api/ldap-admin/create_ldap_orgination(CreateLdapOrganizationReq) returns (response);
@ -58,28 +58,6 @@ type SaveApiReq {
Remark string `json:"remark"`
}
//获取部门列表
type GetDepartmentsRsp {
List []*DepartmentsItem `json:"list"`
}
type DepartmentsItem {
Id int64 `json:"id"`
Name string `json:"name"`
Remark string `json:"remark"`
Type string `json:"type"`
ParentId int64 `json:"parent_id"`
Dn string `json:"dn"`
SyncState int64 `json:"sync_state"`
Sort int64 `json:"sort"`
Child []*DepartmentsItem `json:"child"`
Members []Member `json:"members"`
}
type Member {
Id int64 `json:"id"`
Name string `json:"name"`
Nickname string `json:"nickname"`
Email string `json:"email"`
}
//保存菜单
type SaveMenuReq {
Id int64 `json:"id"`