fix
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/ldap_lib"
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"context"
|
||||
@@ -84,72 +83,28 @@ func (l *GetLdapOrganizationMembersLogic) GetLdapOrganizationMembers(req *types.
|
||||
//从新赋值filter
|
||||
filter = "(&(objectClass=posixAccount)(objectClass=inetOrgPerson)(|" + filterBuilder.String() + "))"
|
||||
//从用户基本组中找到员工
|
||||
result, err = ldapServer.Search(l.svcCtx.Config.Ldap.PeopleGroupDN, ldap.ScopeWholeSubtree, filter, nil, nil)
|
||||
userList, err := ldapServer.GetLdapBaseTeamUsersByParams(filter)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "查询ldap帐号信息失败,"+err.Error())
|
||||
}
|
||||
userList := make([]types.GetLdapOrganizationMembersItem, 0, memberCount)
|
||||
for _, entry := range result.Entries {
|
||||
user := types.GetLdapOrganizationMembersItem{
|
||||
UserDN: entry.DN,
|
||||
}
|
||||
canAppend := true
|
||||
for _, attr := range entry.Attributes {
|
||||
switch attr.Name {
|
||||
case "uidNumber": //用户id
|
||||
if len(attr.Values) == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "用户id不存在")
|
||||
}
|
||||
user.UserId, err = strconv.ParseInt(attr.Values[0], 10, 64)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "用户id转数字失败")
|
||||
}
|
||||
case "sn": //用户真名
|
||||
user.UserName = strings.Join(attr.Values, "")
|
||||
case "mail": //邮箱
|
||||
user.Email = strings.Join(attr.Values, "")
|
||||
case "mobile": //手机号
|
||||
user.Mobile = strings.Join(attr.Values, "")
|
||||
case "postalAddress": //头像
|
||||
user.Avatar = strings.Join(attr.Values, "")
|
||||
case "employeeType": //人员类型
|
||||
if len(attr.Values) == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "用户类型不存在")
|
||||
}
|
||||
user.EmployeeType, err = strconv.ParseInt(attr.Values[0], 10, 64)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "用户类型转数字失败")
|
||||
}
|
||||
case "postalCode": //状态
|
||||
if len(attr.Values) == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "用户状态不存在")
|
||||
}
|
||||
user.Status, err = strconv.ParseInt(attr.Values[0], 10, 64)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "用户状态转数字失败")
|
||||
}
|
||||
//无效员工就不要显示了
|
||||
if user.Status != 1 {
|
||||
//从该组中移除该成员
|
||||
if err = ldapServer.RemoveUserFromOrganization(req.OrganizationDN, entry.DN); err != nil {
|
||||
logx.Error("移除组中离职成员失败,", err.Error())
|
||||
}
|
||||
canAppend = false //要移除的成员就不要显示了
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
//添加列表
|
||||
if canAppend {
|
||||
userList = append(userList, user)
|
||||
}
|
||||
list := make([]types.GetLdapOrganizationMembersItem, 0, memberCount)
|
||||
for _, user := range userList {
|
||||
list = append(list, types.GetLdapOrganizationMembersItem{
|
||||
UserId: user.UserId,
|
||||
UserDN: user.UserDN,
|
||||
UserName: user.UserName,
|
||||
Email: user.Email,
|
||||
Mobile: user.Mobile,
|
||||
Avatar: user.Avatar,
|
||||
EmployeeType: user.EmployeeType,
|
||||
Status: user.Status,
|
||||
CreateTime: user.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
UpdateTime: user.UpdateTime.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetLdapOrganizationMembersRsp{
|
||||
List: userList,
|
||||
List: list,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,8 @@ func (l *GetLdapUserInfoLogic) GetLdapUserInfo(req *types.GetLdapUserInfoReq, us
|
||||
Avatar: user.Avatar,
|
||||
Status: user.Status,
|
||||
EmployeeTpye: user.EmployeeType,
|
||||
CreateTime: user.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
UpdateTime: user.UpdateTime.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,8 @@ func (l *GetLdapUsersLogic) GetLdapUsers(req *types.GetLdapUsersReq, userinfo *a
|
||||
Avatar: v.Avatar,
|
||||
EmployeeType: v.EmployeeType,
|
||||
Status: v.Status,
|
||||
CreateTime: v.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
UpdateTime: v.UpdateTime.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetLdapUsersRsp{
|
||||
|
||||
@@ -174,6 +174,8 @@ type GetLdapUserInfoRsp struct {
|
||||
Avatar string `json:"avatar"` //头像地址
|
||||
EmployeeTpye int64 `json:"employee_tpye"` //雇佣类型 1正式 2实习 3外包
|
||||
Status int64 `json:"status,options=0|1"` //状态 1正常0离职
|
||||
CreateTime string `json:"create_time"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
}
|
||||
|
||||
type AddLdapOrganizationMemberReq struct {
|
||||
@@ -203,6 +205,8 @@ type GetLdapOrganizationMembersItem struct {
|
||||
Avatar string `json:"avatar"` //头像地址
|
||||
EmployeeType int64 `json:"employee_type"`
|
||||
Status int64 `json:"status,options=0|1"` //状态 1正常0离职
|
||||
CreateTime string `json:"create_time"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
}
|
||||
|
||||
type GetLdapUsersReq struct {
|
||||
@@ -223,6 +227,8 @@ type GetLdapUsersItem struct {
|
||||
Avatar string `json:"avatar"` //头像地址
|
||||
EmployeeType int64 `json:"employee_type"`
|
||||
Status int64 `json:"status,options=0|1"` //状态 1正常0离职
|
||||
CreateTime string `json:"create_time"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
|
||||
Reference in New Issue
Block a user