Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
poc-api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
poc
poc-api
Commits
8ada8e16
Commit
8ada8e16
authored
Mar 12, 2025
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 文件转换多次异常
parent
5422c7e8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
39 deletions
+34
-39
KnowledgeServiceImpl.java
...om/poc/knowledge/aggregate/impl/KnowledgeServiceImpl.java
+34
-39
No files found.
src/main/java/cn/com/poc/knowledge/aggregate/impl/KnowledgeServiceImpl.java
View file @
8ada8e16
...
@@ -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
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment