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
5422c7e8
Commit
5422c7e8
authored
Mar 12, 2025
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 文件转换多次异常
parent
b6c56139
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
31 deletions
+19
-31
KnowledgeServiceImpl.java
...om/poc/knowledge/aggregate/impl/KnowledgeServiceImpl.java
+19
-31
No files found.
src/main/java/cn/com/poc/knowledge/aggregate/impl/KnowledgeServiceImpl.java
View file @
5422c7e8
...
...
@@ -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
(
documentF
ile
);
boolean
check
=
knowledgeType
.
equals
(
KnowledgeConstant
.
KnowledgeType
.
BASE
)
?
checkBaseKnowledgeDocument
(
file
)
:
checkQAKnowledgeDocument
(
f
ile
);
if
(!
check
)
{
throw
new
I18nMessageException
(
"knowledge.document.check.fail"
);
}
...
...
@@ -386,11 +386,7 @@ 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
);
private
boolean
checkBaseKnowledgeDocument
(
File
file
)
{
// 文件大小不能超过10M
long
fileSizeInBytes
=
file
.
length
();
double
fileSizeInMB
=
(
double
)
fileSizeInBytes
/
(
1024
*
1024
);
...
...
@@ -409,24 +405,16 @@ public class KnowledgeServiceImpl implements KnowledgeService {
if
(
charCount
>
100
*
10000
)
{
throw
new
I18nMessageException
(
"exception/file.content.more.than.100w"
);
}
}
catch
(
IOException
e
)
{
logger
.
error
(
"checkBaseKnowledgeDocument error :{}"
,
e
);
return
false
;
}
return
true
;
}
private
boolean
checkQAKnowledgeDocument
(
MultipartFile
multipartF
ile
)
{
private
boolean
checkQAKnowledgeDocument
(
File
f
ile
)
{
//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
);
...
...
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