From f8b8d98723b285d7759cb5acc609535505f8f99f Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 16 Nov 2023 16:57:29 +0800 Subject: [PATCH] fix --- model/gmodel/ldap_user_gen.go | 16 ++++ model/gmodel/ldap_user_group_gen.go | 4 +- model/gmodel/ldap_user_logic.go | 8 ++ model/gmodel/var_gen.go | 2 + server/ldap-admin/internal/config/config.go | 2 +- .../internal/handler/createldapuserhandler.go | 35 ++++++++ .../internal/handler/deleteldapuserhandler.go | 35 ++++++++ .../handler/getldapuserinfohandler.go | 35 ++++++++ server/ldap-admin/internal/handler/routes.go | 20 +++++ .../internal/handler/updateldapuserhandler.go | 35 ++++++++ .../internal/logic/createldapuserlogic.go | 88 +++++++++++++++++++ .../internal/logic/deleteldapuserlogic.go | 43 +++++++++ .../internal/logic/getldapuserinfologic.go | 43 +++++++++ .../internal/logic/getorginationslogic.go | 6 +- .../internal/logic/updateldapuserlogic.go | 43 +++++++++ server/ldap-admin/internal/types/types.go | 18 ++++ server_api/ldap-admin.api | 32 ++++++- utils/chinese_to_pinyin/chinese_to_pinyin.go | 30 +++++++ 18 files changed, 490 insertions(+), 5 deletions(-) create mode 100644 model/gmodel/ldap_user_gen.go create mode 100644 model/gmodel/ldap_user_logic.go create mode 100644 server/ldap-admin/internal/handler/createldapuserhandler.go create mode 100644 server/ldap-admin/internal/handler/deleteldapuserhandler.go create mode 100644 server/ldap-admin/internal/handler/getldapuserinfohandler.go create mode 100644 server/ldap-admin/internal/handler/updateldapuserhandler.go create mode 100644 server/ldap-admin/internal/logic/createldapuserlogic.go create mode 100644 server/ldap-admin/internal/logic/deleteldapuserlogic.go create mode 100644 server/ldap-admin/internal/logic/getldapuserinfologic.go create mode 100644 server/ldap-admin/internal/logic/updateldapuserlogic.go create mode 100644 utils/chinese_to_pinyin/chinese_to_pinyin.go diff --git a/model/gmodel/ldap_user_gen.go b/model/gmodel/ldap_user_gen.go new file mode 100644 index 00000000..d534adf5 --- /dev/null +++ b/model/gmodel/ldap_user_gen.go @@ -0,0 +1,16 @@ +package gmodel + +import ( + "gorm.io/gorm" +) + +// ldap_user ldap_用户id递增表 +type LdapUser struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // +} +type LdapUserModel struct { + db *gorm.DB + name string +} + +func NewLdapUserModel(db *gorm.DB) *LdapUserModel { return &LdapUserModel{db: db, name: "ldap_user"} } diff --git a/model/gmodel/ldap_user_group_gen.go b/model/gmodel/ldap_user_group_gen.go index bef006ec..7706b4b1 100644 --- a/model/gmodel/ldap_user_group_gen.go +++ b/model/gmodel/ldap_user_group_gen.go @@ -6,8 +6,8 @@ import ( // ldap_user_group 用户权限分组表 type LdapUserGroup struct { - GroupId *int64 `gorm:"default:0;" json:"group_id"` // - UserId *string `gorm:"default:'0';" json:"user_id"` // + GroupId *int64 `gorm:"default:0;" json:"group_id"` // + UserId *int64 `gorm:"default:0;" json:"user_id"` // } type LdapUserGroupModel struct { db *gorm.DB diff --git a/model/gmodel/ldap_user_logic.go b/model/gmodel/ldap_user_logic.go new file mode 100644 index 00000000..422460ca --- /dev/null +++ b/model/gmodel/ldap_user_logic.go @@ -0,0 +1,8 @@ +package gmodel + +import "context" + +// TODO: 使用model的属性做你想做的 +func (u *LdapUserModel) Create(ctx context.Context, data *LdapUser) error { + return u.db.WithContext(ctx).Model(&LdapUser{}).Create(&data).Error +} diff --git a/model/gmodel/var_gen.go b/model/gmodel/var_gen.go index 9c1449cb..d0fd481e 100644 --- a/model/gmodel/var_gen.go +++ b/model/gmodel/var_gen.go @@ -114,6 +114,7 @@ type AllModelsGen struct { LdapGroup *LdapGroupModel // ldap_group 权限组表 LdapGroupMenus *LdapGroupMenusModel // ldap_group_menus 权限分组菜单表 LdapMenus *LdapMenusModel // ldap_menus 菜单表 + LdapUser *LdapUserModel // ldap_user ldap_用户id递增表 LdapUserGroup *LdapUserGroupModel // ldap_user_group 用户权限分组表 } @@ -230,6 +231,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen { LdapGroup: NewLdapGroupModel(gdb), LdapGroupMenus: NewLdapGroupMenusModel(gdb), LdapMenus: NewLdapMenusModel(gdb), + LdapUser: NewLdapUserModel(gdb), LdapUserGroup: NewLdapUserGroupModel(gdb), } return models diff --git a/server/ldap-admin/internal/config/config.go b/server/ldap-admin/internal/config/config.go index 6a0cd74f..b09aa030 100644 --- a/server/ldap-admin/internal/config/config.go +++ b/server/ldap-admin/internal/config/config.go @@ -17,6 +17,6 @@ type Config struct { Password string BaseDN string RootDN string - PeopleGroupOu string + PeopleGroupDN string } } diff --git a/server/ldap-admin/internal/handler/createldapuserhandler.go b/server/ldap-admin/internal/handler/createldapuserhandler.go new file mode 100644 index 00000000..9f69d186 --- /dev/null +++ b/server/ldap-admin/internal/handler/createldapuserhandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/ldap-admin/internal/logic" + "fusenapi/server/ldap-admin/internal/svc" + "fusenapi/server/ldap-admin/internal/types" +) + +func CreateLdapUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.CreateLdapUserReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewCreateLdapUserLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.CreateLdapUser(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/ldap-admin/internal/handler/deleteldapuserhandler.go b/server/ldap-admin/internal/handler/deleteldapuserhandler.go new file mode 100644 index 00000000..f36b160c --- /dev/null +++ b/server/ldap-admin/internal/handler/deleteldapuserhandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/ldap-admin/internal/logic" + "fusenapi/server/ldap-admin/internal/svc" + "fusenapi/server/ldap-admin/internal/types" +) + +func DeleteLdapUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.DeleteLdapUserReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewDeleteLdapUserLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.DeleteLdapUser(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/ldap-admin/internal/handler/getldapuserinfohandler.go b/server/ldap-admin/internal/handler/getldapuserinfohandler.go new file mode 100644 index 00000000..d2e7116b --- /dev/null +++ b/server/ldap-admin/internal/handler/getldapuserinfohandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/ldap-admin/internal/logic" + "fusenapi/server/ldap-admin/internal/svc" + "fusenapi/server/ldap-admin/internal/types" +) + +func GetLdapUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.GetLdapUserInfoReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewGetLdapUserInfoLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.GetLdapUserInfo(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/ldap-admin/internal/handler/routes.go b/server/ldap-admin/internal/handler/routes.go index 7b821992..0c0edc2e 100644 --- a/server/ldap-admin/internal/handler/routes.go +++ b/server/ldap-admin/internal/handler/routes.go @@ -62,6 +62,26 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/ldap-admin/update_ldap_orgination", Handler: UpdateLdapOrginationHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/api/ldap-admin/create_ldap_user", + Handler: CreateLdapUserHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/api/ldap-admin/update_ldap_user", + Handler: UpdateLdapUserHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/api/ldap-admin/delete_ldap_user", + Handler: DeleteLdapUserHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/api/ldap-admin/get_ldap_user_info", + Handler: GetLdapUserInfoHandler(serverCtx), + }, }, ) } diff --git a/server/ldap-admin/internal/handler/updateldapuserhandler.go b/server/ldap-admin/internal/handler/updateldapuserhandler.go new file mode 100644 index 00000000..a0e9bc93 --- /dev/null +++ b/server/ldap-admin/internal/handler/updateldapuserhandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/ldap-admin/internal/logic" + "fusenapi/server/ldap-admin/internal/svc" + "fusenapi/server/ldap-admin/internal/types" +) + +func UpdateLdapUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.UpdateLdapUserReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewUpdateLdapUserLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.UpdateLdapUser(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/ldap-admin/internal/logic/createldapuserlogic.go b/server/ldap-admin/internal/logic/createldapuserlogic.go new file mode 100644 index 00000000..734fa657 --- /dev/null +++ b/server/ldap-admin/internal/logic/createldapuserlogic.go @@ -0,0 +1,88 @@ +package logic + +import ( + "fmt" + "fusenapi/model/gmodel" + "fusenapi/utils/auth" + "fusenapi/utils/basic" + "fusenapi/utils/chinese_to_pinyin" + "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 CreateLdapUserLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewCreateLdapUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLdapUserLogic { + return &CreateLdapUserLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *CreateLdapUserLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *CreateLdapUserLogic) CreateLdapUser(req *types.CreateLdapUserReq, userinfo *auth.UserInfo) (resp *basic.Response) { + req.UserName = strings.Trim(req.UserName, " ") + req.Mobile = strings.Trim(req.Mobile, " ") + req.Email = strings.Trim(req.Email, " ") + req.Password = strings.Trim(req.Password, " ") + if req.UserName == "" { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "用户名不能为空") + } + if req.Password == "" { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "密码不能为空") + } + ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN) + //把用户名转pinyin + userNamePinyin := chinese_to_pinyin.ChineseToPinyin(req.UserName) + //新增一条记录获取递增用户id + userData := &gmodel.LdapUser{} + if err := l.svcCtx.AllModels.LdapUser.Create(l.ctx, userData); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "获取自增用户id失败") + } + userDN := fmt.Sprintf("cn=%s,%s", userNamePinyin, l.svcCtx.Config.Ldap.PeopleGroupDN) + if err := ldapServer.Create(userDN, map[string][]string{ + "objectClass": {"person", "organizationalPerson", "inetOrgPerson", "posixAccount", "top", "shadowAccount"}, //固有属性 + "shadowLastChange": {"19676"}, //固有属性 + "shadowMin": {"0"}, //固有属性 + "shadowMax": {"99999"}, //固有属性 + "shadowWarning": {"7"}, //固有属性 + "loginShell": {"/usr/sbin/nologin"}, //固有属性 + "homeDirectory": {"/home/users/" + userNamePinyin}, + "uidNumber": {fmt.Sprintf("%d", userData.Id)}, + "gidNumber": {fmt.Sprintf("%d", userData.Id)}, + "uid": {fmt.Sprintf("%d", userData.Id)}, + "cn": {userNamePinyin}, + "sn": {req.UserName}, + "mail": {req.Email}, + "postalCode": {fmt.Sprintf("%d", req.Status)}, + "departmentNumber": {"0"}, + "postalAddress": {req.Avatar}, + "mobile": {req.Mobile}, + "userPassword": {req.Password}, + }); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "添加用户失败,", err.Error()) + } + return resp.SetStatusWithMessage(basic.CodeOK, "添加用户成功") +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *CreateLdapUserLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } diff --git a/server/ldap-admin/internal/logic/deleteldapuserlogic.go b/server/ldap-admin/internal/logic/deleteldapuserlogic.go new file mode 100644 index 00000000..96f8897d --- /dev/null +++ b/server/ldap-admin/internal/logic/deleteldapuserlogic.go @@ -0,0 +1,43 @@ +package logic + +import ( + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/ldap-admin/internal/svc" + "fusenapi/server/ldap-admin/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type DeleteLdapUserLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewDeleteLdapUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteLdapUserLogic { + return &DeleteLdapUserLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *DeleteLdapUserLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *DeleteLdapUserLogic) DeleteLdapUser(req *types.DeleteLdapUserReq, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + + return resp.SetStatus(basic.CodeOK) +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *DeleteLdapUserLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } diff --git a/server/ldap-admin/internal/logic/getldapuserinfologic.go b/server/ldap-admin/internal/logic/getldapuserinfologic.go new file mode 100644 index 00000000..c6fb366a --- /dev/null +++ b/server/ldap-admin/internal/logic/getldapuserinfologic.go @@ -0,0 +1,43 @@ +package logic + +import ( + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/ldap-admin/internal/svc" + "fusenapi/server/ldap-admin/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetLdapUserInfoLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetLdapUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLdapUserInfoLogic { + return &GetLdapUserInfoLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *GetLdapUserInfoLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *GetLdapUserInfoLogic) GetLdapUserInfo(req *types.GetLdapUserInfoReq, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + + return resp.SetStatus(basic.CodeOK) +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *GetLdapUserInfoLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } diff --git a/server/ldap-admin/internal/logic/getorginationslogic.go b/server/ldap-admin/internal/logic/getorginationslogic.go index ec0747f2..8e42358f 100644 --- a/server/ldap-admin/internal/logic/getorginationslogic.go +++ b/server/ldap-admin/internal/logic/getorginationslogic.go @@ -47,7 +47,11 @@ func (l *GetorginationsLogic) Getorginations(req *types.Request, userinfo *auth. return resp.SetStatusWithMessage(basic.CodeServiceErr, "root用户DN未设置") } ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN) - filter := "(&(objectClass=*)(!(ou=" + l.svcCtx.Config.Ldap.PeopleGroupOu + "))(!(" + rootCn[0] + ")))" //所有object但是不包括people以及root用户 + peopleDNSlice := strings.Split(l.svcCtx.Config.Ldap.PeopleGroupDN, ",") + if len(peopleDNSlice) <= 1 { + return resp.SetStatusWithMessage(basic.CodeServiceErr, "基础用户组的DN未配置") + } + filter := "(&(objectClass=*)(!(" + peopleDNSlice[0] + "))(!(" + rootCn[0] + ")))" //所有object但是不包括people以及root用户 searchResult, err := ldapServer.Search(l.svcCtx.Config.Ldap.BaseDN, filter, nil, nil) if err != nil { return resp.SetStatusWithMessage(basic.CodeServiceErr, "查询失败:"+err.Error()) diff --git a/server/ldap-admin/internal/logic/updateldapuserlogic.go b/server/ldap-admin/internal/logic/updateldapuserlogic.go new file mode 100644 index 00000000..c4b61f1d --- /dev/null +++ b/server/ldap-admin/internal/logic/updateldapuserlogic.go @@ -0,0 +1,43 @@ +package logic + +import ( + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/ldap-admin/internal/svc" + "fusenapi/server/ldap-admin/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type UpdateLdapUserLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewUpdateLdapUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLdapUserLogic { + return &UpdateLdapUserLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *UpdateLdapUserLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *UpdateLdapUserLogic) UpdateLdapUser(req *types.UpdateLdapUserReq, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + + return resp.SetStatus(basic.CodeOK) +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *UpdateLdapUserLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } diff --git a/server/ldap-admin/internal/types/types.go b/server/ldap-admin/internal/types/types.go index d3860ba7..02f84a97 100644 --- a/server/ldap-admin/internal/types/types.go +++ b/server/ldap-admin/internal/types/types.go @@ -88,6 +88,24 @@ type UpdateLdapOrginationReq struct { BusinessCategory string `json:"business_category"` //组织分类名称 } +type CreateLdapUserReq struct { + UserName string `json:"user_name"` //用户名 + Email string `json:"email"` //邮箱 + Password string `json:"password"` //密码 + Mobile string `json:"mobile"` //手机号 + Avatar string `json:"avatar"` //头像地址 + Status int64 `json:"status,options=0|1"` //状态 1正常0离职 +} + +type UpdateLdapUserReq struct { +} + +type DeleteLdapUserReq struct { +} + +type GetLdapUserInfoReq struct { +} + type Request struct { } diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api index 2d2ec105..e2b65bdf 100644 --- a/server_api/ldap-admin.api +++ b/server_api/ldap-admin.api @@ -39,9 +39,21 @@ service ldap-admin { //删除ldap组织 @handler DeleteLdapOrginationHandler post /api/ldap-admin/delete_ldap_orgination(DeleteLdapOrginationReq) returns (response); - //修改组织 + //修改ldap组织 @handler UpdateLdapOrginationHandler post /api/ldap-admin/update_ldap_orgination(UpdateLdapOrginationReq) returns (response); + //添加ldap用户到员工基本组中 + @handler CreateLdapUserHandler + post /api/ldap-admin/create_ldap_user(CreateLdapUserReq) returns (response); + //修改ldap用户信息 + @handler UpdateLdapUserHandler + post /api/ldap-admin/update_ldap_user(UpdateLdapUserReq) returns (response); + //删除ldap用户 + @handler DeleteLdapUserHandler + post /api/ldap-admin/delete_ldap_user(DeleteLdapUserReq) returns (response); + //获取ldap用户信息 + @handler GetLdapUserInfoHandler + get /api/ldap-admin/get_ldap_user_info(GetLdapUserInfoReq) returns (response); } type GetApisReq { @@ -123,4 +135,22 @@ type DeleteLdapOrginationReq { type UpdateLdapOrginationReq { OrginationDN string `json:"orgination_dn"` //组织dn BusinessCategory string `json:"business_category"` //组织分类名称 +} +//添加ldap用户到员工基本组中 +type CreateLdapUserReq { + UserName string `json:"user_name"` //用户名 + Email string `json:"email"` //邮箱 + Password string `json:"password"` //密码 + Mobile string `json:"mobile"` //手机号 + Avatar string `json:"avatar"` //头像地址 + Status int64 `json:"status,options=0|1"` //状态 1正常0离职 +} +//修改ldap用户信息 +type UpdateLdapUserReq { +} +//删除ldap用户 +type DeleteLdapUserReq { +} +//获取ldap用户信息 +type GetLdapUserInfoReq { } \ No newline at end of file diff --git a/utils/chinese_to_pinyin/chinese_to_pinyin.go b/utils/chinese_to_pinyin/chinese_to_pinyin.go new file mode 100644 index 00000000..6ebc4990 --- /dev/null +++ b/utils/chinese_to_pinyin/chinese_to_pinyin.go @@ -0,0 +1,30 @@ +package chinese_to_pinyin + +import ( + "github.com/mozillazg/go-pinyin" + "strings" + "unicode" +) + +func ChineseToPinyin(str string) string { + p := pinyin.NewArgs() + p.Style = pinyin.Normal + finalStr := strings.Builder{} + for _, v := range str { + //判断是不是汉字 + if isChineseCharacter(v) { + result := pinyin.Pinyin(strings.ToLower(string(v)), p) + r := strings.Builder{} + for _, v := range result { + r.WriteString(v[0]) + } + finalStr.WriteString(r.String()) + } else { + finalStr.WriteString(string(v)) + } + } + return finalStr.String() +} +func isChineseCharacter(c rune) bool { + return unicode.Is(unicode.Scripts["Han"], c) +}