From 4d3370408f1b68f09de7051f3ab4fa64c437ae68 Mon Sep 17 00:00:00 2001 From: luoweijian <1329394916@qq.com> Date: Wed, 17 Jun 2026 17:35:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E5=8D=B7=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExamRecordApplicationServiceImpl.java | 16 ++++++- .../entity/TaskPaperSnapshotEntity.java | 5 ++ .../SaveOrUpdateTaskDomainServiceImpl.java | 47 ++++++++++++++----- 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/project/exam/application/impl/ExamRecordApplicationServiceImpl.java b/src/main/java/com/project/exam/application/impl/ExamRecordApplicationServiceImpl.java index 88a8b78..44a38ad 100644 --- a/src/main/java/com/project/exam/application/impl/ExamRecordApplicationServiceImpl.java +++ b/src/main/java/com/project/exam/application/impl/ExamRecordApplicationServiceImpl.java @@ -8,6 +8,10 @@ import com.project.exam.domain.dto.ExamRecordDTO; import com.project.exam.domain.dto.ExamRecordPictureDTO; import com.project.exam.domain.param.ExamRecordParam; import com.project.exam.domain.service.*; +import com.project.exam.domain.service.strategy.PaperAssemblyStrategy; +import com.project.exam.domain.service.strategy.PaperAssemblyStrategyFactory; +import com.project.task.domain.entity.TaskEntity; +import com.project.task.domain.service.TaskBaseService; import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -18,6 +22,13 @@ public class ExamRecordApplicationServiceImpl implements ExamRecordApplicationSe @Autowired private AssemblePaperDomainService assemblePaperDomainService; + // V1.1 新增:组卷策略工厂 + @Autowired + private PaperAssemblyStrategyFactory paperAssemblyStrategyFactory; + + @Autowired + private TaskBaseService taskBaseService; + @Autowired private StepSaveExamRecordDomainService stepSaveExamRecordDomainService; @@ -53,7 +64,10 @@ public class ExamRecordApplicationServiceImpl implements ExamRecordApplicationSe @Override public Result assemblePaper(Long taskId) throws Exception { - return Result.success(assemblePaperDomainService.assemblePaper(taskId , SecurityUtils.getUserId())); + // V1.1:按考试模式分发到不同组卷策略 + TaskEntity task = taskBaseService.getById(taskId); + PaperAssemblyStrategy strategy = paperAssemblyStrategyFactory.getStrategy(task.getExamMode()); + return Result.success(strategy.assemblePaper(taskId, SecurityUtils.getUserId())); } @Override diff --git a/src/main/java/com/project/task/domain/entity/TaskPaperSnapshotEntity.java b/src/main/java/com/project/task/domain/entity/TaskPaperSnapshotEntity.java index f08e6fe..9c119b9 100644 --- a/src/main/java/com/project/task/domain/entity/TaskPaperSnapshotEntity.java +++ b/src/main/java/com/project/task/domain/entity/TaskPaperSnapshotEntity.java @@ -35,6 +35,11 @@ public class TaskPaperSnapshotEntity extends BaseEntity { @Comment("原始套卷ID(追溯用)") private Long paperId; + @Column(name = "set_index") + @TableField("set_index") + @Comment("组内序号(1~N),用于随机抽卷") + private Integer setIndex; + @Column(name = "question_id") @TableField("question_id") @Comment("题目ID") diff --git a/src/main/java/com/project/task/domain/service/impl/SaveOrUpdateTaskDomainServiceImpl.java b/src/main/java/com/project/task/domain/service/impl/SaveOrUpdateTaskDomainServiceImpl.java index c79c5f1..4d0e763 100644 --- a/src/main/java/com/project/task/domain/service/impl/SaveOrUpdateTaskDomainServiceImpl.java +++ b/src/main/java/com/project/task/domain/service/impl/SaveOrUpdateTaskDomainServiceImpl.java @@ -247,37 +247,62 @@ public class SaveOrUpdateTaskDomainServiceImpl implements SaveOrUpdateTaskDomain /** * 经典模式(仅创建时):冻结套卷题目快照 - * 查询套卷关联的题目,深拷贝题目内容(题干+选项+答案+解析)写入快照表 + * 查询同 paperGroupId 下所有版本的题目,深拷贝题目内容写入快照表 + * 考生开考时从快照中随机抽一个版本 * 后续套题变更不影响已建任务的快照数据 */ private void buildPaperSnapshot(Long taskId, Long classicPaperId) { - // 1. 查询套卷关联的题目(按 sortOrder 排序) - List paperQuestions = classicPaperQuestionBaseService.list( + // 1. 查询套卷所属的 paperGroupId + ClassicPaperEntity paper = classicPaperBaseService.getById(classicPaperId); + if (paper == null || paper.getPaperGroupId() == null) { + return; + } + Long paperGroupId = paper.getPaperGroupId(); + + // 2. 查询同组下所有套卷 + List groupPapers = classicPaperBaseService.list( + new LambdaQueryWrapper() + .eq(ClassicPaperEntity::getPaperGroupId, paperGroupId)); + if (groupPapers.isEmpty()) { + return; + } + + // 3. 收集所有套卷的题目ID + List allPaperIds = groupPapers.stream() + .map(ClassicPaperEntity::getId) + .collect(Collectors.toList()); + + List allPaperQuestions = classicPaperQuestionBaseService.list( new LambdaQueryWrapper() - .eq(ClassicPaperQuestionEntity::getPaperId, classicPaperId) - .orderByAsc(ClassicPaperQuestionEntity::getSortOrder)); - if (paperQuestions.isEmpty()) { + .in(ClassicPaperQuestionEntity::getPaperId, allPaperIds) + .orderByAsc(ClassicPaperQuestionEntity::getPaperId, ClassicPaperQuestionEntity::getSortOrder)); + if (allPaperQuestions.isEmpty()) { return; } - // 2. 批量查询题目详情 - List questionIds = paperQuestions.stream() + // 4. 批量查询题目详情 + List questionIds = allPaperQuestions.stream() .map(ClassicPaperQuestionEntity::getQuestionId) .distinct() .collect(Collectors.toList()); Map questionMap = questionBaseService.listByIds(questionIds).stream() .collect(Collectors.toMap(QuestionEntity::getId, q -> q)); - // 3. 构建快照并批量保存(深拷贝 QuestionDetail 全部字段,含图片URL) + // 5. 建立 paperId → setIndex 映射 + Map paperSetIndexMap = groupPapers.stream() + .collect(Collectors.toMap(ClassicPaperEntity::getId, ClassicPaperEntity::getSetIndex)); + + // 6. 构建快照并批量保存(深拷贝 QuestionDetail 全部字段,含图片URL) List snapshots = new ArrayList<>(); - for (ClassicPaperQuestionEntity pq : paperQuestions) { + for (ClassicPaperQuestionEntity pq : allPaperQuestions) { QuestionEntity question = questionMap.get(pq.getQuestionId()); if (question == null) { continue; } TaskPaperSnapshotEntity snapshot = new TaskPaperSnapshotEntity(); snapshot.setTaskId(taskId); - snapshot.setPaperId(classicPaperId); + snapshot.setPaperId(pq.getPaperId()); + snapshot.setSetIndex(paperSetIndexMap.getOrDefault(pq.getPaperId(), 0)); snapshot.setQuestionId(pq.getQuestionId()); snapshot.setSortOrder(pq.getSortOrder()); snapshot.setQuestionType(pq.getQuestionType());