Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
wangxiaolu-sfa-common-core
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
sfa
wangxiaolu-sfa-common-core
Commits
0298612c
提交
0298612c
authored
6月 24, 2025
作者:
000516
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加飞书工具
上级
c2cc134e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
83 行增加
和
0 行删除
+83
-0
FeiShuUtil.java
src/main/java/com/sfa/common/core/utils/sdk/FeiShuUtil.java
+83
-0
没有找到文件。
src/main/java/com/sfa/common/core/utils/sdk/FeiShuUtil.java
浏览文件 @
0298612c
...
...
@@ -19,6 +19,7 @@ import com.lark.oapi.service.contact.v3.model.ChildrenDepartmentReq;
import
com.lark.oapi.service.contact.v3.model.ChildrenDepartmentResp
;
import
com.lark.oapi.service.contact.v3.model.FindByDepartmentUserReq
;
import
com.lark.oapi.service.contact.v3.model.FindByDepartmentUserResp
;
import
com.lark.oapi.service.corehr.v2.model.*
;
import
com.sfa.common.core.enums.ECode
;
import
com.sfa.common.core.exception.ServiceException
;
import
com.sfa.common.core.exception.auth.NotLoginException
;
...
...
@@ -115,6 +116,51 @@ public class FeiShuUtil {
}
}
/**
* 批量获取飞书人事部门信息
* https://open.feishu.cn/document/corehr-v1/organization-management/department/batch_get?appId=cli_a8d8e0fc58d9100e
*/
public
Department
getDepartmentCorehr
(
String
deptId
)
{
// 判断部门ID,如果是"od-"开头,部门ID类型为"open_department_id",否则为"people_corehr_department_id"
String
departmentIdType
=
deptId
.
startsWith
(
"od-"
)
?
"open_department_id"
:
"people_corehr_department_id"
;
log
.
info
(
"部门ID<{}>所属类型为:{}"
,
deptId
,
departmentIdType
);
String
[]
deptIds
=
new
String
[]{
deptId
};
try
{
Client
client
=
getClientLUZX
();
// 创建请求对象
BatchGetDepartmentReq
req
=
BatchGetDepartmentReq
.
newBuilder
()
.
userIdType
(
"open_id"
)
.
departmentIdType
(
departmentIdType
)
.
batchGetDepartmentReqBody
(
BatchGetDepartmentReqBody
.
newBuilder
()
.
departmentIdList
(
deptIds
)
.
fields
(
new
String
[]{
"department_name"
,
"parent_department_id"
,
"code"
,
"manager"
,
"is_root"
,
"effective_date"
,
"expiration_date"
,
"active"
,
"custom_fields"
})
.
departmentNameList
(
new
String
[]{})
.
build
())
.
build
();
BatchGetDepartmentResp
resp
=
client
.
corehr
().
v2
().
department
().
batchGet
(
req
);
// 处理服务端错误
if
(!
resp
.
success
())
{
log
.
error
(
String
.
format
(
"code:%s,msg:%s,reqId:%s, resp:%s"
,
resp
.
getCode
(),
resp
.
getMsg
(),
resp
.
getRequestId
(),
Jsons
.
createGSON
(
true
,
false
).
toJson
(
JsonParser
.
parseString
(
new
String
(
resp
.
getRawResponse
().
getBody
(),
UTF_8
)))));
return
null
;
}
Department
[]
items
=
resp
.
getData
().
getItems
();
return
items
[
0
];
}
catch
(
Exception
e
)
{
log
.
error
(
"获取飞书人事部门失效,停止执行!"
);
throw
new
RuntimeException
(
e
);
}
}
/**
* 根据部门父编码获取子部门
...
...
@@ -296,4 +342,41 @@ public class FeiShuUtil {
public
JSONObject
pullSheetOneRange
(
String
sheetToken
,
String
botToken1
,
String
ranges
)
{
return
pullSheet
(
sheetToken
,
botToken1
,
ranges
).
getJSONObject
(
0
);
}
/**
* 批量查询员工信息
* https://open.feishu.cn/document/corehr-v1/employee/batch_get?appId=cli_a8d8e0fc58d9100e
*/
public
Employee
getEmployeeReq
(
String
employmentId
)
{
try
{
Client
client
=
getClientLUZX
();
// 创建请求对象
BatchGetEmployeeReq
req
=
BatchGetEmployeeReq
.
newBuilder
()
.
userIdType
(
"people_corehr_id"
)
.
batchGetEmployeeReqBody
(
BatchGetEmployeeReqBody
.
newBuilder
()
.
fields
(
new
String
[]{
"employee_number"
,
"person_info.preferred_name"
,
"department_id"
,
"person_info.bank_account_list"
}).
employmentIds
(
new
String
[]{
employmentId
})
.
build
())
.
build
();
BatchGetEmployeeResp
resp
=
client
.
corehr
().
v2
().
employee
().
batchGet
(
req
);
// 处理服务端错误
if
(!
resp
.
success
())
{
log
.
error
(
String
.
format
(
"code:%s,msg:%s,reqId:%s, resp:%s"
,
resp
.
getCode
(),
resp
.
getMsg
(),
resp
.
getRequestId
(),
Jsons
.
createGSON
(
true
,
false
).
toJson
(
JsonParser
.
parseString
(
new
String
(
resp
.
getRawResponse
().
getBody
(),
UTF_8
)))));
return
null
;
}
// 只查询一个员工
Employee
item
=
resp
.
getData
().
getItems
()[
0
];
return
item
;
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论