|
|
|
@ -223,7 +223,10 @@ public class SaveOrUpdateTaskDomainServiceImpl implements SaveOrUpdateTaskDomain |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 复制簇记录,建立新旧ID映射(因为 clusterId 需要指向新创建的簇)
|
|
|
|
Map<Long, Long> clusterIdMapping = new HashMap<>(); |
|
|
|
List<TaskKnowledgeClusterEntity> newClusters = new ArrayList<>(); |
|
|
|
// 用来临时记录 旧ID -> 新实体 的映射
|
|
|
|
Map<Long, TaskKnowledgeClusterEntity> tempClusterMap = new HashMap<>(); |
|
|
|
|
|
|
|
for (TaskKnowledgeClusterEntity template : templateClusters) { |
|
|
|
TaskKnowledgeClusterEntity newCluster = new TaskKnowledgeClusterEntity(); |
|
|
|
newCluster.setTaskId(taskId); |
|
|
|
@ -231,11 +234,24 @@ public class SaveOrUpdateTaskDomainServiceImpl implements SaveOrUpdateTaskDomain |
|
|
|
newCluster.setClusterTopic(template.getClusterTopic()); |
|
|
|
newCluster.setClusterSize(template.getClusterSize()); |
|
|
|
newCluster.setGroupId(classicPaperSetId); |
|
|
|
taskKnowledgeClusterBaseService.save(newCluster); |
|
|
|
clusterIdMapping.put(template.getId(), newCluster.getId()); |
|
|
|
|
|
|
|
newClusters.add(newCluster); |
|
|
|
tempClusterMap.put(template.getId(), newCluster); |
|
|
|
} |
|
|
|
|
|
|
|
if (!newClusters.isEmpty()) { |
|
|
|
// ⚠️ 优化点:一次性批量插入!此时 MyBatis-Plus 会将数据库生成的 ID 回填到 newClusters 的对象中
|
|
|
|
taskKnowledgeClusterBaseService.saveBatch(newClusters); |
|
|
|
} |
|
|
|
|
|
|
|
// 4. 复制知识点记录,更新 clusterId 指向新创建的簇
|
|
|
|
// 4. 构建 新旧 ID 映射
|
|
|
|
Map<Long, Long> clusterIdMapping = new HashMap<>(); |
|
|
|
for (Map.Entry<Long, TaskKnowledgeClusterEntity> entry : tempClusterMap.entrySet()) { |
|
|
|
// 此时 entry.getValue().getId() 已经有值了
|
|
|
|
clusterIdMapping.put(entry.getKey(), entry.getValue().getId()); |
|
|
|
} |
|
|
|
|
|
|
|
// 5. 复制知识点记录,更新 clusterId 指向新创建的簇
|
|
|
|
List<TaskKnowledgePointEntity> newPoints = new ArrayList<>(); |
|
|
|
for (TaskKnowledgePointEntity template : templatePoints) { |
|
|
|
TaskKnowledgePointEntity newPoint = new TaskKnowledgePointEntity(); |
|
|
|
@ -309,14 +325,13 @@ public class SaveOrUpdateTaskDomainServiceImpl implements SaveOrUpdateTaskDomain |
|
|
|
snapshot.setQuestionId(pq.getQuestionId()); |
|
|
|
snapshot.setSortOrder(pq.getSortOrder()); |
|
|
|
snapshot.setQuestionType(pq.getQuestionType()); |
|
|
|
// 深拷贝 questionDetail,避免快照与 QuestionEntity 共享同一对象引用
|
|
|
|
QuestionEntity.QuestionDetail detailCopy = new QuestionEntity.QuestionDetail(); |
|
|
|
BeanUtils.copyProperties(question.getQuestionDetail(), detailCopy); |
|
|
|
snapshot.setQuestionDetail(detailCopy); |
|
|
|
if (question.getQuestionDetail() != null) { |
|
|
|
snapshot.setQuestionDetail(new QuestionEntity.QuestionDetail(question.getQuestionDetail())); |
|
|
|
} |
|
|
|
snapshots.add(snapshot); |
|
|
|
} |
|
|
|
if (!snapshots.isEmpty()) { |
|
|
|
taskPaperSnapshotBaseService.saveBatch(snapshots); |
|
|
|
taskPaperSnapshotBaseService.saveBatch(snapshots , 300); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|