|
|
@@ -1,22 +1,31 @@
|
|
|
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.StringUtils;
|
|
|
import com.fs.common.utils.poi.ExcelUtil;
|
|
|
import com.fs.framework.service.TokenService;
|
|
|
import com.fs.qw.domain.QwTagGroup;
|
|
|
import com.fs.qw.service.IQwTagGroupService;
|
|
|
import com.fs.qw.vo.QwTagGroupAddParam;
|
|
|
import com.fs.qw.vo.QwTagGroupListVO;
|
|
|
+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.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.net.SocketTimeoutException;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -25,6 +34,7 @@ import java.util.List;
|
|
|
* @author fs
|
|
|
* @date 2024-06-20
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@RestController
|
|
|
@RequestMapping("/qw/tagGroup")
|
|
|
public class QwTagGroupController extends BaseController
|
|
|
@@ -36,6 +46,10 @@ public class QwTagGroupController extends BaseController
|
|
|
|
|
|
@Autowired
|
|
|
private RedisTemplate redisTemplate;
|
|
|
+
|
|
|
+ /** HTTP调用超时时间(秒) */
|
|
|
+ @Value("${qw.api.timeout:30}")
|
|
|
+ private int apiTimeout;
|
|
|
/**
|
|
|
* 查询企微客户标签组列表
|
|
|
*/
|
|
|
@@ -74,8 +88,26 @@ public class QwTagGroupController extends BaseController
|
|
|
@PostMapping("/syncTag/{corpId}")
|
|
|
public R syncTag(@PathVariable("corpId") String corpId)
|
|
|
{
|
|
|
-
|
|
|
- return qwTagGroupService.syncQwTagGroup(corpId);
|
|
|
+ // 从当前登录用户获取租户ID
|
|
|
+ Long tenantId = SecurityUtils.getTenantId();
|
|
|
+ String url = OpenQwConfig.api + "/qw/tagGroup/syncTag/" + 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());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -110,8 +142,27 @@ public class QwTagGroupController extends BaseController
|
|
|
@PostMapping
|
|
|
public AjaxResult add(@RequestBody QwTagGroupAddParam qwTagGroup)
|
|
|
{
|
|
|
-
|
|
|
- return toAjax(qwTagGroupService.insertQwTagGroupParam(qwTagGroup));
|
|
|
+ // 从当前登录用户获取租户ID
|
|
|
+ Long tenantId = SecurityUtils.getTenantId();
|
|
|
+ String url = OpenQwConfig.api + "/qw/tagGroup?tenantId=" + tenantId;
|
|
|
+ try {
|
|
|
+ HttpResponse response = HttpRequest.post(url)
|
|
|
+ .body(JSON.toJSONString(qwTagGroup))
|
|
|
+ .timeout(apiTimeout * 1000)
|
|
|
+ .execute();
|
|
|
+ if (response.getStatus() == 200) {
|
|
|
+ return JSON.parseObject(response.body(), AjaxResult.class);
|
|
|
+ } else {
|
|
|
+ log.error("新增标签组失败,HTTP状态码: {}", response.getStatus());
|
|
|
+ return AjaxResult.error("新增标签组失败,服务返回状态码: " + response.getStatus());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("新增标签组异常, url={}", url, e);
|
|
|
+ if (e.getCause() instanceof SocketTimeoutException) {
|
|
|
+ return AjaxResult.error("新增标签组超时,请稍后重试");
|
|
|
+ }
|
|
|
+ return AjaxResult.error("新增标签组失败: " + e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -122,8 +173,27 @@ public class QwTagGroupController extends BaseController
|
|
|
@PutMapping
|
|
|
public AjaxResult edit(@RequestBody QwTagGroupAddParam qwTagGroup)
|
|
|
{
|
|
|
-
|
|
|
- return toAjax(qwTagGroupService.updateQwTagGroupParam(qwTagGroup));
|
|
|
+ // 从当前登录用户获取租户ID
|
|
|
+ Long tenantId = SecurityUtils.getTenantId();
|
|
|
+ String url = OpenQwConfig.api + "/qw/tagGroup/update?tenantId=" + tenantId;
|
|
|
+ try {
|
|
|
+ HttpResponse response = HttpRequest.post(url)
|
|
|
+ .body(JSON.toJSONString(qwTagGroup))
|
|
|
+ .timeout(apiTimeout * 1000)
|
|
|
+ .execute();
|
|
|
+ if (response.getStatus() == 200) {
|
|
|
+ return JSON.parseObject(response.body(), AjaxResult.class);
|
|
|
+ } else {
|
|
|
+ log.error("修改标签组失败,HTTP状态码: {}", response.getStatus());
|
|
|
+ return AjaxResult.error("修改标签组失败,服务返回状态码: " + response.getStatus());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("修改标签组异常, url={}", url, e);
|
|
|
+ if (e.getCause() instanceof SocketTimeoutException) {
|
|
|
+ return AjaxResult.error("修改标签组超时,请稍后重试");
|
|
|
+ }
|
|
|
+ return AjaxResult.error("修改标签组失败: " + e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -131,10 +201,29 @@ public class QwTagGroupController extends BaseController
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('qw:tagGroup:remove')")
|
|
|
@Log(title = "企微客户标签组", businessType = BusinessType.DELETE)
|
|
|
- @DeleteMapping("/{ids}")
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
public R remove(@PathVariable Long[] ids)
|
|
|
{
|
|
|
-
|
|
|
- return qwTagGroupService.deleteQwTagGroupByIds(ids);
|
|
|
+ // 从当前登录用户获取租户ID
|
|
|
+ Long tenantId = SecurityUtils.getTenantId();
|
|
|
+ String url = OpenQwConfig.api + "/qw/tagGroup/delete/" + StringUtils.join(ids, ",") + "?tenantId=" + tenantId;
|
|
|
+ try {
|
|
|
+ HttpResponse response = HttpRequest.post(url)
|
|
|
+ .body(JSON.toJSONString(ids))
|
|
|
+ .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());
|
|
|
+ }
|
|
|
}
|
|
|
}
|