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
1575edd3
Commit
1575edd3
authored
Nov 06, 2026
by
wujipeng
Browse files
题库导入逻辑修改
parent
50a3f966
Changes
8
Show whitespace changes
Inline
Side-by-side
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/TheoreticalLibraryImportPreviewVO.java
View file @
1575edd3
...
...
@@ -14,6 +14,10 @@ public class TheoreticalLibraryImportPreviewVO {
private
Integer
totalCount
;
private
Integer
normalCount
;
private
Integer
abnormalCount
;
/** 增量导入中预计新增的题目数。 */
private
Integer
insertCount
;
/** 题干完全匹配现有题库、预计保留原ID更新的题目数。 */
private
Integer
updateCount
;
/** 按判断题、单选题、多选题顺序返回数量,供左侧题型树直接渲染。 */
private
Map
<
String
,
Integer
>
questionTypeCounts
=
new
LinkedHashMap
<>();
private
List
<
TheoreticalLibraryImportQuestionVO
>
abnormalQuestions
;
...
...
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/TheoreticalLibraryImportQuestionVO.java
View file @
1575edd3
...
...
@@ -26,6 +26,9 @@ public class TheoreticalLibraryImportQuestionVO {
private
List
<
TheoreticalLibraryImportBracketVO
>
answerCandidates
=
new
ArrayList
<>();
private
List
<
TheoreticalLibraryImportIssueVO
>
issues
=
new
ArrayList
<>();
/** 增量导入动作:INSERT新增,UPDATE更新已有题。 */
private
String
importAction
;
/** 是否需要管理员处理;由 issues 是否为空计算后回填。 */
private
Boolean
abnormal
;
/** 命中数据库重复题时返回原题 ID,便于前端查看原题。 */
...
...
practical-business/src/main/java/com/platform/business/service/impl/TheoreticalLibraryImportPreviewServiceImpl.java
View file @
1575edd3
...
...
@@ -145,8 +145,7 @@ public class TheoreticalLibraryImportPreviewServiceImpl
if
(
decision
==
null
)
{
throw
new
BusinessException
(
"第 "
+
question
.
getSourceRow
()
+
" 行异常尚未处理"
);
}
boolean
duplicate
=
hasIssue
(
question
,
"DUPLICATE_IN_FILE"
)
||
hasIssue
(
question
,
"DUPLICATE_IN_DATABASE"
);
boolean
duplicate
=
hasIssue
(
question
,
"DUPLICATE_IN_FILE"
);
if
(
duplicate
&&
decision
.
getSkip
()
==
null
)
{
throw
new
BusinessException
(
"第 "
+
question
.
getSourceRow
()
+
" 行重复题需选择跳过或仍然导入"
);
...
...
@@ -470,6 +469,7 @@ public class TheoreticalLibraryImportPreviewServiceImpl
private
void
markDuplicates
(
String
scope
,
List
<
TheoreticalLibraryImportQuestionVO
>
questions
)
{
Map
<
String
,
TheoreticalLibraryImportQuestionVO
>
firstInFile
=
new
HashMap
<>();
for
(
TheoreticalLibraryImportQuestionVO
question
:
questions
)
{
question
.
setImportAction
(
"INSERT"
);
String
key
=
duplicateKey
(
scope
,
question
);
TheoreticalLibraryImportQuestionVO
first
=
firstInFile
.
putIfAbsent
(
key
,
question
);
if
(
first
!=
null
)
{
...
...
@@ -493,8 +493,8 @@ public class TheoreticalLibraryImportPreviewServiceImpl
String
duplicateId
=
existingIds
.
get
(
duplicateKey
(
scope
,
question
));
if
(
duplicateId
!=
null
)
{
question
.
setDuplicateQuestionId
(
duplicateId
);
addIssue
(
question
.
getIssues
(),
"DUPLICATE_IN_DATABASE"
,
"题库中已存在相同层级、题型和题干的题目,请选择跳过或仍然导入
"
);
// 增量导入自动保留原题ID更新,不再把数据库命中作为待处理异常。
question
.
setImportAction
(
"UPDATE
"
);
}
question
.
setAbnormal
(!
question
.
getIssues
().
isEmpty
());
}
...
...
@@ -515,6 +515,10 @@ public class TheoreticalLibraryImportPreviewServiceImpl
result
.
setTotalCount
(
questions
.
size
());
result
.
setAbnormalCount
(
abnormal
.
size
());
result
.
setNormalCount
(
normal
.
size
());
result
.
setInsertCount
((
int
)
questions
.
stream
()
.
filter
(
question
->
"INSERT"
.
equals
(
question
.
getImportAction
())).
count
());
result
.
setUpdateCount
((
int
)
questions
.
stream
()
.
filter
(
question
->
"UPDATE"
.
equals
(
question
.
getImportAction
())).
count
());
Map
<
String
,
Integer
>
counts
=
result
.
getQuestionTypeCounts
();
QUESTION_TYPES
.
forEach
(
type
->
counts
.
put
(
type
,
0
));
questions
.
forEach
(
question
->
counts
.
computeIfPresent
(
...
...
@@ -574,9 +578,15 @@ public class TheoreticalLibraryImportPreviewServiceImpl
}
private
String
key
(
String
...
values
)
{
return
Arrays
.
stream
(
values
)
.
map
(
value
->
Objects
.
toString
(
value
,
""
).
replaceAll
(
"\\s+"
,
""
).
trim
())
.
collect
(
Collectors
.
joining
(
"|"
));
StringBuilder
key
=
new
StringBuilder
();
for
(
String
value
:
values
)
{
if
(
value
==
null
)
{
key
.
append
(
"-1:"
);
}
else
{
key
.
append
(
value
.
length
()).
append
(
':'
).
append
(
value
);
}
}
return
key
.
toString
();
}
private
void
addIssue
(
List
<
TheoreticalLibraryImportIssueVO
>
issues
,
...
...
practical-business/src/main/java/com/platform/business/service/impl/TheoreticalLibraryServiceImpl.java
View file @
1575edd3
...
...
@@ -28,8 +28,10 @@ import javax.servlet.http.HttpServletResponse;
import
java.io.IOException
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
...
...
@@ -69,7 +71,7 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
}
@Override
@Transactional
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Result
<
Boolean
>
importTheoreticalLibrary
(
MultipartFile
file
,
UserEntity
administrator
)
throws
IOException
{
...
...
@@ -80,8 +82,6 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
if
(
Objects
.
requireNonNull
(
file
.
getOriginalFilename
()).
contains
(
"技能竞赛"
))
{
scope
=
"技能竞赛"
;
prefix
=
"J"
;
//删除原始旧数据
remove
(
new
LambdaQueryWrapper
<
TheoreticalLibraryEntity
>().
eq
(
TheoreticalLibraryEntity:
:
getScope
,
scope
));
return
handleJn
(
file
,
prefix
,
codeLev
,
scope
,
administrator
);
}
else
{
//判断是污水还是污泥
...
...
@@ -108,8 +108,6 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
default
:
return
Result
.
fail
(
"文件名需包含污水/污泥(一级~五级)、技能竞赛"
);
}
//删除原始旧数据
remove
(
new
LambdaQueryWrapper
<
TheoreticalLibraryEntity
>().
eq
(
TheoreticalLibraryEntity:
:
getScope
,
scope
));
return
handleWsWn
(
file
,
prefix
,
codeLev
,
scope
,
administrator
);
}
}
...
...
@@ -289,9 +287,8 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
.
optionE
(
optionE
)
.
build
());
}
saveBatch
(
theoreticalLibraryList
);
//删除脏数据
removeDirtyData
();
// 增量写入:命中完全相同题目时保留原ID更新,未命中才新增,不再清空整个竞赛题库。
upsertLegacyRows
(
scope
,
theoreticalLibraryList
);
// 旧竞赛模板仍由本入口导入;同步新节点和管理字段,保证新旧页面数据一致。
synchronizeImportedScope
(
scope
,
administrator
);
return
Result
.
success
(
"导入成功"
);
...
...
@@ -503,15 +500,139 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
.
optionE
(
optionE
)
.
build
());
}
saveBatch
(
theoreticalLibraryList
);
//删除脏数据
removeDirtyData
();
// 增量写入:历史题目和未出现在本次文件中的目录全部保留。
upsertLegacyRows
(
scope
,
theoreticalLibraryList
);
// 旧职级模板导入后补齐六级树及新字段,旧接口无需感知新表结构。
synchronizeImportedScope
(
scope
,
administrator
);
return
Result
.
success
(
"导入成功"
);
}
}
/**
* 将旧模板拆分结果增量合并到理论题库。
*
* <p>题目使用“范围 + 四级旧层级 + 题型 + 完整题干”作为稳定匹配键,所有字段均按
* Java字符串精确比较,不去空格、不忽略大小写。命中时只刷新Excel能够提供的旧模板字段,
* 保留原记录ID以及后台维护的状态、难度、分值、解析、关键词和创建人;未命中才新增。
* 结构行使用其层级、序号和题型标题匹配,避免每次增量导入重复生成目录占位记录。</p>
*/
private
void
upsertLegacyRows
(
String
scope
,
List
<
TheoreticalLibraryEntity
>
importedRows
)
{
List
<
TheoreticalLibraryEntity
>
existingRows
=
list
(
new
LambdaQueryWrapper
<
TheoreticalLibraryEntity
>()
.
eq
(
TheoreticalLibraryEntity:
:
getScope
,
scope
));
LegacyImportPlan
plan
=
buildLegacyImportPlan
(
existingRows
,
importedRows
);
if
(!
plan
.
getInserts
().
isEmpty
())
{
saveBatch
(
plan
.
getInserts
());
}
if
(!
plan
.
getUpdates
().
isEmpty
())
{
updateBatchById
(
plan
.
getUpdates
());
}
}
/** 纯内存生成增量计划,便于对精确匹配、旧字段保留和新增判定进行回归测试。 */
private
LegacyImportPlan
buildLegacyImportPlan
(
List
<
TheoreticalLibraryEntity
>
existingRows
,
List
<
TheoreticalLibraryEntity
>
importedRows
)
{
Map
<
String
,
TheoreticalLibraryEntity
>
rowByKey
=
new
LinkedHashMap
<>();
if
(
existingRows
!=
null
)
{
for
(
TheoreticalLibraryEntity
existing
:
existingRows
)
{
rowByKey
.
putIfAbsent
(
legacyImportKey
(
existing
),
existing
);
}
}
List
<
TheoreticalLibraryEntity
>
inserts
=
new
ArrayList
<>();
Map
<
String
,
TheoreticalLibraryEntity
>
updates
=
new
LinkedHashMap
<>();
for
(
TheoreticalLibraryEntity
imported
:
importedRows
)
{
// 旧拆题器可能生成空题干题目;增量模式直接忽略,不能再全表执行脏数据删除。
if
(
Boolean
.
TRUE
.
equals
(
imported
.
getIsProblem
())
&&
!
StringUtils
.
isNotBlank
(
imported
.
getProblem
()))
{
continue
;
}
String
key
=
legacyImportKey
(
imported
);
TheoreticalLibraryEntity
existing
=
rowByKey
.
get
(
key
);
if
(
existing
==
null
)
{
inserts
.
add
(
imported
);
rowByKey
.
put
(
key
,
imported
);
continue
;
}
mergeLegacyImportFields
(
existing
,
imported
);
// 同一文件内重复题会命中尚未入库的新对象,此时只合并一次,不产生无ID更新。
if
(
StringUtils
.
isNotBlank
(
existing
.
getId
()))
{
updates
.
put
(
existing
.
getId
(),
existing
);
}
}
return
new
LegacyImportPlan
(
inserts
,
new
ArrayList
<>(
updates
.
values
()));
}
/** 只覆盖旧Excel真实携带的字段,管理端扩展字段继续使用数据库原值。 */
private
void
mergeLegacyImportFields
(
TheoreticalLibraryEntity
target
,
TheoreticalLibraryEntity
source
)
{
target
.
setScope
(
source
.
getScope
());
target
.
setIsProblem
(
source
.
getIsProblem
());
target
.
setLev
(
source
.
getLev
());
target
.
setSequence
(
source
.
getSequence
());
target
.
setCode
(
source
.
getCode
());
target
.
setFirstLevelName
(
source
.
getFirstLevelName
());
target
.
setSecondLevelName
(
source
.
getSecondLevelName
());
target
.
setThirdLevelName
(
source
.
getThirdLevelName
());
target
.
setFourthLevelName
(
source
.
getFourthLevelName
());
target
.
setType
(
source
.
getType
());
target
.
setProblem
(
source
.
getProblem
());
target
.
setAnswer
(
source
.
getAnswer
());
target
.
setOptionA
(
source
.
getOptionA
());
target
.
setOptionB
(
source
.
getOptionB
());
target
.
setOptionC
(
source
.
getOptionC
());
target
.
setOptionD
(
source
.
getOptionD
());
target
.
setOptionE
(
source
.
getOptionE
());
}
/**
* 使用长度前缀构造无碰撞键;null和空字符串严格区分,符合“内容一模一样”的匹配要求。
*/
private
String
legacyImportKey
(
TheoreticalLibraryEntity
row
)
{
boolean
question
=
Boolean
.
TRUE
.
equals
(
row
.
getIsProblem
());
String
common
=
keyPart
(
question
?
"QUESTION"
:
"STRUCTURE"
)
+
keyPart
(
row
.
getScope
())
+
keyPart
(
row
.
getFirstLevelName
())
+
keyPart
(
row
.
getSecondLevelName
())
+
keyPart
(
row
.
getThirdLevelName
())
+
keyPart
(
row
.
getFourthLevelName
())
+
keyPart
(
row
.
getType
())
+
keyPart
(
row
.
getProblem
());
// 题目身份只看范围、路径、题型和题干;结构占位行没有题干,需要序号与层级深度区分。
return
question
?
common
:
common
+
keyPart
(
row
.
getLev
())
+
keyPart
(
row
.
getSequence
());
}
private
String
keyPart
(
Object
value
)
{
if
(
value
==
null
)
{
return
"-1:"
;
}
String
text
=
String
.
valueOf
(
value
);
return
text
.
length
()
+
":"
+
text
;
}
/** 本次增量导入需要新增和更新的记录;未列入计划的历史记录保持不变。 */
static
final
class
LegacyImportPlan
{
private
final
List
<
TheoreticalLibraryEntity
>
inserts
;
private
final
List
<
TheoreticalLibraryEntity
>
updates
;
LegacyImportPlan
(
List
<
TheoreticalLibraryEntity
>
inserts
,
List
<
TheoreticalLibraryEntity
>
updates
)
{
this
.
inserts
=
inserts
;
this
.
updates
=
updates
;
}
List
<
TheoreticalLibraryEntity
>
getInserts
()
{
return
inserts
;
}
List
<
TheoreticalLibraryEntity
>
getUpdates
()
{
return
updates
;
}
}
/**
* 将旧模板刚导入的结构行和题目行一起投影到新版层级表。
*
...
...
@@ -519,8 +640,8 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
* 的独立记录。如果只同步题目行,没有题目的空分支会从管理端树中消失,
* 因此这里必须查询指定 scope 的全部记录。结构行只创建自身已提供的
* 层级,题目行则使用“未分类”节点补到固定末级并回填 {@code node_id}。
* 当前管理员由控制器根据 JWT 获取,
统一传到题目与本次新建节点的审计字段中
;
* 已存在节点
仍
保留原创建人,避免
一次
导入篡改历史归属。</p>
* 当前管理员由控制器根据 JWT 获取,
仅写入新题、新节点或缺失审计字段的历史题
;
* 已存在
题目和
节点保留原创建人,避免
增量
导入篡改历史归属。</p>
*/
private
void
synchronizeImportedScope
(
String
scope
,
UserEntity
administrator
)
{
List
<
TheoreticalLibraryEntity
>
importedRows
=
list
(
...
...
@@ -618,20 +739,33 @@ public class TheoreticalLibraryServiceImpl extends ServiceImpl<TheoreticalLibrar
/**
* 只回写真正的题目行,历史结构行仍保持原表数据不变。
* 创建人
ID 与名称必须成对取自当前登录管理员,不能继续使用无法追溯到用户的固定文案
。
*
新题
创建人
取当前登录管理员;增量命中的已有题保留原创建人和管理端扩展属性
。
*/
private
void
updateImportedQuestion
(
TheoreticalLibraryEntity
question
,
String
bankType
,
TheoreticalLibraryNodeEntity
leaf
,
UserEntity
administrator
)
{
question
.
setBankType
(
bankType
);
question
.
setNodeId
(
leaf
.
getId
());
// 增量更新不得重置管理员已经维护的扩展属性;只有新题或旧空值才补默认值。
if
(
question
.
getStatus
()
==
null
)
{
question
.
setStatus
(
1
);
}
if
(!
StringUtils
.
isNotBlank
(
question
.
getDifficulty
()))
{
question
.
setDifficulty
(
"MEDIUM"
);
}
if
(
question
.
getScore
()
==
null
)
{
question
.
setScore
(
defaultScore
(
question
.
getType
()));
question
.
setParticipate
(
question
.
getParticipate
()
==
null
||
question
.
getParticipate
());
}
if
(
question
.
getParticipate
()
==
null
)
{
question
.
setParticipate
(
true
);
}
if
(!
StringUtils
.
isNotBlank
(
question
.
getCreateUserId
()))
{
question
.
setCreateUserId
(
administrator
==
null
?
null
:
administrator
.
getId
());
question
.
setCreateUserName
(
displayName
(
administrator
));
question
.
setCreateTime
(
question
.
getCreateTime
()
==
null
?
new
Date
()
:
question
.
getCreateTime
());
}
if
(
question
.
getCreateTime
()
==
null
)
{
question
.
setCreateTime
(
new
Date
());
}
question
.
setUpdateTime
(
new
Date
());
updateById
(
question
);
}
...
...
practical-business/src/main/resources/bootstrap.yml
View file @
1575edd3
spring
:
profiles
:
active
:
prd
active
:
dev
# Tomcat还维护独立的表单POST上限;与multipart请求上限保持一致,避免大视频在进入Controller前
# 被Servlet容器拒绝。文件仍由MultipartFile流式落盘,不会因此整体加载到JVM内存。
...
...
practical-business/src/main/resources/theoretical-library-import-preview-api.md
View file @
1575edd3
...
...
@@ -10,6 +10,8 @@
接口读取原有五列层级题库模板,例如
`污水三级理论题库.xlsx`
。正式导入仍由原接口和
原拆题方法完成;新增确认接口只在内存中应用预览页决定,再把修正版文件交给原导入服务。
落库已改为增量模式:完全匹配的题目保留原ID更新,不存在的题目新增,未出现在文件中的历史
题目和目录不删除。
支持
`.xlsx`
、
`.xls`
,单文件不超过 10MB。文件名必须包含以下一种路由信息:
...
...
@@ -52,6 +54,8 @@
"totalCount"
:
120
,
"normalCount"
:
116
,
"abnormalCount"
:
4
,
"insertCount"
:
110
,
"updateCount"
:
10
,
"questionTypeCounts"
:
{
"判断题"
:
40
,
"单选题"
:
50
,
...
...
@@ -65,6 +69,7 @@
"rawProblem"
:
"以下(B)方法常用于处理含铅(Pb)废水。"
,
"problem"
:
"以下(B)方法常用于处理含铅(Pb)废水。"
,
"answer"
:
"P"
,
"importAction"
:
"INSERT"
,
"firstLevelName"
:
"基本要求"
,
"secondLevelName"
:
"职业道德"
,
"thirdLevelName"
:
"基本知识"
,
...
...
@@ -98,6 +103,8 @@
| 题目总数 |
`totalCount`
|
| 无需处理 |
`normalCount`
|
| 待处理初始值 |
`abnormalCount`
|
| 预计新增 |
`insertCount`
|
| 预计更新 |
`updateCount`
|
| 左侧题型树 |
`questionTypeCounts`
,再按题目
`type`
分组 |
| 异常题目 Tab |
`abnormalQuestions`
|
| 无异常 Tab |
`normalQuestions`
|
...
...
@@ -106,13 +113,16 @@
`answer`
是旧拆题算法产生的默认结果。存在
`ANSWER_BRACKET_AMBIGUOUS`
时不能直接采用,
必须以管理员选择的
`answerCandidates.index`
为准。
每题的
`importAction`
为
`INSERT`
或
`UPDATE`
。
`UPDATE`
同时返回
`duplicateQuestionId`
,表示确认导入后保留该题ID并更新答案、选项、编号等旧Excel字段;这类
数据库命中是正常增量动作,不进入异常 Tab。
## 4. 异常代码与处理组件
| code | 含义 | 前端处理 |
|---|---|---|
|
`ANSWER_BRACKET_AMBIGUOUS`
| 题干至少两组纯英文字母括号 | 点选答案括号,提交
`answerCandidateIndex`
|
|
`DUPLICATE_IN_FILE`
| 与本文件前一题重复 | “跳过/仍然导入”,提交
`skip`
|
|
`DUPLICATE_IN_DATABASE`
| 同范围、四级层级、题型、题干已存在 | “跳过/仍然导入”,提交
`skip`
|
|
`OPTION_MISSING`
| 题目下一行没有选项 | 编辑完整选项后提交
`options`
|
|
`OPTION_PARSE_ERROR`
| 未识别出(A)~(E)标记 | 编辑完整选项后提交
`options`
|
|
`OPTION_DUPLICATE_LABEL`
| 选项字母重复 | 编辑完整选项后提交
`options`
|
...
...
@@ -172,7 +182,7 @@
| 字段 | 必填条件 | 说明 |
|---|---|---|
|
`sourceRow`
| 始终必填 | 直接使用预览返回值,不要用列表序号代替 |
|
`skip`
| 重复题必填 |
`true`
跳过,
`false`
仍然导入 |
|
`skip`
|
文件内
重复题必填 |
`true`
跳过,
`false`
仍然导入
;数据库命中无需提交
|
|
`answerCandidateIndex`
| 答案括号歧义且未跳过 | 使用候选项的
`index`
|
|
`options`
| 选项异常且未跳过 | 2~5 项,从 A 开始连续、不可重复、内容非空,并覆盖答案字母 |
...
...
@@ -205,7 +215,20 @@ await axios.post('/theoretical/library/import/confirm', form);
}
```
原导入按文件名对应范围执行覆盖导入;这是既有行为,本次没有改变。
确认后按文件名对应范围执行增量导入,不再删除该范围旧数据。
### 5.4 增量匹配与更新范围
一道题只有以下字段全部精确一致时才判定为
`UPDATE`
:
-
题库范围
`scope`
;
-
原四级层级路径;
-
题型;
-
拆题后的完整题干。
匹配不自动去空格、不忽略大小写,题干多一个空格也会作为新题新增。命中更新时保留原题ID,
只覆盖旧Excel携带的编号、答案和选项等字段;后台维护的状态、难度、分值、解析、关键词及创建人
保持原值。文件中没有出现的历史题目和目录不删除。
## 6. 推荐前端调用时序
...
...
@@ -213,8 +236,7 @@ await axios.post('/theoretical/library/import/confirm', form);
2.
调用
`/import/preview`
,保存原始
`File`
对象;
3.
渲染双 Tab,按
`issues.code`
收集处理决定;
4.
待处理数归零后,将同一个
`File`
和
`decisions`
提交
`/import/confirm`
;
5.
成功后展示成功数。当前旧导入为整范围覆盖且返回布尔值,因此成功数可使用
`totalCount - skip=true 的题数`
,失败数为跳过数;
5.
成功后分别展示
`insertCount`
和
`updateCount`
;文件内选择跳过的题目从对应数量中扣除;
6.
关闭弹窗并刷新题库树、统计和列表。
如果预览后用户重新选择文件,必须清空旧预览及全部
`decisions`
,禁止把旧行号应用到新文件。
...
...
@@ -228,7 +250,7 @@ await axios.post('/theoretical/library/import/confirm', form);
| 格式错误 | 仅支持 .xlsx 或 .xls 文件 |
| 文件名无法路由 | 文件名需包含污水/污泥(一级~五级)或技能竞赛 |
| 异常未处理 | 第 N 行异常尚未处理 |
| 重复题未选择动作 | 第 N 行重复题需选择跳过或仍然导入 |
|
文件内
重复题未选择动作 | 第 N 行重复题需选择跳过或仍然导入 |
| 未选择答案括号 | 第 N 行需选择有效的答案括号 |
| 修正选项不合法 | 第 N 行修正后的选项字母必须从 A 开始连续且不可重复 |
...
...
@@ -241,4 +263,5 @@ await axios.post('/theoretical/library/import/confirm', form);
使用本次提供的
`污水三级理论题库.xlsx`
进行本地真实文件解析:共拆出 1200 题,
其中判断题 300、单选题 600、多选题 300;在不连接现有题库重复数据的情况下,
1181 题无异常、19 题需处理。部署环境还会叠加数据库重复校验,因此实际异常数可能增加。
1181 题无异常、19 题需处理。部署环境命中的相同数据库题目会计入
`updateCount`
,不会增加
异常数;文件内重复、答案括号歧义和选项异常仍会增加待处理数量。
practical-business/src/test/java/com/platform/business/service/impl/TheoreticalLibraryImportPreviewServiceImplTest.java
View file @
1575edd3
...
...
@@ -2,6 +2,7 @@ package com.platform.business.service.impl;
import
com.platform.business.mapper.TheoreticalLibraryMapper
;
import
com.platform.business.model.dto.TheoreticalLibraryImportDecisionDTO
;
import
com.platform.business.model.entity.TheoreticalLibraryEntity
;
import
com.platform.business.model.vo.TheoreticalLibraryImportPreviewVO
;
import
com.platform.business.model.vo.TheoreticalLibraryImportQuestionVO
;
import
com.platform.exception.BusinessException
;
...
...
@@ -100,6 +101,42 @@ class TheoreticalLibraryImportPreviewServiceImplTest {
assertThrows
(
BusinessException
.
class
,
()
->
service
.
preview
(
file
));
}
@Test
void
previewShouldClassifyExactDatabaseMatchAsAutomaticUpdate
()
throws
Exception
{
TheoreticalLibraryEntity
existing
=
new
TheoreticalLibraryEntity
();
existing
.
setId
(
"question-1"
);
existing
.
setScope
(
"污水三级"
);
existing
.
setIsProblem
(
true
);
existing
.
setFirstLevelName
(
"第一章"
);
existing
.
setSecondLevelName
(
"第一节"
);
existing
.
setThirdLevelName
(
"第一目"
);
existing
.
setFourthLevelName
(
"知识点一"
);
existing
.
setType
(
"单选题"
);
existing
.
setProblem
(
"标准题( )。"
);
when
(
theoreticalLibraryMapper
.
selectList
(
any
()))
.
thenReturn
(
Collections
.
singletonList
(
existing
));
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
,
"标准题(A)。"
);
cell
(
sheet
,
10
,
"(A)正确 (B)错误"
);
});
TheoreticalLibraryImportPreviewVO
result
=
service
.
preview
(
file
);
assertEquals
(
1
,
result
.
getUpdateCount
());
assertEquals
(
0
,
result
.
getInsertCount
());
assertEquals
(
0
,
result
.
getAbnormalCount
());
TheoreticalLibraryImportQuestionVO
question
=
result
.
getNormalQuestions
().
get
(
0
);
assertEquals
(
"UPDATE"
,
question
.
getImportAction
());
assertEquals
(
"question-1"
,
question
.
getDuplicateQuestionId
());
assertTrue
(
question
.
getIssues
().
stream
()
.
noneMatch
(
issue
->
"DUPLICATE_IN_DATABASE"
.
equals
(
issue
.
getCode
())));
}
@Test
void
confirmPreparationShouldMakeSelectedAnswerVisibleToLegacySplitter
()
throws
Exception
{
when
(
theoreticalLibraryMapper
.
selectList
(
any
())).
thenReturn
(
Collections
.
emptyList
());
...
...
practical-business/src/test/java/com/platform/business/service/impl/TheoreticalLibraryServiceImplTest.java
View file @
1575edd3
...
...
@@ -20,6 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import
java.util.stream.Collectors
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNotNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
...
...
@@ -161,6 +162,70 @@ class TheoreticalLibraryServiceImplTest {
assertEquals
(
"admin-id"
,
ReflectionTestUtils
.
invokeMethod
(
service
,
"displayName"
,
user
));
}
@Test
void
incrementalPlanShouldUpdateExactQuestionAndKeepManagedFields
()
{
TheoreticalLibraryEntity
existing
=
importedQuestion
(
"existing-id"
,
"相同题干( )"
);
existing
.
setAnswer
(
"A"
);
existing
.
setOptionA
(
"旧选项"
);
existing
.
setStatus
(
0
);
existing
.
setDifficulty
(
"HARD"
);
existing
.
setScore
(
8
D
);
existing
.
setCreateUserId
(
"original-admin"
);
existing
.
setCreateUserName
(
"原创建人"
);
TheoreticalLibraryEntity
imported
=
importedQuestion
(
null
,
"相同题干( )"
);
imported
.
setAnswer
(
"B"
);
imported
.
setOptionA
(
"新选项"
);
TheoreticalLibraryEntity
newQuestion
=
importedQuestion
(
null
,
"新增题干( )"
);
TheoreticalLibraryServiceImpl
.
LegacyImportPlan
plan
=
ReflectionTestUtils
.
invokeMethod
(
service
,
"buildLegacyImportPlan"
,
Arrays
.
asList
(
existing
),
Arrays
.
asList
(
imported
,
newQuestion
));
assertEquals
(
1
,
plan
.
getUpdates
().
size
());
assertEquals
(
1
,
plan
.
getInserts
().
size
());
TheoreticalLibraryEntity
update
=
plan
.
getUpdates
().
get
(
0
);
assertEquals
(
"existing-id"
,
update
.
getId
());
assertEquals
(
"B"
,
update
.
getAnswer
());
assertEquals
(
"新选项"
,
update
.
getOptionA
());
// Excel没有这些管理字段,增量更新必须保留管理员原有设置。
assertEquals
(
0
,
update
.
getStatus
());
assertEquals
(
"HARD"
,
update
.
getDifficulty
());
assertEquals
(
8
D
,
update
.
getScore
());
assertEquals
(
"original-admin"
,
update
.
getCreateUserId
());
}
@Test
void
incrementalPlanShouldUseExactContentAndNeverDeleteMissingHistory
()
{
TheoreticalLibraryEntity
existing
=
importedQuestion
(
"existing-id"
,
"题干( )"
);
TheoreticalLibraryEntity
whitespaceDifferent
=
importedQuestion
(
null
,
"题干 ( )"
);
TheoreticalLibraryServiceImpl
.
LegacyImportPlan
plan
=
ReflectionTestUtils
.
invokeMethod
(
service
,
"buildLegacyImportPlan"
,
Arrays
.
asList
(
existing
),
Arrays
.
asList
(
whitespaceDifferent
));
assertEquals
(
1
,
plan
.
getInserts
().
size
());
assertTrue
(
plan
.
getUpdates
().
isEmpty
());
// 计划模型没有删除集合,未出现在Excel中的existing-id天然保持不变。
assertFalse
(
plan
.
getInserts
().
contains
(
existing
));
}
private
TheoreticalLibraryEntity
importedQuestion
(
String
id
,
String
problem
)
{
TheoreticalLibraryEntity
question
=
new
TheoreticalLibraryEntity
();
question
.
setId
(
id
);
question
.
setScope
(
"污水三级"
);
question
.
setIsProblem
(
true
);
question
.
setLev
(
0
);
question
.
setSequence
(
""
);
question
.
setFirstLevelName
(
"第一章"
);
question
.
setSecondLevelName
(
"第一节"
);
question
.
setThirdLevelName
(
"第一目"
);
question
.
setFourthLevelName
(
"知识点一"
);
question
.
setType
(
"单选题"
);
question
.
setProblem
(
problem
);
return
question
;
}
/** 构造仅包含同步链路所需字段的旧表记录。 */
private
TheoreticalLibraryEntity
row
(
String
id
,
boolean
question
)
{
TheoreticalLibraryEntity
row
=
new
TheoreticalLibraryEntity
();
...
...
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