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
9c8e2241
Commit
9c8e2241
authored
Sep 14, 2026
by
王蔡翾
Browse files
考试标记bug修复
parent
04bb4f11
Changes
2
Show whitespace changes
Inline
Side-by-side
practical-business/src/main/resources/com/platform/business/mapper/UserMapper.xml
View file @
9c8e2241
...
@@ -53,9 +53,9 @@
...
@@ -53,9 +53,9 @@
user.del_flag,
user.del_flag,
role.id as roleId,
role.id as roleId,
role.name as roleName,
role.name as roleName,
user.
exam_flag,
active_exam.exam_student_id is not null as
exam_flag,
u
se
r.
exam
_
type as examType,
se
lected_
exam
.
type as examType,
user.
exam_oneself_id,
active_exam.exam_student_id as
exam_oneself_id,
user.level,
user.level,
user.simulation_flag,
user.simulation_flag,
user.simulation_id
user.simulation_id
...
@@ -69,6 +69,31 @@
...
@@ -69,6 +69,31 @@
role
role
on
on
sys_user_and_role.role_id = role.id
sys_user_and_role.role_id = role.id
<!--
用户信息接口实时派生当前考试,避免定时同步间隔内返回已经结束的旧标记。
已开考记录优先使用个人end_time;未开考记录使用统一考试计划结束点。
-->
left join (
select candidate.student_id,
min(candidate.id) as exam_student_id
from exam_student candidate
inner join exam exam_plan on exam_plan.id = candidate.exam_id
where exam_plan.exam_time
<
= current_timestamp
and coalesce(
from_unixtime(candidate.end_time / 1000),
timestampadd(
minute,
greatest(coalesce(exam_plan.duration, 0), 0),
exam_plan.exam_time
)
)
>
current_timestamp
and coalesce(candidate.submit, 0) = 0
group by candidate.student_id
) active_exam on active_exam.student_id = user.id
left join exam_student selected_candidate
on selected_candidate.id = active_exam.exam_student_id
left join exam selected_exam
on selected_exam.id = selected_candidate.exam_id
where user.phone_number = #{userName}
where user.phone_number = #{userName}
</select>
</select>
<update
id=
"closeExam"
>
<update
id=
"closeExam"
>
...
@@ -84,41 +109,43 @@
...
@@ -84,41 +109,43 @@
simulation_id = null
simulation_id = null
where id = #{studentId}
where id = #{studentId}
</update>
</update>
<update
id=
"
activateDueExam
s"
>
<update
id=
"
syncExamFlag
s"
>
<!--
<!--
到达计划开始时间后批量激活学员考试状态。结束时间采用[开始时间, 开始时间+时长)
同一条幂等SQL同时激活当前考试、清理已结束或已交卷的旧标记。未开考时使用考试
半开区间,与新增考试的冲突判断完全一致,因此首尾相接的两场考试不会同时生效。
计划结束点;已经开考时优先使用个人倒计时end_time。有效区间统一采用
理论与实训考试共用该状态;submit历史空值按未交卷处理
。
[开始时间, 结束时间),结束时刻立即清理examFlag、应考记录ID和考试类型
。
-->
-->
update `user` target_user
update `user` target_user
inner
join (
left
join (
select candidate.student_id,
select candidate.student_id,
min(candidate.id) as exam_student_id
min(candidate.id) as exam_student_id
from exam_student candidate
from exam_student candidate
inner join exam exam_plan on exam_plan.id = candidate.exam_id
inner join exam exam_plan on exam_plan.id = candidate.exam_id
where exam_plan.exam_time
<
= #{now}
where exam_plan.exam_time
<
= #{now}
and timestampadd(
and coalesce(
from_unixtime(candidate.end_time / 1000),
timestampadd(
minute,
minute,
greatest(coalesce(exam_plan.duration, 0), 0),
greatest(coalesce(exam_plan.duration, 0), 0),
exam_plan.exam_time
exam_plan.exam_time
)
)
>
#{now}
)
>
#{now}
and coalesce(candidate.submit, 0) = 0
and coalesce(candidate.submit, 0) = 0
group by candidate.student_id
group by candidate.student_id
) active_exam on active_exam.student_id = target_user.id
) active_exam on active_exam.student_id = target_user.id
inner
join exam_student selected_candidate
left
join exam_student selected_candidate
on selected_candidate.id = active_exam.exam_student_id
on selected_candidate.id = active_exam.exam_student_id
inner
join exam selected_exam
left
join exam selected_exam
on selected_exam.id = selected_candidate.exam_id
on selected_exam.id = selected_candidate.exam_id
<!--
<!--
exam
_t
ype必须取自min(candidate.id)最终选中的同一
条应考记录,不能直接在聚合子查询中
exam
T
ype必须取自min(candidate.id)最终选中的同一
场考试;LEFT JOIN同时保留没有
随意选择exam_plan.type,否则同一学员存在多条候选记录时,考试ID和类型可能不对应
。
有效考试的用户,使三个持久化字段能够被原子清空
。
-->
-->
set target_user.exam_flag =
true
,
set target_user.exam_flag =
active_exam.exam_student_id is not null
,
target_user.exam_oneself_id = active_exam.exam_student_id,
target_user.exam_oneself_id = active_exam.exam_student_id,
target_user.exam_type = selected_exam.type
target_user.exam_type = selected_exam.type
where coalesce(target_user.exam_flag, 0) = 0
where coalesce(target_user.exam_flag, 0)
<>
(active_exam.exam_student_id is not null)
or target_user.exam_oneself_id is null
or not (target_user.exam_oneself_id
<
=> active_exam.exam_student_id)
or target_user.exam_oneself_id
<>
active_exam.exam_student_id
or not (target_user.exam_type
<
=> selected_exam.type)
or coalesce(target_user.exam_type, '')
<>
coalesce(selected_exam.type, '')
</update>
</update>
</mapper>
</mapper>
practical-business/src/test/java/com/platform/business/mapper/UserMapperXmlTest.java
View file @
9c8e2241
...
@@ -19,7 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
...
@@ -19,7 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class
UserMapperXmlTest
{
class
UserMapperXmlTest
{
@Test
@Test
void
queryByUserNameShould
Return
CurrentExamType
()
throws
Exception
{
void
queryByUserNameShould
Derive
CurrentExam
StateAnd
Type
()
throws
Exception
{
Configuration
configuration
=
parseMapper
();
Configuration
configuration
=
parseMapper
();
BoundSql
boundSql
=
configuration
.
getMappedStatement
(
BoundSql
boundSql
=
configuration
.
getMappedStatement
(
...
@@ -27,8 +27,15 @@ class UserMapperXmlTest {
...
@@ -27,8 +27,15 @@ class UserMapperXmlTest {
.
getBoundSql
(
Collections
.
singletonMap
(
"userName"
,
"13800000000"
));
.
getBoundSql
(
Collections
.
singletonMap
(
"userName"
,
"13800000000"
));
String
sql
=
boundSql
.
getSql
().
replaceAll
(
"\\s+"
,
" "
).
toLowerCase
(
Locale
.
ROOT
);
String
sql
=
boundSql
.
getSql
().
replaceAll
(
"\\s+"
,
" "
).
toLowerCase
(
Locale
.
ROOT
);
// 使用显式别名保证不依赖不同环境的MyBatis下划线转换配置,接口始终返回examType。
// 接口不读取可能滞后的持久化标记,而是从同一条当前有效应考记录派生三个字段。
assertTrue
(
sql
.
contains
(
"user.exam_type as examtype"
));
assertTrue
(
sql
.
contains
(
"active_exam.exam_student_id is not null as exam_flag"
));
assertTrue
(
sql
.
contains
(
"active_exam.exam_student_id as exam_oneself_id"
));
assertTrue
(
sql
.
contains
(
"selected_exam.type as examtype"
));
assertTrue
(
sql
.
contains
(
"from_unixtime(candidate.end_time / 1000)"
));
assertTrue
(
sql
.
contains
(
") > current_timestamp"
));
assertTrue
(
sql
.
contains
(
"coalesce(candidate.submit, 0) = 0"
));
assertTrue
(
sql
.
contains
(
"selected_candidate.id = active_exam.exam_student_id"
));
assertTrue
(
sql
.
contains
(
"selected_exam.id = selected_candidate.exam_id"
));
}
}
@Test
@Test
...
@@ -51,27 +58,30 @@ class UserMapperXmlTest {
...
@@ -51,27 +58,30 @@ class UserMapperXmlTest {
}
}
@Test
@Test
void
activateDueExam
sShould
Use
Activ
eHalfOpenTimeRang
e
()
throws
Exception
{
void
syncExamFlag
sShouldActiv
ateCurrentExamAndClearExpiredStat
e
()
throws
Exception
{
Configuration
configuration
=
parseMapper
();
Configuration
configuration
=
parseMapper
();
BoundSql
boundSql
=
configuration
.
getMappedStatement
(
BoundSql
boundSql
=
configuration
.
getMappedStatement
(
"com.platform.business.mapper.UserMapper.
activateDueExam
s"
)
"com.platform.business.mapper.UserMapper.
syncExamFlag
s"
)
.
getBoundSql
(
Collections
.
singletonMap
(
.
getBoundSql
(
Collections
.
singletonMap
(
"now"
,
Timestamp
.
valueOf
(
"2026-09-18 09:00:00"
)));
"now"
,
Timestamp
.
valueOf
(
"2026-09-18 09:00:00"
)));
String
sql
=
boundSql
.
getSql
().
replaceAll
(
"\\s+"
,
" "
).
toLowerCase
();
String
sql
=
boundSql
.
getSql
().
replaceAll
(
"\\s+"
,
" "
).
toLowerCase
();
// 开始时刻包含
在活动区间内,结束时刻不包含,必须与考试冲突校验的边界一致
。
// 开始时刻包含
、结束时刻不包含;个人end_time优先,未开考记录回退到计划结束点
。
assertTrue
(
sql
.
contains
(
"exam_plan.exam_time <= ?"
));
assertTrue
(
sql
.
contains
(
"exam_plan.exam_time <= ?"
));
assertTrue
(
sql
.
contains
(
"from_unixtime(candidate.end_time / 1000)"
));
assertTrue
(
sql
.
contains
(
"greatest(coalesce(exam_plan.duration, 0), 0)"
));
assertTrue
(
sql
.
contains
(
"greatest(coalesce(exam_plan.duration, 0), 0)"
));
assertTrue
(
sql
.
contains
(
") > ?"
));
assertTrue
(
sql
.
contains
(
") > ?"
));
assertTrue
(
sql
.
contains
(
"coalesce(candidate.submit, 0) = 0"
));
assertTrue
(
sql
.
contains
(
"coalesce(candidate.submit, 0) = 0"
));
assertTrue
(
sql
.
contains
(
"selected_candidate.id = active_exam.exam_student_id"
));
assertTrue
(
sql
.
contains
(
"selected_candidate.id = active_exam.exam_student_id"
));
assertTrue
(
sql
.
contains
(
"selected_exam.id = selected_candidate.exam_id"
));
assertTrue
(
sql
.
contains
(
"selected_exam.id = selected_candidate.exam_id"
));
assertTrue
(
sql
.
contains
(
"target_user.exam_flag = true"
));
// LEFT JOIN使无有效考试的用户也能进入更新,三个字段必须一起激活或清空。
assertTrue
(
sql
.
contains
(
"left join ("
));
assertTrue
(
sql
.
contains
(
"target_user.exam_flag = active_exam.exam_student_id is not null"
));
assertTrue
(
sql
.
contains
(
"target_user.exam_oneself_id = active_exam.exam_student_id"
));
assertTrue
(
sql
.
contains
(
"target_user.exam_oneself_id = active_exam.exam_student_id"
));
assertTrue
(
sql
.
contains
(
"target_user.exam_type = selected_exam.type"
));
assertTrue
(
sql
.
contains
(
"target_user.exam_type = selected_exam.type"
));
assertTrue
(
sql
.
contains
(
"
coalesce
(target_user.exam_
type, '') "
assertTrue
(
sql
.
contains
(
"
not
(target_user.exam_
oneself_id <=> active_exam.exam_student_id)"
));
+
"<> coalesce(
selected_exam.type
, ''
)"
));
assertTrue
(
sql
.
contains
(
"not (target_user.exam_type <=>
selected_exam.type)"
));
assertEquals
(
2
,
boundSql
.
getParameterMappings
().
size
());
assertEquals
(
2
,
boundSql
.
getParameterMappings
().
size
());
}
}
...
...
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