mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-08 01:48:33 +08:00
workweixin
This commit is contained in:
parent
89ca99e153
commit
d4ca040849
@ -35,8 +35,6 @@ import org.springframework.stereotype.Service;
|
|||||||
public class WorkweixinOrganizationService extends AbstractSynchronizerService implements ISynchronizerService{
|
public class WorkweixinOrganizationService extends AbstractSynchronizerService implements ISynchronizerService{
|
||||||
final static Logger _logger = LoggerFactory.getLogger(WorkweixinOrganizationService.class);
|
final static Logger _logger = LoggerFactory.getLogger(WorkweixinOrganizationService.class);
|
||||||
|
|
||||||
WorkWeixinDeptsResponse deptsResponse;
|
|
||||||
|
|
||||||
String access_token;
|
String access_token;
|
||||||
|
|
||||||
static String DEPTS_URL="https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s";
|
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()) {
|
for(WorkWeixinDepts dept : rsp.getDepartment()) {
|
||||||
_logger.info("dept : " + dept.getId()+" "+ dept.getName()+" "+ dept.getParentid());
|
_logger.info("dept : " + dept.getId()+" "+ dept.getName()+" "+ dept.getParentid());
|
||||||
Organizations org = buildOrganization(dept);
|
Organizations organization = buildOrganization(dept);
|
||||||
if(organizationsService.findOne("id = ? and instid = ?",
|
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) {
|
new int[] { Types.VARCHAR, Types.VARCHAR }) == null) {
|
||||||
organizationsService.insert(org);
|
organizationsService.insert(organization);
|
||||||
}else {
|
}else {
|
||||||
organizationsService.update(org);
|
organizationsService.update(organization);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +66,7 @@ public class WorkweixinOrganizationService extends AbstractSynchronizerService i
|
|||||||
public WorkWeixinDeptsResponse requestDepartmentList(String access_token) {
|
public WorkWeixinDeptsResponse requestDepartmentList(String access_token) {
|
||||||
HttpRequestAdapter request =new HttpRequestAdapter();
|
HttpRequestAdapter request =new HttpRequestAdapter();
|
||||||
String responseBody = request.get(String.format(DEPTS_URL, access_token));
|
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);
|
_logger.info("response : " + responseBody);
|
||||||
for(WorkWeixinDepts dept : deptsResponse.getDepartment()) {
|
for(WorkWeixinDepts dept : deptsResponse.getDepartment()) {
|
||||||
@ -97,12 +95,4 @@ public class WorkweixinOrganizationService extends AbstractSynchronizerService i
|
|||||||
this.access_token = access_token;
|
this.access_token = access_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorkWeixinDeptsResponse getDeptsResponse() {
|
|
||||||
return deptsResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeptsResponse(WorkWeixinDeptsResponse deptsResponse) {
|
|
||||||
this.deptsResponse = deptsResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,26 +17,25 @@
|
|||||||
|
|
||||||
package org.maxkey.synchronizer.workweixin;
|
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.entity.UserInfo;
|
||||||
import org.maxkey.synchronizer.AbstractSynchronizerService;
|
import org.maxkey.synchronizer.AbstractSynchronizerService;
|
||||||
import org.maxkey.synchronizer.ISynchronizerService;
|
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.WorkWeixinUsers;
|
||||||
import org.maxkey.synchronizer.workweixin.entity.WorkWeixinUsersResponse;
|
import org.maxkey.synchronizer.workweixin.entity.WorkWeixinUsersResponse;
|
||||||
import org.maxkey.util.JsonUtils;
|
import org.maxkey.util.JsonUtils;
|
||||||
import org.maxkey.web.HttpRequestAdapter;
|
import org.maxkey.web.HttpRequestAdapter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class WorkweixinUsersService extends AbstractSynchronizerService implements ISynchronizerService{
|
public class WorkweixinUsersService extends AbstractSynchronizerService implements ISynchronizerService{
|
||||||
final static Logger _logger = LoggerFactory.getLogger(WorkweixinUsersService.class);
|
final static Logger _logger = LoggerFactory.getLogger(WorkweixinUsersService.class);
|
||||||
|
|
||||||
@Autowired
|
|
||||||
WorkweixinOrganizationService workweixinOrganizationService;
|
|
||||||
|
|
||||||
String access_token;
|
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";
|
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() {
|
public void sync() {
|
||||||
_logger.info("Sync Users...");
|
_logger.info("Sync Users...");
|
||||||
try {
|
try {
|
||||||
|
List<Organizations> organizations =
|
||||||
for (WorkWeixinDepts dept : workweixinOrganizationService.getDeptsResponse().getDepartment()) {
|
organizationsService.find("instid = ?",
|
||||||
|
new Object[] { this.synchronizer.getInstId() },
|
||||||
|
new int[] { Types.VARCHAR});
|
||||||
|
for(Organizations dept : organizations) {
|
||||||
HttpRequestAdapter request =new HttpRequestAdapter();
|
HttpRequestAdapter request =new HttpRequestAdapter();
|
||||||
String responseBody = request.get(String.format(USERS_URL, access_token,dept.getId()));
|
String responseBody = request.get(String.format(USERS_URL, access_token,dept.getId()));
|
||||||
WorkWeixinUsersResponse usersResponse =JsonUtils.gson2Object(responseBody, WorkWeixinUsersResponse.class);
|
WorkWeixinUsersResponse usersResponse =JsonUtils.gson2Object(responseBody, WorkWeixinUsersResponse.class);
|
||||||
@ -54,7 +56,14 @@ public class WorkweixinUsersService extends AbstractSynchronizerService implemen
|
|||||||
for(WorkWeixinUsers user : usersResponse.getUserlist()) {
|
for(WorkWeixinUsers user : usersResponse.getUserlist()) {
|
||||||
UserInfo userInfo = buildUserInfo(user);
|
UserInfo userInfo = buildUserInfo(user);
|
||||||
_logger.info("userInfo : " + userInfo);
|
_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;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setAccess_token(String access_token) {
|
public void setAccess_token(String access_token) {
|
||||||
this.access_token = access_token;
|
this.access_token = access_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWorkweixinOrganizationService(WorkweixinOrganizationService workweixinOrganizationService) {
|
|
||||||
this.workweixinOrganizationService = workweixinOrganizationService;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user