This commit is contained in:
laodaming 2023-11-15 11:49:00 +08:00
parent 3ef91f9b93
commit 99e7ce25de

View File

@ -33,10 +33,10 @@ func NewGetDepartmentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
// func (l *GetDepartmentsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // func (l *GetDepartmentsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// } // }
type mapDnItem struct { type mapDnItem struct {
EntryAttribute []*ldap.EntryAttribute `json:"entry_attribute"` Attribute map[string]interface{} `json:"attribute"`
DN string `json:"dn"` DN string `json:"dn"`
Sort int `json:"sort"` Sort int `json:"sort"`
Child []*mapDnItem `json:"child"` Child []*mapDnItem `json:"child"`
} }
func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
@ -59,11 +59,23 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.
sortNum := 0 sortNum := 0
for _, v := range searchResult.Entries { for _, v := range searchResult.Entries {
sortNum++ sortNum++
attribute := make(map[string]interface{})
for _, attr := range v.Attributes {
if attr.Name == "objectClass" {
mapObjectClass := make(map[string]struct{})
for _, objectClassItem := range attr.Values {
mapObjectClass[objectClassItem] = struct{}{}
}
attribute[attr.Name] = mapObjectClass
} else {
attribute[attr.Name] = strings.Join(attr.Values, ",")
}
}
mapDN[v.DN] = &mapDnItem{ mapDN[v.DN] = &mapDnItem{
DN: v.DN, DN: v.DN,
EntryAttribute: v.Attributes, Attribute: attribute,
Sort: sortNum, Sort: sortNum,
Child: make([]*mapDnItem, 0, 100), Child: make([]*mapDnItem, 0, 100),
} }
} }
//组织层级关系 //组织层级关系