Commit 2f555448 authored by alex yao's avatar alex yao

feat: 问答知识库 新增/更新分片内容,字数校验

parent a8f6cd98
...@@ -81,8 +81,6 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -81,8 +81,6 @@ public class KnowledgeServiceImpl implements KnowledgeService {
//记录成功 //记录成功
List<BizKnowledgeDocumentEntity> result = new ArrayList<>(); List<BizKnowledgeDocumentEntity> result = new ArrayList<>();
for (MultipartFile documentFile : documentFiles) { for (MultipartFile documentFile : documentFiles) {
//todo 根据知识库类型,对文件内容进行校验
//获取文件名 //获取文件名
String documentName = documentFile.getOriginalFilename(); String documentName = documentFile.getOriginalFilename();
String type = documentFile.getOriginalFilename().substring(documentFile.getOriginalFilename().lastIndexOf(".") + 1, documentFile.getOriginalFilename().length()); String type = documentFile.getOriginalFilename().substring(documentFile.getOriginalFilename().lastIndexOf(".") + 1, documentFile.getOriginalFilename().length());
...@@ -93,6 +91,7 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -93,6 +91,7 @@ public class KnowledgeServiceImpl implements KnowledgeService {
// 统计文件字符数 // 统计文件字符数
String fileContent = DocumentLoad.documentToText(file).replaceAll(StringUtils.LF, StringUtils.EMPTY).replaceAll(StringUtils.CR, StringUtils.EMPTY);//文件内容 String fileContent = DocumentLoad.documentToText(file).replaceAll(StringUtils.LF, StringUtils.EMPTY).replaceAll(StringUtils.CR, StringUtils.EMPTY);//文件内容
long charCount = fileContent.length(); long charCount = fileContent.length();
// 文档校验
boolean check = knowledgeType.equals(KnowledgeConstant.KnowledgeType.BASE) ? checkBaseKnowledgeDocument(file) : checkQAKnowledgeDocument(file); boolean check = knowledgeType.equals(KnowledgeConstant.KnowledgeType.BASE) ? checkBaseKnowledgeDocument(file) : checkQAKnowledgeDocument(file);
if (!check) { if (!check) {
throw new I18nMessageException("knowledge.document.check.fail"); throw new I18nMessageException("knowledge.document.check.fail");
...@@ -443,8 +442,8 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -443,8 +442,8 @@ public class KnowledgeServiceImpl implements KnowledgeService {
while (cellIterator.hasNext()) { while (cellIterator.hasNext()) {
Cell next = cellIterator.next(); Cell next = cellIterator.next();
if (StringUtils.isNotBlank(next.toString())) { if (StringUtils.isNotBlank(next.toString())) {
if (next.toString().length() > 1000) { // 每格字数不可超1000字 if (next.toString().length() > 300) { // 每格字数不可超1000字
throw new I18nMessageException("exception/file.cell.content.more.than.1000"); throw new I18nMessageException("exception/file.cell.content.more.than.300");
} }
totalWordCount += next.toString().length(); totalWordCount += next.toString().length();
} }
......
...@@ -65,6 +65,7 @@ public class QAKnowledgeServiceImpl implements QAKnowledgeService { ...@@ -65,6 +65,7 @@ public class QAKnowledgeServiceImpl implements QAKnowledgeService {
public void updateKnowledgeChunkDoc(Integer kdId, String chunkRelationId, List<ChunkInfo> chunkInfos) { public void updateKnowledgeChunkDoc(Integer kdId, String chunkRelationId, List<ChunkInfo> chunkInfos) {
logger.info("updateKnowledgeChunkDoc: kdId={}, chunkRelationId={}, chunkInfos={}", kdId, chunkRelationId, chunkInfos); logger.info("updateKnowledgeChunkDoc: kdId={}, chunkRelationId={}, chunkInfos={}", kdId, chunkRelationId, chunkInfos);
String knowledgeId = getKnowledgeId(kdId); String knowledgeId = getKnowledgeId(kdId);
checkChunkInfos(chunkInfos);
demandQAKnowledgeService.updateKnowledgeChunkDoc(knowledgeId, chunkRelationId, chunkInfos); demandQAKnowledgeService.updateKnowledgeChunkDoc(knowledgeId, chunkRelationId, chunkInfos);
} }
...@@ -72,6 +73,7 @@ public class QAKnowledgeServiceImpl implements QAKnowledgeService { ...@@ -72,6 +73,7 @@ public class QAKnowledgeServiceImpl implements QAKnowledgeService {
public void addKnowledgeChunk(Integer kdId, List<ChunkInfo> chunkInfos, Integer chunkSort) { public void addKnowledgeChunk(Integer kdId, List<ChunkInfo> chunkInfos, Integer chunkSort) {
logger.info("addKnowledgeChunk: kdId={}, chunkInfos={}, chunkSort={}", kdId, chunkInfos, chunkSort); logger.info("addKnowledgeChunk: kdId={}, chunkInfos={}, chunkSort={}", kdId, chunkInfos, chunkSort);
String knowledgeId = getKnowledgeId(kdId); String knowledgeId = getKnowledgeId(kdId);
checkChunkInfos(chunkInfos);
demandQAKnowledgeService.addKnowledgeChunk(knowledgeId, chunkInfos, chunkSort); demandQAKnowledgeService.addKnowledgeChunk(knowledgeId, chunkInfos, chunkSort);
} }
...@@ -105,5 +107,18 @@ public class QAKnowledgeServiceImpl implements QAKnowledgeService { ...@@ -105,5 +107,18 @@ public class QAKnowledgeServiceImpl implements QAKnowledgeService {
return knowledgeDocumentEntity.getKnowledgeId(); return knowledgeDocumentEntity.getKnowledgeId();
} }
private void checkChunkInfos(List<ChunkInfo> chunkInfos) {
int totalWordCount = 0;
for (ChunkInfo chunkInfo : chunkInfos) {
totalWordCount += chunkInfo.getContent().length();
if (chunkInfo.getContent().length() > 300) {
throw new I18nMessageException("exception/file.cell.content.more.than.300");
}
if (totalWordCount > 3000) {
throw new I18nMessageException("exception/file.cell.content.more.than.3000");
}
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment