From b376d406d71fda29769edb5a4c50aee847cc41c4 Mon Sep 17 00:00:00 2001 From: GoCo Date: Thu, 4 Sep 2025 09:24:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=A2=9E=E5=8A=A0=E5=BD=93=E5=89=8D=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=98=AF=E5=90=A6=E5=B7=B2=E6=8A=A5=E5=90=8D=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aiol/controller/AiolCourseController.java | 24 ++++++++++++++++++- .../aiol/dto/CourseWithTeacherInfo.java | 5 ++++ 2 files changed, 28 insertions(+), 1 deletion(-) 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; }