From 286616c13a45d6288391c7318723196d72d01460 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 9 Nov 2023 16:53:31 +0800 Subject: [PATCH] fix --- .../internal/logic/syncfeishugroupslogic.go | 6 +- utils/feishu/api.go | 191 ------------------ 2 files changed, 1 insertion(+), 196 deletions(-) diff --git a/server/feishu-sync/internal/logic/syncfeishugroupslogic.go b/server/feishu-sync/internal/logic/syncfeishugroupslogic.go index 8ab2800d..c37129f2 100644 --- a/server/feishu-sync/internal/logic/syncfeishugroupslogic.go +++ b/server/feishu-sync/internal/logic/syncfeishugroupslogic.go @@ -43,11 +43,7 @@ func (l *SyncFeiShuGroupsLogic) SyncFeiShuGroups(req *types.Request, userinfo *a if err != nil { log.Fatalln(err) } - users, err := feishuApi.FindUsersByDepartment(token.TenantAccessToken) - if err != nil { - log.Fatalln(err) - } - fmt.Println(users) + fmt.Println("token 信息:", token) return resp.SetStatus(basic.CodeOK) } diff --git a/utils/feishu/api.go b/utils/feishu/api.go index 4154c77b..2fb73963 100644 --- a/utils/feishu/api.go +++ b/utils/feishu/api.go @@ -38,194 +38,3 @@ func (f *FeiShuApi) GetTenantAccessToken() (resp GetTenantAccessTokenRsp, err er } return resp, nil } - -// 获取部门列表 -type GetDepartmentsFeiShuRsp struct { - Code int `json:"code"` - Msg string `json:"msg"` - Data struct { - HasMore bool `json:"has_more"` - PageToken string `json:"page_token"` - Items []DeptItem `json:"items"` - } `json:"data"` -} -type DeptItem struct { - Name string `json:"name"` - I18NName struct { - ZhCn string `json:"zh_cn"` - JaJp string `json:"ja_jp"` - EnUs string `json:"en_us"` - } `json:"i18n_name"` - ParentDepartmentId string `json:"parent_department_id"` - DepartmentId string `json:"department_id"` - OpenDepartmentId string `json:"open_department_id"` - LeaderUserId string `json:"leader_user_id"` - ChatId string `json:"chat_id"` - Order string `json:"order"` - UnitIds []string `json:"unit_ids"` - MemberCount int `json:"member_count"` - Status struct { - IsDeleted bool `json:"is_deleted"` - } `json:"status"` -} - -func (f *FeiShuApi) GetDepartments(tenantAccessToken string) (resp []DeptItem, err error) { - url := f.ApiHost + "/open-apis/contact/v3/departments" - header := map[string]string{ - "Content-Type": "application/json; charset=utf-8", - "Authorization": "Bearer " + tenantAccessToken, - } - req := map[string]interface{}{ - "fetch_child": true, - "page_token": "", - "page_size": 50, - "department_id": "0", - } - for { - postData, _ := json.Marshal(req) - //先不循环 - requestRsp, err := curl.ApiCall2(url, "GET", header, bytes.NewReader(postData), time.Second*15) - if err != nil { - return nil, err - } - var parseData GetDepartmentsFeiShuRsp - if err = json.Unmarshal(requestRsp, &parseData); err != nil { - return nil, err - } - resp = append(resp, parseData.Data.Items...) - if !parseData.Data.HasMore { - break - } - req["page_token"] = parseData.Data.PageToken - } - return resp, nil -} - -// 获取部门直属用户列表 -type FindUsersByDepartmentFeiShuRsp struct { - Code int `json:"code"` - Msg string `json:"msg"` - Data struct { - HasMore bool `json:"has_more"` - PageToken string `json:"page_token"` - Items []UserItems `json:"items"` - } `json:"data"` -} -type UserItems struct { - UnionId string `json:"union_id"` - UserId string `json:"user_id"` - OpenId string `json:"open_id"` - Name string `json:"name"` - EnName string `json:"en_name"` - Nickname string `json:"nickname"` - Email string `json:"email"` - Mobile string `json:"mobile"` - MobileVisible bool `json:"mobile_visible"` - Gender int `json:"gender"` - AvatarKey string `json:"avatar_key"` - Avatar struct { - Avatar72 string `json:"avatar_72"` - Avatar240 string `json:"avatar_240"` - Avatar640 string `json:"avatar_640"` - AvatarOrigin string `json:"avatar_origin"` - } `json:"avatar"` - Status struct { - IsFrozen bool `json:"is_frozen"` - IsResigned bool `json:"is_resigned"` - IsActivated bool `json:"is_activated"` - IsExited bool `json:"is_exited"` - IsUnjoin bool `json:"is_unjoin"` - } `json:"status"` - DepartmentIds []string `json:"department_ids"` - LeaderUserId string `json:"leader_user_id"` - City string `json:"city"` - Country string `json:"country"` - WorkStation string `json:"work_station"` - JoinTime int `json:"join_time"` - IsTenantManager bool `json:"is_tenant_manager"` - EmployeeNo string `json:"employee_no"` - EmployeeType int `json:"employee_type"` - Orders []struct { - DepartmentId string `json:"department_id"` - UserOrder int `json:"user_order"` - DepartmentOrder int `json:"department_order"` - IsPrimaryDept bool `json:"is_primary_dept"` - } `json:"orders"` - CustomAttrs []struct { - Type string `json:"type"` - Id string `json:"id"` - Value struct { - Text string `json:"text"` - Url string `json:"url"` - PcUrl string `json:"pc_url"` - OptionId string `json:"option_id"` - OptionValue string `json:"option_value"` - Name string `json:"name"` - PictureUrl string `json:"picture_url"` - GenericUser struct { - Id string `json:"id"` - Type int `json:"type"` - } `json:"generic_user"` - } `json:"value"` - } `json:"custom_attrs"` - EnterpriseEmail string `json:"enterprise_email"` - JobTitle string `json:"job_title"` - IsFrozen bool `json:"is_frozen"` - Geo string `json:"geo"` - JobLevelId string `json:"job_level_id"` - JobFamilyId string `json:"job_family_id"` - DepartmentPath []struct { - DepartmentId string `json:"department_id"` - DepartmentName struct { - Name string `json:"name"` - I18NName struct { - ZhCn string `json:"zh_cn"` - JaJp string `json:"ja_jp"` - EnUs string `json:"en_us"` - } `json:"i18n_name"` - } `json:"department_name"` - DepartmentPath struct { - DepartmentIds []string `json:"department_ids"` - DepartmentPathName struct { - Name string `json:"name"` - I18NName struct { - ZhCn string `json:"zh_cn"` - JaJp string `json:"ja_jp"` - EnUs string `json:"en_us"` - } `json:"i18n_name"` - } `json:"department_path_name"` - } `json:"department_path"` - } `json:"department_path"` - DottedLineLeaderUserIds []string `json:"dotted_line_leader_user_ids"` -} - -func (f *FeiShuApi) FindUsersByDepartment(tenantAccessToken string) (resp []UserItems, err error) { - url := f.ApiHost + "/open-apis/contact/v3/users/find_by_department" - header := map[string]string{ - "Content-Type": "application/json; charset=utf-8", - "Authorization": "Bearer " + tenantAccessToken, - } - req := map[string]interface{}{ - "page_token": "", - "page_size": 50, - "department_id": "0", - } - for { - postData, _ := json.Marshal(req) - //先不循环 - requestRsp, err := curl.ApiCall2(url, "GET", header, bytes.NewReader(postData), time.Second*15) - if err != nil { - return nil, err - } - var parseData FindUsersByDepartmentFeiShuRsp - if err = json.Unmarshal(requestRsp, &parseData); err != nil { - return nil, err - } - resp = append(resp, parseData.Data.Items...) - if !parseData.Data.HasMore { - break - } - req["page_token"] = parseData.Data.PageToken - } - return resp, nil -}