Commit 5422c7e8 authored by alex yao's avatar alex yao

fix: 文件转换多次异常

parent b6c56139
......@@ -93,7 +93,7 @@ public class KnowledgeServiceImpl implements KnowledgeService {
// 统计文件字符数
String fileContent = DocumentLoad.documentToText(file).replaceAll(StringUtils.LF, StringUtils.EMPTY).replaceAll(StringUtils.CR, StringUtils.EMPTY);//文件内容
long charCount = fileContent.length();
boolean check = knowledgeType.equals(KnowledgeConstant.KnowledgeType.BASE) ? checkBaseKnowledgeDocument(documentFile) : checkQAKnowledgeDocument(documentFile);
boolean check = knowledgeType.equals(KnowledgeConstant.KnowledgeType.BASE) ? checkBaseKnowledgeDocument(file) : checkQAKnowledgeDocument(file);
if (!check) {
throw new I18nMessageException("knowledge.document.check.fail");
}
......@@ -386,47 +386,35 @@ public class KnowledgeServiceImpl implements KnowledgeService {
}
private boolean checkBaseKnowledgeDocument(MultipartFile multipartFile) {
try {
String type = multipartFile.getOriginalFilename().substring(multipartFile.getOriginalFilename().lastIndexOf(".") + 1, multipartFile.getOriginalFilename().length());
File file = File.createTempFile(UUIDTool.getUUID(), "." + type);
multipartFile.transferTo(file);
// 文件大小不能超过10M
long fileSizeInBytes = file.length();
double fileSizeInMB = (double) fileSizeInBytes / (1024 * 1024);
if (fileSizeInMB > 10) {
throw new I18nMessageException("exception/upload.more.than.10m");
}
private boolean checkBaseKnowledgeDocument(File file) {
// 文件大小不能超过10M
long fileSizeInBytes = file.length();
double fileSizeInMB = (double) fileSizeInBytes / (1024 * 1024);
if (fileSizeInMB > 10) {
throw new I18nMessageException("exception/upload.more.than.10m");
}
//文件内容不能为空
String fileContent = DocumentLoad.documentToText(file).replaceAll(StringUtils.LF, StringUtils.EMPTY).replaceAll(StringUtils.CR, StringUtils.EMPTY);//文件内容
if (StringUtils.isBlank(fileContent)) {
throw new I18nMessageException("exception/error.file.content.is.null");
}
//获取文件字符数
long charCount = fileContent.length();
//文件字符数不能超过100w
if (charCount > 100 * 10000) {
throw new I18nMessageException("exception/file.content.more.than.100w");
}
} catch (IOException e) {
logger.error("checkBaseKnowledgeDocument error :{}", e);
return false;
//文件内容不能为空
String fileContent = DocumentLoad.documentToText(file).replaceAll(StringUtils.LF, StringUtils.EMPTY).replaceAll(StringUtils.CR, StringUtils.EMPTY);//文件内容
if (StringUtils.isBlank(fileContent)) {
throw new I18nMessageException("exception/error.file.content.is.null");
}
//获取文件字符数
long charCount = fileContent.length();
//文件字符数不能超过100w
if (charCount > 100 * 10000) {
throw new I18nMessageException("exception/file.content.more.than.100w");
}
return true;
}
private boolean checkQAKnowledgeDocument(MultipartFile multipartFile) {
private boolean checkQAKnowledgeDocument(File file) {
//1、上传文件列数超过10列,提示:上传文件内容不能超过10列
//2、上传文件行数超过1500行,提示:上传文件内容不能超过1500行
//3、上传文件单一行字数超过3000字,提示:上传文件内容单一行字数不能超过3000字
//4、单格不可超1000字
//5、文件大小不能超过10M
try {
String type = multipartFile.getOriginalFilename().substring(multipartFile.getOriginalFilename().lastIndexOf(".") + 1, multipartFile.getOriginalFilename().length());
File file = File.createTempFile(UUIDTool.getUUID(), "." + type);
multipartFile.transferTo(file);
// 文件大小不能超过10M
long fileSizeInBytes = file.length();
double fileSizeInMB = (double) fileSizeInBytes / (1024 * 1024);
......
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