Просмотр исходного кода

Merge branch 'feature/fix_CourseServiceImpl_dropcourse' of FanYanPeng/EAI-Backend into refactor

JiangPengYu 7 месяцев назад
Родитель
Сommit
5128387cc2

+ 11 - 0
src/main/java/com/njuzr/eaibackend/service/impl/CourseServiceImpl.java

@@ -408,6 +408,17 @@ public class CourseServiceImpl implements CourseService {
         if (code == 0) {
             throw MyException.create(HttpStatus.INTERNAL_SERVER_ERROR, "退课失败");
         }
+        ClassStudent classStudent = classStudentMapper.findClassStudentByStudentAndCourse(studentId, courseId);
+        if (classStudent != null) {
+            int csDeleted = classStudentMapper.deleteById(classStudent.getId());
+            if (csDeleted > 0) {
+                classMapper.decreaseStuNumber(classStudent.getClassId(), 1);
+            } else {
+                log.warn("退课时删除班级学生记录失败: studentId={}, courseId={}", studentId, courseId);
+            }
+        } else {
+            log.warn("退课时未找到学生在班级中的记录: studentId={}, courseId={}", studentId, courseId);
+        }
     }
 
     /**