diff --git a/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContentKnow.java b/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContentKnow.java index 023b03b..f150bc6 100644 --- a/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContentKnow.java +++ b/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContentKnow.java @@ -45,7 +45,7 @@ public class ObjectiveContentKnow implements Serializable { * 关联的知识点 */ // private String know; - private Integer knowId; + private Long knowId; } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java index c125417..7ef7db2 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java @@ -20,6 +20,7 @@ import com.teaching.backend.model.vo.knowtmp.KnowTmpVO; import com.teaching.backend.service.courses.IObjectiveContentKnowService; import com.teaching.backend.utils.CourseCode; import lombok.extern.slf4j.Slf4j; +import org.neo4j.driver.internal.value.StringValue; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -30,6 +31,7 @@ import java.math.RoundingMode; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -97,12 +99,19 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl() - .eq(ObjectiveContents::getId, objectiveContentId)).getObjectiveId(); - String pid = courseObjectivesMapper.selectOne(new LambdaQueryWrapper() - .eq(CourseObjectives::getId, objectiveID)).getPid(); - String courseId = courseObjectivesMapper.selectOne(new LambdaQueryWrapper() - .eq(CourseObjectives::getId, pid)).getCourseId(); + String objectiveID = objectiveContentsMapper.selectById(objectiveContentId).getObjectiveId(); + CourseObjectives courseObjective = courseObjectivesMapper.selectOne(new LambdaQueryWrapper() + .eq(CourseObjectives::getId, objectiveID)); + String pid = courseObjective.getPid(); + //当前内容属于总目标类型的 + String courseId; + if(pid.equals(String.valueOf(CourseCode.CONTENT_BELONGS_TO_TOTAL_OBJECTIVE.getValue()))){ + courseId = courseObjective.getCourseId(); + } + else { + courseId = courseObjectivesMapper.selectOne(new LambdaQueryWrapper() + .eq(CourseObjectives::getId, pid)).getCourseId(); + } Integer classhours = coursesMapper.selectById(courseId).getClasshours(); // 获取当前目标内容下关联的知识点数据 @@ -127,22 +136,35 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl objectiveContentKnows) { ObjectiveContentKnowVO vo = new ObjectiveContentKnowVO(); vo.setObjectiveOrContent(objectiveOrContentId); vo.setKnowsNumber(objectiveContentKnows.size()); - // 计算知识点的总时间,并收集关联的知识点部分数据 + // 提取所有的 Know IDs + List knowIds = objectiveContentKnows.stream() + .map(ObjectiveContentKnow::getKnowId) + .collect(Collectors.toList()); + + // 一次性查询所有需要的 Knowtmp 数据 + List knows = knowtmpMapper.selectList(new LambdaQueryWrapper() + .in(Knowtmp::getId, knowIds)); + + // 使用 Map 来存储 Knowtmp 数据,以便快速查找 + Map knowMap = knows.stream() + .collect(Collectors.toMap(Knowtmp::getId, know -> know)); + Double knowsTime = 0.0; List knowTmpVOList = new ArrayList<>(); for (ObjectiveContentKnow contentKnow : objectiveContentKnows) { - Knowtmp know = knowtmpMapper.selectOne(new LambdaQueryWrapper() - .eq(Knowtmp::getId, contentKnow.getKnowId())); + Knowtmp know = knowMap.get(contentKnow.getKnowId()); if (know == null) { - throw new BusinessException(ErrorCode.KNOW_NOT_EXIT); + log.warn("知识点不存在,id:{}", contentKnow.getKnowId()); + // throw new BusinessException(ErrorCode.KNOW_NOT_EXIT); + continue; // 知识点不存在时跳过 } + knowsTime += know.getHour(); // 将当前知识点数据添加到knowTmpVOList中 @@ -158,6 +180,7 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl