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
46eeeaaa
Commit
46eeeaaa
authored
Sep 20, 2026
by
wujipeng
Browse files
优化
parent
cb50ff71
Changes
6
Show whitespace changes
Inline
Side-by-side
practical-business/src/main/java/com/platform/business/mapper/ExamMapper.java
View file @
46eeeaaa
...
...
@@ -38,7 +38,8 @@ public interface ExamMapper extends BaseMapper<ExamEntity> {
Integer
lockAdminExamClass
(
@Param
(
"classId"
)
Integer
classId
);
/**
* 按固定顺序锁定教师与应考学员的用户行,避免跨班并发安排同一人员到重叠场次。
* 按固定顺序锁定教师与应考学员的用户行:既用于确认所有用户真实存在,也让跨班级
* 教师排期校验串行完成。应考学员允许参加不同班级的重叠考试,不依赖该锁限制排期。
*/
List
<
String
>
lockAdminExamUsers
(
@Param
(
"userIds"
)
List
<
String
>
userIds
);
...
...
@@ -76,13 +77,13 @@ public interface ExamMapper extends BaseMapper<ExamEntity> {
@Param
(
"excludeId"
)
Integer
excludeId
);
/**
* 查询与新时间段发生冲突的场次。冲突主体可以是班级、考评教师、监考教师或应考学员。
* 查询与新时间段发生冲突的场次。仅同一班级或任一负责教师重合时判定冲突;
* 不同班级的应考学员即使相同,也允许考试时间重叠。
*/
List
<
ExamAdminDetailVO
>
selectAdminExamConflicts
(
@Param
(
"startTime"
)
Date
startTime
,
@Param
(
"duration"
)
Integer
duration
,
@Param
(
"classId"
)
Integer
classId
,
@Param
(
"teacherIds"
)
List
<
String
>
teacherIds
,
@Param
(
"studentIds"
)
List
<
String
>
studentIds
,
@Param
(
"excludeId"
)
Integer
excludeId
);
/** 锁定考试主记录;返回空表示记录已被其他请求删除。 */
...
...
practical-business/src/main/java/com/platform/business/service/impl/ExamAdminServiceImpl.java
View file @
46eeeaaa
...
...
@@ -163,7 +163,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
prepared
.
invigilatorIds
,
studentIds
);
validateDuplicateName
(
request
.
getClassId
(),
prepared
.
name
,
null
);
validateConflicts
(
request
.
getClassId
(),
prepared
.
name
,
prepared
.
examTime
,
prepared
.
duration
,
prepared
.
chiefIds
,
prepared
.
invigilatorIds
,
studentIds
,
null
);
prepared
.
duration
,
prepared
.
chiefIds
,
prepared
.
invigilatorIds
,
null
);
ExamEntity
entity
=
new
ExamEntity
();
entity
.
setClassId
(
request
.
getClassId
());
...
...
@@ -275,7 +275,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
prepared
.
invigilatorIds
,
studentIds
);
validateDuplicateName
(
existing
.
getClassId
(),
prepared
.
name
,
examId
);
validateConflicts
(
existing
.
getClassId
(),
prepared
.
name
,
prepared
.
examTime
,
prepared
.
duration
,
prepared
.
chiefIds
,
prepared
.
invigilatorIds
,
studentIds
,
examId
);
prepared
.
duration
,
prepared
.
chiefIds
,
prepared
.
invigilatorIds
,
examId
);
ExamEntity
update
=
new
ExamEntity
();
update
.
setId
(
examId
);
...
...
@@ -460,15 +460,19 @@ public class ExamAdminServiceImpl implements ExamAdminService {
}
}
/** 将数据库返回的冲突场次转换为页面可直接展示的明确错误。 */
/**
* 将数据库返回的冲突场次转换为页面可直接展示的明确错误。
*
* <p>冲突范围只包含同班级考试和负责教师排期。应考学员只校验其是否属于当前班级,
* 不参与跨班级时间冲突判断,因此这里不接收也不向Mapper传递学员ID。</p>
*/
private
void
validateConflicts
(
Integer
classId
,
String
name
,
Date
startTime
,
Integer
duration
,
List
<
String
>
chiefIds
,
List
<
String
>
invigilatorIds
,
List
<
String
>
studentIds
,
Integer
excludeId
)
{
LinkedHashSet
<
String
>
teacherIds
=
new
LinkedHashSet
<>(
chiefIds
);
teacherIds
.
addAll
(
invigilatorIds
);
List
<
ExamAdminDetailVO
>
conflicts
=
examMapper
.
selectAdminExamConflicts
(
startTime
,
duration
,
classId
,
new
ArrayList
<>(
teacherIds
),
studentIds
,
excludeId
);
classId
,
new
ArrayList
<>(
teacherIds
),
excludeId
);
if
(
conflicts
==
null
||
conflicts
.
isEmpty
())
{
return
;
}
...
...
@@ -484,7 +488,9 @@ public class ExamAdminServiceImpl implements ExamAdminService {
if
(
teacherMatches
(
conflict
,
invigilatorIds
))
{
throw
new
BusinessException
(
"监考教师与考试“"
+
conflictName
+
"”时间冲突"
);
}
throw
new
BusinessException
(
"应考学员与考试“"
+
conflictName
+
"”时间冲突"
);
// SQL只会返回同班级或教师重合的考试;若历史教师关系数据不完整,仍应保守拦截,
// 不能因为无法区分教师角色而误放行已经确认的跨班级教师冲突。
throw
new
BusinessException
(
"教师与考试“"
+
conflictName
+
"”时间冲突"
);
}
private
boolean
teacherMatches
(
ExamAdminDetailVO
conflict
,
List
<
String
>
teacherIds
)
{
...
...
practical-business/src/main/resources/com/platform/business/mapper/ExamMapper.xml
View file @
46eeeaaa
...
...
@@ -359,6 +359,7 @@
<if
test=
"excludeId != null"
>
and e.id
<>
#{excludeId}
</if>
<!-- 跨班级允许相同学员参加重叠考试,因此这里只比较班级和负责教师。 -->
and (
e.class_id = #{classId}
or (
...
...
@@ -393,15 +394,6 @@
</foreach>
)
)
or exists (
select 1
from exam_student conflict_student
where conflict_student.exam_id = e.id
and conflict_student.student_id in
<foreach
collection=
"studentIds"
item=
"studentId"
open=
"("
separator=
","
close=
")"
>
#{studentId}
</foreach>
)
)
order by e.exam_time asc, e.id asc
</select>
...
...
practical-business/src/main/resources/exam-management-api.md
View file @
46eeeaaa
...
...
@@ -75,7 +75,8 @@
-
两组教师各至少一人、组内自动去重,允许同一教师同时承担两个角色;任一首席考评员
均可阅卷和发布成绩。
-
至少选择1名、最多500名班级学员,ID不得重复。
-
同班级、首席考评员、监考教师或任一应考学员的考试时间不能重叠。
-
同一班级的考试时间不能重叠;任一首席考评员或监考教师也不能被安排到时间重叠的考试。
-
不同班级的应考学员不参与时间冲突限制,即使学员相同也允许考试时间重叠。
-
同一班级内考试名称不能重复。
成功后返回完整考试详情。考试与应考关系在同一事务内保存,任一步失败都会回滚。
...
...
@@ -100,7 +101,8 @@
编辑不允许切换考试类型,也不改变理论试卷、禁止交卷时间或应考学员;实训考试可切换
已发布规则并刷新总分快照,两组教师均可重新多选。考试已到开始时间,或任一考生已开始、
交卷、产生分数后禁止编辑。新的时间和任一教师安排仍会执行完整冲突校验。
交卷、产生分数后禁止编辑。新的时间仍校验同班级考试和任一教师安排;不同班级的应考学员
不参与时间冲突限制。
新数组字段非null时优先;没有数组字段的旧客户端仍可提交
`chiefExaminerId`
和
`invigilatorId`
。响应旧字段返回列表第一人,同时通过
`chiefExaminerIds/chiefExaminers`
...
...
practical-business/src/test/java/com/platform/business/mapper/ExamMapperXmlTest.java
View file @
46eeeaaa
...
...
@@ -43,7 +43,6 @@ class ExamMapperXmlTest {
conflictParameters
.
put
(
"duration"
,
90
);
conflictParameters
.
put
(
"classId"
,
1
);
conflictParameters
.
put
(
"teacherIds"
,
Arrays
.
asList
(
"teacher-1"
,
"teacher-2"
));
conflictParameters
.
put
(
"studentIds"
,
Arrays
.
asList
(
"student-1"
,
"student-2"
));
conflictParameters
.
put
(
"excludeId"
,
null
);
String
conflictSql
=
configuration
.
getMappedStatement
(
"com.platform.business.mapper.ExamMapper.selectAdminExamConflicts"
)
...
...
@@ -52,15 +51,17 @@ class ExamMapperXmlTest {
.
replaceAll
(
"\\s+"
,
" "
)
.
toLowerCase
();
/*
* 新考试与旧考试采用半开区间重叠判断,
并通过应考关系检查任一重复学员
。
*
即使学员属于不同班级、教师也不同,只要考试时间重叠就必须拒绝新增
。
* 新考试与旧考试采用半开区间重叠判断,
但只比较班级和负责教师
。
*
应考关系不能出现在冲突SQL中,否则同一学员进入不同班级后会错误阻止重叠排期
。
*/
assertTrue
(
conflictSql
.
contains
(
"e.exam_time < timestampadd(minute, ?, ?)"
));
assertTrue
(
conflictSql
.
contains
(
"timestampadd(minute, coalesce(e.duration, 0), e.exam_time) > ?"
));
assertTrue
(
conflictSql
.
contains
(
"from exam_student conflict_student"
));
assertTrue
(
conflictSql
.
contains
(
"conflict_student.student_id in"
));
assertTrue
(
conflictSql
.
contains
(
"e.class_id = ?"
));
assertTrue
(
conflictSql
.
contains
(
"from exam_teacher_assignment teacher_assignment"
));
// 详情列仍可通过exam_student统计应考人数,但不能再按学员ID参与冲突筛选。
assertFalse
(
conflictSql
.
contains
(
"from exam_student conflict_student"
));
assertFalse
(
conflictSql
.
contains
(
"conflict_student.student_id in"
));
/*
* 通用考试分页必须查出时长供服务层计算三态;顶部汇总则必须独立统计全表,
...
...
practical-business/src/test/java/com/platform/business/service/impl/ExamAdminServiceImplTest.java
View file @
46eeeaaa
...
...
@@ -107,7 +107,7 @@ class ExamAdminServiceImplTest {
mockValidRelationships
();
when
(
examMapper
.
countAdminExamDuplicateName
(
1
,
"测试考试"
,
null
)).
thenReturn
(
0
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
anyList
(),
anyList
(),
eq
(
null
)))
anyList
(),
eq
(
null
)))
.
thenReturn
(
Collections
.
emptyList
());
when
(
examMapper
.
insert
(
any
(
ExamEntity
.
class
))).
thenAnswer
(
invocation
->
{
ExamEntity
entity
=
invocation
.
getArgument
(
0
);
...
...
@@ -169,7 +169,7 @@ class ExamAdminServiceImplTest {
.
thenReturn
(
practiceRule
(
6
,
"一级"
,
"120.00"
));
when
(
examMapper
.
countAdminExamDuplicateName
(
1
,
"测试考试"
,
null
)).
thenReturn
(
0
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
anyList
(),
anyList
(),
eq
(
null
)))
anyList
(),
eq
(
null
)))
.
thenReturn
(
Collections
.
emptyList
());
when
(
examMapper
.
insert
(
any
(
ExamEntity
.
class
))).
thenAnswer
(
invocation
->
{
ExamEntity
entity
=
invocation
.
getArgument
(
0
);
...
...
@@ -256,7 +256,7 @@ class ExamAdminServiceImplTest {
conflict
.
setClassId
(
1
);
conflict
.
setName
(
"已有考试"
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
anyList
(),
anyList
(),
eq
(
null
)))
anyList
(),
eq
(
null
)))
.
thenReturn
(
Collections
.
singletonList
(
conflict
));
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
...
...
@@ -267,7 +267,7 @@ class ExamAdminServiceImplTest {
}
@Test
void
createShouldRejectOverlappingExamFor
AnyCandidate
()
{
void
createShouldRejectOverlappingExamFor
ChiefExaminerAcrossClasses
()
{
ExamAdminSaveDTO
request
=
validCreateRequest
();
mockWritableClass
();
mockValidPaper
();
...
...
@@ -277,17 +277,41 @@ class ExamAdminServiceImplTest {
conflict
.
setId
(
8
);
conflict
.
setClassId
(
2
);
conflict
.
setName
(
"其他班级考试"
);
conflict
.
setChiefExaminerId
(
"teacher-
3
"
);
conflict
.
setChiefExaminerId
(
"teacher-
1
"
);
conflict
.
setInvigilatorId
(
"teacher-4"
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
anyList
(),
anyList
(),
eq
(
null
)))
anyList
(),
eq
(
null
)))
.
thenReturn
(
Collections
.
singletonList
(
conflict
));
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
create
(
request
));
// 不同班级仍必须限制教师重复排期,但不再因应考学员重复而拦截。
assertEquals
(
"首席考评员与考试“其他班级考试”时间冲突"
,
error
.
getMessage
());
verify
(
examMapper
,
never
()).
insert
(
any
(
ExamEntity
.
class
));
}
@Test
void
createShouldRejectOverlappingExamForInvigilatorAcrossClasses
()
{
ExamAdminSaveDTO
request
=
validCreateRequest
();
mockWritableClass
();
mockValidPaper
();
mockValidRelationships
();
when
(
examMapper
.
countAdminExamDuplicateName
(
1
,
"测试考试"
,
null
)).
thenReturn
(
0
);
ExamAdminDetailVO
conflict
=
new
ExamAdminDetailVO
();
conflict
.
setId
(
9
);
conflict
.
setClassId
(
2
);
conflict
.
setName
(
"其他班级监考"
);
conflict
.
setChiefExaminerId
(
"teacher-3"
);
conflict
.
setInvigilatorId
(
"teacher-2"
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
anyList
(),
eq
(
null
)))
.
thenReturn
(
Collections
.
singletonList
(
conflict
));
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
create
(
request
));
// 班级和教师均不相同时,冲突只能来自重复安排的应考学员。
assertEquals
(
"应考学员与考试“其他班级考试”时间冲突"
,
error
.
getMessage
());
assertEquals
(
"监考教师与考试“其他班级监考”时间冲突"
,
error
.
getMessage
());
verify
(
examMapper
,
never
()).
insert
(
any
(
ExamEntity
.
class
));
}
...
...
@@ -352,7 +376,7 @@ class ExamAdminServiceImplTest {
.
thenReturn
(
practiceRule
(
6
,
"一级"
,
"100.00"
));
when
(
examMapper
.
countAdminExamDuplicateName
(
1
,
"修改后考试"
,
7
)).
thenReturn
(
0
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
120
),
eq
(
1
),
anyList
(),
anyList
(),
eq
(
7
)))
anyList
(),
eq
(
7
)))
.
thenReturn
(
Collections
.
emptyList
());
when
(
examMapper
.
updateAdminExam
(
any
(
ExamEntity
.
class
))).
thenReturn
(
1
);
ExamAdminDetailVO
detail
=
new
ExamAdminDetailVO
();
...
...
@@ -405,7 +429,7 @@ class ExamAdminServiceImplTest {
.
thenReturn
(
practiceRule
(
7
,
"一级"
,
"120.00"
));
when
(
examMapper
.
countAdminExamDuplicateName
(
1
,
"切换实操规则"
,
7
)).
thenReturn
(
0
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
anyList
(),
anyList
(),
eq
(
7
))).
thenReturn
(
Collections
.
emptyList
());
anyList
(),
eq
(
7
))).
thenReturn
(
Collections
.
emptyList
());
when
(
examMapper
.
updateAdminExam
(
any
(
ExamEntity
.
class
))).
thenReturn
(
1
);
ExamAdminDetailVO
detail
=
new
ExamAdminDetailVO
();
detail
.
setId
(
7
);
...
...
@@ -428,6 +452,48 @@ class ExamAdminServiceImplTest {
assertEquals
(
new
BigDecimal
(
"72.00"
),
captor
.
getValue
().
getPassScore
());
}
@Test
void
updateShouldRejectOverlappingExamForTeacherAcrossClasses
()
{
ExamEntity
existing
=
new
ExamEntity
();
existing
.
setId
(
7
);
existing
.
setClassId
(
1
);
existing
.
setType
(
ExamAdminConstants
.
TYPE_THEORY
);
existing
.
setExamTime
(
Timestamp
.
valueOf
(
"2099-09-18 09:00:00"
));
existing
.
setChiefId
(
"teacher-1"
);
existing
.
setInvigilationId
(
"teacher-2"
);
existing
.
setTotalScore
(
new
BigDecimal
(
"100.00"
));
existing
.
setPassScore
(
new
BigDecimal
(
"60.00"
));
when
(
examMapper
.
selectAdminExamForUpdate
(
7
)).
thenReturn
(
existing
);
when
(
examMapper
.
countAdminExamAttempts
(
7
)).
thenReturn
(
0
);
when
(
examMapper
.
lockAdminExamClass
(
1
)).
thenReturn
(
1
);
when
(
examMapper
.
selectAdminExamClass
(
1
)).
thenReturn
(
managedClass
());
when
(
examMapper
.
selectAdminExamStudentIds
(
7
))
.
thenReturn
(
Arrays
.
asList
(
"student-1"
,
"student-2"
));
mockValidRelationships
();
when
(
examMapper
.
countAdminExamDuplicateName
(
1
,
"调整时间后的考试"
,
7
)).
thenReturn
(
0
);
ExamAdminDetailVO
conflict
=
new
ExamAdminDetailVO
();
conflict
.
setId
(
8
);
conflict
.
setClassId
(
2
);
conflict
.
setName
(
"其他班级考试"
);
conflict
.
setChiefExaminerId
(
"teacher-1"
);
conflict
.
setInvigilatorId
(
"teacher-4"
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
anyList
(),
eq
(
7
))).
thenReturn
(
Collections
.
singletonList
(
conflict
));
ExamAdminUpdateDTO
request
=
new
ExamAdminUpdateDTO
();
request
.
setName
(
"调整时间后的考试"
);
request
.
setType
(
ExamAdminConstants
.
TYPE_THEORY
);
request
.
setExamTime
(
Timestamp
.
valueOf
(
"2099-09-19 10:00:00"
));
request
.
setDuration
(
90
);
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
update
(
7
,
request
));
// 编辑与新增共用同一套规则:放开跨班学员,但跨班教师的重叠排期仍必须拦截。
assertEquals
(
"首席考评员与考试“其他班级考试”时间冲突"
,
error
.
getMessage
());
verify
(
examMapper
,
never
()).
updateAdminExam
(
any
(
ExamEntity
.
class
));
}
@Test
void
createShouldPropagateCandidateFailureForTransactionRollback
()
{
ExamAdminSaveDTO
request
=
validCreateRequest
();
...
...
@@ -436,7 +502,7 @@ class ExamAdminServiceImplTest {
mockValidRelationships
();
when
(
examMapper
.
countAdminExamDuplicateName
(
1
,
"测试考试"
,
null
)).
thenReturn
(
0
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
anyList
(),
anyList
(),
eq
(
null
)))
anyList
(),
eq
(
null
)))
.
thenReturn
(
Collections
.
emptyList
());
when
(
examMapper
.
insert
(
any
(
ExamEntity
.
class
))).
thenAnswer
(
invocation
->
{
ExamEntity
entity
=
invocation
.
getArgument
(
0
);
...
...
@@ -593,7 +659,7 @@ class ExamAdminServiceImplTest {
.
thenReturn
(
Arrays
.
asList
(
"student-1"
,
"student-2"
));
when
(
examMapper
.
countAdminExamDuplicateName
(
1
,
"测试考试"
,
null
)).
thenReturn
(
0
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
anyList
(),
anyList
(),
eq
(
null
))).
thenReturn
(
Collections
.
emptyList
());
anyList
(),
eq
(
null
))).
thenReturn
(
Collections
.
emptyList
());
when
(
examMapper
.
insert
(
any
(
ExamEntity
.
class
))).
thenAnswer
(
invocation
->
{
ExamEntity
entity
=
invocation
.
getArgument
(
0
);
entity
.
setId
(
101
);
...
...
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