From 57564c886b73f4b240a033e675d4662743d6abe3 Mon Sep 17 00:00:00 2001 From: xiaotong <345561446@qq.com> Date: Fri, 29 Dec 2023 10:08:49 +0800 Subject: [PATCH] feat(user): Added `CreateUser`/`UpdateUser`/`UpdateUserPosition`/`DeleteUser`/`BatchDeleteUser` (#33) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加发送弹窗消息 * add 用户创建,更新,职务更新,删除,批量删除功能 * optimize: user --------- Co-authored-by: val1nna --- feature.md | 10 ++--- user.go | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 5 deletions(-) diff --git a/feature.md b/feature.md index d53dd1e..10fde5a 100644 --- a/feature.md +++ b/feature.md @@ -58,11 +58,11 @@ ### 用户管理 -- [ ] 创建用户 -- [ ] 更新用户 -- [ ] 更新用户部门职务信息 -- [ ] 删除用户 -- [ ] 批量删除用户 +- [x] 创建用户 `user.go@CreateUser` +- [x] 更新用户 `user.go@UpdateUser` +- [x] 更新用户部门职务信息 `user.go@UpdateUserPosition` +- [x] 删除用户 `user.go@DeleteUser` +- [x] 批量删除用户 `user.go@BatchDeleteUser` - [x] 获取用户信息 `user.go@GetUser` - [x] 获取部门用户详细信息 `user.go@GetDeptUserList` - [x] 获取部门用户 `user.go@GetDeptUserSimpleList` diff --git a/user.go b/user.go index a1f5ffe..bcc7a1b 100644 --- a/user.go +++ b/user.go @@ -6,6 +6,41 @@ import ( "strconv" ) +type CreateUserRequest struct { + UserId string `json:"userId"` + Name string `json:"name"` + Gender int `json:"gender"` + Mobile string `json:"mobile"` + Phone string `json:"phone"` + Email string `json:"email"` + Dept []int `json:"dept"` + EnableState EnableState `json:"enableState"` + ShortCode string `json:"shortCode"` +} + +type UpdateUserRequest struct { + UserId string `json:"userId"` + Name string `json:"name"` + Gender int `json:"gender"` + Mobile string `json:"mobile"` + Phone string `json:"phone"` + Email string `json:"email"` + Dept []int `json:"dept"` + ShortCode string `json:"shortCode"` +} + +type UpdateUserPositionRequest struct { + UserId string `json:"userId"` + DeptId int `json:"deptId"` + Position string `json:"position"` + Weight int `json:"weight"` + SortId int `json:"sortId"` +} + +type BatchDeleteUserRequest struct { + DelList []string `json:"delList"` +} + type DeptDetail struct { DeptId int `json:"deptId"` Position string `json:"position"` @@ -48,6 +83,81 @@ type UpdateUserEnableStateRequest struct { EnableState EnableState `json:"enableState"` } +func (c *Client) CreateUser(ctx context.Context, request CreateUserRequest) (response Response, err error) { + req, err := c.newRequest(ctx, http.MethodPost, "/cgi/user/create", + withRequestAccessToken(), + withRequestEncrypt(), + withRequestBody(request), + ) + + if err != nil { + return + } + + err = c.sendRequest(req, &response) + return +} + +func (c *Client) UpdateUser(ctx context.Context, request UpdateUserRequest) (response Response, err error) { + req, err := c.newRequest(ctx, http.MethodPost, "/cgi/user/update", + withRequestAccessToken(), + withRequestEncrypt(), + withRequestBody(request), + ) + + if err != nil { + return + } + + err = c.sendRequest(req, &response) + return +} + +func (c *Client) UpdateUserPosition(ctx context.Context, request UpdateUserPositionRequest) (response Response, err error) { + req, err := c.newRequest(ctx, http.MethodPost, "/cgi/user/positionupdate", + withRequestAccessToken(), + withRequestEncrypt(), + withRequestBody(request), + ) + + if err != nil { + return + } + + err = c.sendRequest(req, &response) + return +} + +func (c *Client) DeleteUser(ctx context.Context, userId string) (response Response, err error) { + req, err := c.newRequest(ctx, http.MethodPost, "/cgi/user/delete", + withRequestAccessToken(), + withRequestEncrypt(), + withRequestParamsKV("userId", userId), + ) + + if err != nil { + return + } + + err = c.sendRequest(req, &response) + return +} + +func (c *Client) BatchDeleteUser(ctx context.Context, request BatchDeleteUserRequest) (response Response, err error) { + req, err := c.newRequest(ctx, http.MethodPost, "/cgi/user/batchdelete", + withRequestAccessToken(), + withRequestEncrypt(), + withRequestBody(request), + ) + + if err != nil { + return + } + + err = c.sendRequest(req, &response) + return +} + func (c *Client) GetUser(ctx context.Context, userId string) (response UserResponse, err error) { req, err := c.newRequest(ctx, http.MethodGet, "/cgi/user/get", withRequestAccessToken(),