"...sms/service/git@gitlab.ruzhoukj.com:wujipeng/ops.git" did not exist on "db3474419f493ed29dbbcdbd94e048eaa05c3b7f"
Commit 3940c44a authored by wujipeng's avatar wujipeng
Browse files

Merge remote-tracking branch 'origin/dev-v1.0' into dev-v1.0

parents 5ce67d0d 9c8e2241
...@@ -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;
/** 应出勤课次,包含请假。 */ /** 应出勤课次,包含请假。 */
......
...@@ -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;
......
...@@ -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 activateDueExams(@Param("now") Date now); int syncExamFlags(@Param("now") Date now);
} }
...@@ -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) {
// 已开考记录优先使用个人倒计时结束点;历史空值回退到统一考试计划结束点。
long actualEnd = row.getEndTime() == null ? scheduledEnd : row.getEndTime();
if (now >= actualEnd) {
row.setWorkflowStatus("ENDED");
row.setAction("WAIT");
} else {
row.setWorkflowStatus("IN_PROGRESS"); row.setWorkflowStatus("IN_PROGRESS");
row.setAction(isTheory(row.getType()) ? "RESUME" : "VIEW_INSTRUCTIONS"); 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) {
......
...@@ -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 activateDueExams() { public void syncExamFlags() {
userMapper.activateDueExams(new Date()); userMapper.syncExamFlags(new Date());
} }
} }
...@@ -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%`。
......
...@@ -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 &gt;= #{startDate}</if> <if test="startDate != null">and s.date &gt;= #{startDate}</if>
<if test="endDate != null">and s.date &lt;= #{endDate}</if> <if test="endDate != null">and s.date &lt;= #{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>
......
...@@ -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)
) &gt; 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)
) &lt;= CURRENT_TIMESTAMP
)
</if> </if>
ORDER BY e.exam_time DESC, e.id DESC ORDER BY e.exam_time DESC, e.id DESC
</select> </select>
......
...@@ -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,
user.exam_type as examType, selected_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 &lt;= current_timestamp
and coalesce(
from_unixtime(candidate.end_time / 1000),
timestampadd(
minute,
greatest(coalesce(exam_plan.duration, 0), 0),
exam_plan.exam_time
)
) &gt; 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="activateDueExams"> <update id="syncExamFlags">
<!-- <!--
到达计划开始时间后批量激活学员考试状态。结束时间采用[开始时间, 开始时间+时长) 同一条幂等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 &lt;= #{now} where exam_plan.exam_time &lt;= #{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
)
) &gt; #{now} ) &gt; #{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_type必须取自min(candidate.id)最终选中的同一条应考记录,不能直接在聚合子查询中 examType必须取自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) &lt;&gt; (active_exam.exam_student_id is not null)
or target_user.exam_oneself_id is null or not (target_user.exam_oneself_id &lt;=> active_exam.exam_student_id)
or target_user.exam_oneself_id &lt;&gt; active_exam.exam_student_id or not (target_user.exam_type &lt;=> selected_exam.type)
or coalesce(target_user.exam_type, '') &lt;&gt; coalesce(selected_exam.type, '')
</update> </update>
</mapper> </mapper>
...@@ -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`:正式成绩可见。
......
...@@ -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));
} }
......
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(
......
...@@ -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 queryByUserNameShouldReturnCurrentExamType() throws Exception { void queryByUserNameShouldDeriveCurrentExamStateAndType() 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 activateDueExamsShouldUseActiveHalfOpenTimeRange() throws Exception { void syncExamFlagsShouldActivateCurrentExamAndClearExpiredState() throws Exception {
Configuration configuration = parseMapper(); Configuration configuration = parseMapper();
BoundSql boundSql = configuration.getMappedStatement( BoundSql boundSql = configuration.getMappedStatement(
"com.platform.business.mapper.UserMapper.activateDueExams") "com.platform.business.mapper.UserMapper.syncExamFlags")
.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());
} }
......
...@@ -71,6 +71,7 @@ class StudentExamCenterServiceImplTest { ...@@ -71,6 +71,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(95D); waiting.setScore(95D);
when(mapper.selectPage(query, "student-1")).thenReturn(Collections.singletonList(waiting)); when(mapper.selectPage(query, "student-1")).thenReturn(Collections.singletonList(waiting));
...@@ -82,6 +83,40 @@ class StudentExamCenterServiceImplTest { ...@@ -82,6 +83,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);
......
...@@ -21,15 +21,15 @@ class ExamFlagSyncTaskTest { ...@@ -21,15 +21,15 @@ class ExamFlagSyncTaskTest {
private UserMapper userMapper; private UserMapper userMapper;
@Test @Test
void activateDueExamsShouldPassCurrentTimeToBatchUpdate() { void syncExamFlagsShouldPassCurrentTimeToBatchUpdate() {
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.activateDueExams(); task.syncExamFlags();
ArgumentCaptor<Date> now = ArgumentCaptor.forClass(Date.class); ArgumentCaptor<Date> now = ArgumentCaptor.forClass(Date.class);
verify(userMapper).activateDueExams(now.capture()); verify(userMapper).syncExamFlags(now.capture());
// 调度任务必须使用本轮执行时刻,不能缓存应用启动时的旧时间。 // 调度任务必须使用本轮执行时刻,不能缓存应用启动时的旧时间。
assertTrue(now.getValue().getTime() >= before); assertTrue(now.getValue().getTime() >= before);
assertTrue(now.getValue().getTime() <= System.currentTimeMillis()); assertTrue(now.getValue().getTime() <= System.currentTimeMillis());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment