From 4ccef54e7edb9a0a914207cf5072afc8071a115f Mon Sep 17 00:00:00 2001 From: GoCo Date: Sat, 6 Sep 2025 09:57:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aiol/controller/AiolCourseController.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolCourseController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolCourseController.java index 76efaa04..fe93ce0c 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolCourseController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolCourseController.java @@ -28,6 +28,7 @@ import org.jeecg.modules.aiol.constant.EntityPermissionConst; import org.jeecg.modules.aiol.mapper.AiolCourseSignupMapper; import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.mapper.SysUserMapper; +import org.springframework.beans.BeanUtils; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -617,4 +618,55 @@ public class AiolCourseController extends JeecgController> queryMoreCourses( + @PathVariable(value = "courseId") String courseId, + @RequestParam(value = "limit", defaultValue = "6") Integer limit) { + try { + // 1. 查询所有课程(排除当前课程) + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.ne("id", courseId); + queryWrapper.eq("status", 1); // 只推荐进行中的课程 + + List allCourses = aiolCourseService.list(queryWrapper); + + if (allCourses.isEmpty()) { + return Result.OK(new ArrayList<>()); + } + + // 2. 随机选择课程 + List result = new ArrayList<>(); + List selectedCourses; + + if (allCourses.size() <= limit) { + selectedCourses = allCourses; + } else { + // 随机打乱并取前limit个 + Collections.shuffle(allCourses); + selectedCourses = allCourses.subList(0, limit); + } + + // 3. 转换为CourseWithTeacherInfo格式 + for (AiolCourse course : selectedCourses) { + CourseWithTeacherInfo courseWithTeacher = new CourseWithTeacherInfo(); + // 复制课程基本信息 + BeanUtils.copyProperties(course, courseWithTeacher); + + // 获取讲师信息 + List teachers = aiolCourseService.getCourseTeacherList(course.getId()); + courseWithTeacher.setTeacherList(teachers); + + result.add(courseWithTeacher); + } + + return Result.OK(result); + + } catch (Exception e) { + log.error("查询更多课程失败: courseId={}, error={}", courseId, e.getMessage(), e); + return Result.error("查询更多课程失败: " + e.getMessage()); + } + } }