Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
practical_train
Commits
af106c16
Commit
af106c16
authored
Nov 09, 2026
by
wujipeng
Browse files
优化
parent
b224d61a
Changes
4
Show whitespace changes
Inline
Side-by-side
practical-business/src/main/java/com/platform/business/service/impl/TheoreticalLibraryImportPreviewServiceImpl.java
View file @
af106c16
...
@@ -507,6 +507,20 @@ public class TheoreticalLibraryImportPreviewServiceImpl
...
@@ -507,6 +507,20 @@ public class TheoreticalLibraryImportPreviewServiceImpl
markers
.
add
(
new
OptionMarker
(
markers
.
add
(
new
OptionMarker
(
matcher
.
group
(
1
).
toUpperCase
(
Locale
.
ROOT
),
matcher
.
start
(),
matcher
.
end
()));
matcher
.
group
(
1
).
toUpperCase
(
Locale
.
ROOT
),
matcher
.
start
(),
matcher
.
end
()));
}
}
/*
* 字母括号也可能是选项正文,例如实际文件中 C 选项的单位
* “kgBOD5/kgMLSS·(D)”。若最后一个字母括号与前文紧贴,且其后
* 没有任何内容,它不具备独立选项的分隔和正文特征,因此作为
* 前一选项内容保留。前面有空白分隔的空选项仍按选项标记处理。
*/
if
(
markers
.
size
()
>
1
)
{
OptionMarker
last
=
markers
.
get
(
markers
.
size
()
-
1
);
boolean
attachedToPreviousText
=
last
.
start
>
0
&&
!
Character
.
isWhitespace
(
optionText
.
charAt
(
last
.
start
-
1
));
if
(
attachedToPreviousText
&&
isBlank
(
optionText
.
substring
(
last
.
end
)))
{
markers
.
remove
(
markers
.
size
()
-
1
);
}
}
if
(
markers
.
isEmpty
())
{
if
(
markers
.
isEmpty
())
{
addIssue
(
result
.
issues
,
"OPTION_PARSE_ERROR"
,
"未识别到(A)~(E)选项标记"
);
addIssue
(
result
.
issues
,
"OPTION_PARSE_ERROR"
,
"未识别到(A)~(E)选项标记"
);
return
;
return
;
...
...
practical-business/src/main/java/com/platform/business/service/impl/TheoreticalLibraryServiceImpl.java
View file @
af106c16
...
@@ -207,25 +207,11 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
...
@@ -207,25 +207,11 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
//拿到下一行内容并且跳过下一轮
//拿到下一行内容并且跳过下一轮
String
stringCellValue
=
getCellValueAsString
(
sheet
.
getRow
(++
i
).
getCell
(
4
));
String
stringCellValue
=
getCellValueAsString
(
sheet
.
getRow
(++
i
).
getCell
(
4
));
if
(
StringUtils
.
isNotEmpty
(
stringCellValue
))
{
if
(
StringUtils
.
isNotEmpty
(
stringCellValue
))
{
String
replace
=
normalizeOptionMarkers
(
stringCellValue
)
List
<
String
>
parsedOptions
=
splitLegacyOptions
(
stringCellValue
);
.
replace
(
"(A)"
,
""
).
replace
(
"(B)"
,
"&&"
)
optionA
=
optionAt
(
parsedOptions
,
0
);
.
replace
(
"(C)"
,
"&&"
).
replace
(
"(D)"
,
"&&"
).
replace
(
" "
,
""
);
optionB
=
optionAt
(
parsedOptions
,
1
);
String
[]
split
=
replace
.
split
(
"&&"
);
optionC
=
optionAt
(
parsedOptions
,
2
);
if
(
split
.
length
==
4
)
{
optionD
=
optionAt
(
parsedOptions
,
3
);
optionD
=
split
[
3
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionC
=
split
[
2
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionB
=
split
[
1
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
else
if
(
split
.
length
==
3
)
{
optionC
=
split
[
2
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionB
=
split
[
1
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
else
if
(
split
.
length
==
2
)
{
optionB
=
split
[
1
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
else
if
(
split
.
length
==
1
)
{
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
}
}
}
}
}
else
if
(
typeTip
==
3
)
{
}
else
if
(
typeTip
==
3
)
{
...
@@ -239,31 +225,12 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
...
@@ -239,31 +225,12 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
}
}
//拿到下一行内容并且跳过下一轮
//拿到下一行内容并且跳过下一轮
String
stringCellValue
=
getCellValueAsString
(
sheet
.
getRow
(++
i
).
getCell
(
4
));
String
stringCellValue
=
getCellValueAsString
(
sheet
.
getRow
(++
i
).
getCell
(
4
));
String
replace
=
normalizeOptionMarkers
(
stringCellValue
)
List
<
String
>
parsedOptions
=
splitLegacyOptions
(
stringCellValue
);
.
replace
(
"(A)"
,
""
).
replace
(
"(B)"
,
"&&"
)
optionA
=
optionAt
(
parsedOptions
,
0
);
.
replace
(
"(C)"
,
"&&"
).
replace
(
"(D)"
,
"&&"
).
replace
(
"(E)"
,
"&&"
).
replace
(
" "
,
""
);
optionB
=
optionAt
(
parsedOptions
,
1
);
String
[]
split
=
replace
.
split
(
"&&"
);
optionC
=
optionAt
(
parsedOptions
,
2
);
if
(
split
.
length
==
5
)
{
optionD
=
optionAt
(
parsedOptions
,
3
);
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionE
=
optionAt
(
parsedOptions
,
4
);
optionB
=
split
[
1
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionC
=
split
[
2
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionD
=
split
[
3
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionE
=
split
[
4
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
else
if
(
split
.
length
==
4
)
{
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionB
=
split
[
1
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionC
=
split
[
2
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionD
=
split
[
3
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
else
if
(
split
.
length
==
3
)
{
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionB
=
split
[
1
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionC
=
split
[
2
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
else
if
(
split
.
length
==
2
)
{
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionB
=
split
[
1
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
else
if
(
split
.
length
==
1
)
{
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
}
}
}
}
}
}
...
@@ -423,25 +390,11 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
...
@@ -423,25 +390,11 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
String
stringCellValue
=
getCellValueAsString
(
sheet
.
getRow
(++
i
).
getCell
(
4
));
String
stringCellValue
=
getCellValueAsString
(
sheet
.
getRow
(++
i
).
getCell
(
4
));
System
.
out
.
println
(
"单选题答案--------------"
+
stringCellValue
);
System
.
out
.
println
(
"单选题答案--------------"
+
stringCellValue
);
if
(
StringUtils
.
isNotEmpty
(
stringCellValue
))
{
if
(
StringUtils
.
isNotEmpty
(
stringCellValue
))
{
String
replace
=
normalizeOptionMarkers
(
stringCellValue
)
List
<
String
>
parsedOptions
=
splitLegacyOptions
(
stringCellValue
);
.
replace
(
"(A)"
,
""
).
replace
(
"(B)"
,
"&&"
)
optionA
=
optionAt
(
parsedOptions
,
0
);
.
replace
(
"(C)"
,
"&&"
).
replace
(
"(D)"
,
"&&"
).
replace
(
" "
,
""
);
optionB
=
optionAt
(
parsedOptions
,
1
);
String
[]
split
=
replace
.
split
(
"&&"
);
optionC
=
optionAt
(
parsedOptions
,
2
);
if
(
split
.
length
==
4
)
{
optionD
=
optionAt
(
parsedOptions
,
3
);
optionD
=
split
[
3
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionC
=
split
[
2
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionB
=
split
[
1
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
else
if
(
split
.
length
==
3
)
{
optionC
=
split
[
2
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionB
=
split
[
1
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
else
if
(
split
.
length
==
2
)
{
optionB
=
split
[
1
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
else
if
(
split
.
length
==
1
)
{
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
}
}
}
}
}
else
if
(
typeTip
==
3
)
{
}
else
if
(
typeTip
==
3
)
{
...
@@ -453,31 +406,12 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
...
@@ -453,31 +406,12 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
//拿到下一行内容并且跳过下一轮
//拿到下一行内容并且跳过下一轮
String
stringCellValue
=
getCellValueAsString
(
sheet
.
getRow
(++
i
).
getCell
(
4
));
String
stringCellValue
=
getCellValueAsString
(
sheet
.
getRow
(++
i
).
getCell
(
4
));
System
.
out
.
println
(
"多选题答案--------------"
+
stringCellValue
);
System
.
out
.
println
(
"多选题答案--------------"
+
stringCellValue
);
String
replace
=
normalizeOptionMarkers
(
stringCellValue
)
List
<
String
>
parsedOptions
=
splitLegacyOptions
(
stringCellValue
);
.
replace
(
"(A)"
,
""
).
replace
(
"(B)"
,
"&&"
)
optionA
=
optionAt
(
parsedOptions
,
0
);
.
replace
(
"(C)"
,
"&&"
).
replace
(
"(D)"
,
"&&"
).
replace
(
"(E)"
,
"&&"
).
replace
(
" "
,
""
);
optionB
=
optionAt
(
parsedOptions
,
1
);
String
[]
split
=
replace
.
split
(
"&&"
);
optionC
=
optionAt
(
parsedOptions
,
2
);
if
(
split
.
length
==
5
)
{
optionD
=
optionAt
(
parsedOptions
,
3
);
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionE
=
optionAt
(
parsedOptions
,
4
);
optionB
=
split
[
1
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionC
=
split
[
2
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionD
=
split
[
3
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionE
=
split
[
4
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
else
if
(
split
.
length
==
4
)
{
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionB
=
split
[
1
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionC
=
split
[
2
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionD
=
split
[
3
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
else
if
(
split
.
length
==
3
)
{
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionB
=
split
[
1
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionC
=
split
[
2
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
else
if
(
split
.
length
==
2
)
{
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
optionB
=
split
[
1
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
else
if
(
split
.
length
==
1
)
{
optionA
=
split
[
0
].
replaceAll
(
"\r\n?|\n"
,
""
);
}
}
}
}
}
}
}
...
@@ -893,19 +827,41 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
...
@@ -893,19 +827,41 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
}
}
/**
/**
*
将可识别的选项标记统一成旧切分逻辑期望的全角大写格式
。
*
按 A~E 字母括号切分旧格式选项,并保留选项正文中的字母括号
。
*
*
* <p>仅改写 A~E 的单字母括号,不会改动选项内容里的数值、单位或普通括号。</p>
* <p>若末尾字母括号与前文紧贴且其后没有内容,例如 C 选项单位中的
* {@code kgMLSS·(D)},则将其作为前一选项的正文,而不是空的 D 选项。</p>
*/
*/
private
String
normalizeOptionMarker
s
(
String
optionText
)
{
private
List
<
String
>
splitLegacyOption
s
(
String
optionText
)
{
Matcher
matcher
=
LEGACY_OPTION_MARKER
.
matcher
(
optionText
);
Matcher
matcher
=
LEGACY_OPTION_MARKER
.
matcher
(
optionText
);
StringBuffer
normalized
=
new
StringBuffer
();
List
<
Integer
>
starts
=
new
ArrayList
<>();
List
<
Integer
>
ends
=
new
ArrayList
<>();
while
(
matcher
.
find
())
{
while
(
matcher
.
find
())
{
String
label
=
matcher
.
group
(
1
).
toUpperCase
(
Locale
.
ROOT
);
starts
.
add
(
matcher
.
start
());
matcher
.
appendReplacement
(
normalized
,
Matcher
.
quoteReplacement
(
"("
+
label
+
")"
));
ends
.
add
(
matcher
.
end
());
}
if
(
starts
.
size
()
>
1
)
{
int
last
=
starts
.
size
()
-
1
;
boolean
attachedToPreviousText
=
starts
.
get
(
last
)
>
0
&&
!
Character
.
isWhitespace
(
optionText
.
charAt
(
starts
.
get
(
last
)
-
1
));
if
(
attachedToPreviousText
&&
optionText
.
substring
(
ends
.
get
(
last
)).
trim
().
isEmpty
())
{
starts
.
remove
(
last
);
ends
.
remove
(
last
);
}
}
matcher
.
appendTail
(
normalized
);
}
return
normalized
.
toString
();
List
<
String
>
options
=
new
ArrayList
<>();
for
(
int
index
=
0
;
index
<
starts
.
size
();
index
++)
{
int
contentEnd
=
index
+
1
<
starts
.
size
()
?
starts
.
get
(
index
+
1
)
:
optionText
.
length
();
options
.
add
(
optionText
.
substring
(
ends
.
get
(
index
),
contentEnd
).
replaceAll
(
"\\s+"
,
""
));
}
return
options
;
}
/** 安全读取解析后的选项,文件未提供的后续选项继续保持 null。 */
private
String
optionAt
(
List
<
String
>
options
,
int
index
)
{
return
index
<
options
.
size
()
?
options
.
get
(
index
)
:
null
;
}
}
@Override
@Override
...
...
practical-business/src/test/java/com/platform/business/service/impl/TheoreticalLibraryImportPreviewServiceImplTest.java
View file @
af106c16
...
@@ -124,6 +124,32 @@ class TheoreticalLibraryImportPreviewServiceImplTest {
...
@@ -124,6 +124,32 @@ class TheoreticalLibraryImportPreviewServiceImplTest {
||
option
.
getContent
().
contains
(
"(d)"
)));
||
option
.
getContent
().
contains
(
"(d)"
)));
}
}
@Test
void
previewShouldKeepTrailingLetterBracketInsidePreviousOptionContent
()
throws
Exception
{
when
(
theoreticalLibraryMapper
.
selectList
(
any
())).
thenReturn
(
Collections
.
emptyList
());
MockMultipartFile
file
=
workbook
(
"污泥四级理论题库_导入测试(增量).xlsx"
,
sheet
->
{
hierarchy
(
sheet
,
4
,
0
,
"基本要求"
);
hierarchy
(
sheet
,
5
,
1
,
"职业道德"
);
hierarchy
(
sheet
,
6
,
2
,
"职业道德的基本知识"
);
hierarchy
(
sheet
,
7
,
3
,
"道德的基本概念"
);
cell
(
sheet
,
8
,
"多选题"
);
cell
(
sheet
,
9
,
"(测试)可能导致污泥膨胀的工艺条件有(AC)"
);
// 使用用户提供文件 Sheet3!E20 的原始文本复现问题。
cell
(
sheet
,
10
,
"(A)低DO(<1mg/L) (B)高SRT(>20天) "
+
"(C)高F/M(>0.5kgBOD5/kgMLSS·(D)"
);
});
TheoreticalLibraryImportQuestionVO
question
=
service
.
preview
(
file
).
getNormalQuestions
().
get
(
0
);
assertEquals
(
"AC"
,
question
.
getAnswer
());
assertEquals
(
3
,
question
.
getOptions
().
size
());
assertEquals
(
"ABC"
,
question
.
getOptions
().
stream
()
.
map
(
option
->
option
.
getLabel
()).
collect
(
java
.
util
.
stream
.
Collectors
.
joining
()));
assertEquals
(
"高F/M(>0.5kgBOD5/kgMLSS·(D)"
,
question
.
getOptions
().
get
(
2
).
getContent
());
}
@Test
@Test
void
previewShouldUseLastValidBracketAsMultipleChoiceAnswer
()
throws
Exception
{
void
previewShouldUseLastValidBracketAsMultipleChoiceAnswer
()
throws
Exception
{
when
(
theoreticalLibraryMapper
.
selectList
(
any
())).
thenReturn
(
Collections
.
emptyList
());
when
(
theoreticalLibraryMapper
.
selectList
(
any
())).
thenReturn
(
Collections
.
emptyList
());
...
...
practical-business/src/test/java/com/platform/business/service/impl/TheoreticalLibraryServiceImplTest.java
View file @
af106c16
...
@@ -50,14 +50,14 @@ class TheoreticalLibraryServiceImplTest {
...
@@ -50,14 +50,14 @@ class TheoreticalLibraryServiceImplTest {
@Test
@Test
void
legacyParserShouldNormalizeMixedMarkersAndUseLastMultipleAnswer
()
{
void
legacyParserShouldNormalizeMixedMarkersAndUseLastMultipleAnswer
()
{
String
option
Text
=
ReflectionTestUtils
.
invokeMethod
(
List
<
String
>
option
s
=
ReflectionTestUtils
.
invokeMethod
(
service
,
"
normalizeOptionMarkers"
,
"(A)甲 (b)乙 ( C )丙 (D)丁
"
);
service
,
"
splitLegacyOptions"
,
"(A)甲 (b)乙 ( C )高F/M(>0.5kgBOD5/kgMLSS·(D)
"
);
String
answer
=
ReflectionTestUtils
.
invokeMethod
(
String
answer
=
ReflectionTestUtils
.
invokeMethod
(
service
,
"multipleAnswer"
,
"(A)工艺中正确条件为 (a c)"
);
service
,
"multipleAnswer"
,
"(A)工艺中正确条件为 (a c)"
);
String
problem
=
ReflectionTestUtils
.
invokeMethod
(
String
problem
=
ReflectionTestUtils
.
invokeMethod
(
service
,
"replaceLastMultipleAnswer"
,
"(A)工艺中正确条件为 (a c)"
);
service
,
"replaceLastMultipleAnswer"
,
"(A)工艺中正确条件为 (a c)"
);
assertEquals
(
"(A)甲 (B)乙 (C)丙
(D)
丁
"
,
option
Text
);
assertEquals
(
Arrays
.
asList
(
"甲"
,
"乙"
,
"高F/M(>0.5kgBOD5/kgMLSS·
(D)"
)
,
option
s
);
assertEquals
(
"AC"
,
answer
);
assertEquals
(
"AC"
,
answer
);
assertEquals
(
"(A)工艺中正确条件为 ( )"
,
problem
);
assertEquals
(
"(A)工艺中正确条件为 ( )"
,
problem
);
}
}
...
...
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