fix(portal):优化密钥处理逻辑

- 修改 Mapper XML,支持将空字符串密钥更新为 NULL
- 在服务层特殊处理 secretKey,将 null 转为空字符串以触发更新
- 增强密钥验证逻辑,空密钥时直接返回文档地址
- 完善密钥校验判断,明确抛出“密钥不能为空”异常
master
zangch@mesnac.com 1 month ago
parent e9f3aa47aa
commit d24aec4219

@ -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 {

@ -79,7 +79,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="documentAddress != null">document_address = #{documentAddress},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="webCode != null">web_code = #{webCode},</if>
<if test="secretKey != null">secretKey = #{secretKey},</if>
<if test="secretKey != null">
secretKey = <choose>
<when test="secretKey == ''">NULL</when>
<otherwise>#{secretKey}</otherwise>
</choose>,
</if>
<if test="json != null">json = #{json},</if>
<if test="type != null">type = #{type},</if>
</trim>

Loading…
Cancel
Save