|
|
|
@ -32,6 +32,9 @@ import java.io.IOException;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.function.Predicate;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@ -77,13 +80,22 @@ public class KGServiceImpl implements KGService {
|
|
|
|
|
if (CollUtil.isEmpty(sourceDTOList)){
|
|
|
|
|
return sourceKgInfoList;
|
|
|
|
|
}
|
|
|
|
|
// 根据fileId进行去重
|
|
|
|
|
sourceDTOList = sourceDTOList.stream().filter(distinctPredicate(SourceDTO::getFileId)).collect(Collectors.toList());
|
|
|
|
|
// qanything 中文件id与文件内容的映射
|
|
|
|
|
Map<String, String> fileIdMapContent = sourceDTOList.stream().collect(Collectors.toMap(SourceDTO::getFileId, SourceDTO::getContent, (o, n) -> o));
|
|
|
|
|
Set<String> qaFileId = sourceDTOList.stream().map(SourceDTO::getFileId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
|
|
// 优先选择的文档id
|
|
|
|
|
Set<String> preferFileIds = new HashSet<>();
|
|
|
|
|
if (CollUtil.isNotEmpty(qaFileId)) {
|
|
|
|
|
// 优先使用数据库中配置的信息
|
|
|
|
|
List<KgInfo> preferKgInfoList = kgInfoService.lambdaQuery().in(KgInfo::getFileQaDocId, qaFileId).list();
|
|
|
|
|
List<SourceKgInfo> sourceKgInfos = preferKgInfoList.stream().peek(kgInfo->preferFileIds.add(kgInfo.getFileQaDocId()))
|
|
|
|
|
.map(SourceKgInfo::kgInfo2SourceKgInfo)
|
|
|
|
|
.peek(kgInfo->{
|
|
|
|
|
if (StrUtil.isEmpty(kgInfo.getContent())){
|
|
|
|
|
kgInfo.setContent(fileIdMapContent.get(kgInfo.getFileQaDocId()));
|
|
|
|
|
}
|
|
|
|
|
}).map(SourceKgInfo::kgInfo2SourceKgInfo)
|
|
|
|
|
.filter(source-> StrUtil.isNotEmpty(source.getSummary())).collect(Collectors.toList());
|
|
|
|
|
sourceKgInfoList.addAll(sourceKgInfos);
|
|
|
|
|
}
|
|
|
|
@ -141,4 +153,11 @@ public class KGServiceImpl implements KGService {
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static <K> Predicate<K> distinctPredicate(Function<K, Object> function) {
|
|
|
|
|
ConcurrentHashMap<Object, Boolean> map = new ConcurrentHashMap<>();
|
|
|
|
|
// 根据key进行去重,并排除为null的数据
|
|
|
|
|
return t -> null == map.putIfAbsent(function.apply(t), true);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|