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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
//! 飞书发薪(Payroll)服务
//!
//! 提供飞书发薪的完整功能集,支持发薪活动管理、发薪明细查询、算薪项配置、
//! 成本分摊、薪资组管理等企业级薪酬管理能力。是企业薪酬体系的核心基础。
//!
//! # 核心功能
//!
//! ## 发薪活动管理
//! - 💰 发薪活动创建和管理
//! - 📊 发薪状态跟踪监控
//! - 🔒 发薪活动封存处理
//! - 📈 发薪数据统计分析
//! - 🔄 发薪流程自动化
//!
//! ## 发薪明细查询
//! - 📋 发薪明细批量查询
//! - 🔍 多维度筛选和检索
//! - 📊 薪资结构分析展示
//! - 📈 发薪数据统计汇总
//! - 📱 移动端明细查看
//!
//! ## 算薪项配置
//! - ⚙️ 算薪项参数配置管理
//! - 📊 算薪项批量查询
//! - 🔢 薪酬计算规则设置
//! - 📋 算薪项目分类管理
//! - 🔄 算薪逻辑优化调整
//!
//! ## 外部数据源管理
//! - 🔗 外部算薪数据集成
//! - 📊 数据源记录管理
//! - 🔄 数据同步和更新
//! - 📋 数据源配置信息
//! - 🛡️ 数据安全和验证
//!
//! ## 成本分摊管理
//! - 📊 成本分摊报表生成
//! - 🎯 成本分摊方案管理
//! - 📈 成本分摊规则配置
//! - 💼 成本中心分配
//! - 📋 分摊数据统计分析
//!
//! ## 薪资组管理
//! - 👥 薪资组基本信息管理
//! - ⚙️ 薪资组配置和设置
//! - 📊 薪资组统计分析
//! - 🔄 薪资组调整和优化
//! - 📋 薪资组成员管理
//!
//! # 使用示例
//!
//! ```rust
//! use open_lark::prelude::*;
//!
//! let client = LarkClient::builder("app_id", "app_secret")
//!     .with_app_type(AppType::SelfBuild)
//!     .build();
//!
//! // 获取发薪服务
//! let payroll = &client.payroll;
//!
//! // 查询发薪活动
//! // let activity_request = ListPaymentActivityRequest::builder()
//! //     .page_size(50)
//! //     .status("active")
//! //     .year("2024")
//! //     .build();
//! // let activities = payroll.payment_activity.list(activity_request, None).await?;
//!
//! // 查询发薪明细
//! // let detail_request = ListPaymentDetailRequest::builder()
//! //     .payment_activity_id("activity_123")
//! //     .employee_id("emp_456")
//! //     .page_size(100)
//! //     .build();
//! // let details = payroll.payment_detail.list(detail_request, None).await?;
//!
//! // 查询算薪项
//! // let acct_request = ListAcctItemRequest::builder()
//! //     .paygroup_id("paygroup_789")
//! //     .category("basic_salary")
//! //     .build();
//! // let acct_items = payroll.acct_item.list(acct_request, None).await?;
//!
//! // 查询成本分摊报表
//! // let report_request = ListCostAllocationReportRequest::builder()
//! //     .start_date("2024-01-01")
//! //     .end_date("2024-12-31")
//! //     .cost_center_id("cc_123")
//! //     .build();
//! // let reports = payroll.cost_allocation_report.list(report_request, None).await?;
//!
//! // 管理外部数据源
//! // let datasource_request = CreateDatasourceRecordRequest::builder()
//! //     .datasource_id("ds_456")
//! //     .employee_id("emp_789")
//! //     .data(serde_json::json!({
//! //         "bonus": 5000,
//! //         "allowance": 1000
//! //     }))
//! //     .build();
//! // payroll.datasource_record.create(datasource_request, None).await?;
//! ```
//!
//! # 薪酬管理特性
//!
//! - 💰 完整的薪酬管理体系
//! - 📊 精准的成本分摊机制
//! - 🔗 灵活的外部数据集成
//! - 📋 标准化的薪酬处理流程
//! - 🛡️ 严格的数据安全保护
//!
//! # 企业应用
//!
//! - 💼 企业薪酬管理系统
//! - 📊 财务成本分析报告
//! - 🔗 HR系统数据集成
//! - 📋 合规性管理支持
//! - 📈 薪酬数据分析洞察

pub mod acct_item;
pub mod cost_allocation_plan;
pub mod cost_allocation_report;
pub mod datasource;
pub mod datasource_record;
pub mod models;
pub mod paygroup;
pub mod payment_activity;
pub mod payment_detail;
pub mod v1;

use crate::core::config::Config;

use acct_item::AcctItemService;
use cost_allocation_plan::CostAllocationPlanService;
use cost_allocation_report::CostAllocationReportService;
use datasource::DatasourceService;
use datasource_record::DatasourceRecordService;
use paygroup::PaygroupService;
use payment_activity::PaymentActivityService;
use payment_detail::PaymentDetailService;

/// 飞书发薪服务
///
/// 飞书发薪为企业提供了完整的薪酬管理和发薪处理功能,包括发薪活动管理、
/// 发薪明细查询、算薪项配置、成本分摊等核心功能。本服务封装了相关API接口,支持:
///
/// ## 主要功能
///
/// ### 发薪明细管理
/// - 查询发薪活动明细列表
/// - 批量查询发薪明细
/// - 支持多维度筛选和分页查询
///
/// ### 发薪活动管理
/// - 查询发薪活动列表
/// - 封存发薪活动
/// - 发薪活动状态变更监听
///
/// ### 外部数据源管理
/// - 创建/更新外部算薪数据
/// - 批量查询外部算薪数据记录
/// - 获取外部数据源配置信息
///
/// ### 算薪项配置
/// - 批量查询算薪项
/// - 算薪项参数配置
///
/// ### 成本分摊管理
/// - 查询成本分摊报表汇总数据
/// - 批量查询成本分摊方案
/// - 成本分摊规则配置
///
/// ### 薪资组管理
/// - 获取薪资组基本信息
/// - 薪资组配置管理
///
/// ## 使用场景
///
/// - **薪酬管理系统**: 与第三方薪酬系统集成发薪数据
/// - **财务报表**: 基于发薪数据生成财务和成本分摊报表
/// - **合规管理**: 确保发薪流程符合法规要求
/// - **成本控制**: 通过成本分摊实现精细化成本管理
/// - **薪酬分析**: 分析薪酬结构和发薪趋势
///
/// ## 权限要求
///
/// 使用本服务需要相应的应用权限:
/// - `payroll:payment_detail`: 发薪明细查询权限
/// - `payroll:payment_activity`: 发薪活动管理权限
/// - `payroll:datasource`: 外部数据源管理权限
/// - `payroll:acct_item`: 算薪项查询权限
/// - `payroll:cost_allocation`: 成本分摊查询权限
/// - `payroll:paygroup`: 薪资组查询权限
///
/// ## 示例用法
///
/// ```ignore
/// use open_lark::prelude::*;
/// use open_lark::service::payroll::models::*;
///
/// // 创建客户端
/// let client = LarkClient::builder(app_id, app_secret)
///     .with_app_type(AppType::SelfBuild)
///     .build();
///
/// // 查询发薪活动列表
/// let activity_request = PaymentActivityListRequest {
///     page_size: Some(50),
///     page_token: None,
///     status: Some("active".to_string()),
///     ..Default::default()
/// };
///
/// let activities = client.payroll.payment_activity.list_activities(activity_request, None).await?;
///
/// // 查询发薪明细
/// let detail_request = PaymentDetailListRequest {
///     payment_activity_id: "activity_123".to_string(),
///     page_size: Some(100),
///     employee_id: Some("emp_456".to_string()),
///     ..Default::default()
/// };
///
/// let details = client.payroll.payment_detail.list_details(detail_request, None).await?;
///
/// // 查询成本分摊报表
/// let report_request = CostAllocationReportListRequest {
///     start_date: "2024-01-01".to_string(),
///     end_date: "2024-12-31".to_string(),
///     cost_center_id: Some("cc_789".to_string()),
///     ..Default::default()
/// };
///
/// let reports = client.payroll.cost_allocation_report.list_reports(report_request, None).await?;
/// ```
pub struct PayrollService {
    /// 发薪明细服务
    pub payment_detail: PaymentDetailService,
    /// 发薪活动服务
    pub payment_activity: PaymentActivityService,
    /// 外部数据源记录服务
    pub datasource_record: DatasourceRecordService,
    /// 外部数据源服务
    pub datasource: DatasourceService,
    /// 算薪项服务
    pub acct_item: AcctItemService,
    /// 成本分摊报表服务
    pub cost_allocation_report: CostAllocationReportService,
    /// 成本分摊方案服务
    pub cost_allocation_plan: CostAllocationPlanService,
    /// 薪资组服务
    pub paygroup: PaygroupService,
}

impl PayrollService {
    pub fn new(config: Config) -> Self {
        Self {
            payment_detail: PaymentDetailService::new(config.clone()),
            payment_activity: PaymentActivityService::new(config.clone()),
            datasource_record: DatasourceRecordService::new(config.clone()),
            datasource: DatasourceService::new(config.clone()),
            acct_item: AcctItemService::new(config.clone()),
            cost_allocation_report: CostAllocationReportService::new(config.clone()),
            cost_allocation_plan: CostAllocationPlanService::new(config.clone()),
            paygroup: PaygroupService::new(config),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::time::Duration;

    #[test]
    fn test_payroll_service_creation() {
        let config = Config::default();
        let service = PayrollService::new(config.clone());

        assert_eq!(service.payment_detail.config.app_id, config.app_id);
        assert_eq!(service.payment_detail.config.app_secret, config.app_secret);
        assert_eq!(service.payment_activity.config.app_id, config.app_id);
        assert_eq!(service.datasource_record.config.app_id, config.app_id);
        assert_eq!(service.datasource.config.app_id, config.app_id);
        assert_eq!(service.acct_item.config.app_id, config.app_id);
        assert_eq!(service.cost_allocation_report.config.app_id, config.app_id);
        assert_eq!(service.cost_allocation_plan.config.app_id, config.app_id);
        assert_eq!(service.paygroup.config.app_id, config.app_id);
    }

    #[test]
    fn test_payroll_service_with_custom_config() {
        let config = Config::builder()
            .app_id("payroll_test_app")
            .app_secret("payroll_test_secret")
            .req_timeout(Duration::from_secs(240))
            .build();

        let service = PayrollService::new(config.clone());

        assert_eq!(service.payment_detail.config.app_id, "payroll_test_app");
        assert_eq!(
            service.payment_detail.config.app_secret,
            "payroll_test_secret"
        );
        assert_eq!(
            service.payment_detail.config.req_timeout,
            Some(Duration::from_secs(240))
        );
        assert_eq!(service.payment_activity.config.app_id, "payroll_test_app");
        assert_eq!(
            service.datasource.config.req_timeout,
            Some(Duration::from_secs(240))
        );
        assert_eq!(service.acct_item.config.app_secret, "payroll_test_secret");
        assert_eq!(
            service.cost_allocation_report.config.req_timeout,
            Some(Duration::from_secs(240))
        );
        assert_eq!(service.paygroup.config.app_id, "payroll_test_app");
    }

    #[test]
    fn test_payroll_service_config_independence() {
        let config1 = Config::builder().app_id("payroll_app_1").build();

        let config2 = Config::builder().app_id("payroll_app_2").build();

        let service1 = PayrollService::new(config1);
        let service2 = PayrollService::new(config2);

        assert_eq!(service1.payment_detail.config.app_id, "payroll_app_1");
        assert_eq!(service2.payment_detail.config.app_id, "payroll_app_2");
        assert_ne!(
            service1.payment_detail.config.app_id,
            service2.payment_detail.config.app_id
        );
        assert_ne!(
            service1.datasource.config.app_id,
            service2.paygroup.config.app_id
        );
    }

    #[test]
    fn test_payroll_service_sub_services_accessible() {
        let config = Config::default();
        let service = PayrollService::new(config.clone());

        assert_eq!(service.payment_detail.config.app_id, config.app_id);
        assert_eq!(service.payment_activity.config.app_id, config.app_id);
        assert_eq!(service.datasource_record.config.app_id, config.app_id);
        assert_eq!(service.datasource.config.app_id, config.app_id);
        assert_eq!(service.acct_item.config.app_id, config.app_id);
        assert_eq!(service.cost_allocation_report.config.app_id, config.app_id);
        assert_eq!(service.cost_allocation_plan.config.app_id, config.app_id);
        assert_eq!(service.paygroup.config.app_id, config.app_id);
    }

    #[test]
    fn test_payroll_service_config_cloning() {
        let config = Config::builder()
            .app_id("clone_test_app")
            .app_secret("clone_test_secret")
            .build();

        let service = PayrollService::new(config.clone());

        assert_eq!(service.payment_detail.config.app_id, "clone_test_app");
        assert_eq!(
            service.payment_detail.config.app_secret,
            "clone_test_secret"
        );
        assert_eq!(
            service.payment_activity.config.app_secret,
            "clone_test_secret"
        );
        assert_eq!(service.datasource_record.config.app_id, "clone_test_app");
        assert_eq!(service.datasource.config.app_secret, "clone_test_secret");
        assert_eq!(service.acct_item.config.app_id, "clone_test_app");
        assert_eq!(
            service.cost_allocation_plan.config.app_secret,
            "clone_test_secret"
        );
        assert_eq!(service.paygroup.config.app_id, "clone_test_app");
    }

    #[test]
    fn test_payroll_service_timeout_propagation() {
        let config = Config::builder()
            .req_timeout(Duration::from_secs(220))
            .build();

        let service = PayrollService::new(config);

        assert_eq!(
            service.payment_detail.config.req_timeout,
            Some(Duration::from_secs(220))
        );
        assert_eq!(
            service.payment_activity.config.req_timeout,
            Some(Duration::from_secs(220))
        );
        assert_eq!(
            service.datasource_record.config.req_timeout,
            Some(Duration::from_secs(220))
        );
        assert_eq!(
            service.datasource.config.req_timeout,
            Some(Duration::from_secs(220))
        );
        assert_eq!(
            service.acct_item.config.req_timeout,
            Some(Duration::from_secs(220))
        );
        assert_eq!(
            service.cost_allocation_report.config.req_timeout,
            Some(Duration::from_secs(220))
        );
        assert_eq!(
            service.cost_allocation_plan.config.req_timeout,
            Some(Duration::from_secs(220))
        );
        assert_eq!(
            service.paygroup.config.req_timeout,
            Some(Duration::from_secs(220))
        );
    }

    #[test]
    fn test_payroll_service_multiple_instances() {
        let config = Config::default();

        let service1 = PayrollService::new(config.clone());
        let service2 = PayrollService::new(config.clone());

        assert_eq!(
            service1.payment_detail.config.app_id,
            service2.payment_detail.config.app_id
        );
        assert_eq!(
            service1.payment_detail.config.app_secret,
            service2.payment_detail.config.app_secret
        );
        assert_eq!(
            service1.payment_activity.config.app_id,
            service2.payment_activity.config.app_id
        );
        assert_eq!(
            service1.datasource.config.app_secret,
            service2.datasource.config.app_secret
        );
        assert_eq!(
            service1.acct_item.config.app_id,
            service2.acct_item.config.app_id
        );
        assert_eq!(
            service1.cost_allocation_report.config.app_secret,
            service2.cost_allocation_report.config.app_secret
        );
        assert_eq!(
            service1.paygroup.config.app_id,
            service2.paygroup.config.app_id
        );
    }

    #[test]
    fn test_payroll_service_config_consistency() {
        let config = Config::builder()
            .app_id("consistency_test")
            .app_secret("consistency_secret")
            .req_timeout(Duration::from_secs(190))
            .build();

        let service = PayrollService::new(config);

        assert_eq!(service.payment_detail.config.app_id, "consistency_test");
        assert_eq!(
            service.payment_detail.config.app_secret,
            "consistency_secret"
        );
        assert_eq!(
            service.payment_detail.config.req_timeout,
            Some(Duration::from_secs(190))
        );
        assert_eq!(service.payment_activity.config.app_id, "consistency_test");
        assert_eq!(
            service.datasource_record.config.app_secret,
            "consistency_secret"
        );
        assert_eq!(
            service.datasource.config.req_timeout,
            Some(Duration::from_secs(190))
        );
        assert_eq!(service.acct_item.config.app_id, "consistency_test");
        assert_eq!(
            service.cost_allocation_plan.config.app_secret,
            "consistency_secret"
        );
        assert_eq!(
            service.paygroup.config.req_timeout,
            Some(Duration::from_secs(190))
        );
    }
}