gitee.com/larksuite/oapi-sdk-go/v3@v3.0.3/service/ehr/v1/api.go (about)

     1  // Package ehr code generated by oapi sdk gen
     2  /*
     3   * MIT License
     4   *
     5   * Copyright (c) 2022 Lark Technologies Pte. Ltd.
     6   *
     7   * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
     8   *
     9   * The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software.
    10   *
    11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    12   */
    13  
    14  package larkehr
    15  
    16  import (
    17  	"bytes"
    18  	"context"
    19  	"net/http"
    20  
    21  	"gitee.com/larksuite/oapi-sdk-go/v3/core"
    22  )
    23  
    24  func NewService(config *larkcore.Config) *EhrService {
    25  	e := &EhrService{config: config}
    26  	e.Attachment = &attachment{service: e}
    27  	e.Employee = &employee{service: e}
    28  	return e
    29  }
    30  
    31  type EhrService struct {
    32  	config     *larkcore.Config
    33  	Attachment *attachment // 附件
    34  	Employee   *employee   // 员工
    35  }
    36  
    37  type attachment struct {
    38  	service *EhrService
    39  }
    40  type employee struct {
    41  	service *EhrService
    42  }
    43  
    44  // 下载附件
    45  //
    46  // - 根据文件 token 下载文件。;;调用 「批量获取员工花名册信息」接口的返回值中,「文件」类型的字段 id,即是文件 token
    47  //
    48  // - ![image.png](//sf1-ttcdn-tos.pstatp.com/obj/open-platform-opendoc/bed391d2a8ce6ed2d5985ea69bf92850_9GY1mnuDXP.png)
    49  //
    50  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/ehr/ehr-v1/attachment/get
    51  //
    52  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/ehrv1/get_attachment.go
    53  func (a *attachment) Get(ctx context.Context, req *GetAttachmentReq, options ...larkcore.RequestOptionFunc) (*GetAttachmentResp, error) {
    54  	// 发起请求
    55  	apiReq := req.apiReq
    56  	apiReq.ApiPath = "/open-apis/ehr/v1/attachments/:token"
    57  	apiReq.HttpMethod = http.MethodGet
    58  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
    59  	apiResp, err := larkcore.Request(ctx, apiReq, a.service.config, options...)
    60  	if err != nil {
    61  		return nil, err
    62  	}
    63  	// 反序列响应结果
    64  	resp := &GetAttachmentResp{ApiResp: apiResp}
    65  	// 如果是下载,则设置响应结果
    66  	if apiResp.StatusCode == http.StatusOK {
    67  		resp.File = bytes.NewBuffer(apiResp.RawBody)
    68  		resp.FileName = larkcore.FileNameByHeader(apiResp.Header)
    69  		return resp, err
    70  	}
    71  	err = apiResp.JSONUnmarshalBody(resp)
    72  	if err != nil {
    73  		return nil, err
    74  	}
    75  	return resp, err
    76  }
    77  
    78  // 批量获取员工花名册信息
    79  //
    80  // - 根据员工飞书用户 ID / 员工状态 / 雇员类型等搜索条件 ,批量获取员工花名册字段信息。字段包括「系统标准字段 / system_fields」和「自定义字段 / custom_fields」
    81  //
    82  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/ehr/ehr-v1/employee/list
    83  //
    84  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/ehrv1/list_employee.go
    85  func (e *employee) List(ctx context.Context, req *ListEmployeeReq, options ...larkcore.RequestOptionFunc) (*ListEmployeeResp, error) {
    86  	// 发起请求
    87  	apiReq := req.apiReq
    88  	apiReq.ApiPath = "/open-apis/ehr/v1/employees"
    89  	apiReq.HttpMethod = http.MethodGet
    90  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
    91  	apiResp, err := larkcore.Request(ctx, apiReq, e.service.config, options...)
    92  	if err != nil {
    93  		return nil, err
    94  	}
    95  	// 反序列响应结果
    96  	resp := &ListEmployeeResp{ApiResp: apiResp}
    97  	err = apiResp.JSONUnmarshalBody(resp)
    98  	if err != nil {
    99  		return nil, err
   100  	}
   101  	return resp, err
   102  }
   103  func (e *employee) ListByIterator(ctx context.Context, req *ListEmployeeReq, options ...larkcore.RequestOptionFunc) (*ListEmployeeIterator, error) {
   104  	return &ListEmployeeIterator{
   105  		ctx:      ctx,
   106  		req:      req,
   107  		listFunc: e.List,
   108  		options:  options,
   109  		limit:    req.Limit}, nil
   110  }