fusenapi/server/ldap-admin/internal/logic/getldapuserslogic.go

69 lines
2.0 KiB
Go
Raw Normal View History

2023-11-20 09:16:17 +00:00
package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/ldap_lib"
"strings"
"context"
"fusenapi/server/ldap-admin/internal/svc"
"fusenapi/server/ldap-admin/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetLdapUsersLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetLdapUsersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLdapUsersLogic {
return &GetLdapUsersLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *GetLdapUsersLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *GetLdapUsersLogic) GetLdapUsers(req *types.GetLdapUsersReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.PageCookie = strings.Trim(req.PageCookie, " ")
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN, l.svcCtx.Config.Ldap.PeopleGroupDN)
pageSize := uint32(20)
list, cookie, err := ldapServer.GetLdapBaseTeamUserList(pageSize, req.PageCookie)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "查询用户列表报错,"+err.Error())
}
rspList := make([]types.GetLdapUsersItem, 0, len(list))
for _, v := range list {
rspList = append(rspList, types.GetLdapUsersItem{
UserId: v.UserId,
UserDN: v.UserDN,
UserName: v.UserName,
Email: v.Email,
Mobile: v.Mobile,
Avatar: v.Avatar,
EmployeeType: v.EmployeeType,
Status: v.Status,
2023-11-21 03:39:03 +00:00
CreateTime: v.CreateTime.Format("2006-01-02 15:04:05"),
UpdateTime: v.UpdateTime.Format("2006-01-02 15:04:05"),
2023-11-20 09:16:17 +00:00
})
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetLdapUsersRsp{
List: rspList,
PagingCookie: cookie,
})
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *GetLdapUsersLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }