|
|
@@ -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}")
|