From f97d4d9c6d0e75852c006a7f2954311950a56821 Mon Sep 17 00:00:00 2001
From: eson <9673575+githubcontent@user.noreply.gitee.com>
Date: Fri, 24 Nov 2023 10:17:10 +0800
Subject: [PATCH 1/5] =?UTF-8?q?=E6=B5=8B=E8=AF=95=20email=E6=9B=B4?=
 =?UTF-8?q?=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 model/gmodel/fs_user_info_logic.go                    | 3 +--
 server/info/internal/handler/usergetprofilehandler.go | 3 ---
 server/info/internal/logic/usergetprofilelogic.go     | 2 --
 server_api/info.api                                   | 2 +-
 4 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/model/gmodel/fs_user_info_logic.go b/model/gmodel/fs_user_info_logic.go
index 435e6b99..b94c561a 100644
--- a/model/gmodel/fs_user_info_logic.go
+++ b/model/gmodel/fs_user_info_logic.go
@@ -8,7 +8,6 @@ import (
 	"fmt"
 	"fusenapi/utils/fssql"
 	"fusenapi/utils/handlers"
-	"log"
 
 	"gorm.io/gorm"
 )
@@ -101,7 +100,7 @@ func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId in
 	if !ok {
 		return m.getDefaultProfile(ctx, tname)
 	}
-	log.Println(v, guestId, userId)
+
 	var info map[string]any
 	err = json.Unmarshal([]byte(v), &info)
 	if err != nil {
diff --git a/server/info/internal/handler/usergetprofilehandler.go b/server/info/internal/handler/usergetprofilehandler.go
index 1426f663..28dafeca 100644
--- a/server/info/internal/handler/usergetprofilehandler.go
+++ b/server/info/internal/handler/usergetprofilehandler.go
@@ -1,7 +1,6 @@
 package handler
 
 import (
-	"log"
 	"net/http"
 	"reflect"
 
@@ -21,8 +20,6 @@ func UserGetProfileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 			return
 		}
 
-		log.Println(userinfo)
-
 		// 创建一个业务逻辑层实例
 		l := logic.NewUserGetProfileLogic(r.Context(), svcCtx)
 
diff --git a/server/info/internal/logic/usergetprofilelogic.go b/server/info/internal/logic/usergetprofilelogic.go
index ee0119bc..b94f5caa 100644
--- a/server/info/internal/logic/usergetprofilelogic.go
+++ b/server/info/internal/logic/usergetprofilelogic.go
@@ -3,7 +3,6 @@ package logic
 import (
 	"fusenapi/utils/auth"
 	"fusenapi/utils/basic"
-	"log"
 
 	"context"
 
@@ -35,7 +34,6 @@ func (l *UserGetProfileLogic) UserGetProfile(req *types.QueryProfileRequest, use
 	// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
 	// userinfo 传入值时, 一定不为null
 
-	log.Println(userinfo)
 	profileBase, err := l.svcCtx.AllModels.FsUserInfo.GetProfile(l.ctx, req.TopKey, userinfo.UserId, userinfo.GuestId)
 	if err != nil {
 		return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
diff --git a/server_api/info.api b/server_api/info.api
index b1e72d37..8e7b2b33 100644
--- a/server_api/info.api
+++ b/server_api/info.api
@@ -112,7 +112,7 @@ type (
 		FirstName *string `json:"first_name,optional"` // 首名
 		LastName  *string `json:"last_name,optional"`  // 后名
 		// UserName    *string `json:"user_name,optional"`   // 用户名
-		Email       *string `json:"email,optional"`       // email
+		Email       *string `json:"email,optional,omitempty"`       // email
 		Mobile      *string `json:"mobile,optional"`      // 电话
 		Resetaurant *string `json:"resetaurant,optional"` // 不知道干什么
 		Company     *string `json:"company,optional"`     // 公司

From 47aefb5e001fb59f63cc9e0a8c6bee78bd35d576 Mon Sep 17 00:00:00 2001
From: eson <9673575+githubcontent@user.noreply.gitee.com>
Date: Fri, 24 Nov 2023 10:25:43 +0800
Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=BA=E5=88=B6?=
 =?UTF-8?q?=E7=BB=99=E8=A1=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 server/info/internal/logic/usergetprofilelogic.go | 8 ++++++++
 server_api/info.api                               | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/server/info/internal/logic/usergetprofilelogic.go b/server/info/internal/logic/usergetprofilelogic.go
index b94f5caa..15f840ac 100644
--- a/server/info/internal/logic/usergetprofilelogic.go
+++ b/server/info/internal/logic/usergetprofilelogic.go
@@ -39,6 +39,14 @@ func (l *UserGetProfileLogic) UserGetProfile(req *types.QueryProfileRequest, use
 		return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
 	}
 
+	user, err := l.svcCtx.AllModels.FsUser.FindUserById(context.TODO(), userinfo.UserId)
+	if err != nil {
+		logx.Error(err)                                // 日志记录错误
+		return resp.SetStatus(basic.CodeDbSqlErr, err) // 返回数据库创建错误
+	}
+
+	profileBase["email"] = *user.Email
+
 	return resp.SetStatus(basic.CodeOK, profileBase)
 }
 
diff --git a/server_api/info.api b/server_api/info.api
index 8e7b2b33..b1e72d37 100644
--- a/server_api/info.api
+++ b/server_api/info.api
@@ -112,7 +112,7 @@ type (
 		FirstName *string `json:"first_name,optional"` // 首名
 		LastName  *string `json:"last_name,optional"`  // 后名
 		// UserName    *string `json:"user_name,optional"`   // 用户名
-		Email       *string `json:"email,optional,omitempty"`       // email
+		Email       *string `json:"email,optional"`       // email
 		Mobile      *string `json:"mobile,optional"`      // 电话
 		Resetaurant *string `json:"resetaurant,optional"` // 不知道干什么
 		Company     *string `json:"company,optional"`     // 公司

From 9ffd7226f90b2e2f7f308eeab19bb8c00fe05add Mon Sep 17 00:00:00 2001
From: eson <9673575+githubcontent@user.noreply.gitee.com>
Date: Fri, 24 Nov 2023 10:38:05 +0800
Subject: [PATCH 3/5] =?UTF-8?q?=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 server/info/internal/logic/usergetprofilelogic.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/server/info/internal/logic/usergetprofilelogic.go b/server/info/internal/logic/usergetprofilelogic.go
index 15f840ac..be80d866 100644
--- a/server/info/internal/logic/usergetprofilelogic.go
+++ b/server/info/internal/logic/usergetprofilelogic.go
@@ -45,7 +45,9 @@ func (l *UserGetProfileLogic) UserGetProfile(req *types.QueryProfileRequest, use
 		return resp.SetStatus(basic.CodeDbSqlErr, err) // 返回数据库创建错误
 	}
 
-	profileBase["email"] = *user.Email
+	if bmap, ok := profileBase["base"].(map[string]any); ok {
+		bmap["email"] = *user.Email
+	}
 
 	return resp.SetStatus(basic.CodeOK, profileBase)
 }

From 82db686b05c222cee8ecb6b2d344aead261c20a4 Mon Sep 17 00:00:00 2001
From: laodaming <11058467+laudamine@user.noreply.gitee.com>
Date: Fri, 24 Nov 2023 10:52:54 +0800
Subject: [PATCH 4/5] fix

---
 .../logic/createldaporganizationlogic.go      |  2 +-
 .../logic/getldaporganizationslogic.go        | 36 ++++++++++---------
 2 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/server/ldap-admin/internal/logic/createldaporganizationlogic.go b/server/ldap-admin/internal/logic/createldaporganizationlogic.go
index c797bd09..c662e47f 100644
--- a/server/ldap-admin/internal/logic/createldaporganizationlogic.go
+++ b/server/ldap-admin/internal/logic/createldaporganizationlogic.go
@@ -48,7 +48,7 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd
 		return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织英文名不能包含中文")
 	}
 	if req.ParentOrganizationDN == "" {
-		return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,父级DN不能为空")
+		req.ParentOrganizationDN = l.svcCtx.Config.Ldap.BaseDN //不传则是第一层级
 	}
 	if req.BusinessCategory == "" {
 		return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,组织分类名不能为空")
diff --git a/server/ldap-admin/internal/logic/getldaporganizationslogic.go b/server/ldap-admin/internal/logic/getldaporganizationslogic.go
index 24aef6d6..1706a018 100644
--- a/server/ldap-admin/internal/logic/getldaporganizationslogic.go
+++ b/server/ldap-admin/internal/logic/getldaporganizationslogic.go
@@ -33,12 +33,13 @@ func NewGetLdapOrganizationsLogic(ctx context.Context, svcCtx *svc.ServiceContex
 // func (l *GetLdapOrganizationsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
 // }
 type DNItem struct {
-	Attribute map[string]interface{} `json:"attribute"`
-	HasMember bool                   `json:"has_member"` //是否有成员
-	DN        string                 `json:"dn"`
-	ParentDN  string                 `json:"parent_dn"`
-	Sort      int                    `json:"sort"`
-	Child     []*DNItem              `json:"child"`
+	Attribute   map[string]interface{} `json:"attribute"`
+	MemberCount int                    `json:"member_count"`
+	Level       int                    `json:"level"`
+	DN          string                 `json:"dn"`
+	ParentDN    string                 `json:"parent_dn"`
+	Sort        int                    `json:"sort"`
+	Child       []*DNItem              `json:"child"`
 }
 
 func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r *http.Request) (resp *basic.Response) {
@@ -55,7 +56,7 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r *
 	if len(peopleDNSlice) <= 1 {
 		return resp.SetStatusWithMessage(basic.CodeServiceErr, "基础用户组的DN未配置")
 	}
-	filter := "(|(&(objectClass=groupOfUniqueNames)(objectClass=top))(objectClass=organization))"
+	filter := "(&(objectClass=groupOfUniqueNames)(objectClass=top))"
 	fields := []string{"businessCategory", "dn", "uniqueMember"}
 	searchResult, err := l.svcCtx.Ldap.Search(l.svcCtx.Config.Ldap.BaseDN, ldap.ScopeWholeSubtree, filter, fields, nil)
 	if err != nil {
@@ -67,22 +68,25 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r *
 	for _, v := range searchResult.Entries {
 		sortNum++
 		attribute := make(map[string]interface{})
-		hasMember := false
+		memberCount := 0
 		for _, attr := range v.Attributes {
 			//判断是否有成员(不包含root用户所以判断大于1)
-			if attr.Name == "uniqueMember" && len(attr.Values) > 1 {
-				hasMember = true
+			if attr.Name == "uniqueMember" {
+				memberCount = len(attr.Values) - 1 //不要包含原始用户
 				continue
 			}
 			attribute[attr.Name] = strings.Join(attr.Values, ",")
 		}
+		dnSlice := strings.ReplaceAll(v.DN, ","+l.svcCtx.Config.Ldap.BaseDN, "") //把最顶级的组织去掉
+		level := len(strings.Split(dnSlice, ","))
 		mapDN[v.DN] = &DNItem{
-			DN:        v.DN,
-			ParentDN:  "",
-			HasMember: hasMember,
-			Attribute: attribute,
-			Sort:      sortNum,
-			Child:     make([]*DNItem, 0, 100),
+			DN:          v.DN,
+			ParentDN:    "",
+			Level:       level,
+			MemberCount: memberCount,
+			Attribute:   attribute,
+			Sort:        sortNum,
+			Child:       make([]*DNItem, 0, 100),
 		}
 	}
 	//组织树形层级关系

From 18d0c3d55c642bea578cd41269c763801bd071d5 Mon Sep 17 00:00:00 2001
From: laodaming <11058467+laudamine@user.noreply.gitee.com>
Date: Fri, 24 Nov 2023 10:55:37 +0800
Subject: [PATCH 5/5] fix

---
 server/ldap-admin/internal/logic/getldaporganizationslogic.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/ldap-admin/internal/logic/getldaporganizationslogic.go b/server/ldap-admin/internal/logic/getldaporganizationslogic.go
index 1706a018..80da8855 100644
--- a/server/ldap-admin/internal/logic/getldaporganizationslogic.go
+++ b/server/ldap-admin/internal/logic/getldaporganizationslogic.go
@@ -72,7 +72,7 @@ func (l *GetLdapOrganizationsLogic) GetLdapOrganizations(req *types.Request, r *
 		for _, attr := range v.Attributes {
 			//判断是否有成员(不包含root用户所以判断大于1)
 			if attr.Name == "uniqueMember" {
-				memberCount = len(attr.Values) - 1 //不要包含原始用户
+				memberCount = len(attr.Values)
 				continue
 			}
 			attribute[attr.Name] = strings.Join(attr.Values, ",")