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) {
// }
type mapDnItem struct {
EntryAttribute []*ldap.EntryAttribute `json:"entry_attribute"`
DN string `json:"dn"`
Sort int `json:"sort"`
Child []*mapDnItem `json:"child"`
Attribute map[string]interface{} `json:"attribute"`
DN string `json:"dn"`
Sort int `json:"sort"`
Child []*mapDnItem `json:"child"`
}
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
for _, v := range searchResult.Entries {
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{
DN: v.DN,
EntryAttribute: v.Attributes,
Sort: sortNum,
Child: make([]*mapDnItem, 0, 100),
DN: v.DN,
Attribute: attribute,
Sort: sortNum,
Child: make([]*mapDnItem, 0, 100),
}
}
//组织层级关系