From 1bb2e190a2b71037d74e27f83d26dcaa8e1395dd Mon Sep 17 00:00:00 2001
From: laodaming <11058467+laudamine@user.noreply.gitee.com>
Date: Mon, 27 Nov 2023 11:18:47 +0800
Subject: [PATCH 01/10] fix

---
 model/gmodel/fs_product_template_v2_logic.go  | 16 ++++++++++++
 .../internal/logic/getproductmodelslogic.go   | 25 +++++++++++++++++--
 server/product/internal/types/types.go        |  3 ++-
 server_api/product.api                        |  3 ++-
 4 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go
index 46e73745..5506950f 100755
--- a/model/gmodel/fs_product_template_v2_logic.go
+++ b/model/gmodel/fs_product_template_v2_logic.go
@@ -185,6 +185,22 @@ func (t *FsProductTemplateV2Model) FindAllByProductIdsTemplateTag(ctx context.Co
 	err = db.Find(&resp).Error
 	return resp, err
 }
+
+// 获取开启云渲染的模板列表
+func (t *FsProductTemplateV2Model) FindAllCloudRenderTemplateByProductIdsTemplateTag(ctx context.Context, productIds []int64, templateTag string, sort string, fields ...string) (resp []FsProductTemplateV2, err error) {
+	if len(productIds) == 0 {
+		return
+	}
+	db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`product_id` in (?) and `template_tag` = ? and `is_del` = ? and `status` = ? and `element_model_id` > ? ", productIds, templateTag, 0, 1, 0)
+	if sort != "" {
+		db = db.Order(sort)
+	}
+	if len(fields) != 0 {
+		db = db.Select(fields[0])
+	}
+	err = db.Find(&resp).Error
+	return resp, err
+}
 func (t *FsProductTemplateV2Model) FindAllByFittingIds(ctx context.Context, fittingIds []int64, fields ...string) (resp []FsProductTemplateV2, err error) {
 	db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in(?) and `status` = ? and `is_del` = ?  ", fittingIds, 1, 0)
 	if len(fields) != 0 {
diff --git a/server/product/internal/logic/getproductmodelslogic.go b/server/product/internal/logic/getproductmodelslogic.go
index 9c6ef437..eca954e3 100644
--- a/server/product/internal/logic/getproductmodelslogic.go
+++ b/server/product/internal/logic/getproductmodelslogic.go
@@ -57,12 +57,33 @@ func (l *GetProductModelsLogic) GetProductModels(req *types.GetProductModelsReq,
 	if len(productList) != len(productIds) {
 		return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "some one product is invalid")
 	}
-	//获取产品所有的模型以及配件
-	modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS})
+	//根据模板标签获取开启了云渲染的模板列表
+	templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllCloudRenderTemplateByProductIdsTemplateTag(l.ctx, productIds, req.TemplateTag, "", "id,product_id,model_id")
+	if err != nil {
+		logx.Error(err)
+		return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product template list")
+	}
+	modelIds := make([]int64, 0, len(templateList))
+	for _, v := range templateList {
+		modelIds = append(modelIds, *v.ModelId)
+	}
+	//获取模型列表
+	modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIds(l.ctx, modelIds, "")
 	if err != nil {
 		logx.Error(err)
 		return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list")
 	}
+	partIds := make([]int64, 0, len(modelList))
+	for _, v := range modelList {
+		if *v.PartId == 0 {
+			continue
+		}
+		partIds = append(partIds, *v.PartId)
+	}
+	//获取配件列表
+	partList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIds(l.ctx, partIds, "")
+	//合并模型和配件
+	modelList = append(modelList, partList...)
 	mapProductModels := make(map[int64][]types.ModelItem)
 	lightIds := make([]int64, 0, len(modelList))
 	for _, v := range modelList {
diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go
index 8a87d03e..ce203d35 100644
--- a/server/product/internal/types/types.go
+++ b/server/product/internal/types/types.go
@@ -172,7 +172,8 @@ type TemplateTagColorInfo struct {
 }
 
 type GetProductModelsReq struct {
-	ProductIds string `form:"product_ids"`
+	ProductIds  string `form:"product_ids"`
+	TemplateTag string `form:"template_tag"`
 }
 
 type ProductItem struct {
diff --git a/server_api/product.api b/server_api/product.api
index 49858ec6..0d5955c9 100644
--- a/server_api/product.api
+++ b/server_api/product.api
@@ -190,7 +190,8 @@ type TemplateTagColorInfo {
 }
 //根据产品获取模型配件列表
 type GetProductModelsReq {
-	ProductIds string `form:"product_ids"`
+	ProductIds  string `form:"product_ids"`
+	TemplateTag string `form:"template_tag"`
 }
 type ProductItem {
 	ModelList []ModelItem `json:"model_list"`

From cbe4e8503d010c15a3129c4d75f04d35ddb662c4 Mon Sep 17 00:00:00 2001
From: laodaming <11058467+laudamine@user.noreply.gitee.com>
Date: Mon, 27 Nov 2023 11:35:47 +0800
Subject: [PATCH 02/10] fix

---
 .../websocket/internal/logic/ws_render_image.go  | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go
index 24aae79e..941f978a 100644
--- a/server/websocket/internal/logic/ws_render_image.go
+++ b/server/websocket/internal/logic/ws_render_image.go
@@ -168,22 +168,6 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
 		w.renderErrResponse(renderImageData.RequestId, renderImageData.RenderData.TemplateTag, "", "选择的模板标签颜色索引越界", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
 		return
 	}
-	//获取产品信息(部分字段)
-	productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId, "id,is_customization")
-	if err != nil {
-		if errors.Is(err, gorm.ErrRecordNotFound) {
-			w.renderErrResponse(renderImageData.RequestId, renderImageData.RenderData.TemplateTag, "", "该产品不存在", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
-			return
-		}
-		w.renderErrResponse(renderImageData.RequestId, renderImageData.RenderData.TemplateTag, "", "获取产品失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
-		logx.Error(err)
-		return
-	}
-	//不可定制
-	if *productInfo.IsCustomization == 0 {
-		w.renderErrResponse(renderImageData.RequestId, renderImageData.RenderData.TemplateTag, "", "该产品不可定制", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
-		return
-	}
 	//获取信息
 	productSize, productTemplate, model3dInfo, switchInfo, err := w.getProductRelationInfo(&renderImageData)
 	if err != nil {

From 209073d08a7fee4662776bae7c07c4cbc68e0014 Mon Sep 17 00:00:00 2001
From: laodaming <11058467+laudamine@user.noreply.gitee.com>
Date: Mon, 27 Nov 2023 11:40:44 +0800
Subject: [PATCH 03/10] fix

---
 server/websocket/internal/logic/ws_render_image.go | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go
index 941f978a..fa42df78 100644
--- a/server/websocket/internal/logic/ws_render_image.go
+++ b/server/websocket/internal/logic/ws_render_image.go
@@ -140,6 +140,11 @@ func (w *wsConnectItem) consumeRenderImageData() {
 
 // 执行渲染任务
 func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageReqMsg) {
+	defer func() {
+		if err := recover(); err != nil {
+			logx.Error("render image panic!!!!!!")
+		}
+	}()
 	if renderImageData.RenderData.Logo == "" {
 		w.renderErrResponse(renderImageData.RequestId, renderImageData.RenderData.TemplateTag, "", "请传入logo", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
 		return

From 6f1ced3bf881d988006b8bca1455e57748586cd4 Mon Sep 17 00:00:00 2001
From: laodaming <11058467+laudamine@user.noreply.gitee.com>
Date: Mon, 27 Nov 2023 11:46:04 +0800
Subject: [PATCH 04/10] fix

---
 .../websocket/internal/logic/ws_render_image.go | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go
index fa42df78..87902472 100644
--- a/server/websocket/internal/logic/ws_render_image.go
+++ b/server/websocket/internal/logic/ws_render_image.go
@@ -281,15 +281,8 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
 	taskId := w.genRenderTaskId(combineImage, renderImageData, model3dInfo, productTemplate, element)
 	//查询有没有缓存的资源,有就返回
 	resource, err := w.logic.svcCtx.AllModels.FsResource.FindOneById(w.logic.ctx, taskId)
-	if err != nil {
-		if !errors.Is(err, gorm.ErrRecordNotFound) {
-			w.renderErrResponse(renderImageData.RequestId, renderImageData.RenderData.TemplateTag, taskId, "获取unity云渲染缓存失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
-			logx.Error("failed to find render resource:", err)
-			return
-		}
-		//无缓存
-		logx.Info("无缓存的渲染图,需要unity")
-	} else { //有缓存
+	switch err {
+	case nil: //有缓存
 		//如果没有debug或者debug模式下开启了缓存则返回缓存
 		if w.debug == nil || w.debug.IsCache == 1 {
 			//返回给客户端
@@ -305,6 +298,12 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
 			return
 		}
 		//否则继续去unity
+	default: //无缓存
+		if !errors.Is(err, gorm.ErrRecordNotFound) {
+			w.renderErrResponse(renderImageData.RequestId, renderImageData.RenderData.TemplateTag, taskId, "获取unity云渲染缓存失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
+			logx.Error("failed to find render resource:", err)
+			return
+		}
 	}
 	//组装数据
 	if err = w.assembleRenderDataToUnity(taskId, resolution, combineImage, renderImageData, productTemplate, model3dInfo, element, productSize); err != nil {

From 4eb435e1d1397dd03489f460187d72cebcc27d81 Mon Sep 17 00:00:00 2001
From: laodaming <11058467+laudamine@user.noreply.gitee.com>
Date: Mon, 27 Nov 2023 12:01:06 +0800
Subject: [PATCH 05/10] fix

---
 server_api/product.api | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server_api/product.api b/server_api/product.api
index 0d5955c9..4a1590a1 100644
--- a/server_api/product.api
+++ b/server_api/product.api
@@ -191,7 +191,7 @@ type TemplateTagColorInfo {
 //根据产品获取模型配件列表
 type GetProductModelsReq {
 	ProductIds  string `form:"product_ids"`
-	TemplateTag string `form:"template_tag"`
+	TemplateTag string `form:"template_tag,optional"`
 }
 type ProductItem {
 	ModelList []ModelItem `json:"model_list"`

From 20a84e48997f6d49b6e3fdebcf49202e552be8f2 Mon Sep 17 00:00:00 2001
From: laodaming <11058467+laudamine@user.noreply.gitee.com>
Date: Mon, 27 Nov 2023 12:02:33 +0800
Subject: [PATCH 06/10] fix

---
 server/product/internal/types/types.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go
index ce203d35..98d6ed74 100644
--- a/server/product/internal/types/types.go
+++ b/server/product/internal/types/types.go
@@ -173,7 +173,7 @@ type TemplateTagColorInfo struct {
 
 type GetProductModelsReq struct {
 	ProductIds  string `form:"product_ids"`
-	TemplateTag string `form:"template_tag"`
+	TemplateTag string `form:"template_tag,optional"`
 }
 
 type ProductItem struct {

From 6585fecc6a77f405603395cf4daf0987ff74fa46 Mon Sep 17 00:00:00 2001
From: laodaming <11058467+laudamine@user.noreply.gitee.com>
Date: Mon, 27 Nov 2023 12:31:53 +0800
Subject: [PATCH 07/10] fix

---
 .../internal/logic/createldapuserlogic.go     | 12 ++--
 server/ldap-admin/internal/types/types.go     | 19 ++---
 server_api/ldap-admin.api                     | 19 ++---
 utils/ldap_lib/ldap_user.go                   | 71 ++++++++++++++++---
 4 files changed, 84 insertions(+), 37 deletions(-)

diff --git a/server/ldap-admin/internal/logic/createldapuserlogic.go b/server/ldap-admin/internal/logic/createldapuserlogic.go
index fecbfdd8..285477de 100644
--- a/server/ldap-admin/internal/logic/createldapuserlogic.go
+++ b/server/ldap-admin/internal/logic/createldapuserlogic.go
@@ -88,7 +88,10 @@ func (l *CreateLdapUserLogic) CreateLdapUser(req *types.CreateLdapUserReq, r *ht
 		"mail":             {req.Email},                           //邮箱
 		"postalCode":       {fmt.Sprintf("%d", req.Status)},       //状态
 		"roomNumber":       {fmt.Sprintf("%d", req.GroupId)},      //权限分组id
-		"departmentNumber": req.OrganizationDNList,                //所属组织部门
+		"departmentNumber": {""},                                  //所属组织部门
+		"telexNumber":      {""},                                  //管理的部门
+		"st":               {fmt.Sprintf("%d", req.Gender)},       //性别
+		"title":            {req.Birthday},                        //生日
 		"postalAddress":    {req.Avatar},                          //头像
 		"mobile":           {req.Mobile},                          //手机号
 		"userPassword":     {req.Password},                        //密码
@@ -97,13 +100,6 @@ func (l *CreateLdapUserLogic) CreateLdapUser(req *types.CreateLdapUserReq, r *ht
 		logx.Error(err)
 		return resp.SetStatusWithMessage(basic.CodeServiceErr, "添加用户失败,"+err.Error())
 	}
-	//将用户加入这些部门
-	for _, v := range req.OrganizationDNList {
-		if err = l.svcCtx.Ldap.AddUserToOrganization(v, userDN); err != nil {
-			logx.Error("加入部门失败:", err)
-			continue
-		}
-	}
 	return resp.SetStatusWithMessage(basic.CodeOK, "添加用户成功")
 }
 
diff --git a/server/ldap-admin/internal/types/types.go b/server/ldap-admin/internal/types/types.go
index 55c589df..e5a6c8c3 100644
--- a/server/ldap-admin/internal/types/types.go
+++ b/server/ldap-admin/internal/types/types.go
@@ -143,15 +143,16 @@ type UpdateLdapOrganizationReq struct {
 }
 
 type CreateLdapUserReq struct {
-	UserName           string   `json:"user_name"`                   //用户名
-	Email              string   `json:"email"`                       //邮箱
-	Password           string   `json:"password"`                    //密码
-	Mobile             string   `json:"mobile"`                      //手机号
-	Avatar             string   `json:"avatar"`                      //头像地址
-	EmployeeType       int64    `json:"employee_type,options=1|2|3"` //1正式 2实习 3外包
-	GroupId            int64    `json:"group_id,optional"`           //授权分组id
-	OrganizationDNList []string `json:"organization_dn_list"`        //属于哪些部门
-	Status             int64    `json:"status,options=0|1"`          //状态 1正常0离职
+	UserName     string `json:"user_name"`                   //用户名
+	Email        string `json:"email"`                       //邮箱
+	Password     string `json:"password"`                    //密码
+	Mobile       string `json:"mobile"`                      //手机号
+	Avatar       string `json:"avatar"`                      //头像地址
+	EmployeeType int64  `json:"employee_type,options=1|2|3"` //1正式 2实习 3外包
+	GroupId      int64  `json:"group_id,optional"`           //授权分组id
+	Gender       int64  `json:"gender,options=1|2|3"`        //性别 1男 2女 3未知
+	Birthday     string `json:"birthday"`                    //生日
+	Status       int64  `json:"status,options=0|1"`          //状态 1正常0离职
 }
 
 type UpdateLdapUserReq struct {
diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api
index 93be5c6e..48f9601c 100644
--- a/server_api/ldap-admin.api
+++ b/server_api/ldap-admin.api
@@ -227,15 +227,16 @@ type UpdateLdapOrganizationReq {
 }
 //添加ldap用户帐号
 type CreateLdapUserReq {
-	UserName           string   `json:"user_name"`                   //用户名
-	Email              string   `json:"email"`                       //邮箱
-	Password           string   `json:"password"`                    //密码
-	Mobile             string   `json:"mobile"`                      //手机号
-	Avatar             string   `json:"avatar"`                      //头像地址
-	EmployeeType       int64    `json:"employee_type,options=1|2|3"` //1正式 2实习 3外包
-	GroupId            int64    `json:"group_id,optional"`           //授权分组id
-	OrganizationDNList []string `json:"organization_dn_list"`        //属于哪些部门
-	Status             int64    `json:"status,options=0|1"`          //状态 1正常0离职
+	UserName     string `json:"user_name"`                   //用户名
+	Email        string `json:"email"`                       //邮箱
+	Password     string `json:"password"`                    //密码
+	Mobile       string `json:"mobile"`                      //手机号
+	Avatar       string `json:"avatar"`                      //头像地址
+	EmployeeType int64  `json:"employee_type,options=1|2|3"` //1正式 2实习 3外包
+	GroupId      int64  `json:"group_id,optional"`           //授权分组id
+	Gender       int64  `json:"gender,options=1|2|3"`        //性别 1男 2女 3未知
+	Birthday     string `json:"birthday"`                    //生日
+	Status       int64  `json:"status,options=0|1"`          //状态 1正常0离职
 }
 //修改ldap用户信息
 type UpdateLdapUserReq {
diff --git a/utils/ldap_lib/ldap_user.go b/utils/ldap_lib/ldap_user.go
index 13bf2250..f2706fdc 100644
--- a/utils/ldap_lib/ldap_user.go
+++ b/utils/ldap_lib/ldap_user.go
@@ -9,17 +9,20 @@ import (
 )
 
 type LdapUserInfo struct {
-	UserId             int64    `json:"userId"`
-	UserDN             string   `json:"user_dn"`
-	UserName           string   `json:"user_name"`            //用户名
-	Password           string   `json:"password"`             //密码
-	Email              string   `json:"email"`                //邮箱
-	Mobile             string   `json:"mobile"`               //手机号
-	Avatar             string   `json:"avatar"`               //头像地址
-	EmployeeType       int64    `json:"employee_type"`        //1正式 2实习 3外包
-	GroupId            int64    `json:"group_id"`             //权限组id
-	OrganizationDNList []string `json:"organization_dn_list"` //加入的部门
-	Status             int64    `json:"status,options=0|1"`   //状态 1正常0离职
+	UserId                   int64    `json:"userId"`
+	UserDN                   string   `json:"user_dn"`
+	UserName                 string   `json:"user_name"`                   //用户名
+	Password                 string   `json:"password"`                    //密码
+	Email                    string   `json:"email"`                       //邮箱
+	Mobile                   string   `json:"mobile"`                      //手机号
+	Avatar                   string   `json:"avatar"`                      //头像地址
+	EmployeeType             int64    `json:"employee_type"`               //1正式 2实习 3外包
+	GroupId                  int64    `json:"group_id"`                    //权限组id
+	OrganizationDNList       []string `json:"organization_dn_list"`        //加入的部门
+	ManageOrganizationDNList []string `json:"manage_organization_dn_list"` //管理的部门
+	Gender                   int64    `json:"gender"`                      //性别
+	Birthday                 string   `json:"birthday"`                    //生日
+	Status                   int64    `json:"status,options=0|1"`          //状态 1正常0离职
 }
 
 // 获取用户详情
@@ -87,6 +90,18 @@ func (l *Ldap) GetLdapUserInfo(userDN string) (*LdapUserInfo, error) {
 			}
 		case "departmentNumber": //加入的部门dn集合
 			user.OrganizationDNList = attr.Values
+		case "telexNumber": //管理的部门dn集合
+			user.ManageOrganizationDNList = attr.Values
+		case "st": //性别
+			if len(attr.Values) == 0 {
+				return nil, errors.New("性别不存在")
+			}
+			user.Gender, err = strconv.ParseInt(attr.Values[0], 10, 64)
+			if err != nil {
+				return nil, err
+			}
+		case "title": //生日
+			user.Birthday = strings.Join(attr.Values, ",")
 		}
 	}
 	if user.UserId == 0 {
@@ -156,6 +171,18 @@ func (l *Ldap) GetLdapBaseTeamUserList(pageSize uint32, filter, pageCookie strin
 				}
 			case "departmentNumber": //加入的部门dn集合
 				user.OrganizationDNList = attr.Values
+			case "telexNumber": //管理的部门dn集合
+				user.ManageOrganizationDNList = attr.Values
+			case "st": //性别
+				if len(attr.Values) == 0 {
+					return nil, "", errors.New("性别不存在")
+				}
+				user.Gender, err = strconv.ParseInt(attr.Values[0], 10, 64)
+				if err != nil {
+					return nil, "", err
+				}
+			case "title": //生日
+				user.Birthday = strings.Join(attr.Values, ",")
 			}
 		}
 		list = append(list, user)
@@ -219,6 +246,28 @@ func (l *Ldap) GetLdapBaseTeamUsersByParams(filter string) ([]LdapUserInfo, erro
 				if err != nil {
 					return nil, err
 				}
+			case "roomNumber": //权限组id
+				if len(attr.Values) == 0 {
+					return nil, errors.New("权限组id不存在")
+				}
+				user.GroupId, err = strconv.ParseInt(attr.Values[0], 10, 64)
+				if err != nil {
+					return nil, err
+				}
+			case "departmentNumber": //加入的部门dn集合
+				user.OrganizationDNList = attr.Values
+			case "telexNumber": //管理的部门dn集合
+				user.ManageOrganizationDNList = attr.Values
+			case "st": //性别
+				if len(attr.Values) == 0 {
+					return nil, errors.New("性别不存在")
+				}
+				user.Gender, err = strconv.ParseInt(attr.Values[0], 10, 64)
+				if err != nil {
+					return nil, err
+				}
+			case "title": //生日
+				user.Birthday = strings.Join(attr.Values, ",")
 			}
 		}
 		list = append(list, user)

From f0bb6d4fe252651cf507ce481baf8eff2e3fb451 Mon Sep 17 00:00:00 2001
From: laodaming <11058467+laudamine@user.noreply.gitee.com>
Date: Mon, 27 Nov 2023 14:02:47 +0800
Subject: [PATCH 08/10] fix

---
 .../internal/logic/getldapuserinfologic.go       |  4 +++-
 .../internal/logic/updateldapuserlogic.go        |  2 ++
 server/ldap-admin/internal/types/types.go        | 16 ++++++++++------
 server_api/ldap-admin.api                        | 16 ++++++++++------
 4 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/server/ldap-admin/internal/logic/getldapuserinfologic.go b/server/ldap-admin/internal/logic/getldapuserinfologic.go
index 39168765..1b1a5b52 100644
--- a/server/ldap-admin/internal/logic/getldapuserinfologic.go
+++ b/server/ldap-admin/internal/logic/getldapuserinfologic.go
@@ -54,8 +54,10 @@ func (l *GetLdapUserInfoLogic) GetLdapUserInfo(req *types.GetLdapUserInfoReq, r
 		Email:        user.Email,
 		Mobile:       user.Mobile,
 		Avatar:       user.Avatar,
-		Status:       user.Status,
 		EmployeeTpye: user.EmployeeType,
+		Gender:       user.Gender,
+		Birthday:     user.Birthday,
+		Status:       user.Status,
 	})
 }
 
diff --git a/server/ldap-admin/internal/logic/updateldapuserlogic.go b/server/ldap-admin/internal/logic/updateldapuserlogic.go
index fd3ece66..aa039832 100644
--- a/server/ldap-admin/internal/logic/updateldapuserlogic.go
+++ b/server/ldap-admin/internal/logic/updateldapuserlogic.go
@@ -68,6 +68,8 @@ func (l *UpdateLdapUserLogic) UpdateLdapUser(req *types.UpdateLdapUserReq, r *ht
 		"postalAddress":    {req.Avatar},
 		"postalCode":       {fmt.Sprintf("%d", req.Status)},
 		"employeeType":     {fmt.Sprintf("%d", req.EmployeeType)},
+		"st":               {fmt.Sprintf("%d", req.Gender)}, //性别
+		"title":            {req.Birthday},                  //生日
 	}
 	err := l.svcCtx.Ldap.Update(req.UserDN, attr)
 	if err != nil {
diff --git a/server/ldap-admin/internal/types/types.go b/server/ldap-admin/internal/types/types.go
index e5a6c8c3..be736526 100644
--- a/server/ldap-admin/internal/types/types.go
+++ b/server/ldap-admin/internal/types/types.go
@@ -163,6 +163,8 @@ type UpdateLdapUserReq struct {
 	Status       int64  `json:"status,options=0|1"`          //状态 1正常0离职
 	EmployeeType int64  `json:"employee_type,options=1|2|3"` //1正式 2实习 3外包
 	GroupId      int64  `json:"group_id,optional"`           //权限分组id
+	Gender       int64  `json:"gender,options=1|2|3"`        //性别 1男 2女 3未知
+	Birthday     string `json:"birthday"`                    //生日
 }
 
 type UpdateLdapUserPwdReq struct {
@@ -182,12 +184,14 @@ type GetLdapUserInfoReq struct {
 type GetLdapUserInfoRsp struct {
 	UserId       int64  `json:"user_id"`
 	UserDN       string `json:"user_dn"`
-	UserName     string `json:"user_name"`          //用户名
-	Email        string `json:"email"`              //邮箱
-	Mobile       string `json:"mobile"`             //手机号
-	Avatar       string `json:"avatar"`             //头像地址
-	EmployeeTpye int64  `json:"employee_tpye"`      //雇佣类型 1正式 2实习 3外包
-	Status       int64  `json:"status,options=0|1"` //状态 1正常0离职
+	UserName     string `json:"user_name"`            //用户名
+	Email        string `json:"email"`                //邮箱
+	Mobile       string `json:"mobile"`               //手机号
+	Avatar       string `json:"avatar"`               //头像地址
+	EmployeeTpye int64  `json:"employee_tpye"`        //雇佣类型 1正式 2实习 3外包
+	Gender       int64  `json:"gender,options=1|2|3"` //性别 1男 2女 3未知
+	Birthday     string `json:"birthday"`             //生日
+	Status       int64  `json:"status,options=0|1"`   //状态 1正常0离职
 }
 
 type AddLdapOrganizationMemberReq struct {
diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api
index 48f9601c..69df272b 100644
--- a/server_api/ldap-admin.api
+++ b/server_api/ldap-admin.api
@@ -247,6 +247,8 @@ type UpdateLdapUserReq {
 	Status       int64  `json:"status,options=0|1"`          //状态 1正常0离职
 	EmployeeType int64  `json:"employee_type,options=1|2|3"` //1正式 2实习 3外包
 	GroupId      int64  `json:"group_id,optional"`           //权限分组id
+	Gender       int64  `json:"gender,options=1|2|3"`        //性别 1男 2女 3未知
+	Birthday     string `json:"birthday"`                    //生日
 }
 //修改用户密码
 type UpdateLdapUserPwdReq {
@@ -265,12 +267,14 @@ type GetLdapUserInfoReq {
 type GetLdapUserInfoRsp {
 	UserId       int64  `json:"user_id"`
 	UserDN       string `json:"user_dn"`
-	UserName     string `json:"user_name"`          //用户名
-	Email        string `json:"email"`              //邮箱
-	Mobile       string `json:"mobile"`             //手机号
-	Avatar       string `json:"avatar"`             //头像地址
-	EmployeeTpye int64  `json:"employee_tpye"`      //雇佣类型 1正式 2实习 3外包
-	Status       int64  `json:"status,options=0|1"` //状态 1正常0离职
+	UserName     string `json:"user_name"`            //用户名
+	Email        string `json:"email"`                //邮箱
+	Mobile       string `json:"mobile"`               //手机号
+	Avatar       string `json:"avatar"`               //头像地址
+	EmployeeTpye int64  `json:"employee_tpye"`        //雇佣类型 1正式 2实习 3外包
+	Gender       int64  `json:"gender,options=1|2|3"` //性别 1男 2女 3未知
+	Birthday     string `json:"birthday"`             //生日
+	Status       int64  `json:"status,options=0|1"`   //状态 1正常0离职
 }
 //ldap组织添加成员
 type AddLdapOrganizationMemberReq {

From 42e2001160d2aeddb9fb3fcb47a97d0a329a24f1 Mon Sep 17 00:00:00 2001
From: laodaming <11058467+laudamine@user.noreply.gitee.com>
Date: Mon, 27 Nov 2023 14:04:09 +0800
Subject: [PATCH 09/10] fix

---
 .../logic/getldaporganizationmemberslogic.go       |  2 ++
 server/ldap-admin/internal/types/types.go          | 14 ++++++++------
 server_api/ldap-admin.api                          | 14 ++++++++------
 3 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/server/ldap-admin/internal/logic/getldaporganizationmemberslogic.go b/server/ldap-admin/internal/logic/getldaporganizationmemberslogic.go
index 3ae5c203..8d247918 100644
--- a/server/ldap-admin/internal/logic/getldaporganizationmemberslogic.go
+++ b/server/ldap-admin/internal/logic/getldaporganizationmemberslogic.go
@@ -116,6 +116,8 @@ func (l *GetLdapOrganizationMembersLogic) GetLdapOrganizationMembers(req *types.
 			Mobile:       user.Mobile,
 			Avatar:       user.Avatar,
 			EmployeeType: user.EmployeeType,
+			Gender:       user.Gender,
+			Birthday:     user.Birthday,
 			Status:       user.Status,
 		})
 	}
diff --git a/server/ldap-admin/internal/types/types.go b/server/ldap-admin/internal/types/types.go
index be736526..5fa9f523 100644
--- a/server/ldap-admin/internal/types/types.go
+++ b/server/ldap-admin/internal/types/types.go
@@ -215,12 +215,14 @@ type GetLdapOrganizationMembersRsp struct {
 type GetLdapOrganizationMembersItem struct {
 	UserId       int64  `json:"userId"`
 	UserDN       string `json:"user_dn"`
-	UserName     string `json:"user_name"` //用户名
-	Email        string `json:"email"`     //邮箱
-	Mobile       string `json:"mobile"`    //手机号
-	Avatar       string `json:"avatar"`    //头像地址
-	EmployeeType int64  `json:"employee_type"`
-	Status       int64  `json:"status,options=0|1"` //状态 1正常0离职
+	UserName     string `json:"user_name"`            //用户名
+	Email        string `json:"email"`                //邮箱
+	Mobile       string `json:"mobile"`               //手机号
+	Avatar       string `json:"avatar"`               //头像地址
+	EmployeeType int64  `json:"employee_type"`        //雇佣类型
+	Gender       int64  `json:"gender,options=1|2|3"` //性别 1男 2女 3未知
+	Birthday     string `json:"birthday"`             //生日
+	Status       int64  `json:"status,options=0|1"`   //状态 1正常0离职
 }
 
 type GetLdapUsersReq struct {
diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api
index 69df272b..f98d606b 100644
--- a/server_api/ldap-admin.api
+++ b/server_api/ldap-admin.api
@@ -296,12 +296,14 @@ type GetLdapOrganizationMembersRsp {
 type GetLdapOrganizationMembersItem {
 	UserId       int64  `json:"userId"`
 	UserDN       string `json:"user_dn"`
-	UserName     string `json:"user_name"` //用户名
-	Email        string `json:"email"`     //邮箱
-	Mobile       string `json:"mobile"`    //手机号
-	Avatar       string `json:"avatar"`    //头像地址
-	EmployeeType int64  `json:"employee_type"`
-	Status       int64  `json:"status,options=0|1"` //状态 1正常0离职
+	UserName     string `json:"user_name"`            //用户名
+	Email        string `json:"email"`                //邮箱
+	Mobile       string `json:"mobile"`               //手机号
+	Avatar       string `json:"avatar"`               //头像地址
+	EmployeeType int64  `json:"employee_type"`        //雇佣类型
+	Gender       int64  `json:"gender,options=1|2|3"` //性别 1男 2女 3未知
+	Birthday     string `json:"birthday"`             //生日
+	Status       int64  `json:"status,options=0|1"`   //状态 1正常0离职
 }
 //获取基础用户组中成员列表
 type GetLdapUsersReq {

From fdb80820955f0d1a8918308043e6dc546ed8182b Mon Sep 17 00:00:00 2001
From: laodaming <11058467+laudamine@user.noreply.gitee.com>
Date: Mon, 27 Nov 2023 14:41:10 +0800
Subject: [PATCH 10/10] fix

---
 .../logic/createldaporganizationlogic.go      | 22 ++++++++++++-
 .../removeldaporganizationmemberlogic.go      | 31 +++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/server/ldap-admin/internal/logic/createldaporganizationlogic.go b/server/ldap-admin/internal/logic/createldaporganizationlogic.go
index 6d0d86ad..e32ae70e 100644
--- a/server/ldap-admin/internal/logic/createldaporganizationlogic.go
+++ b/server/ldap-admin/internal/logic/createldaporganizationlogic.go
@@ -68,7 +68,27 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd
 		logx.Error(err)
 		return resp.SetStatusWithMessage(basic.CodeServiceErr, "创建组织失败,"+err.Error())
 	}
-	return resp.SetStatus(basic.CodeOK)
+	user, err := l.svcCtx.Ldap.GetLdapUserInfo(req.OwnerDN)
+	if err != nil {
+		logx.Error(err)
+		return resp.SetStatusWithMessage(basic.CodeServiceErr, "获取负责人信息失败,"+err.Error())
+	}
+	if user.Status != 1 {
+		return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "负责人状态不正常")
+	}
+	//用户加入的部门
+	user.OrganizationDNList = append(user.OrganizationDNList, organizationDN)
+	//用户管理的部门
+	user.ManageOrganizationDNList = append(user.ManageOrganizationDNList, organizationDN)
+	//更新用户信息
+	err = l.svcCtx.Ldap.Update(user.UserDN, map[string][]string{
+		"departmentNumber": user.OrganizationDNList,
+		"telexNumber":      user.ManageOrganizationDNList,
+	})
+	if err != nil {
+		return resp.SetStatusWithMessage(basic.CodeOK, "添加组织成功,但是设置负责人信息失败,"+err.Error())
+	}
+	return resp.SetStatusWithMessage(basic.CodeOK, "添加组织成功")
 }
 
 // 处理逻辑后 w,r 如:重定向, resp 必须重新处理
diff --git a/server/ldap-admin/internal/logic/removeldaporganizationmemberlogic.go b/server/ldap-admin/internal/logic/removeldaporganizationmemberlogic.go
index 8f7f86cc..9bb9cd7e 100644
--- a/server/ldap-admin/internal/logic/removeldaporganizationmemberlogic.go
+++ b/server/ldap-admin/internal/logic/removeldaporganizationmemberlogic.go
@@ -49,11 +49,42 @@ func (l *RemoveLdapOrganizationMemberLogic) RemoveLdapOrganizationMember(req *ty
 	if !email.IsEmailValid(cnEmail) {
 		return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "错误的用户cn")
 	}
+	//获取组织成员列表
 	err := l.svcCtx.Ldap.RemoveUserFromOrganization(req.OrganizationDN, req.UserDN)
 	if err != nil {
 		logx.Error(err)
 		return resp.SetStatusWithMessage(basic.CodeServiceErr, "移除成员失败,"+err.Error())
 	}
+	//获取用户信息
+	userInfo, err := l.svcCtx.Ldap.GetLdapUserInfo(req.UserDN)
+	if err != nil {
+		logx.Error(err)
+		return resp.SetStatusWithMessage(basic.CodeServiceErr, "获取用户信息失败,"+err.Error())
+	}
+	//把属于的组织去掉
+	newOrganizationDNList := make([]string, 0, len(userInfo.OrganizationDNList))
+	for _, v := range userInfo.OrganizationDNList {
+		if v == req.OrganizationDN {
+			continue
+		}
+		newOrganizationDNList = append(newOrganizationDNList, v)
+	}
+	//如果是负责人也要把管理组织标识去掉
+	newManageOrganizationDNList := make([]string, 0, len(userInfo.OrganizationDNList))
+	for _, v := range userInfo.ManageOrganizationDNList {
+		if v == req.OrganizationDN {
+			continue
+		}
+		newManageOrganizationDNList = append(newManageOrganizationDNList, v)
+	}
+	err = l.svcCtx.Ldap.Update(req.UserDN, map[string][]string{
+		"departmentNumber": newOrganizationDNList,       //所属组织部门
+		"telexNumber":      newManageOrganizationDNList, //管理的部门
+	})
+	if err != nil {
+		logx.Error(err)
+		return resp.SetStatusWithMessage(basic.CodeServiceErr, "移除成员成功,但更新用户信息失败")
+	}
 	return resp.SetStatusWithMessage(basic.CodeOK, "移除成员成功")
 }