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
1cfd7e36
提交
1cfd7e36
authored
6月 25, 2025
作者:
000516
浏览文件
操作
浏览文件
下载
差异文件
飞书工具修改,查询人事用户时启动employmentIds、personIds
上级
d7eccd54
77548800
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
33 行增加
和
21 行删除
+33
-21
FeiShuUtil.java
src/main/java/com/sfa/common/core/utils/sdk/FeiShuUtil.java
+33
-21
没有找到文件。
src/main/java/com/sfa/common/core/utils/sdk/FeiShuUtil.java
浏览文件 @
1cfd7e36
...
...
@@ -31,6 +31,7 @@ import org.springframework.stereotype.Component;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
/**
* @author : liqiulin
...
...
@@ -85,8 +86,8 @@ public class FeiShuUtil {
Request
build
=
new
Request
.
Builder
().
url
(
"https://open.feishu.cn/open-apis/authen/v2/oauth/token"
).
addHeader
(
"Content-Type"
,
"application/json; charset=utf-8"
).
post
(
body
).
build
();
Response
execute
=
client
.
newCall
(
build
).
execute
();
JSONObject
rj
=
JSONObject
.
parseObject
(
execute
.
body
().
string
());
if
(!
rj
.
containsKey
(
"access_token"
)){
log
.
error
(
"飞书用户获取失败!"
,
rj
.
toString
());
if
(!
rj
.
containsKey
(
"access_token"
))
{
log
.
error
(
"飞书用户获取失败!"
,
rj
.
toString
());
throw
new
NotLoginException
(
ECode
.
FEISHU_ACCESS_TOKEN_ERROR
);
}
return
rj
.
getString
(
"access_token"
);
...
...
@@ -123,7 +124,7 @@ public class FeiShuUtil {
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
);
log
.
info
(
"部门ID<{}>所属类型为:{}"
,
deptId
,
departmentIdType
);
String
[]
deptIds
=
new
String
[]{
deptId
};
try
{
Client
client
=
getClientLUZX
();
...
...
@@ -176,7 +177,7 @@ public class FeiShuUtil {
.
build
();
ChildrenDepartmentResp
resp
=
client
.
contact
().
department
().
children
(
req
);
if
(!
resp
.
success
())
{
log
.
error
(
String
.
format
(
"%s,code:%s,msg:%s,reqId:%s, resp:%s"
,
"根据部门父编码获取子部门失败"
,
log
.
error
(
String
.
format
(
"%s,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
;
}
...
...
@@ -201,8 +202,8 @@ public class FeiShuUtil {
.
pageSize
(
50
)
.
build
();
FindByDepartmentUserResp
resp
=
client
.
contact
().
user
().
findByDepartment
(
req
);
if
(!
resp
.
success
())
{
log
.
error
(
String
.
format
(
"%s,code:%s,msg:%s,reqId:%s, resp:%s"
,
"获取部门用户"
,
if
(!
resp
.
success
())
{
log
.
error
(
String
.
format
(
"%s,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
;
}
...
...
@@ -225,10 +226,10 @@ public class FeiShuUtil {
JSONObject
resultJson
=
JSONObject
.
parseObject
(
result
);
int
code
=
resultJson
.
getInteger
(
"code"
);
if
(
code
!=
0
)
{
throw
new
RuntimeException
(
"获取飞书表格范围数据错误:"
+
resultJson
.
getString
(
"msg"
));
throw
new
RuntimeException
(
"获取飞书表格范围数据错误:"
+
resultJson
.
getString
(
"msg"
));
}
return
resultJson
.
getJSONObject
(
"data"
).
getJSONArray
(
"valueRanges"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"拉取表格数据失败,停止执行!"
,
e
);
}
return
new
JSONArray
();
...
...
@@ -260,7 +261,7 @@ public class FeiShuUtil {
/**
* 创建审批
*/
public
String
createApproval
(
Map
<
String
,
Object
>
approval
)
{
public
String
createApproval
(
Map
<
String
,
Object
>
approval
)
{
try
{
Client
client
=
getClientLUZX
();
CreateInstanceReq
req
=
CreateInstanceReq
.
newBuilder
()
...
...
@@ -273,28 +274,28 @@ public class FeiShuUtil {
.
build
()
).
build
();
CreateInstanceResp
resp
=
client
.
approval
().
v4
().
instance
().
create
(
req
);
if
(!
resp
.
success
())
{
throw
new
RuntimeException
(
String
.
format
(
"%s,code:%s,msg:%s,reqId:%s, resp:%s"
,
"创建飞书审批失败"
,
if
(!
resp
.
success
())
{
throw
new
RuntimeException
(
String
.
format
(
"%s,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
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
resp
.
getData
())).
getString
(
"instance_code"
);
}
catch
(
Exception
e
)
{
throw
new
ServiceException
(
String
.
format
(
ECode
.
FS_CREATE_APPROVAL_ERROR
.
getMsg
(),
e
.
getMessage
()),
ECode
.
FS_CREATE_APPROVAL_ERROR
.
getCode
());
}
catch
(
Exception
e
)
{
throw
new
ServiceException
(
String
.
format
(
ECode
.
FS_CREATE_APPROVAL_ERROR
.
getMsg
(),
e
.
getMessage
()),
ECode
.
FS_CREATE_APPROVAL_ERROR
.
getCode
());
}
}
public
String
getApprovalInfo
(
String
approvalCode
){
public
String
getApprovalInfo
(
String
approvalCode
)
{
try
{
Client
client
=
getClientLUZX
();
GetInstanceReq
req
=
GetInstanceReq
.
newBuilder
().
instanceId
(
approvalCode
).
build
();
GetInstanceResp
resp
=
client
.
approval
().
v4
().
instance
().
get
(
req
);
// 处理服务端错误
if
(!
resp
.
success
())
{
throw
new
RuntimeException
(
String
.
format
(
"%s,code:%s,msg:%s,reqId:%s, resp:%s"
,
"创建飞书审批失败"
,
if
(!
resp
.
success
())
{
throw
new
RuntimeException
(
String
.
format
(
"%s,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
JSONObject
.
toJSONString
(
resp
.
getData
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
());
return
null
;
}
...
...
@@ -331,9 +332,9 @@ public class FeiShuUtil {
return
resultJson
.
getString
(
"tenant_access_token"
);
}
public
void
appendStyle
(
String
sheetToken
,
Map
<
String
,
Object
>
body
,
String
autoToken
)
{
public
void
appendStyle
(
String
sheetToken
,
Map
<
String
,
Object
>
body
,
String
autoToken
)
{
// body上传
String
result
=
HttpUtil
.
createRequest
(
Method
.
PUT
,
SHEET_URL
+
sheetToken
+
STYLE
)
String
result
=
HttpUtil
.
createRequest
(
Method
.
PUT
,
SHEET_URL
+
sheetToken
+
STYLE
)
.
auth
(
"Bearer "
+
autoToken
).
contentType
(
CONTENT_TYPE
)
.
body
(
JSONObject
.
toJSONString
(
body
))
.
execute
().
body
();
...
...
@@ -343,11 +344,20 @@ public class FeiShuUtil {
return
pullSheet
(
sheetToken
,
botToken1
,
ranges
).
getJSONObject
(
0
);
}
public
Employee
getEmployeeReq
(
String
employmentId
)
{
String
[]
employmentIds
=
{
employmentId
};
return
getPeopleReq
(
employmentIds
,
null
);
}
public
Employee
getPersonReq
(
String
personId
)
{
String
[]
personIds
=
{
personId
};
return
getPeopleReq
(
null
,
personIds
);
}
/**
* 批量查询员工信息
* https://open.feishu.cn/document/corehr-v1/employee/batch_get?appId=cli_a8d8e0fc58d9100e
*/
public
Employee
getEmployeeReq
(
String
employmentId
)
{
private
Employee
getPeopleReq
(
String
[]
employmentIds
,
String
[]
personIds
)
{
try
{
Client
client
=
getClientLUZX
();
// 创建请求对象
...
...
@@ -359,7 +369,9 @@ public class FeiShuUtil {
"person_info.preferred_name"
,
"department_id"
,
"person_info.bank_account_list"
}).
employmentIds
(
new
String
[]{
employmentId
})
})
.
employmentIds
(
employmentIds
)
.
personIds
(
personIds
)
.
build
())
.
build
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论