Commit cdbda0fd authored by wujipeng's avatar wujipeng
Browse files

临时接收仿真数据

parent ee1e563c
......@@ -47,7 +47,8 @@ public interface ExamReviewMapper {
@Param("studentId") String studentId);
List<ExamReviewPracticeItemVO> queryPracticeItems(@Param("examId") Integer examId,
@Param("studentId") String studentId);
@Param("studentId") String studentId,
@Param("useTemporaryTable") boolean useTemporaryTable);
List<TheoreticalPaperStudentDetailEntity> lockQuestions(
@Param("questionIds") List<String> questionIds,
......@@ -61,10 +62,12 @@ public interface ExamReviewMapper {
List<FzGradesEntity> lockPracticeItems(@Param("questionIds") List<String> questionIds,
@Param("examId") Integer examId,
@Param("studentId") String studentId);
@Param("studentId") String studentId,
@Param("useTemporaryTable") boolean useTemporaryTable);
int updatePracticeScore(@Param("questionId") String questionId,
@Param("score") Double score);
@Param("score") Double score,
@Param("useTemporaryTable") boolean useTemporaryTable);
/** 教师暂存后同步待复核总分,正式可见性仍由mark_flag控制。 */
int updatePendingPracticeTotal(@Param("examStudentId") Integer examStudentId,
......@@ -74,7 +77,9 @@ public interface ExamReviewMapper {
int countSubmittedWithoutPaper(@Param("examId") Integer examId);
int countSubmittedWithoutPracticeItems(@Param("examId") Integer examId);
int countSubmittedWithoutPracticeItems(
@Param("examId") Integer examId,
@Param("tempStudentIds") List<String> tempStudentIds);
int countUnscoredSubjective(@Param("examId") Integer examId);
......@@ -82,12 +87,15 @@ public interface ExamReviewMapper {
@Param("studentId") String studentId);
Double calculatePracticeScore(@Param("examId") Integer examId,
@Param("studentId") String studentId);
@Param("studentId") String studentId,
@Param("useTemporaryTable") boolean useTemporaryTable);
int publishStudent(@Param("examStudentId") Integer examStudentId,
@Param("score") Double score);
int publishTask(@Param("examId") Integer examId);
List<ExamReviewRecordVO> queryHistory(@Param("examStudentId") Integer examStudentId);
List<ExamReviewRecordVO> queryHistory(
@Param("examStudentId") Integer examStudentId,
@Param("tempStudentIds") List<String> tempStudentIds);
}
......@@ -27,10 +27,17 @@ public interface FzGradesMapper extends BaseMapper<FzGradesEntity> {
/** 查询每个题号的最新记录;候选行锁已提供主要并发保护。 */
List<FzGradesEntity> selectLatestItems(@Param("examId") Integer examId,
@Param("studentId") String studentId);
@Param("studentId") String studentId,
@Param("useTemporaryTable") boolean useTemporaryTable);
Double sumLatestScores(@Param("examId") Integer examId,
@Param("studentId") String studentId);
@Param("studentId") String studentId,
@Param("useTemporaryTable") boolean useTemporaryTable);
/**
* 将命中路由配置的学员成绩写入临时表。字段清单显式维护,避免外部输入控制表名或主键。
*/
int insertTemporary(FzGradesEntity entity);
/** 首次完整上报只形成待复核成绩,不设置个人或考试发布标记。 */
int submitPracticeStudent(@Param("examStudentId") Integer examStudentId,
......
......@@ -24,7 +24,8 @@ public interface ScoreAdminMapper {
ScoreAdminExamVO findExam(@Param("examId") Integer examId);
List<ScoreAdminStudentVO> queryStudents(@Param("examId") Integer examId,
@Param("query") ScoreAdminStudentQueryDTO query);
@Param("query") ScoreAdminStudentQueryDTO query,
@Param("tempStudentIds") List<String> tempStudentIds);
ScoreAdminStudentDetailVO findStudent(@Param("examStudentId") Integer examStudentId);
......@@ -32,11 +33,14 @@ public interface ScoreAdminMapper {
@Param("studentId") String studentId);
List<FzGradesEntity> queryPracticeItems(@Param("examId") Integer examId,
@Param("studentId") String studentId);
@Param("studentId") String studentId,
@Param("useTemporaryTable") boolean useTemporaryTable);
List<ScoreAdminQuestionStatisticsVO> queryTheoryStatistics(@Param("examId") Integer examId);
List<ScoreAdminQuestionStatisticsVO> queryPracticeStatistics(@Param("examId") Integer examId);
List<ScoreAdminQuestionStatisticsVO> queryPracticeStatistics(
@Param("examId") Integer examId,
@Param("tempStudentIds") List<String> tempStudentIds);
List<ScoreAdminStudentVO> queryPublishedStudents(@Param("examId") Integer examId);
......@@ -54,5 +58,6 @@ public interface ScoreAdminMapper {
/** 查询实训考试各学员每个项目的最新正式成绩。 */
List<ScoreAdminExportPracticeItemVO> queryExportPracticeItems(
@Param("examId") Integer examId);
@Param("examId") Integer examId,
@Param("tempStudentIds") List<String> tempStudentIds);
}
......@@ -40,5 +40,6 @@ public interface StudentScoreMapper {
List<StudentScoreVO.PracticeItem> selectPracticeItems(
@Param("examId") Integer examId,
@Param("studentId") String studentId);
@Param("studentId") String studentId,
@Param("useTemporaryTable") boolean useTemporaryTable);
}
package com.platform.business.service.impl;
import com.platform.business.constant.AccountAdminConstants;
import com.platform.business.config.FzGradesRoutingProperties;
import com.platform.business.constant.ExamAdminConstants;
import com.platform.business.constant.ExamReviewConstants;
import com.platform.business.mapper.ExamReviewMapper;
......@@ -53,6 +54,10 @@ public class ExamReviewServiceImpl implements ExamReviewService {
@Resource
private ExamReviewMapper examReviewMapper;
/** 教师查询、评分和整场发布都按成绩所属学员使用同一表路由。 */
@Resource
private FzGradesRoutingProperties routingProperties = new FzGradesRoutingProperties();
@Resource
private ExamReviewScoreLogMapper scoreLogMapper;
......@@ -89,7 +94,8 @@ public class ExamReviewServiceImpl implements ExamReviewService {
ExamReviewTaskVO task = requireTask(student.getExamId(), teacherId);
if (isPractice(task.getExamType())) {
List<ExamReviewPracticeItemVO> items = examReviewMapper.queryPracticeItems(
student.getExamId(), student.getStudentId());
student.getExamId(), student.getStudentId(),
routingProperties.useTemporaryTable(student.getStudentId()));
if (items == null || items.isEmpty()) {
throw new BusinessException("该考生尚未生成可复核的实训成绩明细");
}
......@@ -209,7 +215,8 @@ public class ExamReviewServiceImpl implements ExamReviewService {
// 任务列表同样以考生 mark_flag 聚合,因此不会发生列表显示待阅卷却无法进入发布的问题。
boolean practiceExam = isPractice(exam.getType());
if (practiceExam) {
if (examReviewMapper.countSubmittedWithoutPracticeItems(examId) > 0) {
if (examReviewMapper.countSubmittedWithoutPracticeItems(
examId, routingProperties.normalizedTemporaryStudentIds()) > 0) {
throw new BusinessException("存在缺少实训明细的已交考生,暂不能发布");
}
} else {
......@@ -225,7 +232,8 @@ public class ExamReviewServiceImpl implements ExamReviewService {
Date now = new Date();
for (ExamStudentEntity student : pendingStudents) {
Double finalScore = practiceExam
? examReviewMapper.calculatePracticeScore(examId, student.getStudentId())
? examReviewMapper.calculatePracticeScore(examId, student.getStudentId(),
routingProperties.useTemporaryTable(student.getStudentId()))
: examReviewMapper.calculateStudentScore(examId, student.getStudentId());
if (finalScore == null) {
finalScore = 0D;
......@@ -270,7 +278,8 @@ public class ExamReviewServiceImpl implements ExamReviewService {
public List<ExamReviewRecordVO> history(Integer examStudentId, String teacherId) {
// 先做带教师ID的关联校验,避免仅凭考生考试记录ID读取其他教师的评分历史。
requireStudent(examStudentId, teacherId);
return examReviewMapper.queryHistory(examStudentId);
return examReviewMapper.queryHistory(
examStudentId, routingProperties.normalizedTemporaryStudentIds());
}
private ExamReviewPaperVO assemblePaper(ExamReviewTaskVO task, ExamReviewStudentVO student,
......@@ -361,13 +370,15 @@ public class ExamReviewServiceImpl implements ExamReviewService {
}
List<FzGradesEntity> lockedItems = examReviewMapper.lockPracticeItems(
itemIds, student.getExamId(), student.getStudentId());
itemIds, student.getExamId(), student.getStudentId(),
routingProperties.useTemporaryTable(student.getStudentId()));
if (lockedItems == null || lockedItems.size() != itemIds.size()) {
throw new BusinessException("实训明细不属于当前考生,或明细不存在");
}
BigDecimal projectedTotal = toBigDecimal(examReviewMapper.calculatePracticeScore(
student.getExamId(), student.getStudentId()));
student.getExamId(), student.getStudentId(),
routingProperties.useTemporaryTable(student.getStudentId())));
projectedTotal = projectedTotal == null ? BigDecimal.ZERO : projectedTotal;
for (FzGradesEntity locked : lockedItems) {
ExamReviewScoreItemDTO requested = requestById.get(locked.getId());
......@@ -388,7 +399,8 @@ public class ExamReviewServiceImpl implements ExamReviewService {
ExamReviewScoreItemDTO requested = requestById.get(locked.getId());
BigDecimal previous = toBigDecimal(locked.getScore());
if (examReviewMapper.updatePracticeScore(
locked.getId(), requested.getScore().doubleValue()) != 1) {
locked.getId(), requested.getScore().doubleValue(),
routingProperties.useTemporaryTable(student.getStudentId())) != 1) {
throw new BusinessException("实训项目评分保存失败,请刷新后重试");
}
String comment = trimToNull(requested.getComment());
......
......@@ -3,6 +3,8 @@ package com.platform.business.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.platform.business.config.FzGradesRoutingProperties;
import com.platform.business.constant.ExamAdminConstants;
import com.platform.business.mapper.FzGradesMapper;
import com.platform.business.model.dto.FzGradesDTO;
......@@ -30,11 +32,18 @@ public class FzGradesServiceImpl extends ServiceImpl<FzGradesMapper, FzGradesEnt
private static final int MAX_ITEM_COUNT = 2000;
/**
* 默认实例保证脱离Spring容器的单元测试仍保持原正式表行为;应用启动后由Spring注入配置Bean。
*/
@javax.annotation.Resource
private FzGradesRoutingProperties routingProperties = new FzGradesRoutingProperties();
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean receive(List<FzGradesDTO> fzGradesList) {
List<FzGradesEntity> incoming = normalizeAndValidateBatch(fzGradesList);
FzGradesEntity first = incoming.get(0);
boolean useTemporaryTable = routingProperties.useTemporaryTable(first.getUserId());
/*
* 锁顺序固定为exam -> exam_student,与教师发布事务保持一致。这样接收请求与发布请求
......@@ -71,7 +80,7 @@ public class FzGradesServiceImpl extends ServiceImpl<FzGradesMapper, FzGradesEnt
}
List<FzGradesEntity> persisted = baseMapper.selectLatestItems(
first.getExamId(), first.getUserId());
first.getExamId(), first.getUserId(), useTemporaryTable);
if (persisted != null && !persisted.isEmpty()) {
// 首次有效上报后数据源即锁定;仅允许完全相同且顺序无关的网络重试幂等成功。
if (sameSnapshot(incoming, persisted)) {
......@@ -83,7 +92,15 @@ public class FzGradesServiceImpl extends ServiceImpl<FzGradesMapper, FzGradesEnt
for (FzGradesEntity entity : incoming) {
// 外部系统不得控制本系统雪花主键,避免恶意覆盖或跨业务主键碰撞。
entity.setId(null);
if (baseMapper.insert(entity) != 1) {
int inserted;
if (useTemporaryTable) {
// 自定义临时表SQL不会经过MyBatis-Plus主键自动填充,因此在应用侧生成同规格雪花ID。
entity.setId(IdWorker.getIdStr());
inserted = baseMapper.insertTemporary(entity);
} else {
inserted = baseMapper.insert(entity);
}
if (inserted != 1) {
throw new BusinessException("仿真实训成绩保存失败,请稍后重试");
}
}
......
package com.platform.business.service.impl;
import com.platform.business.constant.ExamAdminConstants;
import com.platform.business.config.FzGradesRoutingProperties;
import com.platform.business.mapper.ScoreAdminMapper;
import com.platform.business.model.dto.ScoreAdminExamQueryDTO;
import com.platform.business.model.dto.ScoreAdminStudentQueryDTO;
......@@ -93,6 +94,10 @@ public class ScoreAdminServiceImpl implements ScoreAdminService {
@Resource
private ScoreAdminMapper scoreAdminMapper;
/** 管理端详情和跨学员统计均使用同一份受控路由配置。 */
@Resource
private FzGradesRoutingProperties routingProperties = new FzGradesRoutingProperties();
@Resource
private ExamAdminService examAdminService;
......@@ -134,7 +139,8 @@ public class ScoreAdminServiceImpl implements ScoreAdminService {
// 先确认考试存在;未结束场次允许查看应考名单和交卷进度,但SQL不会返回未发布分数。
requireExam(examId);
normalizeStudentQuery(query);
List<ScoreAdminStudentVO> result = scoreAdminMapper.queryStudents(examId, query);
List<ScoreAdminStudentVO> result = scoreAdminMapper.queryStudents(
examId, query, routingProperties.normalizedTemporaryStudentIds());
if (result == null || result.isEmpty()) {
return Collections.emptyList();
}
......@@ -162,7 +168,8 @@ public class ScoreAdminServiceImpl implements ScoreAdminService {
if (isPractice(detail.getExamType())) {
List<com.platform.business.model.entity.FzGradesEntity> items =
scoreAdminMapper.queryPracticeItems(detail.getExamId(), detail.getStudentId());
scoreAdminMapper.queryPracticeItems(detail.getExamId(), detail.getStudentId(),
routingProperties.useTemporaryTable(detail.getStudentId()));
items = items == null ? Collections.emptyList() : items;
if (items.isEmpty()) {
throw new BusinessException("该学员实训试卷明细不存在,请检查成绩上报数据");
......@@ -300,7 +307,8 @@ public class ScoreAdminServiceImpl implements ScoreAdminService {
}
boolean practiceExam = isPractice(exam.getExamType());
List<ScoreAdminQuestionStatisticsVO> result = practiceExam
? scoreAdminMapper.queryPracticeStatistics(examId)
? scoreAdminMapper.queryPracticeStatistics(
examId, routingProperties.normalizedTemporaryStudentIds())
: scoreAdminMapper.queryTheoryStatistics(examId);
if (result == null || result.isEmpty()) {
return Collections.emptyList();
......@@ -352,7 +360,8 @@ public class ScoreAdminServiceImpl implements ScoreAdminService {
List<ScoreAdminExportPracticeItemVO> practiceItems = practiceExam == null
? Collections.emptyList()
: safeList(scoreAdminMapper.queryExportPracticeItems(practiceExam.getExamId()));
: safeList(scoreAdminMapper.queryExportPracticeItems(practiceExam.getExamId(),
routingProperties.normalizedTemporaryStudentIds()));
PracticeExportData practiceData = buildPracticeExportData(practiceItems);
try (HSSFWorkbook workbook = loadExportTemplate()) {
......
package com.platform.business.service.impl;
import com.platform.business.constant.ExamAdminConstants;
import com.platform.business.config.FzGradesRoutingProperties;
import com.platform.business.mapper.StudentScoreMapper;
import com.platform.business.model.dto.StudentScoreQueryDTO;
import com.platform.business.model.vo.StudentScoreVO;
......@@ -39,6 +40,10 @@ public class StudentScoreServiceImpl implements StudentScoreService {
@Resource
private StudentScoreMapper studentScoreMapper;
/** 按成绩所属学员选择正式表或临时表,确保本人详情与管理端使用同一数据源。 */
@Resource
private FzGradesRoutingProperties routingProperties = new FzGradesRoutingProperties();
@Override
public StudentScoreVO.Overview overview(String studentId) {
StudentScoreVO.Overview result = studentScoreMapper.selectOverview(studentId);
......@@ -176,7 +181,7 @@ public class StudentScoreServiceImpl implements StudentScoreService {
private void fillPracticeDetail(StudentScoreVO.Detail detail, String studentId) {
List<StudentScoreVO.PracticeItem> items = studentScoreMapper.selectPracticeItems(
detail.getExamId(), studentId);
detail.getExamId(), studentId, routingProperties.useTemporaryTable(studentId));
items = items == null ? new ArrayList<>() : items;
int passed = 0;
int partial = 0;
......
......@@ -18,6 +18,11 @@ attendance:
# 只有网关已清洗 X-Forwarded-For / X-Real-IP 时才开启。
trust-forwarded-headers: false
# 仿真实训成绩临时表路由。默认不配置任何学员,部署时填写系统学员ID即可。
simulation:
grade-routing:
temporary-student-ids: []
# 消息中心以 1000 人同时在线为基线;node-id 不配置时会按应用名、主机名和随机后缀生成。
notification:
# 多实例不可配置相同node-id,否则会争用同一个exclusive推送队列。
......
......@@ -3,6 +3,35 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.platform.business.mapper.ExamReviewMapper">
<!-- 单学员阅卷读写使用受控布尔值选择物理表,防止任意动态表名注入。 -->
<sql id="selectedGradeTable">
<choose>
<when test="useTemporaryTable">fz_grades_temp</when>
<otherwise>fz_grades</otherwise>
</choose>
</sql>
<!-- 发布校验和审计历史可能同时涉及多个学员,因此在SQL内合并两张表的有效路由行。 -->
<sql id="routedGradeRows">
(
SELECT formal_grade.*
FROM fz_grades formal_grade
<if test="tempStudentIds != null and !tempStudentIds.isEmpty()">
WHERE formal_grade.user_id NOT IN
<foreach collection="tempStudentIds" item="studentId" open="(" separator="," close=")">
#{studentId}
</foreach>
UNION ALL
SELECT temporary_grade.*
FROM fz_grades_temp temporary_grade
WHERE temporary_grade.user_id IN
<foreach collection="tempStudentIds" item="studentId" open="(" separator="," close=")">
#{studentId}
</foreach>
</if>
)
</sql>
<!-- 新关系表是事实来源,旧chief_id精确匹配仅用于尚未迁移的历史考试。 -->
<sql id="chiefPermission">
(exists (
......@@ -240,10 +269,10 @@
g.text, g.result, g.file, g.file_format AS fileFormat,
g.basic_score AS basicScore, g.score,
g.start_time AS startTime, g.submission_time AS submissionTime
FROM fz_grades g
FROM <include refid="selectedGradeTable"/> g
INNER JOIN (
SELECT MAX(id) AS id
FROM fz_grades
FROM <include refid="selectedGradeTable"/>
WHERE exam_id = #{examId} AND user_id = #{studentId}
GROUP BY code
) latest ON latest.id = g.id
......@@ -276,7 +305,7 @@
<!-- 锁定明确归属于当前考试和学员的实训项目,阻止篡改其他考生明细。 -->
<select id="lockPracticeItems" resultType="com.platform.business.model.entity.FzGradesEntity">
SELECT g.*
FROM fz_grades g
FROM <include refid="selectedGradeTable"/> g
WHERE g.exam_id = #{examId}
AND g.user_id = #{studentId}
AND g.id IN
......@@ -287,7 +316,7 @@
</select>
<update id="updatePracticeScore">
UPDATE fz_grades
UPDATE <include refid="selectedGradeTable"/>
SET score = #{score}
WHERE id = #{questionId}
</update>
......@@ -333,7 +362,7 @@
AND IFNULL(es.mark_flag, 0) = 0
AND NOT EXISTS (
SELECT 1
FROM fz_grades g
FROM <include refid="routedGradeRows"/> g
WHERE g.exam_id = es.exam_id AND g.user_id = es.student_id
)
</select>
......@@ -367,10 +396,10 @@
<select id="calculatePracticeScore" resultType="double">
SELECT IFNULL(SUM(g.score), 0)
FROM fz_grades g
FROM <include refid="selectedGradeTable"/> g
INNER JOIN (
SELECT MAX(id) AS id
FROM fz_grades
FROM <include refid="selectedGradeTable"/>
WHERE exam_id = #{examId} AND user_id = #{studentId}
GROUP BY code
) latest ON latest.id = g.id
......@@ -406,7 +435,7 @@
l.created_at AS createdAt
FROM exam_review_score_log l
LEFT JOIN theoretical_paper_student_detail d ON d.id = l.question_id
LEFT JOIN fz_grades practice_item ON practice_item.id = l.question_id
LEFT JOIN <include refid="routedGradeRows"/> practice_item ON practice_item.id = l.question_id
LEFT JOIN user u ON u.id = l.reviewer_id
WHERE l.exam_student_id = #{examStudentId}
ORDER BY l.created_at DESC, l.id DESC
......
......@@ -2,6 +2,14 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.platform.business.mapper.FzGradesMapper">
<!-- 表名只能由服务端布尔路由选择,不接收任意字符串,避免动态表名带来的SQL注入风险。 -->
<sql id="selectedGradeTable">
<choose>
<when test="useTemporaryTable">fz_grades_temp</when>
<otherwise>fz_grades</otherwise>
</choose>
</sql>
<select id="lockPracticeExam" resultType="com.platform.business.model.entity.ExamEntity">
SELECT e.*
FROM exam e
......@@ -25,10 +33,10 @@
g.title, g.type, g.options, g.mark, g.text, g.result, g.file,
g.file_format AS fileFormat, g.score,
g.basic_score AS basicScore, g.right_or_wrong AS rightOrWrong
FROM fz_grades g
FROM <include refid="selectedGradeTable"/> g
INNER JOIN (
SELECT MAX(id) AS id
FROM fz_grades
FROM <include refid="selectedGradeTable"/>
WHERE exam_id = #{examId} AND user_id = #{studentId}
GROUP BY code
) latest ON latest.id = g.id
......@@ -37,15 +45,28 @@
<select id="sumLatestScores" resultType="double">
SELECT IFNULL(SUM(g.score), 0)
FROM fz_grades g
FROM <include refid="selectedGradeTable"/> g
INNER JOIN (
SELECT MAX(id) AS id
FROM fz_grades
FROM <include refid="selectedGradeTable"/>
WHERE exam_id = #{examId} AND user_id = #{studentId}
GROUP BY code
) latest ON latest.id = g.id
</select>
<!-- MyBatis-Plus默认insert继续服务正式表;临时表写入使用独立且固定的SQL。 -->
<insert id="insertTemporary" parameterType="com.platform.business.model.entity.FzGradesEntity">
INSERT INTO fz_grades_temp (
id, exam_id, user_id, code, lev, start_time, submission_time, title, type,
primary_type, secondary_type, `options`, mark, `text`, result, file, file_format,
score, basic_score, right_or_wrong
) VALUES (
#{id}, #{examId}, #{userId}, #{code}, #{lev}, #{startTime}, #{submissionTime},
#{title}, #{type}, #{primaryType}, #{secondaryType}, #{options}, #{mark}, #{text},
#{result}, #{file}, #{fileFormat}, #{score}, #{basicScore}, #{rightOrWrong}
)
</insert>
<update id="submitPracticeStudent">
UPDATE exam_student
SET score = #{score},
......
......@@ -2,6 +2,38 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.platform.business.mapper.ScoreAdminMapper">
<!-- 单学员详情使用受控布尔值选择物理表,绝不拼接请求传入的表名。 -->
<sql id="selectedGradeTable">
<choose>
<when test="useTemporaryTable">fz_grades_temp</when>
<otherwise>fz_grades</otherwise>
</choose>
</sql>
<!--
跨学员统计需要同时覆盖两张物理表:普通学员从正式表读取,配置学员只从临时表读取。
ID列表由服务端配置对象提供,不允许请求参数直接控制路由范围。
-->
<sql id="routedGradeRows">
(
SELECT formal_grade.*
FROM fz_grades formal_grade
<if test="tempStudentIds != null and !tempStudentIds.isEmpty()">
WHERE formal_grade.user_id NOT IN
<foreach collection="tempStudentIds" item="studentId" open="(" separator="," close=")">
#{studentId}
</foreach>
UNION ALL
SELECT temporary_grade.*
FROM fz_grades_temp temporary_grade
WHERE temporary_grade.user_id IN
<foreach collection="tempStudentIds" item="studentId" open="(" separator="," close=")">
#{studentId}
</foreach>
</if>
)
</sql>
<!--
考试汇总统一只使用 exam.mark_flag 与 exam_student.mark_flag 同时发布的分数。
这样即使教师已经暂存了部分主观题分数,也不会提前泄露为管理员端正式成绩。
......@@ -167,7 +199,7 @@
OR IFNULL(es.mark_flag, 0) = 0 THEN FALSE
WHEN UPPER(TRIM(e.type)) IN ('实训考试', '实训', 'PRACTICE') THEN EXISTS (
SELECT 1
FROM fz_grades paper_item
FROM <include refid="routedGradeRows"/> paper_item
WHERE paper_item.exam_id = es.exam_id
AND paper_item.user_id = es.student_id
)
......@@ -329,10 +361,10 @@
g.start_time AS startTime, g.submission_time AS submissionTime,
g.title, g.type, g.options, g.mark, g.text, g.result, g.file,
g.file_format AS fileFormat, g.score, g.basic_score AS basicScore
FROM fz_grades g
FROM <include refid="selectedGradeTable"/> g
INNER JOIN (
SELECT MAX(id) AS id
FROM fz_grades
FROM <include refid="selectedGradeTable"/>
WHERE exam_id = #{examId} AND user_id = #{studentId}
GROUP BY code
) latest ON latest.id = g.id
......@@ -415,10 +447,10 @@
SUM(CASE WHEN LOWER(IFNULL(g.result, '')) IN ('0', 'false', '错误', '未通过', '不合格') THEN 1 ELSE 0 END)
AS failureResultCount,
NULL AS difficulty
FROM fz_grades g
FROM <include refid="routedGradeRows"/> g
INNER JOIN (
SELECT exam_id, user_id, code, MAX(id) AS id
FROM fz_grades
FROM <include refid="routedGradeRows"/>
WHERE exam_id = #{examId}
GROUP BY exam_id, user_id, code
) latest ON latest.id = g.id
......@@ -538,10 +570,10 @@
g.code,
g.secondary_type AS secondaryType,
g.score
FROM fz_grades g
FROM <include refid="routedGradeRows"/> g
INNER JOIN (
SELECT user_id, code, MAX(id) AS id
FROM fz_grades
FROM <include refid="routedGradeRows"/>
WHERE exam_id = #{examId}
GROUP BY user_id, code
) latest ON latest.id = g.id
......
......@@ -3,6 +3,14 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.platform.business.mapper.StudentScoreMapper">
<!-- 单学员查询只允许在两张固定表之间选择,布尔参数由服务端配置计算。 -->
<sql id="selectedGradeTable">
<choose>
<when test="useTemporaryTable">fz_grades_temp</when>
<otherwise>fz_grades</otherwise>
</choose>
</sql>
<!-- 个人统计只使用已经交卷、考试和个人均已发布且分数非空的正式成绩。 -->
<select id="selectOverview" resultType="com.platform.business.model.vo.StudentScoreVO$Overview">
SELECT
......@@ -275,10 +283,10 @@
grade.score,
grade.start_time AS startTime,
grade.submission_time AS submissionTime
FROM fz_grades grade
FROM <include refid="selectedGradeTable"/> grade
INNER JOIN (
SELECT MAX(id) AS id
FROM fz_grades
FROM <include refid="selectedGradeTable"/>
WHERE exam_id = #{examId}
AND user_id = #{studentId}
GROUP BY code
......
......@@ -61,9 +61,12 @@ class ScoreAdminMapperXmlTest {
assertTrue(rosterSql.contains("where es.exam_id = ? order by es.id"));
assertFalse(rosterSql.contains("es.score is not null"));
Map<String, Object> itemParameters = new HashMap<>();
itemParameters.put("examId", 1);
itemParameters.put("tempStudentIds", Collections.emptyList());
String itemSql = normalizeSql(configuration.getMappedStatement(
"com.platform.business.mapper.ScoreAdminMapper.queryExportPracticeItems")
.getBoundSql(1).getSql());
.getBoundSql(itemParameters).getSql());
assertTrue(itemSql.contains("max(id) as id"));
assertTrue(itemSql.contains("ifnull(es.mark_flag, 0) = 1"));
// 汇总表项目名称必须明确读取二级题目类型,禁止继续从旧题目标题取值。
......@@ -118,13 +121,14 @@ class ScoreAdminMapperXmlTest {
Map<String, Object> parameters = new HashMap<>();
parameters.put("examId", 1);
parameters.put("query", query);
parameters.put("tempStudentIds", Collections.emptyList());
String sql = normalizeSql(configuration.getMappedStatement(
"com.platform.business.mapper.ScoreAdminMapper.queryStudents")
.getBoundSql(parameters).getSql());
assertTrue(sql.contains("as paperavailable"));
assertTrue(sql.contains("from fz_grades paper_item"));
assertTrue(sql.contains("from ( select formal_grade.* from fz_grades formal_grade ) paper_item"));
assertTrue(sql.contains("from theoretical_paper_student_detail paper_question"));
assertTrue(sql.contains("coalesce(paper_question.is_problem, 1) = 1"));
}
......
......@@ -229,9 +229,9 @@ class ExamReviewServiceImplTest {
locked.setBasicScore(20D);
when(examReviewMapper.lockStudent(20, "teacher-1")).thenReturn(student);
when(examReviewMapper.findTask(200, "teacher-1")).thenReturn(task);
when(examReviewMapper.lockPracticeItems(any(), anyInt(), any()))
when(examReviewMapper.lockPracticeItems(any(), anyInt(), any(), eq(false)))
.thenReturn(Collections.singletonList(locked));
when(examReviewMapper.calculatePracticeScore(200, "student-2")).thenReturn(90D);
when(examReviewMapper.calculatePracticeScore(200, "student-2", false)).thenReturn(90D);
ExamReviewScoreItemDTO item = new ExamReviewScoreItemDTO();
item.setQuestionId("practice-1");
......@@ -243,7 +243,7 @@ class ExamReviewServiceImplTest {
() -> examReviewService.saveScores(20, request, "teacher-1"));
assertEquals("调整后的实训总分不能超过考试总分", error.getMessage());
verify(examReviewMapper, never()).updatePracticeScore(any(), anyDouble());
verify(examReviewMapper, never()).updatePracticeScore(any(), anyDouble(), eq(false));
verify(scoreLogMapper, never()).insert(any());
}
......@@ -265,10 +265,10 @@ class ExamReviewServiceImplTest {
locked.setBasicScore(20D);
when(examReviewMapper.lockStudent(20, "teacher-1")).thenReturn(student);
when(examReviewMapper.findTask(200, "teacher-1")).thenReturn(task);
when(examReviewMapper.lockPracticeItems(any(), anyInt(), any()))
when(examReviewMapper.lockPracticeItems(any(), anyInt(), any(), eq(false)))
.thenReturn(Collections.singletonList(locked));
when(examReviewMapper.calculatePracticeScore(200, "student-2")).thenReturn(80D);
when(examReviewMapper.updatePracticeScore("practice-1", 25D)).thenReturn(1);
when(examReviewMapper.calculatePracticeScore(200, "student-2", false)).thenReturn(80D);
when(examReviewMapper.updatePracticeScore("practice-1", 25D, false)).thenReturn(1);
when(examReviewMapper.updatePendingPracticeTotal(20, 85D)).thenReturn(1);
when(scoreLogMapper.insert(any(ExamReviewScoreLogEntity.class))).thenReturn(1);
ExamReviewStudentVO reviewStudent = new ExamReviewStudentVO();
......@@ -280,7 +280,7 @@ class ExamReviewServiceImplTest {
responseItem.setId("practice-1");
responseItem.setScore(25D);
responseItem.setBasicScore(20D);
when(examReviewMapper.queryPracticeItems(200, "student-2"))
when(examReviewMapper.queryPracticeItems(200, "student-2", false))
.thenReturn(Collections.singletonList(responseItem));
ExamReviewScoreItemDTO item = new ExamReviewScoreItemDTO();
......@@ -317,7 +317,7 @@ class ExamReviewServiceImplTest {
"practice-3", null, 3D, 5D);
when(examReviewMapper.findStudent(20, "teacher-1")).thenReturn(student);
when(examReviewMapper.findTask(200, "teacher-1")).thenReturn(task);
when(examReviewMapper.queryPracticeItems(200, "student-2"))
when(examReviewMapper.queryPracticeItems(200, "student-2", false))
.thenReturn(Arrays.asList(objectiveOne, objectiveLegacy, unknownType));
ExamReviewPaperVO result = examReviewService.paper(20, "teacher-1");
......@@ -350,8 +350,9 @@ class ExamReviewServiceImplTest {
when(examReviewMapper.lockTask(200, "teacher-1")).thenReturn(exam);
when(examReviewMapper.lockSubmittedStudents(200))
.thenReturn(Collections.singletonList(student));
when(examReviewMapper.countSubmittedWithoutPracticeItems(200)).thenReturn(0);
when(examReviewMapper.calculatePracticeScore(200, "student-2")).thenReturn(88D);
when(examReviewMapper.countSubmittedWithoutPracticeItems(
eq(200), org.mockito.ArgumentMatchers.anyList())).thenReturn(0);
when(examReviewMapper.calculatePracticeScore(200, "student-2", false)).thenReturn(88D);
when(examReviewMapper.publishStudent(20, 88D)).thenReturn(1);
when(examReviewMapper.publishTask(200)).thenReturn(1);
when(scoreLogMapper.insert(any(ExamReviewScoreLogEntity.class))).thenReturn(1);
......
package com.platform.business.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.platform.business.config.FzGradesRoutingProperties;
import com.platform.business.constant.ExamAdminConstants;
import com.platform.business.mapper.FzGradesMapper;
import com.platform.business.model.dto.FzGradesDTO;
......@@ -48,7 +49,7 @@ class FzGradesServiceImplTest {
@Test
void firstCompleteSnapshotShouldSaveAndRemainPendingReview() {
mockWritableCandidate();
when(mapper.selectLatestItems(1, "student-1")).thenReturn(Collections.emptyList());
when(mapper.selectLatestItems(1, "student-1", false)).thenReturn(Collections.emptyList());
when(mapper.insert(any(FzGradesEntity.class))).thenReturn(1);
when(mapper.submitPracticeStudent(eq(9), eq(75D), any(), any(), any(), any()))
.thenReturn(1);
......@@ -67,7 +68,7 @@ class FzGradesServiceImplTest {
@Test
void explicitRightOrWrongShouldBePreservedForObjectiveQuestion() {
mockWritableCandidate();
when(mapper.selectLatestItems(1, "student-1")).thenReturn(Collections.emptyList());
when(mapper.selectLatestItems(1, "student-1", false)).thenReturn(Collections.emptyList());
when(mapper.insert(any(FzGradesEntity.class))).thenReturn(1);
when(mapper.submitPracticeStudent(eq(9), eq(10D), any(), any(), any(), any()))
.thenReturn(1);
......@@ -83,6 +84,26 @@ class FzGradesServiceImplTest {
assertFalse(captor.getValue().getRightOrWrong());
}
@Test
void configuredStudentShouldReceiveAndCheckIdempotencyOnlyInTemporaryTable() {
FzGradesRoutingProperties properties = new FzGradesRoutingProperties();
properties.setTemporaryStudentIds(Collections.singletonList(" student-1 "));
ReflectionTestUtils.setField(service, "routingProperties", properties);
mockWritableCandidate();
when(mapper.selectLatestItems(1, "student-1", true)).thenReturn(Collections.emptyList());
when(mapper.insertTemporary(any(FzGradesEntity.class))).thenReturn(1);
when(mapper.submitPracticeStudent(eq(9), eq(10D), any(), any(), any(), any()))
.thenReturn(1);
assertTrue(service.receive(Collections.singletonList(item("Q-1", 10D))));
ArgumentCaptor<FzGradesEntity> captor = ArgumentCaptor.forClass(FzGradesEntity.class);
verify(mapper).insertTemporary(captor.capture());
// 临时表自定义SQL不经过MyBatis-Plus主键填充,服务层必须预先生成雪花ID。
assertTrue(captor.getValue().getId() != null && !captor.getValue().getId().isEmpty());
verify(mapper, never()).insert(any(FzGradesEntity.class));
}
@Test
void rightOrWrongShouldBeAcceptedFromJsonButHiddenFromEntityResponses() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
......@@ -103,7 +124,7 @@ class FzGradesServiceImplTest {
incoming.setRightOrWrong(true);
FzGradesEntity existing = persisted("Q-1", 50D);
existing.setRightOrWrong(true);
when(mapper.selectLatestItems(1, "student-1"))
when(mapper.selectLatestItems(1, "student-1", false))
.thenReturn(Collections.singletonList(existing));
assertTrue(service.receive(Collections.singletonList(incoming)));
......@@ -120,7 +141,7 @@ class FzGradesServiceImplTest {
FzGradesEntity existing = persisted("Q-1", 50D);
existing.setType("客观题");
existing.setRightOrWrong(null);
when(mapper.selectLatestItems(1, "student-1"))
when(mapper.selectLatestItems(1, "student-1", false))
.thenReturn(Collections.singletonList(existing));
assertTrue(service.receive(Collections.singletonList(incoming)));
......@@ -137,7 +158,7 @@ class FzGradesServiceImplTest {
incoming.setRightOrWrong(false);
FzGradesEntity existing = persisted("Q-1", 50D);
existing.setRightOrWrong(true);
when(mapper.selectLatestItems(1, "student-1"))
when(mapper.selectLatestItems(1, "student-1", false))
.thenReturn(Collections.singletonList(existing));
BusinessException error = assertThrows(BusinessException.class,
......@@ -158,7 +179,7 @@ class FzGradesServiceImplTest {
FzGradesEntity existing = persisted("Q-1", 50D);
existing.setType("客观题");
existing.setRightOrWrong(null);
when(mapper.selectLatestItems(1, "student-1"))
when(mapper.selectLatestItems(1, "student-1", false))
.thenReturn(Collections.singletonList(existing));
BusinessException error = assertThrows(BusinessException.class,
......@@ -173,7 +194,7 @@ class FzGradesServiceImplTest {
@Test
void changedReplayShouldBeRejectedAfterFirstReceipt() {
mockWritableCandidate();
when(mapper.selectLatestItems(1, "student-1"))
when(mapper.selectLatestItems(1, "student-1", false))
.thenReturn(Collections.singletonList(persisted("Q-1", 10D)));
BusinessException error = assertThrows(BusinessException.class,
......@@ -186,7 +207,7 @@ class FzGradesServiceImplTest {
@Test
void changedBasicScoreShouldNotBeTreatedAsIdenticalReplay() {
mockWritableCandidate();
when(mapper.selectLatestItems(1, "student-1"))
when(mapper.selectLatestItems(1, "student-1", false))
.thenReturn(Collections.singletonList(persisted("Q-1", 10D)));
FzGradesDTO changed = item("Q-1", 10D);
changed.setBasicScore(70D);
......
......@@ -96,7 +96,8 @@ class ScoreAdminServiceImplTest {
candidate.setPublished(false);
when(scoreAdminMapper.findExam(1)).thenReturn(upcoming);
when(scoreAdminMapper.queryStudents(
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.any()))
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.any(),
org.mockito.ArgumentMatchers.anyList()))
.thenReturn(Collections.singletonList(candidate));
ScoreAdminExamVO overview = service.exam(1);
......@@ -106,7 +107,8 @@ class ScoreAdminServiceImplTest {
assertEquals(1, students.size());
assertEquals(false, students.get(0).getPublished());
verify(scoreAdminMapper).queryStudents(
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.any());
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.any(),
org.mockito.ArgumentMatchers.anyList());
}
@Test
......@@ -182,7 +184,8 @@ class ScoreAdminServiceImplTest {
result.get(1).getSequence(),
result.get(2).getSequence()));
verify(scoreAdminMapper).queryTheoryStatistics(1);
verify(scoreAdminMapper, never()).queryPracticeStatistics(1);
verify(scoreAdminMapper, never()).queryPracticeStatistics(
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.anyList());
}
@Test
......@@ -192,14 +195,16 @@ class ScoreAdminServiceImplTest {
when(scoreAdminMapper.findExam(1)).thenReturn(exam);
ScoreAdminQuestionStatisticsVO practiceItem = new ScoreAdminQuestionStatisticsVO();
practiceItem.setQuestionCode("1.1");
when(scoreAdminMapper.queryPracticeStatistics(1))
when(scoreAdminMapper.queryPracticeStatistics(
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.anyList()))
.thenReturn(Collections.singletonList(practiceItem));
List<ScoreAdminQuestionStatisticsVO> result = service.questionStatistics(1);
assertEquals("1.1", result.get(0).getQuestionCode());
assertNull(result.get(0).getSequence());
verify(scoreAdminMapper).queryPracticeStatistics(1);
verify(scoreAdminMapper).queryPracticeStatistics(
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.anyList());
verify(scoreAdminMapper, never()).queryTheoryStatistics(1);
}
......@@ -220,7 +225,8 @@ class ScoreAdminServiceImplTest {
ScoreAdminStudentVO notSubmitted = studentPaperState(false, false, false);
ScoreAdminStudentVO missingDetail = studentPaperState(true, true, false);
when(scoreAdminMapper.queryStudents(
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.any()))
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.any(),
org.mockito.ArgumentMatchers.anyList()))
.thenReturn(Arrays.asList(available, notSubmitted, missingDetail));
List<ScoreAdminStudentVO> result = service.students(1, new ScoreAdminStudentQueryDTO());
......@@ -261,7 +267,7 @@ class ScoreAdminServiceImplTest {
void practiceStudentPaperShouldNormalizePositivePartialAndNegativeResultTexts() {
ScoreAdminStudentDetailVO detail = publishedStudentDetail(ExamAdminConstants.TYPE_PRACTICE);
when(scoreAdminMapper.findStudent(2)).thenReturn(detail);
when(scoreAdminMapper.queryPracticeItems(1, "student-1")).thenReturn(Arrays.asList(
when(scoreAdminMapper.queryPracticeItems(1, "student-1", false)).thenReturn(Arrays.asList(
practiceResult("通过"), practiceResult("部分通过"), practiceResult("未通过")));
ScoreAdminStudentDetailVO result = service.student(2);
......@@ -321,7 +327,8 @@ class ScoreAdminServiceImplTest {
.thenReturn(Collections.singletonList(theoryStudent));
when(scoreAdminMapper.queryExportCandidates(2))
.thenReturn(Arrays.asList(practiceStudent, practiceOnlyStudent));
when(scoreAdminMapper.queryExportPracticeItems(2)).thenReturn(Arrays.asList(
when(scoreAdminMapper.queryExportPracticeItems(
org.mockito.ArgumentMatchers.eq(2), org.mockito.ArgumentMatchers.anyList())).thenReturn(Arrays.asList(
practiceItem("student-1", "1.1", "日常运行管理", "20"),
practiceItem("student-2", "1.1", "日常运行管理", "18"),
practiceItem("student-1", "1.2", "基础操作", "19")
......@@ -415,7 +422,8 @@ class ScoreAdminServiceImplTest {
assertEquals(org.apache.poi.ss.usermodel.CellType.BLANK,
workbook.getSheetAt(0).getRow(6).getCell(3).getCellType());
}
verify(scoreAdminMapper, never()).queryExportPracticeItems(org.mockito.ArgumentMatchers.anyInt());
verify(scoreAdminMapper, never()).queryExportPracticeItems(
org.mockito.ArgumentMatchers.anyInt(), org.mockito.ArgumentMatchers.anyList());
}
@Test
......@@ -434,7 +442,8 @@ class ScoreAdminServiceImplTest {
for (int i = 1; i <= 6; i++) {
items.add(practiceItem("student-28", "P" + i, "项目" + i, String.valueOf(i)));
}
when(scoreAdminMapper.queryExportPracticeItems(1)).thenReturn(items);
when(scoreAdminMapper.queryExportPracticeItems(
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.anyList())).thenReturn(items);
MockHttpServletResponse response = new MockHttpServletResponse();
service.exportExam(1, response);
......@@ -467,7 +476,8 @@ class ScoreAdminServiceImplTest {
for (int i = 1; i <= 6; i++) {
items.add(practiceItem("student-1", "P" + i, "项目" + i, "10"));
}
when(scoreAdminMapper.queryExportPracticeItems(1)).thenReturn(items);
when(scoreAdminMapper.queryExportPracticeItems(
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.anyList())).thenReturn(items);
MockHttpServletResponse response = new MockHttpServletResponse();
service.exportExam(1, response);
......@@ -497,7 +507,8 @@ class ScoreAdminServiceImplTest {
when(scoreAdminMapper.queryExportCandidates(1)).thenReturn(Collections.singletonList(
exportStudent("student-1", "张三", "90", true, true)));
List<ScoreAdminExportPracticeItemVO> items = practiceItems(251);
when(scoreAdminMapper.queryExportPracticeItems(1)).thenReturn(items);
when(scoreAdminMapper.queryExportPracticeItems(
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.anyList())).thenReturn(items);
MockHttpServletResponse response = new MockHttpServletResponse();
service.exportExam(1, response);
......@@ -517,7 +528,8 @@ class ScoreAdminServiceImplTest {
when(scoreAdminMapper.findExportExam(1)).thenReturn(practiceExam);
when(scoreAdminMapper.queryExportCandidates(1)).thenReturn(Collections.singletonList(
exportStudent("student-1", "张三", "90", true, true)));
when(scoreAdminMapper.queryExportPracticeItems(1)).thenReturn(practiceItems(252));
when(scoreAdminMapper.queryExportPracticeItems(
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.anyList())).thenReturn(practiceItems(252));
BusinessException error = assertThrows(BusinessException.class,
() -> service.exportExam(1, new MockHttpServletResponse()));
......@@ -536,7 +548,8 @@ class ScoreAdminServiceImplTest {
exportStudent("student-1", "张三", "90", true, true)));
when(scoreAdminMapper.queryExportCandidates(2)).thenReturn(Collections.singletonList(
exportStudent("student-1", "张三", "80", true, true)));
when(scoreAdminMapper.queryExportPracticeItems(1)).thenReturn(Collections.emptyList());
when(scoreAdminMapper.queryExportPracticeItems(
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.anyList())).thenReturn(Collections.emptyList());
service.exportExam(1, new MockHttpServletResponse());
......@@ -551,7 +564,8 @@ class ScoreAdminServiceImplTest {
when(scoreAdminMapper.queryExportCandidates(1)).thenReturn(Collections.singletonList(
exportStudent("student-1", "张三", "90", true, true)));
// 导出专用对象没有 title 字段;secondaryType 为空时必须验证表头只剩项目编号。
when(scoreAdminMapper.queryExportPracticeItems(1)).thenReturn(Collections.singletonList(
when(scoreAdminMapper.queryExportPracticeItems(
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.anyList())).thenReturn(Collections.singletonList(
practiceItem("student-1", "P1", null, "10")));
MockHttpServletResponse response = new MockHttpServletResponse();
......@@ -571,7 +585,8 @@ class ScoreAdminServiceImplTest {
exportStudent("student-1", "张三", "90", true, true),
exportStudent("student-2", "李四", "85", true, true)));
// 同一项目编号的二级题目类型应在全场保持一致,否则无法生成唯一、可信的表头。
when(scoreAdminMapper.queryExportPracticeItems(1)).thenReturn(Arrays.asList(
when(scoreAdminMapper.queryExportPracticeItems(
org.mockito.ArgumentMatchers.eq(1), org.mockito.ArgumentMatchers.anyList())).thenReturn(Arrays.asList(
practiceItem("student-1", "P1", "日常运行管理", "10"),
practiceItem("student-2", "P1", "基础操作", "9")));
......
......@@ -122,7 +122,7 @@ class StudentScoreServiceImplTest {
StudentScoreVO.PracticeItem pass = practiceItem(true, "未通过");
StudentScoreVO.PracticeItem partial = practiceItem(null, "部分通过");
StudentScoreVO.PracticeItem fail = practiceItem(false, "通过");
when(mapper.selectPracticeItems(10, "student-1"))
when(mapper.selectPracticeItems(10, "student-1", false))
.thenReturn(Arrays.asList(pass, partial, fail));
StudentScoreVO.Detail result = service.detail(1, "student-1");
......@@ -147,7 +147,7 @@ class StudentScoreServiceImplTest {
void practiceCorrectRateShouldRoundHalfUpToTwoDecimals() {
StudentScoreVO.Detail detail = detail("实训");
when(mapper.selectDetail(1, "student-1")).thenReturn(detail);
when(mapper.selectPracticeItems(10, "student-1")).thenReturn(Arrays.asList(
when(mapper.selectPracticeItems(10, "student-1", false)).thenReturn(Arrays.asList(
practiceItem(true, null),
practiceItem(false, null),
practiceItem(false, null)));
......@@ -163,7 +163,7 @@ class StudentScoreServiceImplTest {
void allPracticeItemsCorrectShouldReturnOneHundredPercent() {
StudentScoreVO.Detail detail = detail("实训");
when(mapper.selectDetail(1, "student-1")).thenReturn(detail);
when(mapper.selectPracticeItems(10, "student-1")).thenReturn(Arrays.asList(
when(mapper.selectPracticeItems(10, "student-1", false)).thenReturn(Arrays.asList(
practiceItem(true, null), practiceItem(true, null)));
StudentScoreVO.Detail result = service.detail(1, "student-1");
......@@ -177,7 +177,7 @@ class StudentScoreServiceImplTest {
void nonEmptyAllWrongPracticeItemsShouldReturnZeroPercent() {
StudentScoreVO.Detail detail = detail("实训");
when(mapper.selectDetail(1, "student-1")).thenReturn(detail);
when(mapper.selectPracticeItems(10, "student-1")).thenReturn(Arrays.asList(
when(mapper.selectPracticeItems(10, "student-1", false)).thenReturn(Arrays.asList(
practiceItem(false, null), practiceItem(false, null)));
StudentScoreVO.Detail result = service.detail(1, "student-1");
......@@ -191,7 +191,7 @@ class StudentScoreServiceImplTest {
void emptyPracticeItemsShouldReturnZeroStatisticsInsteadOfNull() {
StudentScoreVO.Detail detail = detail("实训考试");
when(mapper.selectDetail(1, "student-1")).thenReturn(detail);
when(mapper.selectPracticeItems(10, "student-1")).thenReturn(Collections.emptyList());
when(mapper.selectPracticeItems(10, "student-1", false)).thenReturn(Collections.emptyList());
StudentScoreVO.Detail result = service.detail(1, "student-1");
......@@ -223,7 +223,7 @@ class StudentScoreServiceImplTest {
StudentScoreVO.Detail detail = detail("实训");
detail.setExamName("水质检测");
when(mapper.selectDetail(1, "student-1")).thenReturn(detail);
when(mapper.selectPracticeItems(10, "student-1")).thenReturn(Collections.emptyList());
when(mapper.selectPracticeItems(10, "student-1", false)).thenReturn(Collections.emptyList());
MockHttpServletResponse response = new MockHttpServletResponse();
service.export(1, "student-1", response);
......
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