synchronizer-feishu

This commit is contained in:
MaxKey 2022-03-07 22:26:44 +08:00
parent 697f72d223
commit 32b5cf1f93
2 changed files with 26 additions and 18 deletions

View File

@ -51,14 +51,20 @@ public class FeishuOrganizationService extends AbstractSynchronizerService imple
try {
while(deptsQueue.element() != null) {
FeishuDeptsResponse rsp = requestDepartmentList(access_token,deptsQueue.poll());
for(FeishuDepts dept : rsp.getData().getItems()) {
_logger.info("dept : " + dept.getDepartment_id()+" "+ dept.getName()+" "+ dept.getParent_department_id());
deptsQueue.add(dept.getDepartment_id());
deptMap.put(dept.getDepartment_id(), dept);
Organizations organization = buildOrganization(dept,deptMap.get(dept.getParent_department_id()));
organizationsService.saveOrUpdate(organization);
_logger.info("Organizations : " + organization);
if(rsp.getCode() == 0 && rsp.getData().getItems() != null) {
for(FeishuDepts dept : rsp.getData().getItems()) {
_logger.info("dept : id {} , Parent {} , Name {} , od {}" ,
dept.getDepartment_id(),
dept.getParent_department_id(),
dept.getName(),
dept.getOpen_department_id()
);
deptsQueue.add(dept.getOpen_department_id());
deptMap.put(dept.getOpen_department_id(), dept);
Organizations organization = buildOrganization(dept,deptMap.get(dept.getParent_department_id()));
organizationsService.saveOrUpdate(organization);
_logger.info("Organizations : " + organization);
}
}
}
} catch (NoSuchElementException e) {
@ -81,12 +87,13 @@ public class FeishuOrganizationService extends AbstractSynchronizerService imple
public Organizations buildOrganization(FeishuDepts dept,FeishuDepts parentDept) {
Organizations org = new Organizations();
org.setId(dept.getDepartment_id()+"");
org.setId(dept.getOpen_department_id()+"");
org.setCode(dept.getDepartment_id()+"");
org.setName(dept.getName());
if(parentDept == null) {
org.setParentId("1");
}else {
org.setParentId(dept.getParent_department_id()+"");
org.setParentId(parentDept.getOpen_department_id()+"");
}
org.setSortIndex(Integer.parseInt(dept.getOrder()));
org.setInstId(this.synchronizer.getInstId());

View File

@ -41,7 +41,7 @@ public class FeishuUsersService extends AbstractSynchronizerService implements I
String access_token;
static String USERS_URL="https://open.feishu.cn/open-apis/contact/v3/users/find_by_department";
static String USERS_URL="https://open.feishu.cn/open-apis/contact/v3/users/find_by_department?department_id=%s&page_size=50";
public void sync() {
_logger.info("Sync Feishu Users...");
@ -54,15 +54,16 @@ public class FeishuUsersService extends AbstractSynchronizerService implements I
HttpRequestAdapter request =new HttpRequestAdapter();
HashMap<String,String> headers =new HashMap<String,String>();
headers.put("Authorization", AuthorizationHeaderUtils.createBearer(access_token));
String responseBody = request.get(String.format(USERS_URL, access_token,dept.getId()),headers);
String responseBody = request.get(String.format(USERS_URL,dept.getId()),headers);
FeishuUsersResponse usersResponse =JsonUtils.gson2Object(responseBody, FeishuUsersResponse.class);
_logger.info("response : " + responseBody);
for(FeishuUsers user : usersResponse.getData().getItems()) {
UserInfo userInfo = buildUserInfo(user);
_logger.info("userInfo : " + userInfo);
userInfo.setPassword(userInfo.getUsername() + "Maxkey@888");
userInfoService.saveOrUpdate(userInfo);
if(usersResponse.getCode() == 0 && usersResponse.getData().getItems() != null) {
for(FeishuUsers user : usersResponse.getData().getItems()) {
UserInfo userInfo = buildUserInfo(user);
_logger.info("userInfo : " + userInfo);
userInfo.setPassword(userInfo.getUsername() + "Maxkey@888");
userInfoService.saveOrUpdate(userInfo);
}
}
}