open-lark 0.14.0

Enterprise-grade Lark/Feishu Open API SDK with comprehensive Chinese documentation and advanced error handling
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
use reqwest::Method;
use serde::{Deserialize, Serialize};

use crate::{
    core::{
        api_req::ApiRequest,
        api_resp::{ApiResponseTrait, BaseResponse, ResponseFormat},
        config::Config,
        constants::AccessTokenType,
        endpoints::corehr::*,
        http::Transport,
        req_option::RequestOption,
        SDKResult,
    },
    service::corehr::models::{
        JobChange, JobChangeCreateRequest, JobChangeSearchRequest, Offboarding,
        OffboardingCreateRequest, OffboardingSearchRequest, PageResponse, PreHire,
        PreHireCreateRequest, PreHireSearchRequest,
    },
};

/// 员工生命周期管理服务(入职/离职/异动)
pub struct LifecycleService {
    pub config: Config,
}

/// 创建待入职响应
#[derive(Debug, Serialize, Deserialize)]
pub struct PreHireCreateResponse {
    /// 待入职信息
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pre_hire: Option<PreHire>,
}

impl ApiResponseTrait for PreHireCreateResponse {
    fn data_format() -> ResponseFormat {
        ResponseFormat::Data
    }
}

/// 搜索待入职响应
#[derive(Debug, Serialize, Deserialize)]
pub struct PreHireSearchResponse {
    /// 待入职信息列表
    #[serde(flatten)]
    pub pre_hires: PageResponse<PreHire>,
}

impl ApiResponseTrait for PreHireSearchResponse {
    fn data_format() -> ResponseFormat {
        ResponseFormat::Data
    }
}

/// 发起异动响应
#[derive(Debug, Serialize, Deserialize)]
pub struct JobChangeCreateResponse {
    /// 异动信息
    #[serde(skip_serializing_if = "Option::is_none")]
    pub job_change: Option<JobChange>,
}

impl ApiResponseTrait for JobChangeCreateResponse {
    fn data_format() -> ResponseFormat {
        ResponseFormat::Data
    }
}

/// 搜索异动响应
#[derive(Debug, Serialize, Deserialize)]
pub struct JobChangeSearchResponse {
    /// 异动信息列表
    #[serde(flatten)]
    pub job_changes: PageResponse<JobChange>,
}

impl ApiResponseTrait for JobChangeSearchResponse {
    fn data_format() -> ResponseFormat {
        ResponseFormat::Data
    }
}

/// 发起离职响应
#[derive(Debug, Serialize, Deserialize)]
pub struct OffboardingCreateResponse {
    /// 离职信息
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offboarding: Option<Offboarding>,
}

impl ApiResponseTrait for OffboardingCreateResponse {
    fn data_format() -> ResponseFormat {
        ResponseFormat::Data
    }
}

/// 搜索离职响应
#[derive(Debug, Serialize, Deserialize)]
pub struct OffboardingSearchResponse {
    /// 离职信息列表
    #[serde(flatten)]
    pub offboardings: PageResponse<Offboarding>,
}

impl ApiResponseTrait for OffboardingSearchResponse {
    fn data_format() -> ResponseFormat {
        ResponseFormat::Data
    }
}

impl LifecycleService {
    pub fn new(config: Config) -> Self {
        Self { config }
    }

    /// 直接创建待入职
    ///
    /// 该接口用于直接创建待入职人员信息,适用于已确定招聘的候选人
    /// 创建入职流程,包含完整的个人信息和任职安排。
    ///
    /// # 参数
    ///
    /// - `request`: 创建待入职请求参数
    /// - `option`: 可选的请求配置
    ///
    /// # 返回值
    ///
    /// 返回创建的待入职信息,包括:
    /// - 待入职ID和状态
    /// - 员工基本信息
    /// - 入职流程信息
    ///
    /// # 示例
    ///
    /// ```ignore
    /// use open_lark::service::corehr::models::{
    ///     PreHireCreateRequest, Person, Employment, I18nText
    /// };
    ///
    /// let request = PreHireCreateRequest {
    ///     person: Person {
    ///         name: Some(I18nText {
    ///             zh_cn: Some("张三".to_string()),
    ///             en_us: Some("Zhang San".to_string()),
    ///         }),
    ///         email: Some("zhangsan@example.com".to_string()),
    ///         phone: Some("13800138000".to_string()),
    ///         ..Default::default()
    ///     },
    ///     employment: Employment {
    ///         hire_date: Some("2024-03-01".to_string()),
    ///         employment_type: Some("full_time".to_string()),
    ///         ..Default::default()
    ///     },
    ///     job_datas: None,
    ///     onboarding_flow_id: Some("flow_123".to_string()),
    ///     expected_hire_date: Some("2024-03-01".to_string()),
    ///     custom_fields: None,
    /// };
    ///
    /// let response = client.corehr.lifecycle.create_pre_hire(request, None).await?;
    /// ```
    pub async fn create_pre_hire(
        &self,
        request: PreHireCreateRequest,
        option: Option<RequestOption>,
    ) -> SDKResult<BaseResponse<PreHireCreateResponse>> {
        let api_req = ApiRequest {
            http_method: Method::POST,
            api_path: COREHR_PRE_HIRES.to_string(),
            supported_access_token_types: vec![AccessTokenType::Tenant],
            body: serde_json::to_vec(&request).unwrap_or_default(),
            ..Default::default()
        };

        // Content-Type 由 Transport 层自动设置

        Transport::request(api_req, &self.config, option).await
    }

    /// 搜索待入职信息
    ///
    /// 该接口用于根据多种条件搜索待入职人员信息,支持按入职状态、
    /// 部门等条件进行筛选,并支持分页查询。
    ///
    /// # 参数
    ///
    /// - `request`: 搜索请求参数
    /// - `option`: 可选的请求配置
    ///
    /// # 返回值
    ///
    /// 返回分页的待入职信息列表,包括:
    /// - 符合条件的待入职人员列表
    /// - 入职状态和进度信息
    /// - 分页信息
    ///
    /// # 示例
    ///
    /// ```ignore
    /// use open_lark::service::corehr::models::PreHireSearchRequest;
    ///
    /// let request = PreHireSearchRequest {
    ///     page_size: Some(50),
    ///     page_token: None,
    ///     user_id_type: Some("open_id".to_string()),
    ///     employee_id_type: Some("employee_id".to_string()),
    ///     department_id_type: Some("open_department_id".to_string()),
    ///     onboarding_status: Some(vec!["pending".to_string(), "in_progress".to_string()]),
    ///     department_ids: Some(vec!["dept_123".to_string()]),
    /// };
    ///
    /// let response = client.corehr.lifecycle.search_pre_hire(request, None).await?;
    /// ```
    pub async fn search_pre_hire(
        &self,
        request: PreHireSearchRequest,
        option: Option<RequestOption>,
    ) -> SDKResult<BaseResponse<PreHireSearchResponse>> {
        let api_req = ApiRequest {
            http_method: Method::POST,
            api_path: COREHR_PRE_HIRES_SEARCH.to_string(),
            supported_access_token_types: vec![AccessTokenType::Tenant],
            body: serde_json::to_vec(&request).unwrap_or_default(),
            ..Default::default()
        };

        // Content-Type 由 Transport 层自动设置

        Transport::request(api_req, &self.config, option).await
    }

    /// 发起员工异动
    ///
    /// 该接口用于发起员工异动流程,包括调岗、调薪、晋升等各种
    /// 人事变动,支持设置新的任职信息和生效日期。
    ///
    /// # 参数
    ///
    /// - `request`: 异动发起请求参数
    /// - `option`: 可选的请求配置
    ///
    /// # 返回值
    ///
    /// 返回创建的异动信息,包括:
    /// - 异动ID和状态
    /// - 异动类型和原因
    /// - 原任职信息和新任职信息
    ///
    /// # 示例
    ///
    /// ```ignore
    /// use open_lark::service::corehr::models::{JobChangeCreateRequest, JobData};
    ///
    /// let request = JobChangeCreateRequest {
    ///     employee_id: "emp_123".to_string(),
    ///     job_change_type_id: "promotion".to_string(),
    ///     job_change_reason_id: Some("performance_excellent".to_string()),
    ///     effective_date: "2024-04-01".to_string(),
    ///     job_data: JobData {
    ///         job_id: Some("senior_engineer".to_string()),
    ///         job_level_id: Some("P7".to_string()),
    ///         department_id: Some("tech_dept".to_string()),
    ///         ..Default::default()
    ///     },
    ///     comments: Some("优秀员工晋升".to_string()),
    ///     custom_fields: None,
    /// };
    ///
    /// let response = client.corehr.lifecycle.create_job_change(request, None).await?;
    /// ```
    pub async fn create_job_change(
        &self,
        request: JobChangeCreateRequest,
        option: Option<RequestOption>,
    ) -> SDKResult<BaseResponse<JobChangeCreateResponse>> {
        let api_req = ApiRequest {
            http_method: Method::POST,
            api_path: COREHR_JOB_CHANGES.to_string(),
            supported_access_token_types: vec![AccessTokenType::Tenant],
            body: serde_json::to_vec(&request).unwrap_or_default(),
            ..Default::default()
        };

        // Content-Type 由 Transport 层自动设置

        Transport::request(api_req, &self.config, option).await
    }

    /// 搜索员工异动信息
    ///
    /// 该接口用于根据多种条件搜索员工异动信息,支持按异动状态、
    /// 异动类型、员工等条件进行筛选,并支持分页查询。
    ///
    /// # 参数
    ///
    /// - `request`: 搜索请求参数
    /// - `option`: 可选的请求配置
    ///
    /// # 返回值
    ///
    /// 返回分页的异动信息列表,包括:
    /// - 符合条件的异动记录列表
    /// - 异动详细信息和状态
    /// - 分页信息
    ///
    /// # 示例
    ///
    /// ```ignore
    /// use open_lark::service::corehr::models::JobChangeSearchRequest;
    ///
    /// let request = JobChangeSearchRequest {
    ///     page_size: Some(50),
    ///     page_token: None,
    ///     user_id_type: Some("open_id".to_string()),
    ///     employee_id_type: Some("employee_id".to_string()),
    ///     department_id_type: Some("open_department_id".to_string()),
    ///     employee_ids: Some(vec!["emp_123".to_string()]),
    ///     job_change_status: Some(vec!["approved".to_string(), "pending".to_string()]),
    ///     job_change_type_ids: Some(vec!["promotion".to_string(), "transfer".to_string()]),
    /// };
    ///
    /// let response = client.corehr.lifecycle.search_job_change(request, None).await?;
    /// ```
    pub async fn search_job_change(
        &self,
        request: JobChangeSearchRequest,
        option: Option<RequestOption>,
    ) -> SDKResult<BaseResponse<JobChangeSearchResponse>> {
        let api_req = ApiRequest {
            http_method: Method::POST,
            api_path: COREHR_JOB_CHANGES_SEARCH.to_string(),
            supported_access_token_types: vec![AccessTokenType::Tenant],
            body: serde_json::to_vec(&request).unwrap_or_default(),
            ..Default::default()
        };

        // Content-Type 由 Transport 层自动设置

        Transport::request(api_req, &self.config, option).await
    }

    /// 操作员工离职
    ///
    /// 该接口用于发起员工离职流程,包括主动离职、辞退等各种
    /// 离职类型,支持设置离职原因和离职日期。
    ///
    /// # 参数
    ///
    /// - `request`: 离职发起请求参数
    /// - `option`: 可选的请求配置
    ///
    /// # 返回值
    ///
    /// 返回创建的离职信息,包括:
    /// - 离职ID和状态
    /// - 离职原因和类型
    /// - 离职日期
    ///
    /// # 示例
    ///
    /// ```ignore
    /// use open_lark::service::corehr::models::OffboardingCreateRequest;
    ///
    /// let request = OffboardingCreateRequest {
    ///     employee_id: "emp_123".to_string(),
    ///     offboarding_reason_id: "personal_reason".to_string(),
    ///     offboarding_date: "2024-05-31".to_string(),
    ///     offboarding_type: Some("voluntary".to_string()),
    ///     comments: Some("个人发展需要".to_string()),
    ///     custom_fields: None,
    /// };
    ///
    /// let response = client.corehr.lifecycle.create_offboarding(request, None).await?;
    /// ```
    pub async fn create_offboarding(
        &self,
        request: OffboardingCreateRequest,
        option: Option<RequestOption>,
    ) -> SDKResult<BaseResponse<OffboardingCreateResponse>> {
        let api_req = ApiRequest {
            http_method: Method::POST,
            api_path: COREHR_OFFBOARDINGS.to_string(),
            supported_access_token_types: vec![AccessTokenType::Tenant],
            body: serde_json::to_vec(&request).unwrap_or_default(),
            ..Default::default()
        };

        // Content-Type 由 Transport 层自动设置

        Transport::request(api_req, &self.config, option).await
    }

    /// 搜索离职信息
    ///
    /// 该接口用于根据多种条件搜索员工离职信息,支持按离职状态、
    /// 离职原因、员工等条件进行筛选,并支持分页查询。
    ///
    /// # 参数
    ///
    /// - `request`: 搜索请求参数
    /// - `option`: 可选的请求配置
    ///
    /// # 返回值
    ///
    /// 返回分页的离职信息列表,包括:
    /// - 符合条件的离职记录列表
    /// - 离职详细信息和状态
    /// - 分页信息
    ///
    /// # 示例
    ///
    /// ```ignore
    /// use open_lark::service::corehr::models::OffboardingSearchRequest;
    ///
    /// let request = OffboardingSearchRequest {
    ///     page_size: Some(50),
    ///     page_token: None,
    ///     user_id_type: Some("open_id".to_string()),
    ///     employee_id_type: Some("employee_id".to_string()),
    ///     department_id_type: Some("open_department_id".to_string()),
    ///     employee_ids: Some(vec!["emp_123".to_string()]),
    ///     offboarding_status: Some(vec!["approved".to_string(), "pending".to_string()]),
    ///     offboarding_reason_ids: Some(vec!["personal_reason".to_string()]),
    /// };
    ///
    /// let response = client.corehr.lifecycle.search_offboarding(request, None).await?;
    /// ```
    pub async fn search_offboarding(
        &self,
        request: OffboardingSearchRequest,
        option: Option<RequestOption>,
    ) -> SDKResult<BaseResponse<OffboardingSearchResponse>> {
        let api_req = ApiRequest {
            http_method: Method::POST,
            api_path: COREHR_OFFBOARDINGS_SEARCH.to_string(),
            supported_access_token_types: vec![AccessTokenType::Tenant],
            body: serde_json::to_vec(&request).unwrap_or_default(),
            ..Default::default()
        };

        // Content-Type 由 Transport 层自动设置

        Transport::request(api_req, &self.config, option).await
    }
}