feat: 🎸 更多课程
This commit is contained in:
parent
bb5a154768
commit
4ccef54e7e
@ -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<AiolCourse, IAiolCours
|
||||
return Result.error("查询课程学生列表失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{courseId}/more_courses")
|
||||
@Operation(summary = "更多课程推荐", description = "根据课程ID推荐相似课程,暂时使用随机推荐算法")
|
||||
@IgnoreAuth
|
||||
public Result<List<CourseWithTeacherInfo>> queryMoreCourses(
|
||||
@PathVariable(value = "courseId") String courseId,
|
||||
@RequestParam(value = "limit", defaultValue = "6") Integer limit) {
|
||||
try {
|
||||
// 1. 查询所有课程(排除当前课程)
|
||||
QueryWrapper<AiolCourse> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.ne("id", courseId);
|
||||
queryWrapper.eq("status", 1); // 只推荐进行中的课程
|
||||
|
||||
List<AiolCourse> allCourses = aiolCourseService.list(queryWrapper);
|
||||
|
||||
if (allCourses.isEmpty()) {
|
||||
return Result.OK(new ArrayList<>());
|
||||
}
|
||||
|
||||
// 2. 随机选择课程
|
||||
List<CourseWithTeacherInfo> result = new ArrayList<>();
|
||||
List<AiolCourse> 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<TeacherInfo> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user