|
|
@@ -650,11 +650,44 @@ public class QwUserController extends BaseController {
|
|
|
public R sync(@PathVariable String corpId)
|
|
|
{
|
|
|
List<String> strings = qwCompanyMapper.selectQwCompanyCorpIdListByCompanyId(getLoginUser().getUser().getCompanyId());
|
|
|
+ Long tenantId = SecurityUtils.getTenantId();
|
|
|
for (String string : strings) {
|
|
|
-
|
|
|
if (string.equals(corpId)){
|
|
|
- qwUserService.syncQwUser(string);
|
|
|
- qwDeptService.insertOrUpdateQwDept(string);
|
|
|
+ // 远程调用 fs-qw-api 同步企微用户
|
|
|
+ String syncUserUrl = OpenQwConfig.baseApi + "/getSyncQwUser?tenantId=" + tenantId + "&corpId=" + corpId;
|
|
|
+ try {
|
|
|
+ HttpResponse response = HttpRequest.post(syncUserUrl)
|
|
|
+ .timeout(apiTimeout * 1000)
|
|
|
+ .execute();
|
|
|
+ if (response.getStatus() != 200) {
|
|
|
+ log.error("同步企微用户失败,HTTP状态码: {}", response.getStatus());
|
|
|
+ return R.error("同步企微用户失败,服务返回状态码: " + response.getStatus());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("同步企微用户异常, url={}", syncUserUrl, e);
|
|
|
+ if (e.getCause() instanceof SocketTimeoutException) {
|
|
|
+ return R.error("同步企微用户超时,请稍后重试");
|
|
|
+ }
|
|
|
+ return R.error("同步企微用户失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 远程调用 fs-qw-api 同步企微部门
|
|
|
+ String syncDeptUrl = OpenQwConfig.baseApi + "/getSyncQwDept?tenantId=" + tenantId + "&corpId=" + corpId;
|
|
|
+ try {
|
|
|
+ HttpResponse response = HttpRequest.post(syncDeptUrl)
|
|
|
+ .timeout(apiTimeout * 1000)
|
|
|
+ .execute();
|
|
|
+ if (response.getStatus() != 200) {
|
|
|
+ log.error("同步企微部门失败,HTTP状态码: {}", response.getStatus());
|
|
|
+ return R.error("同步企微部门失败,服务返回状态码: " + response.getStatus());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("同步企微部门异常, url={}", syncDeptUrl, e);
|
|
|
+ if (e.getCause() instanceof SocketTimeoutException) {
|
|
|
+ return R.error("同步企微部门超时,请稍后重试");
|
|
|
+ }
|
|
|
+ return R.error("同步企微部门失败: " + e.getMessage());
|
|
|
+ }
|
|
|
logger.info("同步完成");
|
|
|
}
|
|
|
}
|
|
|
@@ -667,9 +700,26 @@ public class QwUserController extends BaseController {
|
|
|
public R syncName(@PathVariable String corpId)
|
|
|
{
|
|
|
List<String> strings = qwCompanyMapper.selectQwCompanyCorpIdListByCompanyId(getLoginUser().getUser().getCompanyId());
|
|
|
+ Long tenantId = SecurityUtils.getTenantId();
|
|
|
for (String string : strings) {
|
|
|
if (string.equals(corpId)){
|
|
|
- qwUserService.syncQwUserName(string);
|
|
|
+ // 远程调用 fs-qw-api 同步企微用户名称
|
|
|
+ String syncNameUrl = OpenQwConfig.baseApi + "/getSyncName?tenantId=" + tenantId + "&corpId=" + corpId;
|
|
|
+ try {
|
|
|
+ HttpResponse response = HttpRequest.post(syncNameUrl)
|
|
|
+ .timeout(apiTimeout * 1000)
|
|
|
+ .execute();
|
|
|
+ if (response.getStatus() != 200) {
|
|
|
+ log.error("同步企微用户名称失败,HTTP状态码: {}", response.getStatus());
|
|
|
+ return R.error("同步企微用户名称失败,服务返回状态码: " + response.getStatus());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("同步企微用户名称异常, url={}", syncNameUrl, e);
|
|
|
+ if (e.getCause() instanceof SocketTimeoutException) {
|
|
|
+ return R.error("同步企微用户名称超时,请稍后重试");
|
|
|
+ }
|
|
|
+ return R.error("同步企微用户名称失败: " + e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return R.ok();
|