From d24aec421970fd4c37025ceec622d18c498900cd Mon Sep 17 00:00:00 2001 From: "zangch@mesnac.com" Date: Mon, 3 Nov 2025 14:54:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(portal):=E4=BC=98=E5=8C=96=E5=AF=86?= =?UTF-8?q?=E9=92=A5=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 Mapper XML,支持将空字符串密钥更新为 NULL - 在服务层特殊处理 secretKey,将 null 转为空字符串以触发更新 - 增强密钥验证逻辑,空密钥时直接返回文档地址 - 完善密钥校验判断,明确抛出“密钥不能为空”异常 --- .../service/impl/HwWebDocumentServiceImpl.java | 13 ++++++++++++- .../resources/mapper/portal/HwWebDocumentMapper.xml | 7 ++++++- 2 files changed, 18 insertions(+), 2 deletions(-) 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 3c004e3..0ca351f 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 @@ -68,6 +68,12 @@ public class HwWebDocumentServiceImpl implements IHwWebDocumentService @Override public int updateHwWebDocument(HwWebDocument hwWebDocument) { + // 特殊处理 secretKey:前端不传或传 null 时清空数据库密钥 + // 将 null 转换为空字符串,触发 Mapper 更新条件 + if (hwWebDocument.getSecretKey() == null) { + hwWebDocument.setSecretKey(""); + } + return hwWebDocumentMapper.updateHwWebDocument(hwWebDocument); } @@ -103,13 +109,18 @@ public class HwWebDocumentServiceImpl implements IHwWebDocumentService } String secretKey = document.getSecretKey(); String address = document.getDocumentAddress(); + + // 若数据库密钥为空,则直接返回文件地址 if (secretKey == null || secretKey.trim().isEmpty()) { return address; } + + // 若密钥不为空,则需要验证提供的密钥是否相等 String trimmedProvided = providedKey == null ? null : providedKey.trim(); if (trimmedProvided == null || trimmedProvided.isEmpty()) { - throw new ServiceException("密钥错误"); + throw new ServiceException("密钥不能为空"); } + if (secretKey.trim().equals(trimmedProvided)) { return address; } else { diff --git a/ruoyi-modules/hw-portal/src/main/resources/mapper/portal/HwWebDocumentMapper.xml b/ruoyi-modules/hw-portal/src/main/resources/mapper/portal/HwWebDocumentMapper.xml index d51d660..1e4e922 100644 --- a/ruoyi-modules/hw-portal/src/main/resources/mapper/portal/HwWebDocumentMapper.xml +++ b/ruoyi-modules/hw-portal/src/main/resources/mapper/portal/HwWebDocumentMapper.xml @@ -79,7 +79,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" document_address = #{documentAddress}, create_time = #{createTime}, web_code = #{webCode}, - secretKey = #{secretKey}, + + secretKey = + NULL + #{secretKey} + , + json = #{json}, type = #{type},