package service; import dao.CourseDAO; import dao.ScoreDAO; import entity.Course; /** * CourseService:处理课程相关业务逻辑 */ public class CourseService { private CourseDAO courseDAO = new CourseDAO(); private ScoreDAO scoreDAO = new ScoreDAO(); // 添加课程 public boolean addCourse(Course course) { // 检查编号是否已存在 if (courseDAO.getCourseById(course.getId()) != null) { return false; } return courseDAO.addCourse(course); } // 删除课程(同时删除相关成绩记录) public boolean deleteCourse(String id) { // 删除关联的成绩记录 scoreDAO.deleteScoresByCourse(id); // 删除课程 return courseDAO.deleteCourse(id); } // 更新课程 public boolean updateCourse(Course course) { return courseDAO.updateCourse(course); } // 按编号查询课程 public Course getCourseById(String id) { return courseDAO.getCourseById(id); } // 查询所有课程 public java.util.List getAllCourses() { return courseDAO.getAllCourses(); } }