|
|
@ -108,9 +108,9 @@ public class DocumentService { |
|
|
// 0. 内容去重检查 |
|
|
// 0. 内容去重检查 |
|
|
String contentHash = computeContentHash(content); |
|
|
String contentHash = computeContentHash(content); |
|
|
if (contentHash != null) { |
|
|
if (contentHash != null) { |
|
|
String duplicateTitle = checkContentDuplicate(contentHash); |
|
|
|
|
|
|
|
|
String duplicateTitle = checkContentDuplicate(contentHash, categoryId); |
|
|
if (duplicateTitle != null) { |
|
|
if (duplicateTitle != null) { |
|
|
throw new RuntimeException("文档内容重复,已有同名文档: " + duplicateTitle); |
|
|
|
|
|
|
|
|
throw new RuntimeException("文档内容重复,该分类下已有相同内容的文档: " + duplicateTitle); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1076,15 +1076,16 @@ public class DocumentService { |
|
|
* @param contentHash 内容哈希值 |
|
|
* @param contentHash 内容哈希值 |
|
|
* @return 重复文档的标题,如果不存在重复则返回 null |
|
|
* @return 重复文档的标题,如果不存在重复则返回 null |
|
|
*/ |
|
|
*/ |
|
|
private String checkContentDuplicate(String contentHash) { |
|
|
|
|
|
|
|
|
private String checkContentDuplicate(String contentHash, Long categoryId) { |
|
|
if (contentHash == null) { |
|
|
if (contentHash == null) { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
QueryWrapper<KnowledgeDocument> wrapper = new QueryWrapper<>(); |
|
|
QueryWrapper<KnowledgeDocument> wrapper = new QueryWrapper<>(); |
|
|
wrapper.eq("content_hash", contentHash); |
|
|
wrapper.eq("content_hash", contentHash); |
|
|
|
|
|
wrapper.eq("category_id", categoryId != null ? categoryId : 0L); |
|
|
wrapper.select("title"); |
|
|
wrapper.select("title"); |
|
|
KnowledgeDocument existing = documentMapper.selectOne(wrapper); |
|
|
|
|
|
return existing != null ? existing.getTitle() : null; |
|
|
|
|
|
|
|
|
List<KnowledgeDocument> existing = documentMapper.selectList(wrapper); |
|
|
|
|
|
return existing != null && !existing.isEmpty() ? existing.get(0).getTitle() : null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|