Commit 2c66995a authored by 王蔡翾's avatar 王蔡翾
Browse files

bug修复

parent a8e84103
...@@ -652,11 +652,15 @@ public class TheoreticalPaperAdminServiceImpl implements TheoreticalPaperAdminSe ...@@ -652,11 +652,15 @@ public class TheoreticalPaperAdminServiceImpl implements TheoreticalPaperAdminSe
return TheoreticalPaperAdminConstants.SEQUENCE_ORDERED; return TheoreticalPaperAdminConstants.SEQUENCE_ORDERED;
} }
String normalized = sequence.trim(); String normalized = sequence.trim();
if (!TheoreticalPaperAdminConstants.SEQUENCE_ORDERED.equals(normalized) if (TheoreticalPaperAdminConstants.SEQUENCE_ORDERED.equals(normalized)
&& !TheoreticalPaperAdminConstants.SEQUENCE_RANDOM.equals(normalized)) { || TheoreticalPaperAdminConstants.LEGACY_SEQUENCE_RANDOM.equals(normalized)) {
throw new BusinessException("试题顺序只支持顺序或乱序"); /*
* “乱序”是旧版的答题阶段随机标记。当前业务只在自动组卷时随机抽题,试卷
* 形成后顺序固定,因此兼容旧请求但统一落库为“顺序”。
*/
return TheoreticalPaperAdminConstants.SEQUENCE_ORDERED;
} }
return normalized; throw new BusinessException("试卷生成后仅支持固定顺序");
} }
private String normalizeCreateStatus(String status) { private String normalizeCreateStatus(String status) {
......
...@@ -17,7 +17,7 @@ import java.util.List; ...@@ -17,7 +17,7 @@ import java.util.List;
@Service @Service
public class TheoreticalPaperDetailServiceImpl extends ServiceImpl<TheoreticalPaperDetailMapper, TheoreticalPaperDetailEntity> implements TheoreticalPaperDetailService { public class TheoreticalPaperDetailServiceImpl extends ServiceImpl<TheoreticalPaperDetailMapper, TheoreticalPaperDetailEntity> implements TheoreticalPaperDetailService {
@Override @Override
public List<TheoreticalPaperDetailEntity> selectDisorderly(String paperId) { public List<TheoreticalPaperDetailEntity> selectInPaperOrder(String paperId) {
return baseMapper.selectDisorderly(paperId); return baseMapper.selectInPaperOrder(paperId);
} }
} }
...@@ -38,10 +38,12 @@ server: ...@@ -38,10 +38,12 @@ server:
tomcat: tomcat:
max-http-form-post-size: 510MB max-http-form-post-size: 510MB
# 出勤签到配置。allowed-ip-cidrs 为空时签到会安全拒绝,部署前请补充实际网段。 # 出勤签到配置。allowed-ip-cidrs 为空时会安全拒绝签到,当前按教学网络实际范围配置。
attendance: attendance:
verification-code-valid-minutes: 15 verification-code-valid-minutes: 15
allowed-ip-cidrs: [] # 教学网络地址范围为192.168.10.0至192.168.10.255,对应CIDR前缀/24。
allowed-ip-cidrs:
- 192.168.10.0/24
# 只有网关已清洗 X-Forwarded-For / X-Real-IP 时才开启。 # 只有网关已清洗 X-Forwarded-For / X-Real-IP 时才开启。
trust-forwarded-headers: false trust-forwarded-headers: false
......
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
- 基础信息、计划/实际人数、培训自然日数和动态班级状态。 - 基础信息、计划/实际人数、培训自然日数和动态班级状态。
- 按课程名称、类型和授课教师聚合的课程列表,课时为全部排课课时之和。 - 按课程名称、类型和授课教师聚合的课程列表,课时为全部排课课时之和。
- 聚合课程在最后一节排课的具体结束时刻到达后立即更新为 `ENDED / 已完成`。
- 全班及个人出勤率;只有 `NORMAL/LATE` 计入出勤分子,`ABSENT/LEAVE` 计入分母。 - 全班及个人出勤率;只有 `NORMAL/LATE` 计入出勤分子,`ABSENT/LEAVE` 计入分母。
- 最近一场 `exam.mark_flag=true` 的考试,以及考生侧 `mark_flag=true` 的正式成绩。 - 最近一场 `exam.mark_flag=true` 的考试,以及考生侧 `mark_flag=true` 的正式成绩。
- 最近考试中 60 分及以上人数占有效成绩人数的比例;没有正式成绩时通过率返回 `null`。 - 最近考试中 60 分及以上人数占有效成绩人数的比例;没有正式成绩时通过率返回 `null`。
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
from user u from user u
inner join phone_role role_info on role_info.phone = u.phone_number inner join phone_role role_info on role_info.phone = u.phone_number
where role_info.role_name in ('学生', '学员') where role_info.role_name in ('学生', '学员')
and u.account_status = 'STUDYING' <!-- “学员总数”统计全部未删除学员;在读人数另由活跃模块按STUDYING口径统计。 -->
and coalesce(u.del_flag, 0) = 0) as studentCount, and coalesce(u.del_flag, 0) = 0) as studentCount,
(select count(distinct u.id) (select count(distinct u.id)
from user u from user u
......
...@@ -129,7 +129,10 @@ ...@@ -129,7 +129,10 @@
where c.id = #{classId} where c.id = #{classId}
</select> </select>
<!-- 同名、同类型且由同一教师授课的多次排课合并为详情页的一门逻辑课程。 --> <!--
同名、同类型且由同一教师授课的多次排课合并为详情页的一门逻辑课程。
聚合后仍按首次日期、首次上课时段和首条ID排序,与课程管理列表的规则保持一致。
-->
<select id="selectAdminCourses" resultType="com.platform.business.model.vo.ClassAdminCourseVO"> <select id="selectAdminCourses" resultType="com.platform.business.model.vo.ClassAdminCourseVO">
select select
subject.subject_name as subjectName, subject.subject_name as subjectName,
...@@ -138,12 +141,22 @@ ...@@ -138,12 +141,22 @@
subject.teacher_id as teacherId, subject.teacher_id as teacherId,
teacher.nick_name as teacherName, teacher.nick_name as teacherName,
min(subject.date) as firstDate, min(subject.date) as firstDate,
max(subject.date) as lastDate max(subject.date) as lastDate,
/*
time_frame最后一个“-”后的HH:mm就是该排课的最晚结束时刻;先拼接课程日期,
再在同一逻辑课程的全部排课中取最大值,使最后上课当天也能按具体时刻完成。
*/
str_to_date(max(concat(
date_format(subject.date, '%Y-%m-%d'), ' ',
trim(substring_index(
replace(replace(subject.time_frame, '—', '-'), '–', '-'), '-', -1
))
)), '%Y-%m-%d %H:%i') as lastEndTime
from class_subject subject from class_subject subject
left join user teacher on teacher.id = subject.teacher_id left join user teacher on teacher.id = subject.teacher_id
where subject.class_id = #{classId} where subject.class_id = #{classId}
group by subject.subject_name, subject.type, subject.teacher_id, teacher.nick_name group by subject.subject_name, subject.type, subject.teacher_id, teacher.nick_name
order by min(subject.date) asc, subject.subject_name asc, subject.teacher_id asc order by min(subject.date) asc, min(subject.time_frame) asc, min(subject.id) asc
</select> </select>
<!-- <!--
......
...@@ -195,7 +195,7 @@ ...@@ -195,7 +195,7 @@
</select> </select>
<!-- <!--
管理端班级看板的口径:NORMAL为正常签到;LATE、ABSENT、LEAVE均为异常。 管理端班级看板的口径:NORMAL和LATE都代表实际到课,ABSENT和LEAVE未实际到课。
班级人数和课程数独立于出勤记录统计,确保无记录的在班学员和已排课程不会被遗漏。 班级人数和课程数独立于出勤记录统计,确保无记录的在班学员和已排课程不会被遗漏。
--> -->
<select id="querySummary" resultType="com.platform.business.model.vo.AttendanceSummaryVO"> <select id="querySummary" resultType="com.platform.business.model.vo.AttendanceSummaryVO">
...@@ -220,7 +220,7 @@ ...@@ -220,7 +220,7 @@
sum(case when a.status = 'LEAVE' then 1 else 0 end) as leaveCount, sum(case when a.status = 'LEAVE' then 1 else 0 end) as leaveCount,
sum(case when a.status in ('LATE', 'ABSENT', 'LEAVE') then 1 else 0 end) as abnormalCount, sum(case when a.status in ('LATE', 'ABSENT', 'LEAVE') then 1 else 0 end) as abnormalCount,
case when count(a.id) = 0 then 0 case when count(a.id) = 0 then 0
else round(sum(case when a.status = 'NORMAL' then 1 else 0 end) * 100.0 / count(a.id), 2) else round(sum(case when a.status in ('NORMAL', 'LATE') then 1 else 0 end) * 100.0 / count(a.id), 2)
end as attendanceRate end 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
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</where> </where>
</select> </select>
<!-- 按学员汇总,使用与管理端总览相同的“正常签到/应到”出勤率口径。 --> <!-- 按学员汇总,使用与管理端总览相同的“实际出勤/应出勤”口径。 -->
<select id="queryStudentStatistics" resultType="com.platform.business.model.vo.AttendanceStudentStatisticsVO"> <select id="queryStudentStatistics" resultType="com.platform.business.model.vo.AttendanceStudentStatisticsVO">
select select
a.user_id as studentId, a.user_id as studentId,
...@@ -245,7 +245,7 @@ ...@@ -245,7 +245,7 @@
sum(case when a.status = 'LATE' then 1 else 0 end) as lateCount, sum(case when a.status = 'LATE' then 1 else 0 end) as lateCount,
sum(case when a.status = 'ABSENT' then 1 else 0 end) as absentCount, sum(case when a.status = 'ABSENT' then 1 else 0 end) as absentCount,
sum(case when a.status = 'LEAVE' then 1 else 0 end) as leaveCount, sum(case when a.status = 'LEAVE' then 1 else 0 end) as leaveCount,
round(sum(case when a.status = 'NORMAL' 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 user student on student.id = a.user_id left join user student on student.id = a.user_id
...@@ -278,7 +278,7 @@ ...@@ -278,7 +278,7 @@
sum(case when a.status = 'LATE' then 1 else 0 end) as lateCount, sum(case when a.status = 'LATE' then 1 else 0 end) as lateCount,
sum(case when a.status = 'ABSENT' then 1 else 0 end) as absentCount, sum(case when a.status = 'ABSENT' then 1 else 0 end) as absentCount,
sum(case when a.status = 'LEAVE' then 1 else 0 end) as leaveCount, sum(case when a.status = 'LEAVE' then 1 else 0 end) as leaveCount,
round(sum(case when a.status = 'NORMAL' 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 class c on c.id = s.class_id
......
...@@ -20,9 +20,18 @@ ...@@ -20,9 +20,18 @@
<!-- 列表和详情复用同一字段映射,避免两个接口的命名或时间字段不一致。 --> <!-- 列表和详情复用同一字段映射,避免两个接口的命名或时间字段不一致。 -->
<sql id="userMessageColumns"> <sql id="userMessageColumns">
m.id, m.event_id as eventId, m.message_type as messageType, m.title, m.summary, m.content, m.id, m.event_id as eventId, m.message_type as messageType,
case when current_evaluation.status = 'REVOKED' then '课程评价任务已撤回'
else m.title end as title,
case when current_evaluation.status = 'REVOKED' then '当前新增评价任务已被撤回'
else m.summary end as summary,
case when current_evaluation.status = 'REVOKED' then '当前新增评价任务已被撤回'
else m.content end as content,
m.sender_id as senderId, m.sender_name as senderName, m.business_type as businessType, m.sender_id as senderId, m.sender_name as senderName, m.business_type as businessType,
m.business_id as businessId, m.action_url as actionUrl, m.priority, m.business_id as businessId,
case when current_evaluation.status = 'REVOKED' then null
else m.action_url end as actionUrl,
m.priority,
r.read_flag as readFlag, r.read_at as readAt, m.created_at as createdAt, m.expires_at as expiresAt r.read_flag as readFlag, r.read_at as readAt, m.created_at as createdAt, m.expires_at as expiresAt
</sql> </sql>
...@@ -34,6 +43,12 @@ ...@@ -34,6 +43,12 @@
select <include refid="userMessageColumns"/> select <include refid="userMessageColumns"/>
from notification_message_recipient r from notification_message_recipient r
inner join notification_message m on m.id = r.message_id inner join notification_message m on m.id = r.message_id
<!--
评议通知展示任务当前状态:未撤回时保持原消息,撤回后原通知与撤回通知返回同一文案,
同时清空已失效的任务跳转地址,避免学员进入不存在的待评价页面。
-->
left join evaluation_task current_evaluation
on m.business_type = 'EVALUATION' and current_evaluation.id = m.business_id
where r.user_id = #{userId} where r.user_id = #{userId}
and r.deleted_flag = 0 and r.deleted_flag = 0
and (m.expires_at is null or m.expires_at &gt; now()) and (m.expires_at is null or m.expires_at &gt; now())
...@@ -52,6 +67,8 @@ ...@@ -52,6 +67,8 @@
select <include refid="userMessageColumns"/> select <include refid="userMessageColumns"/>
from notification_message_recipient r from notification_message_recipient r
inner join notification_message m on m.id = r.message_id inner join notification_message m on m.id = r.message_id
left join evaluation_task current_evaluation
on m.business_type = 'EVALUATION' and current_evaluation.id = m.business_id
where r.user_id = #{userId} and r.message_id = #{messageId} and r.deleted_flag = 0 where r.user_id = #{userId} and r.message_id = #{messageId} and r.deleted_flag = 0
and (m.expires_at is null or m.expires_at &gt; now()) and (m.expires_at is null or m.expires_at &gt; now())
limit 1 limit 1
......
...@@ -3,6 +3,21 @@ ...@@ -3,6 +3,21 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.platform.business.mapper.StudentExamCenterMapper"> <mapper namespace="com.platform.business.mapper.StudentExamCenterMapper">
<!--
历史个人试卷可能保留了分组前的原题号,因此答题页仍需按正式试卷相同的题型顺序
分组;服务层随后按返回位置生成连续展示题号,兼容已经开考的历史数据。
-->
<sql id="groupedPaperQuestionOrder">
ORDER BY CASE type
WHEN '判断题' THEN 1
WHEN '单选题' THEN 2
WHEN '多选题' THEN 3
WHEN '主观题' THEN 4
ELSE 5
END,
CAST(sequence AS UNSIGNED), sequence, id
</sql>
<!-- 考试中心可展示全部个人应考关系,但只有双重发布标记均成立时才返回分数。 --> <!-- 考试中心可展示全部个人应考关系,但只有双重发布标记均成立时才返回分数。 -->
<select id="selectPage" resultType="com.platform.business.model.vo.StudentExamCenterVO$ListItem"> <select id="selectPage" resultType="com.platform.business.model.vo.StudentExamCenterVO$ListItem">
SELECT SELECT
...@@ -121,7 +136,7 @@ ...@@ -121,7 +136,7 @@
WHERE exam_id = #{examId} WHERE exam_id = #{examId}
AND student_id = #{studentId} AND student_id = #{studentId}
AND COALESCE(is_problem, 1) = 1 AND COALESCE(is_problem, 1) = 1
ORDER BY CAST(sequence AS UNSIGNED), sequence, id <include refid="groupedPaperQuestionOrder"/>
</select> </select>
<select id="selectQuestionForUpdate" <select id="selectQuestionForUpdate"
......
...@@ -142,9 +142,17 @@ ...@@ -142,9 +142,17 @@
subject.time_frame as timeFrame, subject.time_frame as timeFrame,
subject.subject_name as subjectName, subject.subject_name as subjectName,
coalesce(nullif(teacher.nick_name, ''), teacher.username) as teacherName, coalesce(nullif(teacher.nick_name, ''), teacher.username) as teacherName,
subject.location subject.location,
attendance.status as attendanceStatus
from class_subject subject from class_subject subject
left join user teacher on teacher.id = subject.teacher_id left join user teacher on teacher.id = subject.teacher_id
<!--
首页课程状态必须按当前登录学员读取,不能只根据课程时间推断。
请假审批通过后出勤表会写入LEAVE,服务层据此优先展示“请假”。
-->
left join class_subject_attendance attendance
on attendance.subject_id = subject.id
and attendance.user_id = #{studentId}
where subject.class_id = #{classId} where subject.class_id = #{classId}
and subject.date &gt;= #{startDate} and subject.date &gt;= #{startDate}
and subject.date &lt; #{endDate} and subject.date &lt; #{endDate}
......
...@@ -4,7 +4,11 @@ ...@@ -4,7 +4,11 @@
<mapper namespace="com.platform.business.mapper.TheoreticalPaperDetailMapper"> <mapper namespace="com.platform.business.mapper.TheoreticalPaperDetailMapper">
<select id="selectDisorderly" resultType="com.platform.business.model.entity.TheoreticalPaperDetailEntity"> <!--
自动组卷已经在题库查询阶段随机抽题。这里读取的是已经形成的正式试卷,只按固定的
题型分组和数字题号排序,避免每名学员开考时再次RAND()而得到不同答题顺序。
-->
<select id="selectInPaperOrder" resultType="com.platform.business.model.entity.TheoreticalPaperDetailEntity">
SELECT id, SELECT id,
paper_id, paper_id,
scope, scope,
...@@ -31,8 +35,10 @@ ...@@ -31,8 +35,10 @@
WHEN '判断题' THEN 1 WHEN '判断题' THEN 1
WHEN '单选题' THEN 2 WHEN '单选题' THEN 2
WHEN '多选题' THEN 3 WHEN '多选题' THEN 3
ELSE 4 WHEN '主观题' THEN 4
END, RAND() ELSE 5
END,
CAST(sequence AS UNSIGNED), sequence, id
</select> </select>
</mapper> </mapper>
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
`GET /home/student/courses/next-three-days` `GET /home/student/courses/next-three-days`
固定返回今天、明天、后天三个分组,即使当天没有课程也会返回空 `courses`。课程状态为 `IN_PROGRESS`、`UPCOMING` 或 `PENDING`;距离首个时段开始不超过 60 分钟为 `UPCOMING`。 固定返回今天、明天、后天三个分组,即使当天没有课程也会返回空 `courses`。课程状态为 `LEAVE`、`IN_PROGRESS`、`UPCOMING` 或 `PENDING`;已审批请假优先返回 `LEAVE`,距离首个时段开始不超过 60 分钟为 `UPCOMING`。
## 3. 教师首页 ## 3. 教师首页
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
- `GET /{examStudentId}/instructions`:考试信息与考试须知;实训考试只提供说明。 - `GET /{examStudentId}/instructions`:考试信息与考试须知;实训考试只提供说明。
- `POST /{examStudentId}/start`:开始或恢复理论考试,重复调用返回同一应考记录ID。 - `POST /{examStudentId}/start`:开始或恢复理论考试,重复调用返回同一应考记录ID。
- `GET /attempts/{examStudentId}/paper`:返回个人试卷和已保存答案,不返回正确答案。 - `GET /attempts/{examStudentId}/paper`:返回个人试卷和已保存答案,不返回正确答案。
题目沿用正式试卷的题型分组,组内顺序固定,并返回从1开始的连续题号;随机抽题只发生在
自动组卷阶段,学员开考时不会再次打乱。
- `PUT /attempts/{examStudentId}/questions/{questionId}/answer`:请求体 `{ "actualChoice": "A" }`; - `PUT /attempts/{examStudentId}/questions/{questionId}/answer`:请求体 `{ "actualChoice": "A" }`;
传 `null` 或空白表示清空本题答案。 传 `null` 或空白表示清空本题答案。
- `GET /attempts/{examStudentId}/submit-check`:返回已答/未答数量和禁交状态。 - `GET /attempts/{examStudentId}/submit-check`:返回已答/未答数量和禁交状态。
......
...@@ -109,7 +109,7 @@ practical-business/src/main/resources/sql/theoretical_paper_management.sql ...@@ -109,7 +109,7 @@ practical-business/src/main/resources/sql/theoretical_paper_management.sql
## 6. 旧页面兼容路径 ## 6. 旧页面兼容路径
- `GET /theoretical/paper/auto` 等同规则预览接口。 - `GET /theoretical/paper/auto` 返回相同的公共规则配置,并保留给已登录学员的模拟考场兼容调用;教师端优先使用 `/auto-configuration`。
- `POST /theoretical/paper/create` 接收旧 `CombinationDTO`,但忽略客户端 `num`、`sum`、 - `POST /theoretical/paper/create` 接收旧 `CombinationDTO`,但忽略客户端 `num`、`sum`、
`createUser`、抽题分布和配分规则,服务端重新读取数据库规则;为保持历史行为固定创建 `createUser`、抽题分布和配分规则,服务端重新读取数据库规则;为保持历史行为固定创建
`PUBLISHED` 试卷,并继续返回布尔型 `data`。 `PUBLISHED` 试卷,并继续返回布尔型 `data`。
......
...@@ -32,7 +32,7 @@ import static org.mockito.Mockito.times; ...@@ -32,7 +32,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
/** 教师理论试卷控制器的角色鉴权、可信身份、兼容转换和分页边界测试。 */ /** 理论试卷控制器的角色鉴权、学员只读兼容、可信身份和分页边界测试。 */
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
class TheoreticalPaperControllerTest { class TheoreticalPaperControllerTest {
...@@ -92,6 +92,20 @@ class TheoreticalPaperControllerTest { ...@@ -92,6 +92,20 @@ class TheoreticalPaperControllerTest {
verify(legacyPaperService).exportWithAnswer("paper-1", response); verify(legacyPaperService).exportWithAnswer("paper-1", response);
} }
@Test
void legacyAutoConfigurationShouldAllowAuthenticatedStudentReadOnlyAccess() {
MockHttpServletRequest request = new MockHttpServletRequest();
UserEntity student = new UserEntity();
student.setId("student-1");
when(authenticatedUserService.current(request)).thenReturn(student);
controller.legacyAutoConfiguration("污水一级", request);
// 模拟考场只读取公共规则,不应触发教师角色校验或教师试卷写服务。
verify(legacyPaperService).auto("污水一级");
verify(authenticatedUserService, org.mockito.Mockito.never()).requireTeacher(student);
}
@Test @Test
void legacyCreateShouldIgnoreClientCalculatedAndIdentityFields() { void legacyCreateShouldIgnoreClientCalculatedAndIdentityFields() {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
......
...@@ -13,11 +13,11 @@ import java.util.Date; ...@@ -13,11 +13,11 @@ import java.util.Date;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
/** 管理端出勤看板SQL口径的解析测试,防止迟到再次被误计为正常签到。 */ /** 管理端出勤看板SQL口径的解析测试,防止迟到签到再次漏出实际出勤分子。 */
class AttendanceStatisticsMapperXmlTest { class AttendanceStatisticsMapperXmlTest {
@Test @Test
void summaryShouldExposeDashboardCountsAndUseNormalOnlyForAttendanceRate() throws Exception { void statisticsShouldUseActualAttendanceForAttendanceRate() throws Exception {
Configuration configuration = new Configuration(); Configuration configuration = new Configuration();
parse(configuration, "com/platform/business/mapper/ClassSubjectAttendanceMapper.xml"); parse(configuration, "com/platform/business/mapper/ClassSubjectAttendanceMapper.xml");
...@@ -25,19 +25,31 @@ class AttendanceStatisticsMapperXmlTest { ...@@ -25,19 +25,31 @@ class AttendanceStatisticsMapperXmlTest {
query.setClassId(12); query.setClassId(12);
query.setStartDate(date(2026, Calendar.AUGUST, 1)); query.setStartDate(date(2026, Calendar.AUGUST, 1));
query.setEndDate(date(2026, Calendar.AUGUST, 31)); query.setEndDate(date(2026, Calendar.AUGUST, 31));
String summarySql = statementSql(configuration, "querySummary", query);
// 班级人数来自成员关系、课程数来自排课,二者不依赖是否已经生成出勤记录。
assertTrue(summarySql.contains("select count(*) from class_student member where member.class_id = ?"));
assertTrue(summarySql.contains("from class_subject scoped_subject"));
assertTrue(summarySql.contains("as studentCount"));
assertTrue(summarySql.contains("as courseCount"));
// 迟到仍保留在异常人次展示中,但出勤率必须按NORMAL+LATE实际到课人次计算。
assertTrue(summarySql.contains("a.status in ('LATE', 'ABSENT', 'LEAVE') then 1 else 0 end) as abnormalCount"));
assertActualAttendanceRate(summarySql);
assertActualAttendanceRate(statementSql(configuration, "queryStudentStatistics", query));
assertActualAttendanceRate(statementSql(configuration, "queryCourseStatistics", query));
}
private static String statementSql(Configuration configuration, String statement,
AttendanceQueryDTO query) {
BoundSql boundSql = configuration.getMappedStatement( BoundSql boundSql = configuration.getMappedStatement(
"com.platform.business.mapper.ClassSubjectAttendanceMapper.querySummary") "com.platform.business.mapper.ClassSubjectAttendanceMapper." + statement)
.getBoundSql(query); .getBoundSql(query);
String sql = compact(boundSql.getSql()); return compact(boundSql.getSql());
}
// 班级人数来自成员关系、课程数来自排课,二者不依赖是否已经生成出勤记录。 /** 三个统计维度必须共享同一实际出勤口径,避免总览与明细显示不同百分比。 */
assertTrue(sql.contains("select count(*) from class_student member where member.class_id = ?")); private static void assertActualAttendanceRate(String sql) {
assertTrue(sql.contains("from class_subject scoped_subject")); assertTrue(sql.contains("sum(case when a.status in ('NORMAL', 'LATE') then 1 else 0 end) * 100.0 / count(a.id)"));
assertTrue(sql.contains("as studentCount"));
assertTrue(sql.contains("as courseCount"));
// 图片口径:仅NORMAL进入出勤率分子,其他三个状态组成异常人次。
assertTrue(sql.contains("a.status in ('LATE', 'ABSENT', 'LEAVE') then 1 else 0 end) as abnormalCount"));
assertTrue(sql.contains("sum(case when a.status = 'NORMAL' then 1 else 0 end) * 100.0 / count(a.id)"));
} }
private static void parse(Configuration configuration, String resource) throws Exception { private static void parse(Configuration configuration, String resource) throws Exception {
......
...@@ -18,12 +18,7 @@ class ClassMapperXmlTest { ...@@ -18,12 +18,7 @@ class ClassMapperXmlTest {
@Test @Test
void adminClassQueryShouldUseTheOrderingRequestedByItsCaller() throws Exception { void adminClassQueryShouldUseTheOrderingRequestedByItsCaller() throws Exception {
String resource = "com/platform/business/mapper/ClassMapper.xml"; Configuration configuration = parseMapper();
Configuration configuration = new Configuration();
try (InputStream input = Resources.getResourceAsStream(resource)) {
new XMLMapperBuilder(input, configuration, resource,
configuration.getSqlFragments()).parse();
}
// 模拟卡片分页调用,验证排序发生在数据库分页之前,并以ID作为稳定的第二排序键。 // 模拟卡片分页调用,验证排序发生在数据库分页之前,并以ID作为稳定的第二排序键。
String cardSql = compactSql(adminClassSql(configuration, true)); String cardSql = compactSql(adminClassSql(configuration, true));
...@@ -37,6 +32,31 @@ class ClassMapperXmlTest { ...@@ -37,6 +32,31 @@ class ClassMapperXmlTest {
assertFalse(treeSql.contains("order by c.create_time desc")); assertFalse(treeSql.contains("order by c.create_time desc"));
} }
@Test
void adminClassCoursesShouldMatchCourseManagementOrdering() throws Exception {
Configuration configuration = parseMapper();
Map<String, Object> parameters = new HashMap<>();
parameters.put("classId", 1);
String sql = compactSql(configuration.getMappedStatement(
"com.platform.business.mapper.ClassMapper.selectAdminCourses")
.getBoundSql(parameters).getSql());
// 详情列表经过课程聚合,因此分别取每组最早值来对应课程管理的日期、时段、ID顺序。
assertTrue(sql.contains(
"order by min(subject.date) asc, min(subject.time_frame) asc, min(subject.id) asc"));
}
private static Configuration parseMapper() throws Exception {
String resource = "com/platform/business/mapper/ClassMapper.xml";
Configuration configuration = new Configuration();
try (InputStream input = Resources.getResourceAsStream(resource)) {
new XMLMapperBuilder(input, configuration, resource,
configuration.getSqlFragments()).parse();
}
return configuration;
}
private static String adminClassSql(Configuration configuration, private static String adminClassSql(Configuration configuration,
boolean orderByCreateTime) { boolean orderByCreateTime) {
Map<String, Object> parameters = new HashMap<>(); Map<String, Object> parameters = new HashMap<>();
......
...@@ -6,6 +6,7 @@ import org.apache.ibatis.session.Configuration; ...@@ -6,6 +6,7 @@ import org.apache.ibatis.session.Configuration;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashMap;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
...@@ -32,6 +33,14 @@ class HomeMapperXmlTest { ...@@ -32,6 +33,14 @@ class HomeMapperXmlTest {
"com.platform.business.mapper.AdminHomeMapper.selectTodos") "com.platform.business.mapper.AdminHomeMapper.selectTodos")
.getBoundSql(null).getSql().toUpperCase(); .getBoundSql(null).getSql().toUpperCase();
assertFalse(adminTodoSql.contains("EXAM_REVIEW")); assertFalse(adminTodoSql.contains("EXAM_REVIEW"));
String statisticsSql = configuration.getMappedStatement(
"com.platform.business.mapper.AdminHomeMapper.selectStatistics")
.getBoundSql(new HashMap<String, Object>()).getSql()
.replaceAll("\\s+", " ").toLowerCase();
// 顶部“学员总数”必须覆盖待激活、在读和已结业等全部未删除学员,不能只统计在读状态。
assertTrue(statisticsSql.contains("role_info.role_name in ('学生', '学员')"));
assertFalse(statisticsSql.contains("u.account_status = 'studying'"));
} }
private static void parse(Configuration configuration, String resource) throws Exception { private static void parse(Configuration configuration, String resource) throws Exception {
......
package com.platform.business.mapper;
import com.platform.business.model.dto.NotificationMessageQueryDTO;
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.Configuration;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** 验证评议撤回后,消息列表和详情都会读取任务的当前状态。 */
class NotificationMessageMapperXmlTest {
@Test
void evaluationMessagesShouldDisplayRevokedStateAndDisableStaleAction() throws Exception {
String resource = "com/platform/business/mapper/NotificationMessageMapper.xml";
Configuration configuration = new Configuration();
try (InputStream input = Resources.getResourceAsStream(resource)) {
new XMLMapperBuilder(input, configuration, resource,
configuration.getSqlFragments()).parse();
}
NotificationMessageQueryDTO query = new NotificationMessageQueryDTO();
query.setUserId("S1");
query.setReadStatus("ALL");
Map<String, Object> detailParameters = new HashMap<>();
detailParameters.put("userId", "S1");
detailParameters.put("messageId", "M1");
String namespace = "com.platform.business.mapper.NotificationMessageMapper.";
// 两个接口必须展开同一状态覆盖逻辑,确保历史发布通知和新增撤回通知展示一致。
for (String sql : new String[]{
configuration.getMappedStatement(namespace + "queryUserMessages")
.getBoundSql(query).getSql(),
configuration.getMappedStatement(namespace + "selectUserMessage")
.getBoundSql(detailParameters).getSql()}) {
String normalized = sql.replaceAll("\\s+", " ").toLowerCase();
assertTrue(normalized.contains("left join evaluation_task current_evaluation"));
assertTrue(normalized.contains("current_evaluation.status = 'revoked'"));
assertTrue(normalized.contains("当前新增评价任务已被撤回"));
assertTrue(normalized.contains("then null else m.action_url end as actionurl"));
}
}
}
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