Commit 7da2bd5d authored by alex yao's avatar alex yao

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

parent f4a7df26
...@@ -419,39 +419,39 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -419,39 +419,39 @@ public class KnowledgeServiceImpl implements KnowledgeService {
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() > 700) { // 每格字数不可超1000字 // if (next.toString().length() > 700) { // 每格字数不可超1000字
throw new I18nMessageException("exception/file.cell.content.more.than.700"); // throw new I18nMessageException("exception/file.cell.content.more.than.700");
} // }
totalWordCount += next.toString().length(); // totalWordCount += next.toString().length();
} // }
} // }
if (totalWordCount > 3000) { //每行字数不可超3000字 // if (totalWordCount > 3000) { //每行字数不可超3000字
throw new I18nMessageException("exception/file.rows.content.more.than.3000"); // throw new I18nMessageException("exception/file.rows.content.more.than.3000");
} // }
} // }
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