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
9b9782a3
Commit
9b9782a3
authored
Sep 14, 2026
by
王蔡翾
Browse files
考试标记bug修复
parent
67ead0bb
Changes
15
Hide whitespace changes
Inline
Side-by-side
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/AttendanceStudentStatisticsVO.java
View file @
9b9782a3
...
@@ -11,6 +11,8 @@ public class AttendanceStudentStatisticsVO {
...
@@ -11,6 +11,8 @@ public class AttendanceStudentStatisticsVO {
private
String
studentId
;
private
String
studentId
;
/** 学员姓名。 */
/** 学员姓名。 */
private
String
studentName
;
private
String
studentName
;
/** 统计范围内学员所在班级;跨班级时使用顿号连接班级名称。 */
private
String
className
;
/** 学员完整手机号。 */
/** 学员完整手机号。 */
private
String
studentPhone
;
private
String
studentPhone
;
/** 应出勤课次,包含请假。 */
/** 应出勤课次,包含请假。 */
...
...
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/StudentExamCenterVO.java
View file @
9b9782a3
...
@@ -36,7 +36,7 @@ public final class StudentExamCenterVO {
...
@@ -36,7 +36,7 @@ public final class StudentExamCenterVO {
private
Boolean
studentMarkFlag
;
private
Boolean
studentMarkFlag
;
private
Boolean
examMarkFlag
;
private
Boolean
examMarkFlag
;
private
Double
score
;
private
Double
score
;
/** WAITING、IN_PROGRESS、SUBMITTED或PUBLISHED。 */
/** WAITING、IN_PROGRESS、
ABSENT、ENDED、
SUBMITTED或PUBLISHED。 */
private
String
workflowStatus
;
private
String
workflowStatus
;
/** WAIT、START、RESUME、VIEW_INSTRUCTIONS或VIEW_SCORE。 */
/** WAIT、START、RESUME、VIEW_INSTRUCTIONS或VIEW_SCORE。 */
private
String
action
;
private
String
action
;
...
...
practical-business/src/main/java/com/platform/business/mapper/UserMapper.java
View file @
9b9782a3
...
@@ -22,10 +22,10 @@ public interface UserMapper extends BaseMapper<UserEntity> {
...
@@ -22,10 +22,10 @@ public interface UserMapper extends BaseMapper<UserEntity> {
void
closeSimulation
(
@Param
(
"studentId"
)
String
studentId
);
void
closeSimulation
(
@Param
(
"studentId"
)
String
studentId
);
/**
/**
* 批量
激活已经到达开始时间、尚未结束且尚未交卷的考试
。
* 批量
同步用户的考试标记:激活当前考试,并清理已交卷或已超过有效结束时间的标记
。
*
*
* <p>返回实际发生状态变化的用户数;SQL本身保持幂等,允许多个应用实例重复调度。</p>
* <p>返回实际发生状态变化的用户数;SQL本身保持幂等,允许多个应用实例重复调度。</p>
*/
*/
int
activateDueExam
s
(
@Param
(
"now"
)
Date
now
);
int
syncExamFlag
s
(
@Param
(
"now"
)
Date
now
);
}
}
practical-business/src/main/java/com/platform/business/service/impl/StudentExamCenterServiceImpl.java
View file @
9b9782a3
...
@@ -308,6 +308,7 @@ public class StudentExamCenterServiceImpl implements StudentExamCenterService {
...
@@ -308,6 +308,7 @@ public class StudentExamCenterServiceImpl implements StudentExamCenterService {
&&
Boolean
.
TRUE
.
equals
(
row
.
getStudentMarkFlag
())
&&
Boolean
.
TRUE
.
equals
(
row
.
getStudentMarkFlag
())
&&
Boolean
.
TRUE
.
equals
(
row
.
getExamMarkFlag
())
&&
Boolean
.
TRUE
.
equals
(
row
.
getExamMarkFlag
())
&&
row
.
getScore
()
!=
null
;
&&
row
.
getScore
()
!=
null
;
long
scheduledEnd
=
scheduledEnd
(
row
);
if
(
published
)
{
if
(
published
)
{
row
.
setWorkflowStatus
(
"PUBLISHED"
);
row
.
setWorkflowStatus
(
"PUBLISHED"
);
row
.
setAction
(
"VIEW_SCORE"
);
row
.
setAction
(
"VIEW_SCORE"
);
...
@@ -315,8 +316,19 @@ public class StudentExamCenterServiceImpl implements StudentExamCenterService {
...
@@ -315,8 +316,19 @@ public class StudentExamCenterServiceImpl implements StudentExamCenterService {
row
.
setWorkflowStatus
(
"SUBMITTED"
);
row
.
setWorkflowStatus
(
"SUBMITTED"
);
row
.
setAction
(
"WAIT"
);
row
.
setAction
(
"WAIT"
);
}
else
if
(
row
.
getStartTime
()
!=
null
)
{
}
else
if
(
row
.
getStartTime
()
!=
null
)
{
row
.
setWorkflowStatus
(
"IN_PROGRESS"
);
// 已开考记录优先使用个人倒计时结束点;历史空值回退到统一考试计划结束点。
row
.
setAction
(
isTheory
(
row
.
getType
())
?
"RESUME"
:
"VIEW_INSTRUCTIONS"
);
long
actualEnd
=
row
.
getEndTime
()
==
null
?
scheduledEnd
:
row
.
getEndTime
();
if
(
now
>=
actualEnd
)
{
row
.
setWorkflowStatus
(
"ENDED"
);
row
.
setAction
(
"WAIT"
);
}
else
{
row
.
setWorkflowStatus
(
"IN_PROGRESS"
);
row
.
setAction
(
isTheory
(
row
.
getType
())
?
"RESUME"
:
"VIEW_INSTRUCTIONS"
);
}
}
else
if
(
now
>=
scheduledEnd
)
{
// 考试计划已经结束且从未开考,按缺考展示,不能继续保留为待考。
row
.
setWorkflowStatus
(
"ABSENT"
);
row
.
setAction
(
"WAIT"
);
}
else
{
}
else
{
row
.
setWorkflowStatus
(
"WAITING"
);
row
.
setWorkflowStatus
(
"WAITING"
);
if
(!
isTheory
(
row
.
getType
()))
{
if
(!
isTheory
(
row
.
getType
()))
{
...
@@ -333,6 +345,18 @@ public class StudentExamCenterServiceImpl implements StudentExamCenterService {
...
@@ -333,6 +345,18 @@ public class StudentExamCenterServiceImpl implements StudentExamCenterService {
}
}
}
}
/**
* 计算统一考试计划的结束毫秒数。缺少开始时间视为已结束;空时长和负时长按0分钟处理,
* 与管理端考试状态的历史脏数据兼容规则保持一致。
*/
private
long
scheduledEnd
(
StudentExamCenterVO
.
ListItem
row
)
{
if
(
row
.
getExamTime
()
==
null
)
{
return
Long
.
MIN_VALUE
;
}
long
duration
=
Math
.
max
(
0L
,
row
.
getDuration
()
==
null
?
0L
:
row
.
getDuration
().
longValue
());
return
row
.
getExamTime
().
getTime
()
+
TimeUnit
.
MINUTES
.
toMillis
(
duration
);
}
private
StudentExamCenterVO
.
Attempt
requireAttempt
(
Integer
examStudentId
,
String
studentId
,
private
StudentExamCenterVO
.
Attempt
requireAttempt
(
Integer
examStudentId
,
String
studentId
,
boolean
lock
)
{
boolean
lock
)
{
if
(
examStudentId
==
null
||
examStudentId
<=
0
)
{
if
(
examStudentId
==
null
||
examStudentId
<=
0
)
{
...
...
practical-business/src/main/java/com/platform/business/task/ExamFlagSyncTask.java
View file @
9b9782a3
...
@@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
...
@@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.Date
;
import
java.util.Date
;
/** 定时
把已经进入计划考试时段的应考学员标记为“考试进行中”
。 */
/** 定时
同步用户的考试进行中标记,同时清理已经结束或已经交卷的过期标记
。 */
@Component
@Component
public
class
ExamFlagSyncTask
{
public
class
ExamFlagSyncTask
{
...
@@ -22,7 +22,7 @@ public class ExamFlagSyncTask {
...
@@ -22,7 +22,7 @@ public class ExamFlagSyncTask {
*/
*/
@Scheduled
(
initialDelayString
=
"${exam.flag-sync.initial-delay-millis:1000}"
,
@Scheduled
(
initialDelayString
=
"${exam.flag-sync.initial-delay-millis:1000}"
,
fixedDelayString
=
"${exam.flag-sync.poll-interval-millis:5000}"
)
fixedDelayString
=
"${exam.flag-sync.poll-interval-millis:5000}"
)
public
void
activateDueExam
s
()
{
public
void
syncExamFlag
s
()
{
userMapper
.
activateDueExam
s
(
new
Date
());
userMapper
.
syncExamFlag
s
(
new
Date
());
}
}
}
}
practical-business/src/main/resources/attendance-api.md
View file @
9b9782a3
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
## 管理端
## 管理端
-
`POST /attendance/admin/records/page`
:按班级、课程、状态、日期范围分页查询。
-
`POST /attendance/admin/records/page`
:按班级、课程、状态、日期范围分页查询。
-
`POST /attendance/admin/statistics`
:按班级、课程和日期范围返回班级人数、课程数、应到、正常签到、迟到、缺勤、请假、异常人次及出勤率。管理员接口不修改出勤状态。
-
`POST /attendance/admin/statistics`
:按班级、课程和日期范围返回班级人数、课程数、应到、正常签到、迟到、缺勤、请假、异常人次及出勤率
;
`studentStatistics`
的每行包含
`className`
,跨班级统计时用顿号连接班级名称
。管理员接口不修改出勤状态。
管理端班级看板口径:
`出勤率 = 正常签到 ÷ 应到人次 × 100%`
;迟到、请假、缺勤均归入异常人次。因此图片示例中的 250 次正常签到、15 次迟到、12 次请假、3 次缺勤,得到应到 280 次、异常 30 次、出勤率
`250 ÷ 280 = 89.3%`
。
管理端班级看板口径:
`出勤率 = 正常签到 ÷ 应到人次 × 100%`
;迟到、请假、缺勤均归入异常人次。因此图片示例中的 250 次正常签到、15 次迟到、12 次请假、3 次缺勤,得到应到 280 次、异常 30 次、出勤率
`250 ÷ 280 = 89.3%`
。
...
...
practical-business/src/main/resources/com/platform/business/mapper/ClassSubjectAttendanceMapper.xml
View file @
9b9782a3
...
@@ -239,6 +239,7 @@
...
@@ -239,6 +239,7 @@
select
select
a.user_id as studentId,
a.user_id as studentId,
student.nick_name as studentName,
student.nick_name as studentName,
group_concat(distinct c.name order by c.name separator '、') as className,
student.phone_number as studentPhone,
student.phone_number as studentPhone,
count(a.id) as requiredCount,
count(a.id) as requiredCount,
sum(case when a.status = 'NORMAL' then 1 else 0 end) as normalCount,
sum(case when a.status = 'NORMAL' then 1 else 0 end) as normalCount,
...
@@ -248,6 +249,7 @@
...
@@ -248,6 +249,7 @@
round(sum(case when a.status in ('NORMAL', 'LATE') then 1 else 0 end) * 100.0 / count(a.id), 2) as attendanceRate
round(sum(case when a.status in ('NORMAL', 'LATE') then 1 else 0 end) * 100.0 / count(a.id), 2) as attendanceRate
from class_subject_attendance a
from class_subject_attendance a
inner join class_subject s on s.id = a.subject_id
inner join class_subject s on s.id = a.subject_id
left join class c on c.id = s.class_id
left join user student on student.id = a.user_id
left join user student on student.id = a.user_id
<where>
<where>
<if
test=
"subjectId != null"
>
and s.id = #{subjectId}
</if>
<if
test=
"subjectId != null"
>
and s.id = #{subjectId}
</if>
...
@@ -257,6 +259,10 @@
...
@@ -257,6 +259,10 @@
<if
test=
"startDate != null"
>
and s.date
>
= #{startDate}
</if>
<if
test=
"startDate != null"
>
and s.date
>
= #{startDate}
</if>
<if
test=
"endDate != null"
>
and s.date
<
= #{endDate}
</if>
<if
test=
"endDate != null"
>
and s.date
<
= #{endDate}
</if>
</where>
</where>
<!--
未指定班级时同一学员可能命中多段历史班级;保持每名学员一行,并将实际参与统计的
班级名称去重后连接,避免增加className后把原有学员统计拆成多行。
-->
group by a.user_id, student.nick_name, student.phone_number
group by a.user_id, student.nick_name, student.phone_number
order by attendanceRate desc, student.nick_name asc
order by attendanceRate desc, student.nick_name asc
</select>
</select>
...
...
practical-business/src/main/resources/com/platform/business/mapper/StudentExamCenterMapper.xml
View file @
9b9782a3
...
@@ -49,9 +49,20 @@
...
@@ -49,9 +49,20 @@
</if>
</if>
<if
test=
"query.status == 'PENDING'"
>
<if
test=
"query.status == 'PENDING'"
>
AND COALESCE(es.submit, 0) = 0
AND COALESCE(es.submit, 0) = 0
AND COALESCE(
FROM_UNIXTIME(es.end_time / 1000),
TIMESTAMPADD(MINUTE, GREATEST(COALESCE(e.duration, 0), 0), e.exam_time)
)
>
CURRENT_TIMESTAMP
</if>
</if>
<if
test=
"query.status == 'COMPLETED'"
>
<if
test=
"query.status == 'COMPLETED'"
>
AND COALESCE(es.submit, 0) = 1
AND (
COALESCE(es.submit, 0) = 1
OR e.exam_time IS NULL
OR COALESCE(
FROM_UNIXTIME(es.end_time / 1000),
TIMESTAMPADD(MINUTE, GREATEST(COALESCE(e.duration, 0), 0), e.exam_time)
)
<
= CURRENT_TIMESTAMP
)
</if>
</if>
ORDER BY e.exam_time DESC, e.id DESC
ORDER BY e.exam_time DESC, e.id DESC
</select>
</select>
...
...
practical-business/src/main/resources/com/platform/business/mapper/UserMapper.xml
View file @
9b9782a3
...
@@ -53,8 +53,8 @@
...
@@ -53,8 +53,8 @@
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,
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
...
@@ -68,6 +68,27 @@
...
@@ -68,6 +68,27 @@
role
role
on
on
sys_user_and_role.role_id = role.id
sys_user_and_role.role_id = role.id
<!--
用户信息接口直接按数据库当前时刻派生考试标记,避免在5秒定时同步窗口内返回旧值。
已开考记录优先使用个人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
where user.phone_number = #{userName}
where user.phone_number = #{userName}
</select>
</select>
<update
id=
"closeExam"
>
<update
id=
"closeExam"
>
...
@@ -82,31 +103,33 @@
...
@@ -82,31 +103,33 @@
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历史空值按未交卷处理
。
清理。有效区间统一采用[开始时间, 结束时间),结束时刻立即返回false
。
-->
-->
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(
minute,
from_unixtime(candidate.end_time / 1000),
greatest(coalesce(exam_plan.duration, 0), 0),
timestampadd(
exam_plan.exam_time
minute,
greatest(coalesce(exam_plan.duration, 0), 0),
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
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
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
</update>
</update>
</mapper>
</mapper>
practical-business/src/main/resources/student-exam-center-api.md
View file @
9b9782a3
...
@@ -12,10 +12,13 @@
...
@@ -12,10 +12,13 @@
{
"pageNum"
:
1
,
"pageSize"
:
10
,
"keyword"
:
"理论"
,
"status"
:
"ALL"
}
{
"pageNum"
:
1
,
"pageSize"
:
10
,
"keyword"
:
"理论"
,
"status"
:
"ALL"
}
```
```
`status`
支持
`ALL/PENDING/COMPLETED`
。返回行中的
`workflowStatus`
为:
`status`
支持
`ALL/PENDING/COMPLETED`
:
`PENDING`
包含尚未结束的待考和进行中场次,
`COMPLETED`
包含缺考、已结束、已交卷和已发布场次。返回行中的
`workflowStatus`
为:
-
`WAITING`
:尚未开考;
-
`WAITING`
:尚未开考;
-
`IN_PROGRESS`
:已经开始且尚未交卷;
-
`IN_PROGRESS`
:已经开始且尚未交卷;
-
`ABSENT`
:考试已经结束且学员从未开考;
-
`ENDED`
:学员已经开考,但个人考试时间结束时仍未交卷;
-
`SUBMITTED`
:已经交卷但成绩尚未正式发布;
-
`SUBMITTED`
:已经交卷但成绩尚未正式发布;
-
`PUBLISHED`
:正式成绩可见。
-
`PUBLISHED`
:正式成绩可见。
...
...
practical-business/src/test/java/com/platform/business/mapper/AttendanceStatisticsMapperXmlTest.java
View file @
9b9782a3
...
@@ -35,7 +35,12 @@ class AttendanceStatisticsMapperXmlTest {
...
@@ -35,7 +35,12 @@ class AttendanceStatisticsMapperXmlTest {
// 迟到仍保留在异常人次展示中,但出勤率必须按NORMAL+LATE实际到课人次计算。
// 迟到仍保留在异常人次展示中,但出勤率必须按NORMAL+LATE实际到课人次计算。
assertTrue
(
summarySql
.
contains
(
"a.status in ('LATE', 'ABSENT', 'LEAVE') then 1 else 0 end) as abnormalCount"
));
assertTrue
(
summarySql
.
contains
(
"a.status in ('LATE', 'ABSENT', 'LEAVE') then 1 else 0 end) as abnormalCount"
));
assertActualAttendanceRate
(
summarySql
);
assertActualAttendanceRate
(
summarySql
);
assertActualAttendanceRate
(
statementSql
(
configuration
,
"queryStudentStatistics"
,
query
));
String
studentSql
=
statementSql
(
configuration
,
"queryStudentStatistics"
,
query
);
// 学员统计必须带出实际参与统计的班级;多段历史关系仍保持每名学员一行。
assertTrue
(
studentSql
.
contains
(
"left join class c on c.id = s.class_id"
));
assertTrue
(
studentSql
.
contains
(
"group_concat(distinct c.name order by c.name separator '、') as className"
));
assertActualAttendanceRate
(
studentSql
);
assertActualAttendanceRate
(
statementSql
(
configuration
,
"queryCourseStatistics"
,
query
));
assertActualAttendanceRate
(
statementSql
(
configuration
,
"queryCourseStatistics"
,
query
));
}
}
...
...
practical-business/src/test/java/com/platform/business/mapper/StudentLearningMapperXmlTest.java
View file @
9b9782a3
package
com.platform.business.mapper
;
package
com.platform.business.mapper
;
import
com.platform.business.model.dto.StudentExamCenterQueryDTO
;
import
org.apache.ibatis.builder.xml.XMLMapperBuilder
;
import
org.apache.ibatis.builder.xml.XMLMapperBuilder
;
import
org.apache.ibatis.io.Resources
;
import
org.apache.ibatis.io.Resources
;
import
org.apache.ibatis.session.Configuration
;
import
org.apache.ibatis.session.Configuration
;
...
@@ -9,6 +10,8 @@ import java.io.ByteArrayOutputStream;
...
@@ -9,6 +10,8 @@ import java.io.ByteArrayOutputStream;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
...
@@ -42,6 +45,33 @@ class StudentLearningMapperXmlTest {
...
@@ -42,6 +45,33 @@ class StudentLearningMapperXmlTest {
assertFalse
(
paperSql
.
contains
(
"rand()"
));
assertFalse
(
paperSql
.
contains
(
"rand()"
));
}
}
@Test
void
examCenterStatusFiltersShouldTreatExpiredAttemptsAsCompleted
()
throws
Exception
{
Configuration
configuration
=
parse
(
"com/platform/business/mapper/StudentExamCenterMapper.xml"
);
StudentExamCenterQueryDTO
query
=
new
StudentExamCenterQueryDTO
();
Map
<
String
,
Object
>
parameters
=
new
HashMap
<>();
parameters
.
put
(
"query"
,
query
);
parameters
.
put
(
"studentId"
,
"student-1"
);
query
.
setStatus
(
"PENDING"
);
String
pendingSql
=
compact
(
configuration
.
getMappedStatement
(
"com.platform.business.mapper.StudentExamCenterMapper.selectPage"
)
.
getBoundSql
(
parameters
).
getSql
());
// 未交卷只有在个人或计划结束时间仍在未来时才属于待考/进行中。
assertTrue
(
pendingSql
.
contains
(
"from_unixtime(es.end_time / 1000)"
));
assertTrue
(
pendingSql
.
contains
(
"> current_timestamp"
));
query
.
setStatus
(
"COMPLETED"
);
String
completedSql
=
compact
(
configuration
.
getMappedStatement
(
"com.platform.business.mapper.StudentExamCenterMapper.selectPage"
)
.
getBoundSql
(
parameters
).
getSql
());
// 已交卷、缺考和超时未交卷都归入已完成筛选,避免历史场次继续显示为待考。
assertTrue
(
completedSql
.
contains
(
"coalesce(es.submit, 0) = 1"
));
assertTrue
(
completedSql
.
contains
(
"or e.exam_time is null"
));
assertTrue
(
completedSql
.
contains
(
"<= current_timestamp"
));
}
@Test
@Test
void
paperDetailMapperShouldKeepGroupedFixedOrderWithoutRandomization
()
throws
Exception
{
void
paperDetailMapperShouldKeepGroupedFixedOrderWithoutRandomization
()
throws
Exception
{
Configuration
configuration
=
parse
(
Configuration
configuration
=
parse
(
...
...
practical-business/src/test/java/com/platform/business/mapper/UserMapperXmlTest.java
View file @
9b9782a3
...
@@ -38,22 +38,42 @@ class UserMapperXmlTest {
...
@@ -38,22 +38,42 @@ class UserMapperXmlTest {
}
}
@Test
@Test
void
activateDueExamsShouldUseActiveHalfOpenTimeRange
()
throws
Exception
{
void
userMessageShouldDeriveExamFlagFromCurrentActiveAttempt
()
throws
Exception
{
Configuration
configuration
=
parseMapper
();
BoundSql
boundSql
=
configuration
.
getMappedStatement
(
"com.platform.business.mapper.UserMapper.queryByUserName"
)
.
getBoundSql
(
Collections
.
singletonMap
(
"userName"
,
"13800000000"
));
String
sql
=
boundSql
.
getSql
().
replaceAll
(
"\\s+"
,
" "
).
toLowerCase
();
// 接口查询不直接返回可能滞后的user.exam_flag,而是按当前有效考试实时派生两个字段。
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
(
"from_unixtime(candidate.end_time / 1000)"
));
assertTrue
(
sql
.
contains
(
") > current_timestamp"
));
assertTrue
(
sql
.
contains
(
"coalesce(candidate.submit, 0) = 0"
));
}
@Test
void
syncExamFlagsShouldActivateCurrentExamAndClearExpiredFlag
()
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
(
"target_user.exam_flag = true"
));
// LEFT JOIN使无有效考试的用户也进入更新范围,从而同时清理flag和个人考试ID。
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
(
"not (target_user.exam_oneself_id <=> active_exam.exam_student_id)"
));
assertEquals
(
2
,
boundSql
.
getParameterMappings
().
size
());
assertEquals
(
2
,
boundSql
.
getParameterMappings
().
size
());
}
}
...
...
practical-business/src/test/java/com/platform/business/service/impl/StudentExamCenterServiceImplTest.java
View file @
9b9782a3
...
@@ -70,6 +70,7 @@ class StudentExamCenterServiceImplTest {
...
@@ -70,6 +70,7 @@ class StudentExamCenterServiceImplTest {
StudentExamCenterVO
.
ListItem
waiting
=
new
StudentExamCenterVO
.
ListItem
();
StudentExamCenterVO
.
ListItem
waiting
=
new
StudentExamCenterVO
.
ListItem
();
waiting
.
setType
(
ExamAdminConstants
.
TYPE_THEORY
);
waiting
.
setType
(
ExamAdminConstants
.
TYPE_THEORY
);
waiting
.
setExamTime
(
new
Date
(
System
.
currentTimeMillis
()
-
1000
));
waiting
.
setExamTime
(
new
Date
(
System
.
currentTimeMillis
()
-
1000
));
waiting
.
setDuration
(
90
);
waiting
.
setScore
(
95
D
);
waiting
.
setScore
(
95
D
);
when
(
mapper
.
selectPage
(
query
,
"student-1"
)).
thenReturn
(
Collections
.
singletonList
(
waiting
));
when
(
mapper
.
selectPage
(
query
,
"student-1"
)).
thenReturn
(
Collections
.
singletonList
(
waiting
));
...
@@ -81,6 +82,40 @@ class StudentExamCenterServiceImplTest {
...
@@ -81,6 +82,40 @@ class StudentExamCenterServiceImplTest {
assertNull
(
rows
.
get
(
0
).
getScore
());
assertNull
(
rows
.
get
(
0
).
getScore
());
}
}
@Test
void
pageShouldMarkNeverStartedEndedExamAsAbsent
()
{
StudentExamCenterQueryDTO
query
=
new
StudentExamCenterQueryDTO
();
StudentExamCenterVO
.
ListItem
absent
=
new
StudentExamCenterVO
.
ListItem
();
absent
.
setType
(
ExamAdminConstants
.
TYPE_THEORY
);
absent
.
setExamTime
(
new
Date
(
System
.
currentTimeMillis
()
-
120_000
));
absent
.
setDuration
(
1
);
when
(
mapper
.
selectPage
(
query
,
"student-1"
)).
thenReturn
(
Collections
.
singletonList
(
absent
));
StudentExamCenterVO
.
ListItem
result
=
service
.
page
(
query
,
"student-1"
).
get
(
0
);
// 从未开考且统一考试时段已结束,应明确显示缺考,且不能再提供开始考试入口。
assertEquals
(
"ABSENT"
,
result
.
getWorkflowStatus
());
assertEquals
(
"WAIT"
,
result
.
getAction
());
}
@Test
void
pageShouldMarkStartedExpiredExamAsEnded
()
{
StudentExamCenterQueryDTO
query
=
new
StudentExamCenterQueryDTO
();
StudentExamCenterVO
.
ListItem
ended
=
new
StudentExamCenterVO
.
ListItem
();
ended
.
setType
(
ExamAdminConstants
.
TYPE_THEORY
);
ended
.
setExamTime
(
new
Date
(
System
.
currentTimeMillis
()
-
120_000
));
ended
.
setDuration
(
90
);
ended
.
setStartTime
(
System
.
currentTimeMillis
()
-
120_000
);
ended
.
setEndTime
(
System
.
currentTimeMillis
()
-
60_000
);
when
(
mapper
.
selectPage
(
query
,
"student-1"
)).
thenReturn
(
Collections
.
singletonList
(
ended
));
StudentExamCenterVO
.
ListItem
result
=
service
.
page
(
query
,
"student-1"
).
get
(
0
);
// 已开考记录使用个人倒计时结束点,超时未交卷显示已结束而不是仍允许恢复。
assertEquals
(
"ENDED"
,
result
.
getWorkflowStatus
());
assertEquals
(
"WAIT"
,
result
.
getAction
());
}
@Test
@Test
void
startShouldRejectRecordNotOwnedByCurrentStudent
()
{
void
startShouldRejectRecordNotOwnedByCurrentStudent
()
{
when
(
mapper
.
selectAttemptForUpdate
(
1
,
"student-1"
)).
thenReturn
(
null
);
when
(
mapper
.
selectAttemptForUpdate
(
1
,
"student-1"
)).
thenReturn
(
null
);
...
...
practical-business/src/test/java/com/platform/business/task/ExamFlagSyncTaskTest.java
View file @
9b9782a3
...
@@ -21,15 +21,15 @@ class ExamFlagSyncTaskTest {
...
@@ -21,15 +21,15 @@ class ExamFlagSyncTaskTest {
private
UserMapper
userMapper
;
private
UserMapper
userMapper
;
@Test
@Test
void
activateDueExam
sShouldPassCurrentTimeToBatchUpdate
()
{
void
syncExamFlag
sShouldPassCurrentTimeToBatchUpdate
()
{
ExamFlagSyncTask
task
=
new
ExamFlagSyncTask
();
ExamFlagSyncTask
task
=
new
ExamFlagSyncTask
();
ReflectionTestUtils
.
setField
(
task
,
"userMapper"
,
userMapper
);
ReflectionTestUtils
.
setField
(
task
,
"userMapper"
,
userMapper
);
long
before
=
System
.
currentTimeMillis
();
long
before
=
System
.
currentTimeMillis
();
task
.
activateDueExam
s
();
task
.
syncExamFlag
s
();
ArgumentCaptor
<
Date
>
now
=
ArgumentCaptor
.
forClass
(
Date
.
class
);
ArgumentCaptor
<
Date
>
now
=
ArgumentCaptor
.
forClass
(
Date
.
class
);
verify
(
userMapper
).
activateDueExam
s
(
now
.
capture
());
verify
(
userMapper
).
syncExamFlag
s
(
now
.
capture
());
// 调度任务必须使用本轮执行时刻,不能缓存应用启动时的旧时间。
// 调度任务必须使用本轮执行时刻,不能缓存应用启动时的旧时间。
assertTrue
(
now
.
getValue
().
getTime
()
>=
before
);
assertTrue
(
now
.
getValue
().
getTime
()
>=
before
);
assertTrue
(
now
.
getValue
().
getTime
()
<=
System
.
currentTimeMillis
());
assertTrue
(
now
.
getValue
().
getTime
()
<=
System
.
currentTimeMillis
());
...
...
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