From 7821b179e2283f66c4f111e55f3bd8b160d2ec69 Mon Sep 17 00:00:00 2001 From: Alan <3052806735@qq.com> Date: Sun, 25 Aug 2024 21:05:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=AE=E6=A0=87=E5=85=B3=E8=81=94=E7=9F=A5?= =?UTF-8?q?=E8=AF=86=E7=82=B9=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2=E4=BC=98?= =?UTF-8?q?=E5=8C=96--=E5=BC=95=E5=85=A5Map=E5=87=8F=E5=B0=91=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=9F=A5=E8=AF=A2=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/courses/ObjectiveContentKnow.java | 2 +- .../ObjectiveContentKnowServiceImpl.java | 45 ++++++++++++++----- .../teaching/backend/utils/CourseCode.java | 2 +- 3 files changed, 36 insertions(+), 13 deletions(-) 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