Jelajahi Sumber

synchronizer feishu

MaxKey 3 tahun lalu
induk
melakukan
bbb2ba6587
21 mengubah file dengan 1346 tambahan dan 0 penghapusan
  1. 14 0
      maxkey-synchronizers/maxkey-synchronizer-feishu/build.gradle
  2. 90 0
      maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/FeishuAccessTokenService.java
  3. 106 0
      maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/FeishuOrganizationService.java
  4. 75 0
      maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/FeishuSynchronizerService.java
  5. 108 0
      maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/FeishuUsersService.java
  6. 44 0
      maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuDeptStatus.java
  7. 167 0
      maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuDepts.java
  8. 70 0
      maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuDeptsData.java
  9. 50 0
      maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuDeptsResponse.java
  10. 66 0
      maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuI18nName.java
  11. 87 0
      maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuUserStatus.java
  12. 309 0
      maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuUsers.java
  13. 79 0
      maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuUsersData.java
  14. 49 0
      maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuUsersResponse.java
  15. 10 0
      maxkey-synchronizers/maxkey-synchronizer/src/main/java/org/maxkey/synchronizer/entity/AccessToken.java
  16. 17 0
      maxkey-synchronizers/maxkey-synchronizer/src/main/java/org/maxkey/synchronizer/entity/ResponseData.java
  17. 1 0
      maxkey-webs/maxkey-web-mgt/build.gradle
  18. 1 0
      maxkey-webs/maxkey-web-mgt/config/build_docker.gradle
  19. 1 0
      maxkey-webs/maxkey-web-mgt/config/build_jar.gradle
  20. 1 0
      maxkey-webs/maxkey-web-mgt/config/build_standard.gradle
  21. 1 0
      settings.gradle

+ 14 - 0
maxkey-synchronizers/maxkey-synchronizer-feishu/build.gradle

@@ -0,0 +1,14 @@
+description = "maxkey-synchronizer-feishu"
+
+apply plugin: 'java'
+
+dependencies {
+	//local jars
+	implementation fileTree(dir: '../maxkey-lib/*/', include: '*.jar')
+	
+	implementation project(":maxkey-common")
+	implementation project(":maxkey-core")
+	implementation project(":maxkey-persistence")
+	implementation project(":maxkey-synchronizers:maxkey-synchronizer")
+   
+}

+ 90 - 0
maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/FeishuAccessTokenService.java

@@ -0,0 +1,90 @@
+/*
+ * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+
+package org.maxkey.synchronizer.feishu;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.maxkey.synchronizer.entity.AccessToken;
+import org.maxkey.util.JsonUtils;
+import org.maxkey.web.HttpRequestAdapter;
+import org.maxkey.web.HttpRequestAdapter.MediaType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FeishuAccessTokenService {
+	final static Logger _logger = LoggerFactory.getLogger(FeishuAccessTokenService.class);
+	
+	String appId;
+	
+	String appSecret;
+	
+	public static String TOKEN_URL="https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal";
+
+
+	public FeishuAccessTokenService() {}
+	
+	
+	public FeishuAccessTokenService(String appId, String appSecret) {
+		super();
+		this.appId = appId;
+		this.appSecret = appSecret;
+	}
+
+
+	public String requestToken() {
+		HttpRequestAdapter request =new HttpRequestAdapter(MediaType.JSON);
+		Map<String, Object> parameterMap = new HashMap<String, Object>();
+		parameterMap.put("app_id", appId);
+		parameterMap.put("app_secret", appSecret);
+		String responseBody = request.post(TOKEN_URL, parameterMap,null);
+		
+		AccessToken accessToken = JsonUtils.gson2Object(responseBody, AccessToken.class);
+		_logger.debug("accessToken " + accessToken);
+		if(accessToken.getErrcode()== 0){
+			return accessToken.getTenant_access_token();
+		}
+		return "";
+	}
+	
+	
+	public String getAppId() {
+		return appId;
+	}
+
+
+	public void setAppId(String appId) {
+		this.appId = appId;
+	}
+
+
+	public String getAppSecret() {
+		return appSecret;
+	}
+
+
+	public void setAppSecret(String appSecret) {
+		this.appSecret = appSecret;
+	}
+
+
+	public static void main(String[] args) {
+
+	}
+
+}

+ 106 - 0
maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/FeishuOrganizationService.java

@@ -0,0 +1,106 @@
+/*
+ * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+
+package org.maxkey.synchronizer.feishu;
+
+import java.util.HashMap;
+import java.util.NoSuchElementException;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.maxkey.constants.ConstsStatus;
+import org.maxkey.entity.Organizations;
+import org.maxkey.synchronizer.AbstractSynchronizerService;
+import org.maxkey.synchronizer.ISynchronizerService;
+import org.maxkey.synchronizer.feishu.entity.FeishuDepts;
+import org.maxkey.synchronizer.feishu.entity.FeishuDeptsResponse;
+import org.maxkey.util.AuthorizationHeaderUtils;
+import org.maxkey.util.JsonUtils;
+import org.maxkey.web.HttpRequestAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+@Service
+public class FeishuOrganizationService extends AbstractSynchronizerService implements ISynchronizerService{
+	final static Logger _logger = LoggerFactory.getLogger(FeishuOrganizationService.class);
+	
+	String access_token;
+	
+	static String DEPTS_URL="https://open.feishu.cn/open-apis/contact/v3/departments/%s/children?page_size=50";
+	
+	public void sync() {
+		_logger.info("Sync Organizations ...");
+
+		LinkedBlockingQueue<String> deptsQueue = new LinkedBlockingQueue<String>();
+		deptsQueue.add("0");
+		HashMap<String,FeishuDepts> deptMap = new HashMap<String,FeishuDepts>();
+		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);
+				}
+			}
+		} catch (NoSuchElementException e) {
+			_logger.debug("Sync Department successful .");
+		}
+		
+	}
+	
+	public FeishuDeptsResponse requestDepartmentList(String access_token,String deptId) {
+		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(DEPTS_URL, deptId),headers);
+		FeishuDeptsResponse deptsResponse  =JsonUtils.gson2Object(responseBody, FeishuDeptsResponse.class);
+		
+		_logger.info("response : " + responseBody);
+
+		return deptsResponse;
+	}
+	
+	public Organizations buildOrganization(FeishuDepts dept,FeishuDepts parentDept) {
+		Organizations org = new Organizations();
+		org.setId(dept.getDepartment_id()+"");
+		org.setName(dept.getName());
+		if(parentDept == null) {
+			org.setParentId("1");
+		}else {
+			org.setParentId(dept.getParent_department_id()+"");
+		}
+		org.setSortIndex(Integer.parseInt(dept.getOrder()));
+		org.setInstId(this.synchronizer.getInstId());
+		org.setStatus(ConstsStatus.ACTIVE);
+		org.setDescription("Feishu");
+		return org;
+	}
+
+	public String getAccess_token() {
+		return access_token;
+	}
+
+	public void setAccess_token(String access_token) {
+		this.access_token = access_token;
+	}
+
+}

+ 75 - 0
maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/FeishuSynchronizerService.java

@@ -0,0 +1,75 @@
+/*
+ * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+
+package org.maxkey.synchronizer.feishu;
+
+import org.maxkey.entity.Synchronizers;
+import org.maxkey.synchronizer.ISynchronizerService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class FeishuSynchronizerService  implements ISynchronizerService{
+	final static Logger _logger = LoggerFactory.getLogger(FeishuSynchronizerService.class);
+	Synchronizers synchronizer;
+	
+	@Autowired
+	FeishuUsersService feishuUsersService;
+	
+	@Autowired
+	FeishuOrganizationService feishuOrganizationService;
+	
+
+	FeishuAccessTokenService feishuAccessTokenService = new FeishuAccessTokenService();
+	
+	public FeishuSynchronizerService() {
+		super();
+	}
+
+	public void sync() throws Exception {
+		_logger.info("Sync ...");
+		feishuAccessTokenService.setAppId(synchronizer.getPrincipal());
+		feishuAccessTokenService.setAppSecret(synchronizer.getCredentials());
+		String access_token=feishuAccessTokenService.requestToken();
+		
+		feishuOrganizationService.setSynchronizer(synchronizer);
+		feishuOrganizationService.setAccess_token(access_token);
+		feishuOrganizationService.sync();
+		
+		feishuUsersService.setSynchronizer(synchronizer);
+		feishuUsersService.setAccess_token(access_token);
+		//feishuUsersService.sync();
+	}
+
+
+	public void setFeishuUsersService(FeishuUsersService feishuUsersService) {
+		this.feishuUsersService = feishuUsersService;
+	}
+
+	public void setFeishuOrganizationService(FeishuOrganizationService feishuOrganizationService) {
+		this.feishuOrganizationService = feishuOrganizationService;
+	}
+
+	@Override
+	public void setSynchronizer(Synchronizers synchronizer) {
+		this.synchronizer = synchronizer;
+		
+	}
+
+}

+ 108 - 0
maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/FeishuUsersService.java

@@ -0,0 +1,108 @@
+/*
+ * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+
+package org.maxkey.synchronizer.feishu;
+
+import java.sql.Types;
+import java.util.HashMap;
+import java.util.List;
+
+import org.maxkey.constants.ConstsStatus;
+import org.maxkey.entity.Organizations;
+import org.maxkey.entity.UserInfo;
+import org.maxkey.synchronizer.AbstractSynchronizerService;
+import org.maxkey.synchronizer.ISynchronizerService;
+import org.maxkey.synchronizer.feishu.entity.FeishuUsers;
+import org.maxkey.synchronizer.feishu.entity.FeishuUsersResponse;
+import org.maxkey.util.AuthorizationHeaderUtils;
+import org.maxkey.util.JsonUtils;
+import org.maxkey.web.HttpRequestAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+@Service
+public class FeishuUsersService extends AbstractSynchronizerService implements ISynchronizerService{
+	final static Logger _logger = LoggerFactory.getLogger(FeishuUsersService.class);
+	
+	String access_token;
+	
+	static String USERS_URL="https://open.feishu.cn/open-apis/contact/v3/users/find_by_department";
+	
+	public void sync() {
+		_logger.info("Sync Users...");
+		try {
+			List<Organizations> organizations = 
+					 organizationsService.find("instid = ?",
+									 		new Object[] { this.synchronizer.getInstId() },
+					                        new int[] { Types.VARCHAR});
+			for(Organizations dept : organizations) {
+				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);
+				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);
+				}
+			}
+			
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		
+	}
+	
+	public void postSync(UserInfo userInfo) {
+		
+	}
+
+	public UserInfo buildUserInfo(FeishuUsers user) {
+		UserInfo userInfo = new  UserInfo();
+		userInfo.setUsername(user.getUser_id());//账号
+		userInfo.setNickName(user.getNickname());//名字
+		userInfo.setDisplayName(user.getName());//名字
+		
+		userInfo.setMobile(user.getMobile());//手机
+		userInfo.setEmail(user.getEmail());
+		userInfo.setGender(user.getGender());
+		
+		userInfo.setEmployeeNumber(user.getEmployee_no());
+		userInfo.setWorkPhoneNumber(user.getMobile());//工作电话
+		userInfo.setDepartmentId(user.getDepartment_ids()[0]+"");
+		userInfo.setJobTitle(user.getJob_title());//职务
+		userInfo.setWorkAddressFormatted(user.getWork_station());//工作地点
+
+		//激活状态: 1=已激活,2=已禁用,4=未激活,5=退出企业。
+		if(user.getStatus().isIs_activated() ) {
+			userInfo.setStatus(ConstsStatus.ACTIVE);
+		}else {
+			userInfo.setStatus(ConstsStatus.INACTIVE);
+		}
+		userInfo.setInstId(this.synchronizer.getInstId());
+		return userInfo;
+	}
+
+	public void setAccess_token(String access_token) {
+		this.access_token = access_token;
+	}
+}

+ 44 - 0
maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuDeptStatus.java

@@ -0,0 +1,44 @@
+/*
+ * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.maxkey.synchronizer.feishu.entity;
+
+public class FeishuDeptStatus {
+	boolean is_deleted;
+
+	public FeishuDeptStatus() {
+		super();
+
+	}
+
+	public boolean isIs_deleted() {
+		return is_deleted;
+	}
+
+	public void setIs_deleted(boolean is_deleted) {
+		this.is_deleted = is_deleted;
+	}
+
+	@Override
+	public String toString() {
+		StringBuilder builder = new StringBuilder();
+		builder.append("FeishuDeptStatus [is_deleted=");
+		builder.append(is_deleted);
+		builder.append("]");
+		return builder.toString();
+	}
+	
+}

+ 167 - 0
maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuDepts.java

@@ -0,0 +1,167 @@
+/*
+ * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+
+package org.maxkey.synchronizer.feishu.entity;
+
+public class FeishuDepts {
+	
+	String department_id;
+	String parent_department_id;
+	String open_department_id;
+	String name;
+	FeishuI18nName i18n_name;
+	String leader_user_id;
+	String chat_id;
+	String order;
+	int member_count;
+	FeishuDeptStatus status;
+	String is_deleted;
+	String create_group_chat;
+
+	public FeishuDepts() {
+		super();
+	}
+
+	public String getDepartment_id() {
+		return department_id;
+	}
+
+	public void setDepartment_id(String department_id) {
+		this.department_id = department_id;
+	}
+
+	public String getParent_department_id() {
+		return parent_department_id;
+	}
+
+	public void setParent_department_id(String parent_department_id) {
+		this.parent_department_id = parent_department_id;
+	}
+
+	public String getOpen_department_id() {
+		return open_department_id;
+	}
+
+	public void setOpen_department_id(String open_department_id) {
+		this.open_department_id = open_department_id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public FeishuI18nName getI18n_name() {
+		return i18n_name;
+	}
+
+	public void setI18n_name(FeishuI18nName i18n_name) {
+		this.i18n_name = i18n_name;
+	}
+
+	public String getLeader_user_id() {
+		return leader_user_id;
+	}
+
+	public void setLeader_user_id(String leader_user_id) {
+		this.leader_user_id = leader_user_id;
+	}
+
+	public String getChat_id() {
+		return chat_id;
+	}
+
+	public void setChat_id(String chat_id) {
+		this.chat_id = chat_id;
+	}
+
+	public String getOrder() {
+		return order;
+	}
+
+	public void setOrder(String order) {
+		this.order = order;
+	}
+
+	public int getMember_count() {
+		return member_count;
+	}
+
+	public void setMember_count(int member_count) {
+		this.member_count = member_count;
+	}
+
+	public FeishuDeptStatus getStatus() {
+		return status;
+	}
+
+	public void setStatus(FeishuDeptStatus status) {
+		this.status = status;
+	}
+
+	public String getIs_deleted() {
+		return is_deleted;
+	}
+
+	public void setIs_deleted(String is_deleted) {
+		this.is_deleted = is_deleted;
+	}
+
+	public String getCreate_group_chat() {
+		return create_group_chat;
+	}
+
+	public void setCreate_group_chat(String create_group_chat) {
+		this.create_group_chat = create_group_chat;
+	}
+
+	@Override
+	public String toString() {
+		StringBuilder builder = new StringBuilder();
+		builder.append("FeishuDepts [department_id=");
+		builder.append(department_id);
+		builder.append(", parent_department_id=");
+		builder.append(parent_department_id);
+		builder.append(", open_department_id=");
+		builder.append(open_department_id);
+		builder.append(", name=");
+		builder.append(name);
+		builder.append(", i18n_name=");
+		builder.append(i18n_name);
+		builder.append(", leader_user_id=");
+		builder.append(leader_user_id);
+		builder.append(", chat_id=");
+		builder.append(chat_id);
+		builder.append(", order=");
+		builder.append(order);
+		builder.append(", member_count=");
+		builder.append(member_count);
+		builder.append(", status=");
+		builder.append(status);
+		builder.append(", is_deleted=");
+		builder.append(is_deleted);
+		builder.append(", create_group_chat=");
+		builder.append(create_group_chat);
+		builder.append("]");
+		return builder.toString();
+	}
+
+
+}

+ 70 - 0
maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuDeptsData.java

@@ -0,0 +1,70 @@
+/*
+ * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.maxkey.synchronizer.feishu.entity;
+
+import java.util.ArrayList;
+
+import org.maxkey.synchronizer.entity.ResponseData;
+
+public class FeishuDeptsData extends ResponseData {
+
+	boolean has_more;
+	String page_token;
+	ArrayList<FeishuDepts> items;
+
+	public boolean isHas_more() {
+		return has_more;
+	}
+
+	public void setHas_more(boolean has_more) {
+		this.has_more = has_more;
+	}
+
+	public String getPage_token() {
+		return page_token;
+	}
+
+	public void setPage_token(String page_token) {
+		this.page_token = page_token;
+	}
+
+	public ArrayList<FeishuDepts> getItems() {
+		return items;
+	}
+
+	public void setItems(ArrayList<FeishuDepts> items) {
+		this.items = items;
+	}
+
+	public FeishuDeptsData() {
+		super();
+	}
+
+	@Override
+	public String toString() {
+		StringBuilder builder = new StringBuilder();
+		builder.append("FeishuDeptsResponse [has_more=");
+		builder.append(has_more);
+		builder.append(", page_token=");
+		builder.append(page_token);
+		builder.append(", items=");
+		builder.append(items);
+		builder.append("]");
+		return builder.toString();
+	}
+
+}

+ 50 - 0
maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuDeptsResponse.java

@@ -0,0 +1,50 @@
+/*
+ * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.maxkey.synchronizer.feishu.entity;
+
+import org.maxkey.synchronizer.entity.ResponseData;
+
+public class FeishuDeptsResponse extends ResponseData {
+
+	FeishuDeptsData data;
+
+
+	public FeishuDeptsResponse() {
+		super();
+	}
+
+
+	public FeishuDeptsData getData() {
+		return data;
+	}
+
+
+	public void setData(FeishuDeptsData data) {
+		this.data = data;
+	}
+
+
+	@Override
+	public String toString() {
+		StringBuilder builder = new StringBuilder();
+		builder.append("FeishuDeptsResponse [data=");
+		builder.append(data);
+		builder.append("]");
+		return builder.toString();
+	}
+
+}

+ 66 - 0
maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuI18nName.java

@@ -0,0 +1,66 @@
+/*
+ * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.maxkey.synchronizer.feishu.entity;
+
+public class FeishuI18nName {
+
+	String zh_cn;
+	String ja_jp;
+	String en_us;
+
+	public FeishuI18nName() {
+		super();
+	}
+
+	public String getZh_cn() {
+		return zh_cn;
+	}
+
+	public void setZh_cn(String zh_cn) {
+		this.zh_cn = zh_cn;
+	}
+
+	public String getJa_jp() {
+		return ja_jp;
+	}
+
+	public void setJa_jp(String ja_jp) {
+		this.ja_jp = ja_jp;
+	}
+
+	public String getEn_us() {
+		return en_us;
+	}
+
+	public void setEn_us(String en_us) {
+		this.en_us = en_us;
+	}
+
+	@Override
+	public String toString() {
+		StringBuilder builder = new StringBuilder();
+		builder.append("FeishuI18nName [zh_cn=");
+		builder.append(zh_cn);
+		builder.append(", ja_jp=");
+		builder.append(ja_jp);
+		builder.append(", en_us=");
+		builder.append(en_us);
+		builder.append("]");
+		return builder.toString();
+	}
+	
+}

+ 87 - 0
maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuUserStatus.java

@@ -0,0 +1,87 @@
+/*
+ * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+package org.maxkey.synchronizer.feishu.entity;
+
+public class FeishuUserStatus {
+	boolean is_frozen;
+	boolean is_resigned;
+	boolean is_activated;
+	boolean is_exited;
+	boolean is_unjoin;
+
+	public FeishuUserStatus() {
+		super();
+	}
+
+	public boolean isIs_frozen() {
+		return is_frozen;
+	}
+
+	public void setIs_frozen(boolean is_frozen) {
+		this.is_frozen = is_frozen;
+	}
+
+	public boolean isIs_resigned() {
+		return is_resigned;
+	}
+
+	public void setIs_resigned(boolean is_resigned) {
+		this.is_resigned = is_resigned;
+	}
+
+	public boolean isIs_activated() {
+		return is_activated;
+	}
+
+	public void setIs_activated(boolean is_activated) {
+		this.is_activated = is_activated;
+	}
+
+	public boolean isIs_exited() {
+		return is_exited;
+	}
+
+	public void setIs_exited(boolean is_exited) {
+		this.is_exited = is_exited;
+	}
+
+	public boolean isIs_unjoin() {
+		return is_unjoin;
+	}
+
+	public void setIs_unjoin(boolean is_unjoin) {
+		this.is_unjoin = is_unjoin;
+	}
+
+	@Override
+	public String toString() {
+		StringBuilder builder = new StringBuilder();
+		builder.append("FeishuUserStatus [is_frozen=");
+		builder.append(is_frozen);
+		builder.append(", is_resigned=");
+		builder.append(is_resigned);
+		builder.append(", is_activated=");
+		builder.append(is_activated);
+		builder.append(", is_exited=");
+		builder.append(is_exited);
+		builder.append(", is_unjoin=");
+		builder.append(is_unjoin);
+		builder.append("]");
+		return builder.toString();
+	}
+
+}

+ 309 - 0
maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuUsers.java

@@ -0,0 +1,309 @@
+/*
+ * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+
+package org.maxkey.synchronizer.feishu.entity;
+
+import java.util.Arrays;
+
+public class FeishuUsers {
+
+	String union_id;
+	String user_id;
+	String open_id;
+	String name;
+	String en_name;
+	String nickname;
+	String email;
+	String mobile;
+	boolean mobile_visible;
+	int gender;
+	String avatar_key;
+	FeishuUserStatus status;
+	String []department_ids;
+	String leader_user_id;
+	String city;
+	String country;
+	String work_station;
+	int join_time;
+	String is_tenant_manager;
+	String employee_no;
+	long employee_type;
+
+	String enterprise_email;
+	String job_title;
+	String is_frozen;
+
+	public class ExtAttrs {
+
+		String type;
+		String name;
+		String text;
+
+	}
+
+	public String getUnion_id() {
+		return union_id;
+	}
+
+	public void setUnion_id(String union_id) {
+		this.union_id = union_id;
+	}
+
+	public String getUser_id() {
+		return user_id;
+	}
+
+	public void setUser_id(String user_id) {
+		this.user_id = user_id;
+	}
+
+	public String getOpen_id() {
+		return open_id;
+	}
+
+	public void setOpen_id(String open_id) {
+		this.open_id = open_id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getEn_name() {
+		return en_name;
+	}
+
+	public void setEn_name(String en_name) {
+		this.en_name = en_name;
+	}
+
+	public String getNickname() {
+		return nickname;
+	}
+
+	public void setNickname(String nickname) {
+		this.nickname = nickname;
+	}
+
+	public String getEmail() {
+		return email;
+	}
+
+	public void setEmail(String email) {
+		this.email = email;
+	}
+
+	public String getMobile() {
+		return mobile;
+	}
+
+	public void setMobile(String mobile) {
+		this.mobile = mobile;
+	}
+
+	public boolean isMobile_visible() {
+		return mobile_visible;
+	}
+
+	public void setMobile_visible(boolean mobile_visible) {
+		this.mobile_visible = mobile_visible;
+	}
+
+	public int getGender() {
+		return gender;
+	}
+
+	public void setGender(int gender) {
+		this.gender = gender;
+	}
+
+	public String getAvatar_key() {
+		return avatar_key;
+	}
+
+	public void setAvatar_key(String avatar_key) {
+		this.avatar_key = avatar_key;
+	}
+
+	public FeishuUserStatus getStatus() {
+		return status;
+	}
+
+	public void setStatus(FeishuUserStatus status) {
+		this.status = status;
+	}
+
+	public String[] getDepartment_ids() {
+		return department_ids;
+	}
+
+	public void setDepartment_ids(String[] department_ids) {
+		this.department_ids = department_ids;
+	}
+
+	public String getLeader_user_id() {
+		return leader_user_id;
+	}
+
+	public void setLeader_user_id(String leader_user_id) {
+		this.leader_user_id = leader_user_id;
+	}
+
+	public String getCity() {
+		return city;
+	}
+
+	public void setCity(String city) {
+		this.city = city;
+	}
+
+	public String getCountry() {
+		return country;
+	}
+
+	public void setCountry(String country) {
+		this.country = country;
+	}
+
+	public String getWork_station() {
+		return work_station;
+	}
+
+	public void setWork_station(String work_station) {
+		this.work_station = work_station;
+	}
+
+	public int getJoin_time() {
+		return join_time;
+	}
+
+	public void setJoin_time(int join_time) {
+		this.join_time = join_time;
+	}
+
+	public String getIs_tenant_manager() {
+		return is_tenant_manager;
+	}
+
+	public void setIs_tenant_manager(String is_tenant_manager) {
+		this.is_tenant_manager = is_tenant_manager;
+	}
+
+	public String getEmployee_no() {
+		return employee_no;
+	}
+
+	public void setEmployee_no(String employee_no) {
+		this.employee_no = employee_no;
+	}
+
+	public long getEmployee_type() {
+		return employee_type;
+	}
+
+	public void setEmployee_type(long employee_type) {
+		this.employee_type = employee_type;
+	}
+
+	public String getEnterprise_email() {
+		return enterprise_email;
+	}
+
+	public void setEnterprise_email(String enterprise_email) {
+		this.enterprise_email = enterprise_email;
+	}
+
+	public String getJob_title() {
+		return job_title;
+	}
+
+	public void setJob_title(String job_title) {
+		this.job_title = job_title;
+	}
+
+	public String getIs_frozen() {
+		return is_frozen;
+	}
+
+	public void setIs_frozen(String is_frozen) {
+		this.is_frozen = is_frozen;
+	}
+
+	public FeishuUsers() {
+		super();
+	}
+
+	@Override
+	public String toString() {
+		StringBuilder builder = new StringBuilder();
+		builder.append("FeishuUsers [union_id=");
+		builder.append(union_id);
+		builder.append(", user_id=");
+		builder.append(user_id);
+		builder.append(", open_id=");
+		builder.append(open_id);
+		builder.append(", name=");
+		builder.append(name);
+		builder.append(", en_name=");
+		builder.append(en_name);
+		builder.append(", nickname=");
+		builder.append(nickname);
+		builder.append(", email=");
+		builder.append(email);
+		builder.append(", mobile=");
+		builder.append(mobile);
+		builder.append(", mobile_visible=");
+		builder.append(mobile_visible);
+		builder.append(", gender=");
+		builder.append(gender);
+		builder.append(", avatar_key=");
+		builder.append(avatar_key);
+		builder.append(", status=");
+		builder.append(status);
+		builder.append(", department_ids=");
+		builder.append(Arrays.toString(department_ids));
+		builder.append(", leader_user_id=");
+		builder.append(leader_user_id);
+		builder.append(", city=");
+		builder.append(city);
+		builder.append(", country=");
+		builder.append(country);
+		builder.append(", work_station=");
+		builder.append(work_station);
+		builder.append(", join_time=");
+		builder.append(join_time);
+		builder.append(", is_tenant_manager=");
+		builder.append(is_tenant_manager);
+		builder.append(", employee_no=");
+		builder.append(employee_no);
+		builder.append(", employee_type=");
+		builder.append(employee_type);
+		builder.append(", enterprise_email=");
+		builder.append(enterprise_email);
+		builder.append(", job_title=");
+		builder.append(job_title);
+		builder.append(", is_frozen=");
+		builder.append(is_frozen);
+		builder.append("]");
+		return builder.toString();
+	}
+
+}

+ 79 - 0
maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuUsersData.java

@@ -0,0 +1,79 @@
+/*
+ * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+
+package org.maxkey.synchronizer.feishu.entity;
+
+import java.util.ArrayList;
+
+public class FeishuUsersData {
+	boolean has_more;
+	String page_token;
+	
+	ArrayList<FeishuUsers>items;
+	
+	
+	public FeishuUsersData() {
+		super();
+	}
+
+
+	public boolean isHas_more() {
+		return has_more;
+	}
+
+
+	public void setHas_more(boolean has_more) {
+		this.has_more = has_more;
+	}
+
+
+	public String getPage_token() {
+		return page_token;
+	}
+
+
+	public void setPage_token(String page_token) {
+		this.page_token = page_token;
+	}
+
+
+	public ArrayList<FeishuUsers> getItems() {
+		return items;
+	}
+
+
+	public void setItems(ArrayList<FeishuUsers> items) {
+		this.items = items;
+	}
+
+
+	@Override
+	public String toString() {
+		StringBuilder builder = new StringBuilder();
+		builder.append("FeishuUsersData [has_more=");
+		builder.append(has_more);
+		builder.append(", page_token=");
+		builder.append(page_token);
+		builder.append(", items=");
+		builder.append(items);
+		builder.append("]");
+		return builder.toString();
+	}
+
+
+
+}

+ 49 - 0
maxkey-synchronizers/maxkey-synchronizer-feishu/src/main/java/org/maxkey/synchronizer/feishu/entity/FeishuUsersResponse.java

@@ -0,0 +1,49 @@
+/*
+ * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+
+package org.maxkey.synchronizer.feishu.entity;
+
+import org.maxkey.synchronizer.entity.ResponseData;
+
+public class FeishuUsersResponse  extends ResponseData{
+
+	FeishuUsersData data;
+
+	public FeishuUsersResponse() {
+		super();
+	}
+
+	public FeishuUsersData getData() {
+		return data;
+	}
+
+	public void setData(FeishuUsersData data) {
+		this.data = data;
+	}
+
+	@Override
+	public String toString() {
+		StringBuilder builder = new StringBuilder();
+		builder.append("FeishuUsersResponse [data=");
+		builder.append(data);
+		builder.append("]");
+		return builder.toString();
+	}
+
+
+	
+}

+ 10 - 0
maxkey-synchronizers/maxkey-synchronizer/src/main/java/org/maxkey/synchronizer/entity/AccessToken.java

@@ -22,6 +22,8 @@ public class AccessToken {
 	int errcode;
 	String errmsg;
 	String access_token;
+	//feishu access_token
+	String tenant_access_token;
 	String expires_in;
 
 	public AccessToken() {
@@ -52,6 +54,14 @@ public class AccessToken {
 		this.access_token = access_token;
 	}
 
+	public String getTenant_access_token() {
+		return tenant_access_token;
+	}
+
+	public void setTenant_access_token(String tenant_access_token) {
+		this.tenant_access_token = tenant_access_token;
+	}
+
 	public String getExpires_in() {
 		return expires_in;
 	}

+ 17 - 0
maxkey-synchronizers/maxkey-synchronizer/src/main/java/org/maxkey/synchronizer/entity/ResponseData.java

@@ -20,7 +20,10 @@ package org.maxkey.synchronizer.entity;
 public class ResponseData {
 
 	protected long errcode;
+	protected long code;
+	
 	protected String errmsg;
+	protected String msg;
 	
 	public long getErrcode() {
 		return errcode;
@@ -34,6 +37,20 @@ public class ResponseData {
 	public void setErrmsg(String errmsg) {
 		this.errmsg = errmsg;
 	}
+	
+	
+	public long getCode() {
+		return code;
+	}
+	public void setCode(long code) {
+		this.code = code;
+	}
+	public String getMsg() {
+		return msg;
+	}
+	public void setMsg(String msg) {
+		this.msg = msg;
+	}
 	public ResponseData() {
 		super();
 	}

+ 1 - 0
maxkey-webs/maxkey-web-mgt/build.gradle

@@ -22,6 +22,7 @@ dependencies {
    	//synchronizers
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-activedirectory")
+   	implementation project(":maxkey-synchronizers:maxkey-synchronizer-feishu")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-ldap")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-workweixin")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-dingtalk")

+ 1 - 0
maxkey-webs/maxkey-web-mgt/config/build_docker.gradle

@@ -57,6 +57,7 @@ dependencies {
 	//synchronizers
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-activedirectory")
+   	implementation project(":maxkey-synchronizers:maxkey-synchronizer-feishu")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-ldap")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-workweixin")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-dingtalk")

+ 1 - 0
maxkey-webs/maxkey-web-mgt/config/build_jar.gradle

@@ -58,6 +58,7 @@ dependencies {
 	//synchronizers
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-activedirectory")
+   	implementation project(":maxkey-synchronizers:maxkey-synchronizer-feishu")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-ldap")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-workweixin")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-dingtalk")

+ 1 - 0
maxkey-webs/maxkey-web-mgt/config/build_standard.gradle

@@ -22,6 +22,7 @@ dependencies {
 	//synchronizers
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-activedirectory")
+   	implementation project(":maxkey-synchronizers:maxkey-synchronizer-feishu")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-ldap")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-workweixin")
    	implementation project(":maxkey-synchronizers:maxkey-synchronizer-dingtalk")

+ 1 - 0
settings.gradle

@@ -37,6 +37,7 @@ include (
 	'maxkey-synchronizers:maxkey-synchronizer',
 	'maxkey-synchronizers:maxkey-synchronizer-reorgdept',
 	'maxkey-synchronizers:maxkey-synchronizer-activedirectory',
+	'maxkey-synchronizers:maxkey-synchronizer-feishu',
 	'maxkey-synchronizers:maxkey-synchronizer-ldap',
 	'maxkey-synchronizers:maxkey-synchronizer-dingtalk',
 	'maxkey-synchronizers:maxkey-synchronizer-workweixin',