|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.supervision.police.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.supervision.chat.UploadParamEnum;
|
|
|
|
|
import com.supervision.chat.client.CustomMultipartFile;
|
|
|
|
@ -21,7 +22,9 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
@ -43,13 +46,23 @@ public class NoteRecordServiceImpl extends ServiceImpl<NoteRecordMapper, NoteRec
|
|
|
|
|
public void uploadFileToLangChainChat(String caseId) {
|
|
|
|
|
List<NoteRecord> recordList = this.lambdaQuery().eq(NoteRecord::getCaseId, caseId).list();
|
|
|
|
|
ModelCase modelCase = modelCaseService.getById(caseId);
|
|
|
|
|
for (NoteRecord record : recordList) {
|
|
|
|
|
if (StringUtils.isEmpty(modelCase.getCaseNo())) {
|
|
|
|
|
throw new BusinessException("案件编号不能为空");
|
|
|
|
|
log.info("案件编号不能为空");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 查询知识库中已经存在的文件
|
|
|
|
|
LangChainChatRes queryFileListRes = langChainChatService.queryFileList(modelCase.getCaseNo());
|
|
|
|
|
if (!queryFileListRes.getCode().equals(200)) {
|
|
|
|
|
log.info("获取知识库已存在的文件失败");
|
|
|
|
|
}
|
|
|
|
|
HashSet<String> knowledgeFileNameSet = new HashSet<>(JSONUtil.toList((String) queryFileListRes.getData(), String.class));
|
|
|
|
|
Set<String> databaseFileNameSet = new HashSet<>();
|
|
|
|
|
for (NoteRecord record : recordList) {
|
|
|
|
|
for (String fileId : record.getFileIds().split(",")) {
|
|
|
|
|
MinioFile minioFile = minioService.getMinioFile(fileId);
|
|
|
|
|
InputStream inputStream = null;
|
|
|
|
|
databaseFileNameSet.add(minioFile.getFilename());
|
|
|
|
|
if (!knowledgeFileNameSet.contains(minioFile.getFilename())){
|
|
|
|
|
try {
|
|
|
|
|
inputStream = minioService.getObjectInputStream(minioFile);
|
|
|
|
|
// 这里需要把文件传输,传输到知识库中去
|
|
|
|
@ -66,22 +79,27 @@ public class NoteRecordServiceImpl extends ServiceImpl<NoteRecordMapper, NoteRec
|
|
|
|
|
UploadParamEnum.docs.getStrValue());
|
|
|
|
|
if (!langChainChatRes.getCode().equals(200)) {
|
|
|
|
|
log.error("上传文件到知识库失败:{}", langChainChatRes.getMsg());
|
|
|
|
|
}else {
|
|
|
|
|
knowledgeFileNameSet.add(minioFile.getFilename());
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
log.error("从minio中获取文件失败:{}", e.getMessage());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除文件
|
|
|
|
|
// LangChainChatRes langChainChatRes = langChainChatService.deleteFile(DeleteFileDTO.create(noteRecord.getCaseId(), minioFile.getFilename()));
|
|
|
|
|
// if (!langChainChatRes.getCode().equals(200)) {
|
|
|
|
|
// throw new BusinessException("删除文件:" + minioFile.getFilename() + " 失败!");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// 遍历完成,删除知识库有,数据库没有的文件
|
|
|
|
|
for (String fileName : knowledgeFileNameSet) {
|
|
|
|
|
if (!databaseFileNameSet.contains(fileName)) {
|
|
|
|
|
LangChainChatRes langChainChatRes = langChainChatService.deleteFile(DeleteFileDTO.create(modelCase.getCaseNo(), fileName));
|
|
|
|
|
if (!langChainChatRes.getCode().equals(200)) {
|
|
|
|
|
log.error("删除文件:{} 失败!", fileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|