Browse Source

fix(upload): 文档上传去重改为仅同分类内查重

去重范围从全局收窄为按分类:checkContentDuplicate 增加 category_id 条件,不同分类允许内容重复,未分类按 0 归并;修正误导文案并改用 selectList 规避多结果异常
Spring-AI-1.1.2
wanghanlin 2 weeks ago
parent
commit
8256e9ee85
  1. 11
      src/main/java/com/wok/supportbot/service/DocumentService.java

11
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<KnowledgeDocument> 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<KnowledgeDocument> existing = documentMapper.selectList(wrapper);
return existing != null && !existing.isEmpty() ? existing.get(0).getTitle() : null;
}
/**

Loading…
Cancel
Save