提交 0298612c authored 作者: 000516's avatar 000516

添加飞书工具

上级 c2cc134e
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论