Commit 8ada8e16 authored by alex yao's avatar alex yao

fix: 文件转换多次异常

parent 5422c7e8
...@@ -414,49 +414,44 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -414,49 +414,44 @@ public class KnowledgeServiceImpl implements KnowledgeService {
//3、上传文件单一行字数超过3000字,提示:上传文件内容单一行字数不能超过3000字 //3、上传文件单一行字数超过3000字,提示:上传文件内容单一行字数不能超过3000字
//4、单格不可超1000字 //4、单格不可超1000字
//5、文件大小不能超过10M //5、文件大小不能超过10M
try { // 文件大小不能超过10M
// 文件大小不能超过10M long fileSizeInBytes = file.length();
long fileSizeInBytes = file.length(); double fileSizeInMB = (double) fileSizeInBytes / (1024 * 1024);
double fileSizeInMB = (double) fileSizeInBytes / (1024 * 1024); if (fileSizeInMB > 10) {
if (fileSizeInMB > 10) { throw new I18nMessageException("exception/upload.more.than.10m");
throw new I18nMessageException("exception/upload.more.than.10m"); }
}
ExcelReader excelReader = ExcelUtil.getReader(file); ExcelReader excelReader = ExcelUtil.getReader(file);
Workbook workbook = excelReader.getWorkbook(); Workbook workbook = excelReader.getWorkbook();
Sheet sheetAt = workbook.getSheetAt(0); Sheet sheetAt = workbook.getSheetAt(0);
int rowNum = sheetAt.getLastRowNum() - 2;//行数 int rowNum = sheetAt.getLastRowNum() - 2;//行数
if (rowNum > 1500) { if (rowNum > 1500) {
throw new I18nMessageException("exception/file.rows.more.than.1500"); throw new I18nMessageException("exception/file.rows.more.than.1500");
} }
Row row = sheetAt.getRow(2); Row row = sheetAt.getRow(2);
short lastCellNum = row.getLastCellNum();//列数 short lastCellNum = row.getLastCellNum();//列数
if (lastCellNum > 10) { if (lastCellNum > 10) {
throw new I18nMessageException("exception/file.columns.more.than.10"); throw new I18nMessageException("exception/file.columns.more.than.10");
} }
int lastRowNum = sheetAt.getLastRowNum();//最后一行索引 int lastRowNum = sheetAt.getLastRowNum();//最后一行索引
for (int i = 2; i <= lastRowNum; i++) { for (int i = 2; i <= lastRowNum; i++) {
row = sheetAt.getRow(i); row = sheetAt.getRow(i);
//获取单元格内容 //获取单元格内容
Iterator<Cell> cellIterator = row.cellIterator(); Iterator<Cell> cellIterator = row.cellIterator();
//每行字数不能超过3000字 //每行字数不能超过3000字
int totalWordCount = 0; int totalWordCount = 0;
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() > 1000) { // 每格字数不可超1000字
throw new I18nMessageException("exception/file.content.more.than.1000"); throw new I18nMessageException("exception/file.content.more.than.1000");
}
totalWordCount += next.toString().length();
} }
totalWordCount += next.toString().length();
} }
if (totalWordCount > 3000) { //每行字数不可超3000字
throw new I18nMessageException("exception/file.content.more.than.3000");
}
} }
} catch (IOException e) { if (totalWordCount > 3000) { //每行字数不可超3000字
logger.error("checkQAKnowledgeDocument error :{}", e); throw new I18nMessageException("exception/file.content.more.than.3000");
return false; }
} }
return true; return true;
} }
......
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