提交 1cfd7e36 authored 作者: 000516's avatar 000516

飞书工具修改,查询人事用户时启动employmentIds、personIds

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