yys 4 месяцев назад
Родитель
Сommit
c900708411

+ 78 - 6
fs-company/src/main/java/com/fs/company/controller/qw/QwWelcomeController.java

@@ -1,20 +1,28 @@
 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;
 import com.fs.qw.domain.QwWelcome;
 import com.fs.qw.service.IQwWelcomeService;
+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;
 
 /**
@@ -25,6 +33,7 @@ import java.util.List;
  */
 @RestController
 @RequestMapping("/qw/welcome")
+@Slf4j
 public class QwWelcomeController extends BaseController
 {
     @Autowired
@@ -32,6 +41,9 @@ public class QwWelcomeController extends BaseController
 
     @Autowired
     private TokenService tokenService;
+    /** HTTP调用超时时间(秒) */
+    @Value("${qw.api.timeout:30}")
+    private int apiTimeout;
     /**
      * 查询入群欢迎语管理列表
      */
@@ -64,7 +76,28 @@ public class QwWelcomeController extends BaseController
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         qwWelcome.setCompanyId(loginUser.getCompany().getCompanyId());
         qwWelcome.setCreateName(loginUser.getUser().getNickName());
-        return qwWelcomeService.insertQwWelcome(qwWelcome);
+
+        // 从当前登录用户获取租户ID
+        Long tenantId = SecurityUtils.getTenantId();
+        String url = OpenQwConfig.api + "/qw/welcome?tenantId=" + tenantId;
+        try {
+            HttpResponse response = HttpRequest.post(url)
+                    .body(JSON.toJSONString(qwWelcome))
+                    .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());
+        }
     }
 
     /**
@@ -74,7 +107,29 @@ public class QwWelcomeController extends BaseController
     @Log(title = "入群欢迎语管理", businessType = BusinessType.UPDATE)
     @PutMapping
     public R edit(@RequestBody QwWelcome qwWelcome) throws Exception {
-        return qwWelcomeService.updateQwWelcome(qwWelcome);
+
+        // 从当前登录用户获取租户ID
+        Long tenantId = SecurityUtils.getTenantId();
+        String url = OpenQwConfig.api + "/qw/welcome/edit?tenantId=" + tenantId;
+        try {
+            HttpResponse response = HttpRequest.post(url)
+                    .body(JSON.toJSONString(qwWelcome))
+                    .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());
+        }
+
     }
 
     /**
@@ -83,10 +138,27 @@ public class QwWelcomeController extends BaseController
     @PreAuthorize("@ss.hasPermi('qw:welcome:remove')")
     @Log(title = "入群欢迎语管理", businessType = BusinessType.DELETE)
 	@DeleteMapping("/{welcomeIds}")
-    public R remove(@PathVariable Long welcomeIds,@RequestParam(value = "templateId") String templateId)
+    public R remove(@PathVariable Long welcomeIds, @RequestParam(value = "templateId") String templateId)
     {
-
-
-        return qwWelcomeService.deleteQwWelcomeByWelcomeId(welcomeIds,templateId);
+        // 从当前登录用户获取租户ID
+        Long tenantId = SecurityUtils.getTenantId();
+        String url = OpenQwConfig.api + "/qw/welcome/delete?welcomeIds=" + welcomeIds + "&templateId=" + templateId + "&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());
+        }
     }
 }

+ 86 - 0
fs-qw-api/src/main/java/com/fs/app/controller/QwWelcomeController.java

@@ -0,0 +1,86 @@
+package com.fs.app.controller;
+
+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.ServletUtils;
+import com.fs.framework.datasource.TenantDataSourceUtil;
+import com.fs.framework.security.LoginUser;
+import com.fs.framework.service.TokenService;
+import com.fs.qw.domain.QwWelcome;
+import com.fs.qw.service.IQwWelcomeService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 入群欢迎语管理Controller
+ *
+ * @author fs
+ * @date 2024-06-22
+ */
+@RestController
+@RequestMapping("/qw/welcome")
+@Slf4j
+public class QwWelcomeController extends BaseController
+{
+    @Autowired
+    private IQwWelcomeService qwWelcomeService;
+
+    @Autowired
+    private TenantDataSourceUtil tenantDataSourceUtil;
+    /**
+     * 新增入群欢迎语管理
+     */
+    @Log(title = "入群欢迎语管理", businessType = BusinessType.INSERT)
+    @PostMapping
+    public R add(@RequestBody QwWelcome qwWelcome, @RequestParam("tenantId") Long tenantId) throws Exception {
+        log.info("[QwFriendWelcome] 新增入群欢迎语,tenantId={}", tenantId);
+        return tenantDataSourceUtil.executeWithResult(tenantId, () -> {
+            try {
+                return qwWelcomeService.insertQwWelcome(qwWelcome);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        });
+    }
+
+    /**
+     * 修改入群欢迎语管理
+     */
+    @Log(title = "入群欢迎语管理", businessType = BusinessType.UPDATE)
+    @PostMapping("/edit")
+    public R edit(@RequestBody QwWelcome qwWelcome, @RequestParam("tenantId") Long tenantId) throws Exception {
+
+        return tenantDataSourceUtil.executeWithResult(tenantId, () -> {
+            try {
+                return qwWelcomeService.updateQwWelcome(qwWelcome);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        });
+    }
+
+    /**
+     * 删除入群欢迎语管理
+     */
+    @Log(title = "入群欢迎语管理", businessType = BusinessType.DELETE)
+	@PostMapping("/delete")
+    public R remove(@RequestParam Long welcomeIds,@RequestParam(value = "templateId") String templateId, @RequestParam("tenantId") Long tenantId)
+    {
+
+        return tenantDataSourceUtil.executeWithResult(tenantId, () -> {
+            try {
+                return qwWelcomeService.deleteQwWelcomeByWelcomeId(welcomeIds,templateId);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        });
+    }
+}