MaxKey před 3 roky
rodič
revize
d4ca040849

+ 5 - 15
maxkey-identitys/maxkey-synchronizers-workweixin/src/main/java/org/maxkey/synchronizer/workweixin/WorkweixinOrganizationService.java

@@ -35,8 +35,6 @@ import org.springframework.stereotype.Service;
 public class WorkweixinOrganizationService extends AbstractSynchronizerService implements ISynchronizerService{
 	final static Logger _logger = LoggerFactory.getLogger(WorkweixinOrganizationService.class);
 	
-	WorkWeixinDeptsResponse deptsResponse;
-	
 	String access_token;
 	
 	static String DEPTS_URL="https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s";
@@ -49,13 +47,13 @@ public class WorkweixinOrganizationService extends AbstractSynchronizerService i
 			
 			for(WorkWeixinDepts dept : rsp.getDepartment()) {
 				_logger.info("dept : " + dept.getId()+" "+ dept.getName()+" "+ dept.getParentid());
-				Organizations org = buildOrganization(dept);
+				Organizations organization = buildOrganization(dept);
 				if(organizationsService.findOne("id = ? and instid = ?", 
-						new Object[] { org.getId().toString(), org.getInstId() },
+						new Object[] { organization.getId(), organization.getInstId() },
                         new int[] { Types.VARCHAR, Types.VARCHAR }) == null) {
-					organizationsService.insert(org);
+					organizationsService.insert(organization);
 				}else {
-					organizationsService.update(org);
+					organizationsService.update(organization);
 				}
 			}
 
@@ -68,7 +66,7 @@ public class WorkweixinOrganizationService extends AbstractSynchronizerService i
 	public WorkWeixinDeptsResponse requestDepartmentList(String access_token) {
 		HttpRequestAdapter request =new HttpRequestAdapter();
 		String responseBody = request.get(String.format(DEPTS_URL, access_token));
-		deptsResponse  =JsonUtils.gson2Object(responseBody, WorkWeixinDeptsResponse.class);
+		WorkWeixinDeptsResponse deptsResponse  =JsonUtils.gson2Object(responseBody, WorkWeixinDeptsResponse.class);
 		
 		_logger.info("response : " + responseBody);
 		for(WorkWeixinDepts dept : deptsResponse.getDepartment()) {
@@ -97,12 +95,4 @@ public class WorkweixinOrganizationService extends AbstractSynchronizerService i
 		this.access_token = access_token;
 	}
 
-	public WorkWeixinDeptsResponse getDeptsResponse() {
-		return deptsResponse;
-	}
-
-	public void setDeptsResponse(WorkWeixinDeptsResponse deptsResponse) {
-		this.deptsResponse = deptsResponse;
-	}
-
 }

+ 17 - 14
maxkey-identitys/maxkey-synchronizers-workweixin/src/main/java/org/maxkey/synchronizer/workweixin/WorkweixinUsersService.java

@@ -17,26 +17,25 @@
 
 package org.maxkey.synchronizer.workweixin;
 
+import java.sql.Types;
+import java.util.List;
+
+import org.maxkey.entity.Organizations;
 import org.maxkey.entity.UserInfo;
 import org.maxkey.synchronizer.AbstractSynchronizerService;
 import org.maxkey.synchronizer.ISynchronizerService;
-import org.maxkey.synchronizer.workweixin.entity.WorkWeixinDepts;
 import org.maxkey.synchronizer.workweixin.entity.WorkWeixinUsers;
 import org.maxkey.synchronizer.workweixin.entity.WorkWeixinUsersResponse;
 import org.maxkey.util.JsonUtils;
 import org.maxkey.web.HttpRequestAdapter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 @Service
 public class WorkweixinUsersService extends AbstractSynchronizerService implements ISynchronizerService{
 	final static Logger _logger = LoggerFactory.getLogger(WorkweixinUsersService.class);
 	
-	@Autowired
-	WorkweixinOrganizationService workweixinOrganizationService;
-	
 	String access_token;
 	
 	static String USERS_URL="https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=%s&department_id=%s&fetch_child=0";
@@ -44,8 +43,11 @@ public class WorkweixinUsersService extends AbstractSynchronizerService implemen
 	public void sync() {
 		_logger.info("Sync Users...");
 		try {
-			
-			for (WorkWeixinDepts dept : workweixinOrganizationService.getDeptsResponse().getDepartment()) {
+			List<Organizations> organizations = 
+					 organizationsService.find("instid = ?",
+									 		new Object[] { this.synchronizer.getInstId() },
+					                        new int[] { Types.VARCHAR});
+			for(Organizations dept : organizations) {
 				HttpRequestAdapter request =new HttpRequestAdapter();
 				String responseBody = request.get(String.format(USERS_URL, access_token,dept.getId()));
 				WorkWeixinUsersResponse usersResponse  =JsonUtils.gson2Object(responseBody, WorkWeixinUsersResponse.class);
@@ -54,7 +56,14 @@ public class WorkweixinUsersService extends AbstractSynchronizerService implemen
 				for(WorkWeixinUsers user : usersResponse.getUserlist()) {
 					UserInfo userInfo  = buildUserInfo(user);
 					_logger.info("userInfo : " + userInfo);
-					this.userInfoService.merge(userInfo);
+					if(userInfoService.findOne("username = ? and instid = ?",
+							new Object[] { userInfo.getUsername(),this.getSynchronizer().getInstId() },
+	                        new int[] { Types.VARCHAR,Types.VARCHAR}) == null) {
+						userInfo.setPassword(userInfo.getUsername() + "Maxkey@888");
+						this.userInfoService.insert(userInfo);
+					}else {
+						userInfoService.update(userInfo);
+					}
 				}
 			}
 			
@@ -89,13 +98,7 @@ public class WorkweixinUsersService extends AbstractSynchronizerService implemen
 		return userInfo;
 	}
 
-
 	public void setAccess_token(String access_token) {
 		this.access_token = access_token;
 	}
-
-	public void setWorkweixinOrganizationService(WorkweixinOrganizationService workweixinOrganizationService) {
-		this.workweixinOrganizationService = workweixinOrganizationService;
-	}
-
 }