|
|
@ -247,37 +247,62 @@ public class SaveOrUpdateTaskDomainServiceImpl implements SaveOrUpdateTaskDomain |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 经典模式(仅创建时):冻结套卷题目快照 |
|
|
* 经典模式(仅创建时):冻结套卷题目快照 |
|
|
* 查询套卷关联的题目,深拷贝题目内容(题干+选项+答案+解析)写入快照表 |
|
|
* 查询同 paperGroupId 下所有版本的题目,深拷贝题目内容写入快照表 |
|
|
|
|
|
* 考生开考时从快照中随机抽一个版本 |
|
|
* 后续套题变更不影响已建任务的快照数据 |
|
|
* 后续套题变更不影响已建任务的快照数据 |
|
|
*/ |
|
|
*/ |
|
|
private void buildPaperSnapshot(Long taskId, Long classicPaperId) { |
|
|
private void buildPaperSnapshot(Long taskId, Long classicPaperId) { |
|
|
// 1. 查询套卷关联的题目(按 sortOrder 排序)
|
|
|
// 1. 查询套卷所属的 paperGroupId
|
|
|
List<ClassicPaperQuestionEntity> paperQuestions = classicPaperQuestionBaseService.list( |
|
|
ClassicPaperEntity paper = classicPaperBaseService.getById(classicPaperId); |
|
|
|
|
|
if (paper == null || paper.getPaperGroupId() == null) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
Long paperGroupId = paper.getPaperGroupId(); |
|
|
|
|
|
|
|
|
|
|
|
// 2. 查询同组下所有套卷
|
|
|
|
|
|
List<ClassicPaperEntity> groupPapers = classicPaperBaseService.list( |
|
|
|
|
|
new LambdaQueryWrapper<ClassicPaperEntity>() |
|
|
|
|
|
.eq(ClassicPaperEntity::getPaperGroupId, paperGroupId)); |
|
|
|
|
|
if (groupPapers.isEmpty()) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. 收集所有套卷的题目ID
|
|
|
|
|
|
List<Long> allPaperIds = groupPapers.stream() |
|
|
|
|
|
.map(ClassicPaperEntity::getId) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
List<ClassicPaperQuestionEntity> allPaperQuestions = classicPaperQuestionBaseService.list( |
|
|
new LambdaQueryWrapper<ClassicPaperQuestionEntity>() |
|
|
new LambdaQueryWrapper<ClassicPaperQuestionEntity>() |
|
|
.eq(ClassicPaperQuestionEntity::getPaperId, classicPaperId) |
|
|
.in(ClassicPaperQuestionEntity::getPaperId, allPaperIds) |
|
|
.orderByAsc(ClassicPaperQuestionEntity::getSortOrder)); |
|
|
.orderByAsc(ClassicPaperQuestionEntity::getPaperId, ClassicPaperQuestionEntity::getSortOrder)); |
|
|
if (paperQuestions.isEmpty()) { |
|
|
if (allPaperQuestions.isEmpty()) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 2. 批量查询题目详情
|
|
|
// 4. 批量查询题目详情
|
|
|
List<Long> questionIds = paperQuestions.stream() |
|
|
List<Long> questionIds = allPaperQuestions.stream() |
|
|
.map(ClassicPaperQuestionEntity::getQuestionId) |
|
|
.map(ClassicPaperQuestionEntity::getQuestionId) |
|
|
.distinct() |
|
|
.distinct() |
|
|
.collect(Collectors.toList()); |
|
|
.collect(Collectors.toList()); |
|
|
Map<Long, QuestionEntity> questionMap = questionBaseService.listByIds(questionIds).stream() |
|
|
Map<Long, QuestionEntity> questionMap = questionBaseService.listByIds(questionIds).stream() |
|
|
.collect(Collectors.toMap(QuestionEntity::getId, q -> q)); |
|
|
.collect(Collectors.toMap(QuestionEntity::getId, q -> q)); |
|
|
|
|
|
|
|
|
// 3. 构建快照并批量保存(深拷贝 QuestionDetail 全部字段,含图片URL)
|
|
|
// 5. 建立 paperId → setIndex 映射
|
|
|
|
|
|
Map<Long, Integer> paperSetIndexMap = groupPapers.stream() |
|
|
|
|
|
.collect(Collectors.toMap(ClassicPaperEntity::getId, ClassicPaperEntity::getSetIndex)); |
|
|
|
|
|
|
|
|
|
|
|
// 6. 构建快照并批量保存(深拷贝 QuestionDetail 全部字段,含图片URL)
|
|
|
List<TaskPaperSnapshotEntity> snapshots = new ArrayList<>(); |
|
|
List<TaskPaperSnapshotEntity> snapshots = new ArrayList<>(); |
|
|
for (ClassicPaperQuestionEntity pq : paperQuestions) { |
|
|
for (ClassicPaperQuestionEntity pq : allPaperQuestions) { |
|
|
QuestionEntity question = questionMap.get(pq.getQuestionId()); |
|
|
QuestionEntity question = questionMap.get(pq.getQuestionId()); |
|
|
if (question == null) { |
|
|
if (question == null) { |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
TaskPaperSnapshotEntity snapshot = new TaskPaperSnapshotEntity(); |
|
|
TaskPaperSnapshotEntity snapshot = new TaskPaperSnapshotEntity(); |
|
|
snapshot.setTaskId(taskId); |
|
|
snapshot.setTaskId(taskId); |
|
|
snapshot.setPaperId(classicPaperId); |
|
|
snapshot.setPaperId(pq.getPaperId()); |
|
|
|
|
|
snapshot.setSetIndex(paperSetIndexMap.getOrDefault(pq.getPaperId(), 0)); |
|
|
snapshot.setQuestionId(pq.getQuestionId()); |
|
|
snapshot.setQuestionId(pq.getQuestionId()); |
|
|
snapshot.setSortOrder(pq.getSortOrder()); |
|
|
snapshot.setSortOrder(pq.getSortOrder()); |
|
|
snapshot.setQuestionType(pq.getQuestionType()); |
|
|
snapshot.setQuestionType(pq.getQuestionType()); |
|
|
|