From 135e901ff47547ee43987c18d61a9d5c9e56e9d5 Mon Sep 17 00:00:00 2001 From: "zangch@mesnac.com" Date: Fri, 24 Oct 2025 17:26:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(portal):=20=E5=A2=9E=E5=8A=A0=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E5=AF=86=E9=92=A5=E4=BF=9D=E6=8A=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为HwWebDocument实体添加secretKey字段的@JsonIgnore注解- 新方法增getHasSecret用于判断是否存在密钥 - 在toString方法中用hasSecret替换secretKey输出 - 控制器中根据是否有密钥决定是否返回文档地址 -优化密钥验证逻辑,确保安全性 - 服务层改进密钥校验流程和错误处理机制 --- .../portal/controller/HwWebDocumentController.java | 11 ++++++++++- .../java/com/ruoyi/portal/domain/HwWebDocument.java | 8 +++++++- .../service/impl/HwWebDocumentServiceImpl.java | 13 +++++++++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/ruoyi-modules/hw-portal/src/main/java/com/ruoyi/portal/controller/HwWebDocumentController.java b/ruoyi-modules/hw-portal/src/main/java/com/ruoyi/portal/controller/HwWebDocumentController.java index b9d1316..a37c995 100644 --- a/ruoyi-modules/hw-portal/src/main/java/com/ruoyi/portal/controller/HwWebDocumentController.java +++ b/ruoyi-modules/hw-portal/src/main/java/com/ruoyi/portal/controller/HwWebDocumentController.java @@ -46,6 +46,11 @@ public class HwWebDocumentController extends BaseController { startPage(); List list = hwWebDocumentService.selectHwWebDocumentList(hwWebDocument); + for (HwWebDocument doc : list) { + if (doc.getHasSecret()) { + doc.setDocumentAddress(null); + } + } return getDataTable(list); } @@ -69,7 +74,11 @@ public class HwWebDocumentController extends BaseController @GetMapping(value = "/{documentId}") public AjaxResult getInfo(@PathVariable("documentId") String documentId) { - return success(hwWebDocumentService.selectHwWebDocumentByDocumentId(documentId)); + HwWebDocument doc = hwWebDocumentService.selectHwWebDocumentByDocumentId(documentId); + if (doc != null && doc.getHasSecret()) { + doc.setDocumentAddress(null); + } + return success(doc); } /** diff --git a/ruoyi-modules/hw-portal/src/main/java/com/ruoyi/portal/domain/HwWebDocument.java b/ruoyi-modules/hw-portal/src/main/java/com/ruoyi/portal/domain/HwWebDocument.java index b78cf04..fae5c1b 100644 --- a/ruoyi-modules/hw-portal/src/main/java/com/ruoyi/portal/domain/HwWebDocument.java +++ b/ruoyi-modules/hw-portal/src/main/java/com/ruoyi/portal/domain/HwWebDocument.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.core.annotation.Excel; import com.ruoyi.common.core.web.domain.BaseEntity; +import com.fasterxml.jackson.annotation.JsonIgnore; /** * Hw资料文件对象 hw_web_document @@ -32,6 +33,7 @@ public class HwWebDocument extends BaseEntity /** 密钥 */ @Excel(name = "密钥") + @JsonIgnore private String secretKey; /** json */ @@ -89,6 +91,10 @@ public class HwWebDocument extends BaseEntity return secretKey; } + public boolean getHasSecret() { + return secretKey != null && !secretKey.trim().isEmpty(); + } + public String getJson() { return json; } @@ -121,7 +127,7 @@ public class HwWebDocument extends BaseEntity .append("documentAddress", getDocumentAddress()) .append("createTime", getCreateTime()) .append("webCode", getWebCode()) - .append("secretKey", getSecretKey()) + .append("hasSecret", getHasSecret()) .append("json", getJson()) .append("type", getType()) .append("isDelete", getIsDelete()) diff --git a/ruoyi-modules/hw-portal/src/main/java/com/ruoyi/portal/service/impl/HwWebDocumentServiceImpl.java b/ruoyi-modules/hw-portal/src/main/java/com/ruoyi/portal/service/impl/HwWebDocumentServiceImpl.java index d8ec5c4..3c004e3 100644 --- a/ruoyi-modules/hw-portal/src/main/java/com/ruoyi/portal/service/impl/HwWebDocumentServiceImpl.java +++ b/ruoyi-modules/hw-portal/src/main/java/com/ruoyi/portal/service/impl/HwWebDocumentServiceImpl.java @@ -102,11 +102,16 @@ public class HwWebDocumentServiceImpl implements IHwWebDocumentService throw new ServiceException("文件不存在"); } String secretKey = document.getSecretKey(); - if (providedKey != null) { - providedKey = providedKey.trim(); + String address = document.getDocumentAddress(); + if (secretKey == null || secretKey.trim().isEmpty()) { + return address; } - if (secretKey.isEmpty()|| secretKey.equals(providedKey)) { - return document.getDocumentAddress(); + String trimmedProvided = providedKey == null ? null : providedKey.trim(); + if (trimmedProvided == null || trimmedProvided.isEmpty()) { + throw new ServiceException("密钥错误"); + } + if (secretKey.trim().equals(trimmedProvided)) { + return address; } else { throw new ServiceException("密钥错误"); }