From 8256e9ee8539b5e07e14d90923c3c278baca6456 Mon Sep 17 00:00:00 2001 From: wanghanlin <1533525126@qq.com> Date: Tue, 1 Sep 2026 11:10:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(upload):=20=E6=96=87=E6=A1=A3=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=8E=BB=E9=87=8D=E6=94=B9=E4=B8=BA=E4=BB=85=E5=90=8C?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=86=85=E6=9F=A5=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 去重范围从全局收窄为按分类:checkContentDuplicate 增加 category_id 条件,不同分类允许内容重复,未分类按 0 归并;修正误导文案并改用 selectList 规避多结果异常 --- .../com/wok/supportbot/service/DocumentService.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/wok/supportbot/service/DocumentService.java b/src/main/java/com/wok/supportbot/service/DocumentService.java index 40f4a25..d3abc4c 100644 --- a/src/main/java/com/wok/supportbot/service/DocumentService.java +++ b/src/main/java/com/wok/supportbot/service/DocumentService.java @@ -108,9 +108,9 @@ public class DocumentService { // 0. 内容去重检查 String contentHash = computeContentHash(content); if (contentHash != null) { - String duplicateTitle = checkContentDuplicate(contentHash); + String duplicateTitle = checkContentDuplicate(contentHash, categoryId); if (duplicateTitle != null) { - throw new RuntimeException("文档内容重复,已有同名文档: " + duplicateTitle); + throw new RuntimeException("文档内容重复,该分类下已有相同内容的文档: " + duplicateTitle); } } @@ -1076,15 +1076,16 @@ public class DocumentService { * @param contentHash 内容哈希值 * @return 重复文档的标题,如果不存在重复则返回 null */ - private String checkContentDuplicate(String contentHash) { + private String checkContentDuplicate(String contentHash, Long categoryId) { if (contentHash == null) { return null; } QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("content_hash", contentHash); + wrapper.eq("category_id", categoryId != null ? categoryId : 0L); wrapper.select("title"); - KnowledgeDocument existing = documentMapper.selectOne(wrapper); - return existing != null ? existing.getTitle() : null; + List existing = documentMapper.selectList(wrapper); + return existing != null && !existing.isEmpty() ? existing.get(0).getTitle() : null; } /**