|
@@ -3,6 +3,7 @@ package com.fs.qw.service.impl;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.http.HttpRequest;
|
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -44,6 +45,7 @@ import com.fs.qw.utils.RSAUtils;
|
|
|
import com.fs.qw.vo.*;
|
|
import com.fs.qw.vo.*;
|
|
|
import com.fs.qwApi.Result.QwOpenidResult;
|
|
import com.fs.qwApi.Result.QwOpenidResult;
|
|
|
import com.fs.qwApi.Result.QwUploadImgResult;
|
|
import com.fs.qwApi.Result.QwUploadImgResult;
|
|
|
|
|
+import com.fs.qwApi.config.OpenQwConfig;
|
|
|
import com.fs.qwApi.domain.QwUserIdResult;
|
|
import com.fs.qwApi.domain.QwUserIdResult;
|
|
|
import com.fs.qwApi.domain.inner.DeptUser;
|
|
import com.fs.qwApi.domain.inner.DeptUser;
|
|
|
import com.fs.qwApi.param.QwOpenidByUserParams;
|
|
import com.fs.qwApi.param.QwOpenidByUserParams;
|
|
@@ -65,6 +67,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
|
|
+import java.net.SocketTimeoutException;
|
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
|
import java.security.KeyFactory;
|
|
import java.security.KeyFactory;
|
|
|
import java.security.PrivateKey;
|
|
import java.security.PrivateKey;
|
|
@@ -935,30 +938,69 @@ public class QwUserServiceImpl implements IQwUserService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public R syncQwUser(String corpId) {
|
|
|
|
|
|
|
+ public R syncQwUser(String corpId,Long tenantId) {
|
|
|
QwUserIdResult userList = qwApiService.getUserList(corpId);
|
|
QwUserIdResult userList = qwApiService.getUserList(corpId);
|
|
|
List<DeptUser> deptUser = userList.getDept_user();
|
|
List<DeptUser> deptUser = userList.getDept_user();
|
|
|
log.info("返回数据:{}", JSON.toJSONString(userList));
|
|
log.info("返回数据:{}", JSON.toJSONString(userList));
|
|
|
log.info("同步用户数量:{}", deptUser.size());
|
|
log.info("同步用户数量:{}", deptUser.size());
|
|
|
QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
|
|
|
for (DeptUser user : deptUser) {
|
|
for (DeptUser user : deptUser) {
|
|
|
- QwUser qw=qwUserMapper.selectQwUserByCorpIdAndUserId(corpId,qwApiService.getOpenUserid(qwApiService.getToken(corpId,qwCompany.getPermanentCode()),user.getUserid(),corpId));
|
|
|
|
|
|
|
+ String userid = user.getUserid();
|
|
|
|
|
+ String openUserIdRedisKey = "corpId:" + userid;
|
|
|
|
|
+ String redisResult= redisCache.getCacheObject(openUserIdRedisKey);
|
|
|
|
|
+ String openUserId = "";
|
|
|
|
|
+ if (StringUtils.isNotBlank(redisResult)){
|
|
|
|
|
+ openUserId = redisResult;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (userid != null && tenantId != null && qwCompany.getPermanentCode() != null) {
|
|
|
|
|
+ // 远程调用 fs-qw-api 同步企微用户
|
|
|
|
|
+ String url = OpenQwConfig.baseApi + "/getOpenUserid?userId=" + userid + "&corpId=" + corpId + "&permanentCode=" + qwCompany.getPermanentCode() + "&tenantId=" + tenantId;
|
|
|
|
|
+ try {
|
|
|
|
|
+ String result = HttpUtil.createPost(url)
|
|
|
|
|
+ .execute()
|
|
|
|
|
+ .body();
|
|
|
|
|
+ if (StringUtils.isNotBlank(result)) {
|
|
|
|
|
+ R r = JSON.parseObject(result, R.class);
|
|
|
|
|
+ if (!"200".equals(r.get("code").toString())) {
|
|
|
|
|
+ log.error("企微用户获取加密userId,HTTP状态码: {}", r.get("code").toString());
|
|
|
|
|
+ return R.error("企微用户获取加密userId,服务返回状态码: " + r.get("code").toString());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ openUserId = r.get("userId").toString();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("企微用户获取加密userId异常, url={}", url, e);
|
|
|
|
|
+ if (e.getCause() instanceof SocketTimeoutException) {
|
|
|
|
|
+ return R.error("企微用户获取加密userId超时,请稍后重试");
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.error("企微用户获取加密userId失败: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotBlank(openUserId)) {
|
|
|
|
|
+ QwUser qw=qwUserMapper.selectQwUserByCorpIdAndUserId(corpId, openUserId);
|
|
|
// String serverQwUserName = qwApiService.getServerQwUserName(corpId, qwCompany.getOpenSecret(), user.getUserid(),qwCompany.getPermanentCode());
|
|
// String serverQwUserName = qwApiService.getServerQwUserName(corpId, qwCompany.getOpenSecret(), user.getUserid(),qwCompany.getPermanentCode());
|
|
|
// log.info("同步用户名称:{}", serverQwUserName);
|
|
// log.info("同步用户名称:{}", serverQwUserName);
|
|
|
- QwUser qwUser = new QwUser();
|
|
|
|
|
- qwUser.setQwUserId(user.getUserid());
|
|
|
|
|
- qwUser.setDepartment(user.getDepartment().toString());
|
|
|
|
|
|
|
+ QwUser qwUser = new QwUser();
|
|
|
|
|
+ qwUser.setQwUserId(userid);
|
|
|
|
|
+ qwUser.setDepartment(user.getDepartment().toString());
|
|
|
// qwUser.setQwUserName(serverQwUserName);
|
|
// qwUser.setQwUserName(serverQwUserName);
|
|
|
- qwUser.setCorpId(corpId);
|
|
|
|
|
- QwOpenidByUserParams param=new QwOpenidByUserParams();
|
|
|
|
|
- param.setUserid(user.getUserid());
|
|
|
|
|
- QwOpenidResult qwOpenidResult = qwApiService.useridToOpenid(param, corpId);
|
|
|
|
|
- qwUser.setOpenid(qwOpenidResult.getOpenid());
|
|
|
|
|
- if (qw!=null){
|
|
|
|
|
- qwUser.setId(qw.getId());
|
|
|
|
|
- qwUser.setIsDel(0);
|
|
|
|
|
- qwUserMapper.updateQwUser(qwUser);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ qwUser.setCorpId(corpId);
|
|
|
|
|
+// QwOpenidByUserParams param=new QwOpenidByUserParams();
|
|
|
|
|
+// param.setUserid(user.getUserid());
|
|
|
|
|
+// QwOpenidResult qwOpenidResult = qwApiService.useridToOpenid(param, corpId);
|
|
|
|
|
+// qwUser.setOpenid(qwOpenidResult.getOpenid());
|
|
|
|
|
+ if (qw!=null){
|
|
|
|
|
+ qwUser.setId(qw.getId());
|
|
|
|
|
+ qwUser.setIsDel(0);
|
|
|
|
|
+ qwUserMapper.updateQwUser(qwUser);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.error("企微用户获取加密userId为空, userid={}", userid);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|