diff --git a/src/main/java/com/project/classicpaper/domain/entity/ClassicPaperEntity.java b/src/main/java/com/project/classicpaper/domain/entity/ClassicPaperEntity.java index 827f414..4d32295 100644 --- a/src/main/java/com/project/classicpaper/domain/entity/ClassicPaperEntity.java +++ b/src/main/java/com/project/classicpaper/domain/entity/ClassicPaperEntity.java @@ -13,7 +13,9 @@ import org.hibernate.annotations.Comment; @Data @Table(name = "evaluator_classic_paper", indexes = {@Index(name = "Idx_sub_line_id", columnList = "sub_line_id"), - @Index(name = "Idx_status", columnList = "status")}) + @Index(name = "Idx_status", columnList = "status") , + @Index(name = "Idx_setId", columnList = "set_id") + }) @Entity @TableName(value = "evaluator_classic_paper") @EqualsAndHashCode(callSuper = true) diff --git a/src/main/java/com/project/ding/config/SecurityConfig.java b/src/main/java/com/project/ding/config/SecurityConfig.java index 4625490..7e1553d 100644 --- a/src/main/java/com/project/ding/config/SecurityConfig.java +++ b/src/main/java/com/project/ding/config/SecurityConfig.java @@ -31,6 +31,7 @@ public class SecurityConfig { .requestMatchers("/api/login/**" , "/api/public/**", "/api/milvus/**", + "/api/admin/classicPaperSet/importWord", "/api/interaction/**").permitAll() // 管理端锁定 .requestMatchers("/api/admin/**").hasRole("ADMIN") diff --git a/src/main/java/com/project/question/domain/entity/QuestionEntity.java b/src/main/java/com/project/question/domain/entity/QuestionEntity.java index 2fadc36..10e5c9a 100644 --- a/src/main/java/com/project/question/domain/entity/QuestionEntity.java +++ b/src/main/java/com/project/question/domain/entity/QuestionEntity.java @@ -16,10 +16,12 @@ import org.hibernate.annotations.JdbcTypeCode; import org.hibernate.type.SqlTypes; import org.springframework.beans.BeanUtils; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.function.Supplier; +import java.util.stream.Collectors; @Data @@ -77,12 +79,46 @@ public class QuestionEntity extends BaseEntity { private String analysis; // AI解析 // V1.1 新增:简答题得分点(多点得分制) private List scoringPoints; + // 1. 无参构造(Jackson/MyBatis 需要) + public QuestionDetail() {} + + // 2. 拷贝构造函数:实现深拷贝 + public QuestionDetail(QuestionDetail other) { + if (other == null) return; + this.questionContent = other.questionContent; + this.type = other.type; + this.rightAnswer = other.rightAnswer; + this.analysis = other.analysis; + + // 深拷贝 Map:创建新的 HashMap 实例 + if (other.options != null) { + this.options = new HashMap<>(other.options); + } + + // 深拷贝 List:创建新的 List 实例,并拷贝其中的每个 ScoringPoint 对象 + if (other.scoringPoints != null) { + this.scoringPoints = other.scoringPoints.stream() + .map(ScoringPoint::new) // 调用 ScoringPoint 的拷贝构造 + .collect(Collectors.toList()); + } + } } @Data public static class ScoringPoint { private Integer index; // 得分点序号 private String content; // 得分点内容 + + public ScoringPoint() { + } + // 拷贝构造函数 + public ScoringPoint(ScoringPoint other) { + if (other == null) { + return; + } + this.index = other.index; + this.content = other.content; + } } @Override public T toDTO(Supplier supplier) { diff --git a/src/main/java/com/project/question/domain/entity/TaskKnowledgeClusterEntity.java b/src/main/java/com/project/question/domain/entity/TaskKnowledgeClusterEntity.java index c64268b..bc388d1 100644 --- a/src/main/java/com/project/question/domain/entity/TaskKnowledgeClusterEntity.java +++ b/src/main/java/com/project/question/domain/entity/TaskKnowledgeClusterEntity.java @@ -12,7 +12,8 @@ import org.hibernate.annotations.Comment; @Data @Table(name = "evaluator_task_knowledge_cluster" , - indexes = {@Index(name = "Idx_taskId", columnList = "task_id")}) + indexes = {@Index(name = "Idx_taskId", columnList = "task_id") , + @Index(name = "Idx_groupId", columnList = "group_id")}) @Entity @TableName(value = "evaluator_task_knowledge_cluster", autoResultMap = true) @EqualsAndHashCode(callSuper = true) 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 b779920..7b3d852 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 @@ -223,7 +223,10 @@ public class SaveOrUpdateTaskDomainServiceImpl implements SaveOrUpdateTaskDomain } // 3. 复制簇记录,建立新旧ID映射(因为 clusterId 需要指向新创建的簇) - Map clusterIdMapping = new HashMap<>(); + List newClusters = new ArrayList<>(); + // 用来临时记录 旧ID -> 新实体 的映射 + Map 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 clusterIdMapping = new HashMap<>(); + for (Map.Entry entry : tempClusterMap.entrySet()) { + // 此时 entry.getValue().getId() 已经有值了 + clusterIdMapping.put(entry.getKey(), entry.getValue().getId()); + } + + // 5. 复制知识点记录,更新 clusterId 指向新创建的簇 List 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); } }