From b8d3f9e9beb01d6db97c41fb9584f0dc6428b1f0 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 3 Feb 2026 15:19:12 +0800 Subject: [PATCH] 1 --- .../controller/jarvis/CommentController.java | 28 +++++++++++++++++++ .../src/main/resources/application-dev.yml | 3 ++ .../src/main/resources/application-prod.yml | 3 ++ 3 files changed, 34 insertions(+) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/jarvis/CommentController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/jarvis/CommentController.java index 1faad19..2a3d542 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/jarvis/CommentController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/jarvis/CommentController.java @@ -5,12 +5,15 @@ import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.http.HttpUtils; import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.jarvis.domain.Comment; import com.ruoyi.jarvis.domain.dto.CommentApiStatistics; import com.ruoyi.jarvis.domain.dto.CommentStatistics; import com.ruoyi.jarvis.service.ICommentService; 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.*; @@ -28,6 +31,10 @@ public class CommentController extends BaseController { @Autowired private ICommentService commentService; + /** 获取评论外部服务地址(后端转发,避免前端跨域) */ + @Value("${jarvis.server.fetch-comments.base-url:http://192.168.8.60:5008}") + private String fetchCommentsBaseUrl; + /** * 查询京东评论列表 */ @@ -133,5 +140,26 @@ public class CommentController extends BaseController { Map map = commentService.getTbProductTypeMap(); return success(map); } + + /** + * 获取评论(后端转发到外部服务,避免前端跨域) + * 请求转发至:GET {fetch-comments.base-url}/fetch_comments?product_id=xxx + */ + @PreAuthorize("@ss.hasPermi('jarvis:comment:list')") + @Log(title = "评论管理", businessType = BusinessType.OTHER) + @GetMapping("/fetch-comments") + public AjaxResult fetchComments(@RequestParam("product_id") String productId) { + if (StringUtils.isBlank(productId)) { + return error("商品ID(product_id)不能为空"); + } + try { + String url = fetchCommentsBaseUrl + "/fetch_comments"; + String param = "product_id=" + java.net.URLEncoder.encode(productId.trim(), "UTF-8"); + HttpUtils.sendGet(url, param); + return success(); + } catch (Exception e) { + return error("调用获取评论接口失败: " + e.getMessage()); + } + } } diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index c496f13..0d810e6 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -202,6 +202,9 @@ jarvis: base-url: http://192.168.8.88:5001 fetch-path: /fetch_logistics health-path: /health + # 获取评论接口服务地址(后端转发,避免前端跨域) + fetch-comments: + base-url: http://192.168.8.60:5008 # 腾讯文档开放平台配置 # 文档地址:https://docs.qq.com/open/document/app/openapi/v3/sheet/model/spreadsheet.html tencent: diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml index 1647fea..1c9afa5 100644 --- a/ruoyi-admin/src/main/resources/application-prod.yml +++ b/ruoyi-admin/src/main/resources/application-prod.yml @@ -202,6 +202,9 @@ jarvis: base-url: http://127.0.0.1:5001 fetch-path: /fetch_logistics health-path: /health + # 获取评论接口服务地址(后端转发) + fetch-comments: + base-url: http://192.168.8.60:5008 # 腾讯文档开放平台配置 # 文档地址:https://docs.qq.com/open/document/app/openapi/v3/sheet/model/spreadsheet.html tencent: