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 b8163c32..a58eac25 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 @@ -195,8 +195,30 @@ public class AiolCourseController extends JeecgController list = aiolCourseService.getCourseList(categoryId, difficulty, topic); + + // 尝试获取token,判断用户是否登录 + String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN); + if (token != null && !token.trim().isEmpty()) { + try { + String username = JwtUtil.getUsername(token); + LoginUser sysUser = sysBaseApi.getUserByName(username); + + if (sysUser != null) { + // 用户已登录,查询已报名课程并标记 + for (CourseWithTeacherInfo course : list) { + boolean isEnrolled = aiolCourseService.isEnrolled(course.getId(), sysUser.getId()); + course.setIsEnrolled(isEnrolled); + } + } + } catch (Exception e) { + // token无效或解析失败,忽略错误,继续执行原有逻辑 + log.debug("Token解析失败,按未登录用户处理: {}", e.getMessage()); + } + } + if (sort != null) { switch (sort) { case "hottest": diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/dto/CourseWithTeacherInfo.java b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/dto/CourseWithTeacherInfo.java index 97d1fa21..72999e43 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/dto/CourseWithTeacherInfo.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/dto/CourseWithTeacherInfo.java @@ -13,4 +13,9 @@ import java.util.List; public class CourseWithTeacherInfo extends AiolCourse { @Schema(description = "授课讲师列表") private List teacherList; + /** + * 是否已报名该课程 + */ + @Schema(description = "是否已报名该课程") + private Boolean isEnrolled = false; }