增加添加部门接口
This commit is contained in:
parent
def6990eba
commit
6fb16aa12c
|
@ -11,7 +11,7 @@ import (
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
"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) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var req types.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)
|
rl := reflect.ValueOf(l)
|
||||||
basic.BeforeLogic(w, r, rl)
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
resp := l.GetDepartments(&req, userinfo)
|
resp := l.GetOrganizations(&req, userinfo)
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
basic.NormalAfterLogic(w, r, resp)
|
|
@ -44,8 +44,8 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/api/ldap-admin/get_departments",
|
Path: "/api/ldap-admin/get_organizations",
|
||||||
Handler: GetDepartmentsHandler(serverCtx),
|
Handler: GetOrganizationsHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
|
|
|
@ -1,27 +1,28 @@
|
||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/ldap_lib"
|
"fusenapi/utils/ldap_lib"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
"fusenapi/server/ldap-admin/internal/svc"
|
"fusenapi/server/ldap-admin/internal/svc"
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
"fusenapi/server/ldap-admin/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetDepartmentsLogic struct {
|
type GetOrganizationsLogic struct {
|
||||||
logx.Logger
|
logx.Logger
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGetDepartmentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDepartmentsLogic {
|
func NewGetOrganizationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrganizationsLogic {
|
||||||
return &GetDepartmentsLogic{
|
return &GetOrganizationsLogic{
|
||||||
Logger: logx.WithContext(ctx),
|
Logger: logx.WithContext(ctx),
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
svcCtx: svcCtx,
|
svcCtx: svcCtx,
|
||||||
|
@ -29,7 +30,7 @@ func NewGetDepartmentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理进入前逻辑w,r
|
// 处理进入前逻辑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 {
|
type DNItem struct {
|
||||||
Attribute map[string]interface{} `json:"attribute"`
|
Attribute map[string]interface{} `json:"attribute"`
|
||||||
|
@ -39,7 +40,7 @@ type DNItem struct {
|
||||||
Child []*DNItem `json:"child"`
|
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获取组织架构数据
|
//从ldap获取组织架构数据
|
||||||
rootCn := strings.Split(l.svcCtx.Config.Ldap.RootDN, ",")
|
rootCn := strings.Split(l.svcCtx.Config.Ldap.RootDN, ",")
|
||||||
if len(rootCn) == 0 {
|
if len(rootCn) == 0 {
|
||||||
|
@ -112,3 +113,8 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "", list)
|
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)
|
||||||
|
// }
|
|
@ -19,30 +19,6 @@ type SaveApiReq struct {
|
||||||
Remark string `json:"remark"`
|
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 {
|
type SaveMenuReq struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
|
@ -31,8 +31,8 @@ service ldap-admin {
|
||||||
@handler GetMenusHandler
|
@handler GetMenusHandler
|
||||||
get /api/ldap-admin/get_menus(GetMenusReq) returns (response);
|
get /api/ldap-admin/get_menus(GetMenusReq) returns (response);
|
||||||
//获取ldap组织列表
|
//获取ldap组织列表
|
||||||
@handler GetDepartmentsHandler
|
@handler GetOrganizationsHandler
|
||||||
get /api/ldap-admin/get_departments(request) returns (response);
|
get /api/ldap-admin/get_organizations(request) returns (response);
|
||||||
//增加ldap组织
|
//增加ldap组织
|
||||||
@handler CreateLdapOrganizationHandler
|
@handler CreateLdapOrganizationHandler
|
||||||
post /api/ldap-admin/create_ldap_orgination(CreateLdapOrganizationReq) returns (response);
|
post /api/ldap-admin/create_ldap_orgination(CreateLdapOrganizationReq) returns (response);
|
||||||
|
@ -58,28 +58,6 @@ type SaveApiReq {
|
||||||
Remark string `json:"remark"`
|
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 {
|
type SaveMenuReq {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user