Forráskód Böngészése

1、迁移企微的接口迁移到qw-api模块中

yys 1 hónapja
szülő
commit
a8c59146e8

+ 32 - 6
fs-company/src/main/java/com/fs/company/controller/qw/QwDeptController.java

@@ -1,11 +1,14 @@
 package com.fs.company.controller.qw;
 
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
 import com.fs.common.annotation.Log;
 import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
+import com.fs.common.utils.SecurityUtils;
 import com.fs.common.utils.ServletUtils;
 import com.fs.common.utils.StringUtils;
 import com.fs.common.utils.poi.ExcelUtil;
@@ -14,10 +17,14 @@ import com.fs.framework.service.TokenService;
 import com.fs.qw.domain.QwDept;
 import com.fs.qw.mapper.QwCompanyMapper;
 import com.fs.qw.service.IQwDeptService;
+import com.fs.qwApi.config.OpenQwConfig;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
+import java.net.SocketTimeoutException;
 import java.util.List;
 
 /**
@@ -26,6 +33,7 @@ import java.util.List;
  * @author fs
  * @date 2024-08-27
  */
+@Slf4j
 @RestController
 @RequestMapping("/qw/qwDept")
 public class QwDeptController extends BaseController
@@ -39,6 +47,10 @@ public class QwDeptController extends BaseController
     @Autowired
     QwCompanyMapper qwCompanyMapper;
 
+    /** HTTP调用超时时间(秒) */
+    @Value("${qw.api.timeout:30}")
+    private int apiTimeout;
+
     /**
      * 查询企业微信部门列表
      */
@@ -52,19 +64,33 @@ public class QwDeptController extends BaseController
     }
 
     /**
-    * 同步企业微信 部门信息
+    * 同步企业微信 部门信息(远程调用fs-qw-api)
     */
     @PreAuthorize("@ss.hasPermi('qw:qwDept:list')")
     @GetMapping("/syncDept")
     public R syncDept(){
-        QwDept qwDept=new QwDept();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         List<String> strings = qwCompanyMapper.selectQwCompanyCorpIdListByCompanyId(loginUser.getCompany().getCompanyId());
-        for (String string : strings) {
-            qwDeptService.insertOrUpdateQwDept(string);
+        Long tenantId = SecurityUtils.getTenantId();
+        for (String corpId : strings) {
+            String url = OpenQwConfig.api + "/getSyncQwDept?tenantId=" + tenantId + "&corpId=" + corpId;
+            try {
+                HttpResponse response = HttpRequest.post(url)
+                        .timeout(apiTimeout * 1000)
+                        .execute();
+                if (response.getStatus() != 200) {
+                    log.error("同步企微部门失败,corpId={},HTTP状态码: {}", corpId, response.getStatus());
+                    return R.error("同步企微部门失败,服务返回状态码: " + response.getStatus());
+                }
+            } catch (Exception e) {
+                log.error("同步企微部门异常, url={}", url, e);
+                if (e.getCause() instanceof SocketTimeoutException) {
+                    return R.error("同步企微部门超时,请稍后重试");
+                }
+                return R.error("同步企微部门失败: " + e.getMessage());
+            }
         }
-
-        return  R.ok();
+        return R.ok();
     }
 
     /**

+ 32 - 2
fs-company/src/main/java/com/fs/company/controller/qw/QwExternalContactTransferCompanyAuditController.java

@@ -1,11 +1,15 @@
 package com.fs.company.controller.qw;
 
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
+import com.alibaba.fastjson.JSON;
 import com.fs.common.annotation.Log;
 import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
+import com.fs.common.utils.SecurityUtils;
 import com.fs.common.utils.ServletUtils;
 import com.fs.framework.security.LoginUser;
 import com.fs.framework.service.TokenService;
@@ -13,12 +17,17 @@ import com.fs.qw.domain.QwExternalContactTransferCompanyAudit;
 import com.fs.qw.domain.QwExternalContactTransferCompanyAuditUser;
 import com.fs.qw.service.IQwExternalContactTransferCompanyAuditService;
 import com.fs.qw.service.IQwExternalContactTransferCompanyAuditUserService;
+import com.fs.qwApi.config.OpenQwConfig;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
+import java.net.SocketTimeoutException;
 import java.util.List;
 
+@Slf4j
 @RestController
 @RequestMapping("/qw/externalContactTransferCompanyAudit")
 public class QwExternalContactTransferCompanyAuditController extends BaseController {
@@ -30,6 +39,10 @@ public class QwExternalContactTransferCompanyAuditController extends BaseControl
     @Autowired
     private TokenService tokenService;
 
+    /** HTTP调用超时时间(秒) */
+    @Value("${qw.api.timeout:30}")
+    private int apiTimeout;
+
     @PreAuthorize("@ss.hasPermi('qw:externalContactTransferCompanyAudit:list')")
     @GetMapping("/list")
     public TableDataInfo list(QwExternalContactTransferCompanyAudit param) {
@@ -45,8 +58,25 @@ public class QwExternalContactTransferCompanyAuditController extends BaseControl
     @Log(title = "公司转接同步", businessType = BusinessType.INSERT)
     @PostMapping("/sync/{auditId}")
     public R sync(@PathVariable("auditId") Long auditId) {
-        auditService.syncTransfer(auditId);
-        return R.ok();
+        Long tenantId = SecurityUtils.getTenantId();
+        String url = OpenQwConfig.api + "/qw/externalContactTransferCompanyAudit/sync/" + auditId + "?tenantId=" + tenantId;
+        try {
+            HttpResponse response = HttpRequest.post(url)
+                    .timeout(apiTimeout * 1000)
+                    .execute();
+            if (response.getStatus() == 200) {
+                return JSON.parseObject(response.body(), R.class);
+            } else {
+                log.error("同步转接状态失败,HTTP状态码: {}", response.getStatus());
+                return R.error("同步转接状态失败,服务返回状态码: " + response.getStatus());
+            }
+        } catch (Exception e) {
+            log.error("同步转接状态异常, url={}", url, e);
+            if (e.getCause() instanceof SocketTimeoutException) {
+                return R.error("同步转接状态超时,请稍后重试");
+            }
+            return R.error("同步转接状态失败: " + e.getMessage());
+        }
     }
 
     @PreAuthorize("@ss.hasPermi('qw:externalContactTransferCompanyAudit:detail')")

+ 32 - 4
fs-company/src/main/java/com/fs/company/controller/qw/QwExternalContactTransferLogController.java

@@ -1,11 +1,15 @@
 package com.fs.company.controller.qw;
 
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
+import com.alibaba.fastjson.JSON;
 import com.fs.common.annotation.Log;
 import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
+import com.fs.common.utils.SecurityUtils;
 import com.fs.common.utils.ServletUtils;
 import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.company.service.impl.CompanyDeptServiceImpl;
@@ -15,10 +19,14 @@ import com.fs.qw.domain.QwExternalContactTransferLog;
 import com.fs.qw.param.QwExternalContactTransferLogParam;
 import com.fs.qw.service.IQwExternalContactTransferLogService;
 import com.fs.qw.vo.QwExternalContactTransferLogListVO;
+import com.fs.qwApi.config.OpenQwConfig;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
+import java.net.SocketTimeoutException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -28,6 +36,7 @@ import java.util.List;
  * @author fs
  * @date 2024-06-27
  */
+@Slf4j
 @RestController
 @RequestMapping("/qw/externalContactTransferLog")
 public class QwExternalContactTransferLogController extends BaseController
@@ -41,6 +50,10 @@ public class QwExternalContactTransferLogController extends BaseController
     @Autowired
     private CompanyDeptServiceImpl companyDeptService;
 
+    /** HTTP调用超时时间(秒) */
+    @Value("${qw.api.timeout:30}")
+    private int apiTimeout;
+
     /**
      * 查询转接记录列表
      */
@@ -116,10 +129,25 @@ public class QwExternalContactTransferLogController extends BaseController
     @GetMapping("/sync/{corpId}")
     public R syncTag(@PathVariable("corpId") String corpId)
     {
-//        transferService.syncQwExternalContactTransferLog(corpId);
-//
-         qwExternalContactTransferLogService.syncQwExternalContactTransferLog(corpId);
-        return R.ok();
+        Long tenantId = SecurityUtils.getTenantId();
+        String url = OpenQwConfig.api + "/qw/externalContactTransferLog/sync/" + corpId + "?tenantId=" + tenantId;
+        try {
+            HttpResponse response = HttpRequest.get(url)
+                    .timeout(apiTimeout * 1000)
+                    .execute();
+            if (response.getStatus() == 200) {
+                return JSON.parseObject(response.body(), R.class);
+            } else {
+                log.error("同步转接记录失败,HTTP状态码: {}", response.getStatus());
+                return R.error("同步转接记录失败,服务返回状态码: " + response.getStatus());
+            }
+        } catch (Exception e) {
+            log.error("同步转接记录异常, url={}", url, e);
+            if (e.getCause() instanceof SocketTimeoutException) {
+                return R.error("同步转接记录超时,请稍后重试");
+            }
+            return R.error("同步转接记录失败: " + e.getMessage());
+        }
     }
     /**
      * 获取转接记录详细信息

+ 57 - 22
fs-company/src/main/java/com/fs/company/controller/qw/QwGroupChatController.java

@@ -1,25 +1,29 @@
 package com.fs.company.controller.qw;
 
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
+import com.alibaba.fastjson.JSON;
 import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.page.TableDataInfo;
+import com.fs.common.utils.SecurityUtils;
 import com.fs.common.utils.ServletUtils;
 import com.fs.company.service.impl.CompanyDeptServiceImpl;
 import com.fs.framework.security.LoginUser;
 import com.fs.framework.service.TokenService;
 import com.fs.qw.param.QwGroupChatParam;
 import com.fs.qw.service.IQwGroupChatService;
-import com.fs.qw.service.IQwUserService;
 import com.fs.qw.vo.QwGroupChatOptionsVO;
 import com.fs.qw.vo.QwGroupChatVO;
+import com.fs.qwApi.config.OpenQwConfig;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import java.net.SocketTimeoutException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -29,6 +33,7 @@ import java.util.List;
  * @author fs
  * @date 2024-06-20
  */
+@Slf4j
 @RestController
 @RequestMapping("/qw/groupChat")
 public class QwGroupChatController extends BaseController
@@ -42,9 +47,9 @@ public class QwGroupChatController extends BaseController
     @Autowired
     private CompanyDeptServiceImpl companyDeptService;
 
-
-    @Autowired
-    private IQwUserService iQwUserService;
+    /** HTTP调用超时时间(秒) */
+    @Value("${qw.api.timeout:30}")
+    private int apiTimeout;
 
     /**
      * 查询客户群详情列表
@@ -115,28 +120,58 @@ public class QwGroupChatController extends BaseController
     }
 
     /**
-     *  同步 插入客户群信息
+     *  同步 插入客户群信息(远程调用fs-qw-api)
      */
     @GetMapping("/cogradientGroupChat/{corpId}")
-    public R cogradientGroupChat(@PathVariable("corpId") String corpId) throws Exception {
-
-//        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
-//        Long companyId = loginUser.getCompany().getCompanyId();
-        List<String> qwUserIdList=new ArrayList<>();
-        return qwGroupChatService.cogradientGroupChat(corpId,qwUserIdList);
+    public R cogradientGroupChat(@PathVariable("corpId") String corpId) {
+        Long tenantId = SecurityUtils.getTenantId();
+        String url = OpenQwConfig.api + "/qw/groupChat/cogradientGroupChat/" + corpId + "?tenantId=" + tenantId;
+        try {
+            HttpResponse response = HttpRequest.get(url)
+                    .timeout(apiTimeout * 1000)
+                    .execute();
+            if (response.getStatus() == 200) {
+                return JSON.parseObject(response.body(), R.class);
+            } else {
+                log.error("同步客户群信息失败,HTTP状态码: {}", response.getStatus());
+                return R.error("同步客户群信息失败,服务返回状态码: " + response.getStatus());
+            }
+        } catch (Exception e) {
+            log.error("同步客户群信息异常, url={}", url, e);
+            if (e.getCause() instanceof SocketTimeoutException) {
+                return R.error("同步客户群信息超时,请稍后重试");
+            }
+            return R.error("同步客户群信息失败: " + e.getMessage());
+        }
     }
 
     /**
-     *  同步 我的客户群信息
+     *  同步 我的客户群信息(远程调用fs-qw-api)
      */
     @GetMapping("/cogradientMyGroupChat/{corpId}")
-    public R cogradientMyGroupChat(@PathVariable("corpId") String corpId) throws Exception {
-
+    public R cogradientMyGroupChat(@PathVariable("corpId") String corpId) {
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
-
-        List<String> qwUserIdList = iQwUserService.selectQwUserListByCompanyUserId(loginUser.getUser().getUserId(), corpId);
-
-        return qwGroupChatService.cogradientGroupChat(corpId,qwUserIdList);
+        Long tenantId = SecurityUtils.getTenantId();
+        String url = OpenQwConfig.api + "/qw/groupChat/cogradientMyGroupChat/" + corpId
+                + "?tenantId=" + tenantId
+                + "&companyUserId=" + loginUser.getUser().getUserId();
+        try {
+            HttpResponse response = HttpRequest.get(url)
+                    .timeout(apiTimeout * 1000)
+                    .execute();
+            if (response.getStatus() == 200) {
+                return JSON.parseObject(response.body(), R.class);
+            } else {
+                log.error("同步我的客户群信息失败,HTTP状态码: {}", response.getStatus());
+                return R.error("同步我的客户群信息失败,服务返回状态码: " + response.getStatus());
+            }
+        } catch (Exception e) {
+            log.error("同步我的客户群信息异常, url={}", url, e);
+            if (e.getCause() instanceof SocketTimeoutException) {
+                return R.error("同步我的客户群信息超时,请稍后重试");
+            }
+            return R.error("同步我的客户群信息失败: " + e.getMessage());
+        }
     }
 
     @GetMapping("/allList/{corpId}")