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
2f555448
Commit
2f555448
authored
Mar 12, 2025
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 问答知识库 新增/更新分片内容,字数校验
parent
a8f6cd98
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
+18
-4
KnowledgeServiceImpl.java
...om/poc/knowledge/aggregate/impl/KnowledgeServiceImpl.java
+3
-4
QAKnowledgeServiceImpl.java
.../poc/knowledge/aggregate/impl/QAKnowledgeServiceImpl.java
+15
-0
No files found.
src/main/java/cn/com/poc/knowledge/aggregate/impl/KnowledgeServiceImpl.java
View file @
2f555448
...
...
@@ -81,8 +81,6 @@ public class KnowledgeServiceImpl implements KnowledgeService {
//记录成功
List
<
BizKnowledgeDocumentEntity
>
result
=
new
ArrayList
<>();
for
(
MultipartFile
documentFile
:
documentFiles
)
{
//todo 根据知识库类型,对文件内容进行校验
//获取文件名
String
documentName
=
documentFile
.
getOriginalFilename
();
String
type
=
documentFile
.
getOriginalFilename
().
substring
(
documentFile
.
getOriginalFilename
().
lastIndexOf
(
"."
)
+
1
,
documentFile
.
getOriginalFilename
().
length
());
...
...
@@ -93,6 +91,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
(
file
)
:
checkQAKnowledgeDocument
(
file
);
if
(!
check
)
{
throw
new
I18nMessageException
(
"knowledge.document.check.fail"
);
...
...
@@ -443,8 +442,8 @@ public class KnowledgeServiceImpl implements KnowledgeService {
while
(
cellIterator
.
hasNext
())
{
Cell
next
=
cellIterator
.
next
();
if
(
StringUtils
.
isNotBlank
(
next
.
toString
()))
{
if
(
next
.
toString
().
length
()
>
10
00
)
{
// 每格字数不可超1000字
throw
new
I18nMessageException
(
"exception/file.cell.content.more.than.
10
00"
);
if
(
next
.
toString
().
length
()
>
3
00
)
{
// 每格字数不可超1000字
throw
new
I18nMessageException
(
"exception/file.cell.content.more.than.
3
00"
);
}
totalWordCount
+=
next
.
toString
().
length
();
}
...
...
src/main/java/cn/com/poc/knowledge/aggregate/impl/QAKnowledgeServiceImpl.java
View file @
2f555448
...
...
@@ -65,6 +65,7 @@ public class QAKnowledgeServiceImpl implements QAKnowledgeService {
public
void
updateKnowledgeChunkDoc
(
Integer
kdId
,
String
chunkRelationId
,
List
<
ChunkInfo
>
chunkInfos
)
{
logger
.
info
(
"updateKnowledgeChunkDoc: kdId={}, chunkRelationId={}, chunkInfos={}"
,
kdId
,
chunkRelationId
,
chunkInfos
);
String
knowledgeId
=
getKnowledgeId
(
kdId
);
checkChunkInfos
(
chunkInfos
);
demandQAKnowledgeService
.
updateKnowledgeChunkDoc
(
knowledgeId
,
chunkRelationId
,
chunkInfos
);
}
...
...
@@ -72,6 +73,7 @@ public class QAKnowledgeServiceImpl implements QAKnowledgeService {
public
void
addKnowledgeChunk
(
Integer
kdId
,
List
<
ChunkInfo
>
chunkInfos
,
Integer
chunkSort
)
{
logger
.
info
(
"addKnowledgeChunk: kdId={}, chunkInfos={}, chunkSort={}"
,
kdId
,
chunkInfos
,
chunkSort
);
String
knowledgeId
=
getKnowledgeId
(
kdId
);
checkChunkInfos
(
chunkInfos
);
demandQAKnowledgeService
.
addKnowledgeChunk
(
knowledgeId
,
chunkInfos
,
chunkSort
);
}
...
...
@@ -105,5 +107,18 @@ public class QAKnowledgeServiceImpl implements QAKnowledgeService {
return
knowledgeDocumentEntity
.
getKnowledgeId
();
}
private
void
checkChunkInfos
(
List
<
ChunkInfo
>
chunkInfos
)
{
int
totalWordCount
=
0
;
for
(
ChunkInfo
chunkInfo
:
chunkInfos
)
{
totalWordCount
+=
chunkInfo
.
getContent
().
length
();
if
(
chunkInfo
.
getContent
().
length
()
>
300
)
{
throw
new
I18nMessageException
(
"exception/file.cell.content.more.than.300"
);
}
if
(
totalWordCount
>
3000
)
{
throw
new
I18nMessageException
(
"exception/file.cell.content.more.than.3000"
);
}
}
}
}
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