提交 77548800 authored 作者: 000516's avatar 000516

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

上级 0298612c
...@@ -31,6 +31,7 @@ import org.springframework.stereotype.Component; ...@@ -31,6 +31,7 @@ import org.springframework.stereotype.Component;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** /**
* @author : liqiulin * @author : liqiulin
...@@ -85,8 +86,8 @@ public class FeiShuUtil { ...@@ -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(); 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(); Response execute = client.newCall(build).execute();
JSONObject rj = JSONObject.parseObject(execute.body().string()); JSONObject rj = JSONObject.parseObject(execute.body().string());
if (!rj.containsKey("access_token")){ if (!rj.containsKey("access_token")) {
log.error("飞书用户获取失败!",rj.toString()); log.error("飞书用户获取失败!", rj.toString());
throw new NotLoginException(ECode.FEISHU_ACCESS_TOKEN_ERROR); throw new NotLoginException(ECode.FEISHU_ACCESS_TOKEN_ERROR);
} }
return rj.getString("access_token"); return rj.getString("access_token");
...@@ -123,7 +124,7 @@ public class FeiShuUtil { ...@@ -123,7 +124,7 @@ public class FeiShuUtil {
public Department getDepartmentCorehr(String deptId) { public Department getDepartmentCorehr(String deptId) {
// 判断部门ID,如果是"od-"开头,部门ID类型为"open_department_id",否则为"people_corehr_department_id" // 判断部门ID,如果是"od-"开头,部门ID类型为"open_department_id",否则为"people_corehr_department_id"
String departmentIdType = deptId.startsWith("od-") ? "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}; String[] deptIds = new String[]{deptId};
try { try {
Client client = getClientLUZX(); Client client = getClientLUZX();
...@@ -176,7 +177,7 @@ public class FeiShuUtil { ...@@ -176,7 +177,7 @@ public class FeiShuUtil {
.build(); .build();
ChildrenDepartmentResp resp = client.contact().department().children(req); ChildrenDepartmentResp resp = client.contact().department().children(req);
if (!resp.success()) { 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))))); resp.getCode(), resp.getMsg(), resp.getRequestId(), Jsons.createGSON(true, false).toJson(JsonParser.parseString(new String(resp.getRawResponse().getBody(), UTF_8)))));
return null; return null;
} }
...@@ -201,8 +202,8 @@ public class FeiShuUtil { ...@@ -201,8 +202,8 @@ public class FeiShuUtil {
.pageSize(50) .pageSize(50)
.build(); .build();
FindByDepartmentUserResp resp = client.contact().user().findByDepartment(req); FindByDepartmentUserResp resp = client.contact().user().findByDepartment(req);
if(!resp.success()) { 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))))); resp.getCode(), resp.getMsg(), resp.getRequestId(), Jsons.createGSON(true, false).toJson(JsonParser.parseString(new String(resp.getRawResponse().getBody(), UTF_8)))));
return null; return null;
} }
...@@ -225,10 +226,10 @@ public class FeiShuUtil { ...@@ -225,10 +226,10 @@ public class FeiShuUtil {
JSONObject resultJson = JSONObject.parseObject(result); JSONObject resultJson = JSONObject.parseObject(result);
int code = resultJson.getInteger("code"); int code = resultJson.getInteger("code");
if (code != 0) { if (code != 0) {
throw new RuntimeException("获取飞书表格范围数据错误:"+resultJson.getString("msg")); throw new RuntimeException("获取飞书表格范围数据错误:" + resultJson.getString("msg"));
} }
return resultJson.getJSONObject("data").getJSONArray("valueRanges"); return resultJson.getJSONObject("data").getJSONArray("valueRanges");
}catch (Exception e) { } catch (Exception e) {
log.error("拉取表格数据失败,停止执行!", e); log.error("拉取表格数据失败,停止执行!", e);
} }
return new JSONArray(); return new JSONArray();
...@@ -260,7 +261,7 @@ public class FeiShuUtil { ...@@ -260,7 +261,7 @@ public class FeiShuUtil {
/** /**
* 创建审批 * 创建审批
*/ */
public String createApproval(Map<String,Object> approval) { public String createApproval(Map<String, Object> approval) {
try { try {
Client client = getClientLUZX(); Client client = getClientLUZX();
CreateInstanceReq req = CreateInstanceReq.newBuilder() CreateInstanceReq req = CreateInstanceReq.newBuilder()
...@@ -273,28 +274,28 @@ public class FeiShuUtil { ...@@ -273,28 +274,28 @@ public class FeiShuUtil {
.build() .build()
).build(); ).build();
CreateInstanceResp resp = client.approval().v4().instance().create(req); CreateInstanceResp resp = client.approval().v4().instance().create(req);
if(!resp.success()) { if (!resp.success()) {
throw new RuntimeException(String.format("%s,code:%s,msg:%s,reqId:%s, resp:%s","创建飞书审批失败", 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))))); 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"); return JSONObject.parseObject(JSONObject.toJSONString(resp.getData())).getString("instance_code");
}catch (Exception e) { } catch (Exception e) {
throw new ServiceException(String.format(ECode.FS_CREATE_APPROVAL_ERROR.getMsg(),e.getMessage()), ECode.FS_CREATE_APPROVAL_ERROR.getCode()); 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 { try {
Client client = getClientLUZX(); Client client = getClientLUZX();
GetInstanceReq req = GetInstanceReq.newBuilder().instanceId(approvalCode).build(); GetInstanceReq req = GetInstanceReq.newBuilder().instanceId(approvalCode).build();
GetInstanceResp resp = client.approval().v4().instance().get(req); GetInstanceResp resp = client.approval().v4().instance().get(req);
// 处理服务端错误 // 处理服务端错误
if(!resp.success()) { if (!resp.success()) {
throw new RuntimeException(String.format("%s,code:%s,msg:%s,reqId:%s, resp:%s","创建飞书审批失败", 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))))); 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()); return JSONObject.toJSONString(resp.getData());
}catch (Exception e){ } catch (Exception e) {
log.error(e.getMessage()); log.error(e.getMessage());
return null; return null;
} }
...@@ -331,9 +332,9 @@ public class FeiShuUtil { ...@@ -331,9 +332,9 @@ public class FeiShuUtil {
return resultJson.getString("tenant_access_token"); 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上传 // 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) .auth("Bearer " + autoToken).contentType(CONTENT_TYPE)
.body(JSONObject.toJSONString(body)) .body(JSONObject.toJSONString(body))
.execute().body(); .execute().body();
...@@ -343,11 +344,20 @@ public class FeiShuUtil { ...@@ -343,11 +344,20 @@ public class FeiShuUtil {
return pullSheet(sheetToken, botToken1, ranges).getJSONObject(0); 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 * 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 { try {
Client client = getClientLUZX(); Client client = getClientLUZX();
// 创建请求对象 // 创建请求对象
...@@ -359,7 +369,9 @@ public class FeiShuUtil { ...@@ -359,7 +369,9 @@ public class FeiShuUtil {
"person_info.preferred_name", "person_info.preferred_name",
"department_id", "department_id",
"person_info.bank_account_list" "person_info.bank_account_list"
}).employmentIds(new String[]{employmentId}) })
.employmentIds(employmentIds)
.personIds(personIds)
.build()) .build())
.build(); .build();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论