You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
abc/CourseService.java

46 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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<Course> getAllCourses() {
return courseDAO.getAllCourses();
}
}