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; } /**