refactor: remove unused database columns and related code
This commit is contained in:
parent
7b70a03666
commit
d790495890
@ -12,7 +12,6 @@ CREATE TABLE IF NOT EXISTS students (
|
||||
contact VARCHAR(20), -- 联系方式
|
||||
college VARCHAR(50) NOT NULL, -- 学院
|
||||
major VARCHAR(50) NOT NULL, -- 专业
|
||||
is_graduating BOOLEAN DEFAULT FALSE, -- 是否毕业班
|
||||
password VARCHAR(50) NOT NULL -- 密码
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学生信息表';
|
||||
|
||||
@ -47,9 +46,9 @@ CREATE TABLE IF NOT EXISTS leave_requests (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='请假申请表';
|
||||
|
||||
-- 插入示例数据
|
||||
INSERT INTO students (student_id, name, class_name, contact, college, major, is_graduating, password) VALUES
|
||||
('2023208145', '李同学', '云计算G23-1', '15842087237', '信息工程学院', '云计算技术应用', false, '123456'),
|
||||
('2023208146', '张同学', '云计算G23-1', '15842087238', '信息工程学院', '云计算技术应用', false, '123456');
|
||||
INSERT INTO students (student_id, name, class_name, contact, college, major, password) VALUES
|
||||
('2023208145', '李同学', '云计算G23-1', '15842087237', '信息工程学院', '云计算技术应用', '123456'),
|
||||
('2023208146', '张同学', '云计算G23-1', '15842087238', '信息工程学院', '云计算技术应用', '123456');
|
||||
|
||||
INSERT INTO teachers (teacher_id, name, department, contact, password) VALUES
|
||||
('2023001', '王老师', '信息工程学院', '13912345678', '123456'),
|
||||
|
@ -4,7 +4,6 @@ import dao.LeaveRequestDAO;
|
||||
import model.ApprovalStatus;
|
||||
import model.LeaveRequest;
|
||||
import model.Student;
|
||||
import model.Teacher;
|
||||
import util.DatabaseUtil;
|
||||
|
||||
import java.sql.*;
|
||||
@ -12,9 +11,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LeaveRequestDAOImpl implements LeaveRequestDAO {
|
||||
private final StudentDAOImpl studentDAO = new StudentDAOImpl();
|
||||
private final TeacherDAOImpl teacherDAO = new TeacherDAOImpl();
|
||||
|
||||
@Override
|
||||
public int insert(LeaveRequest request) {
|
||||
String sql = "INSERT INTO leave_requests (student_id, start_time, end_time, status, " +
|
||||
@ -97,7 +93,7 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO {
|
||||
@Override
|
||||
public LeaveRequest findById(int id) {
|
||||
String sql = "SELECT lr.*, s.id as student_id, s.student_id as student_number, " +
|
||||
"s.name, s.class_name, s.contact, s.college, s.major, s.is_graduating " +
|
||||
"s.name, s.class_name, s.contact, s.college, s.major " +
|
||||
"FROM leave_requests lr " +
|
||||
"JOIN students s ON lr.student_id = s.id " +
|
||||
"WHERE lr.id = ?";
|
||||
@ -120,7 +116,7 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO {
|
||||
public List<LeaveRequest> findAll() {
|
||||
List<LeaveRequest> requests = new ArrayList<>();
|
||||
String sql = "SELECT lr.*, s.id as student_id, s.student_id as student_number, " +
|
||||
"s.name, s.class_name, s.contact, s.college, s.major, s.is_graduating " +
|
||||
"s.name, s.class_name, s.contact, s.college, s.major " +
|
||||
"FROM leave_requests lr " +
|
||||
"JOIN students s ON lr.student_id = s.id";
|
||||
try (Connection conn = DatabaseUtil.getConnection();
|
||||
@ -140,7 +136,7 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO {
|
||||
public List<LeaveRequest> findByStudentId(int studentId) {
|
||||
List<LeaveRequest> requests = new ArrayList<>();
|
||||
String sql = "SELECT lr.*, s.id as student_id, s.student_id as student_number, " +
|
||||
"s.name, s.class_name, s.contact, s.college, s.major, s.is_graduating " +
|
||||
"s.name, s.class_name, s.contact, s.college, s.major " +
|
||||
"FROM leave_requests lr " +
|
||||
"JOIN students s ON lr.student_id = s.id " +
|
||||
"WHERE lr.student_id = ? ORDER BY lr.request_time DESC";
|
||||
@ -163,7 +159,7 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO {
|
||||
public List<LeaveRequest> findByStatus(ApprovalStatus status) {
|
||||
List<LeaveRequest> requests = new ArrayList<>();
|
||||
String sql = "SELECT lr.*, s.id as student_id, s.student_id as student_number, " +
|
||||
"s.name, s.class_name, s.contact, s.college, s.major, s.is_graduating " +
|
||||
"s.name, s.class_name, s.contact, s.college, s.major " +
|
||||
"FROM leave_requests lr " +
|
||||
"JOIN students s ON lr.student_id = s.id " +
|
||||
"WHERE lr.status = ? ORDER BY lr.request_time DESC";
|
||||
@ -222,7 +218,6 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO {
|
||||
student.setContact(rs.getString("contact"));
|
||||
student.setCollege(rs.getString("college"));
|
||||
student.setMajor(rs.getString("major"));
|
||||
student.setGraduating(rs.getBoolean("is_graduating"));
|
||||
request.setStudent(student);
|
||||
|
||||
Timestamp approvalTime = rs.getTimestamp("approval_time");
|
||||
|
@ -15,7 +15,7 @@ public class StudentDAOImpl implements StudentDAO {
|
||||
|
||||
@Override
|
||||
public int insert(Student student) {
|
||||
String sql = "INSERT INTO students (student_id, name, class_name, contact, college, major, is_graduating, password) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
String sql = "INSERT INTO students (student_id, name, class_name, contact, college, major, password) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
||||
try (Connection conn = DatabaseUtil.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
|
||||
@ -25,8 +25,7 @@ public class StudentDAOImpl implements StudentDAO {
|
||||
stmt.setString(4, student.getContact());
|
||||
stmt.setString(5, student.getCollege());
|
||||
stmt.setString(6, student.getMajor());
|
||||
stmt.setBoolean(7, student.isGraduating());
|
||||
stmt.setString(8, student.getPassword());
|
||||
stmt.setString(7, student.getPassword());
|
||||
|
||||
int affectedRows = stmt.executeUpdate();
|
||||
if (affectedRows == 0) {
|
||||
@ -61,7 +60,7 @@ public class StudentDAOImpl implements StudentDAO {
|
||||
|
||||
@Override
|
||||
public int update(Student student) {
|
||||
String sql = "UPDATE students SET student_id = ?, name = ?, class_name = ?, contact = ?, college = ?, major = ?, is_graduating = ?, password = ? WHERE id = ?";
|
||||
String sql = "UPDATE students SET student_id = ?, name = ?, class_name = ?, contact = ?, college = ?, major = ?, password = ? WHERE id = ?";
|
||||
try (Connection conn = DatabaseUtil.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
|
||||
@ -71,9 +70,8 @@ public class StudentDAOImpl implements StudentDAO {
|
||||
stmt.setString(4, student.getContact());
|
||||
stmt.setString(5, student.getCollege());
|
||||
stmt.setString(6, student.getMajor());
|
||||
stmt.setBoolean(7, student.isGraduating());
|
||||
stmt.setString(8, student.getPassword());
|
||||
stmt.setInt(9, student.getId());
|
||||
stmt.setString(7, student.getPassword());
|
||||
stmt.setInt(8, student.getId());
|
||||
|
||||
return stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
@ -185,7 +183,6 @@ public class StudentDAOImpl implements StudentDAO {
|
||||
student.setContact(rs.getString("contact"));
|
||||
student.setCollege(rs.getString("college"));
|
||||
student.setMajor(rs.getString("major"));
|
||||
student.setGraduating(rs.getBoolean("is_graduating"));
|
||||
student.setPassword(rs.getString("password"));
|
||||
return student;
|
||||
}
|
||||
|
@ -11,30 +11,27 @@ public class Student {
|
||||
private String contact; // 联系方式
|
||||
private String college; // 学院
|
||||
private String major; // 专业
|
||||
private boolean isGraduating; // 是否毕业班
|
||||
private String password; // 登录密码
|
||||
|
||||
// Constructors
|
||||
public Student() {}
|
||||
|
||||
public Student(String studentId, String name, String className, String contact, String college, String major, boolean isGraduating) {
|
||||
public Student(String studentId, String name, String className, String contact, String college, String major) {
|
||||
this.studentId = studentId;
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
this.contact = contact;
|
||||
this.college = college;
|
||||
this.major = major;
|
||||
this.isGraduating = isGraduating;
|
||||
}
|
||||
|
||||
public Student(String studentId, String name, String className, String contact, String college, String major, boolean isGraduating, String password) {
|
||||
public Student(String studentId, String name, String className, String contact, String college, String major, String password) {
|
||||
this.studentId = studentId;
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
this.contact = contact;
|
||||
this.college = college;
|
||||
this.major = major;
|
||||
this.isGraduating = isGraduating;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@ -95,14 +92,6 @@ public class Student {
|
||||
this.major = major;
|
||||
}
|
||||
|
||||
public boolean isGraduating() {
|
||||
return isGraduating;
|
||||
}
|
||||
|
||||
public void setGraduating(boolean graduating) {
|
||||
isGraduating = graduating;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
@ -11,19 +11,6 @@ import java.util.List;
|
||||
public class TeacherService {
|
||||
private final TeacherDAO teacherDAO = DAOFactory.getTeacherDAO();
|
||||
|
||||
/**
|
||||
* 添加教师
|
||||
* @param teacher 教师信息
|
||||
* @return 是否添加成功
|
||||
*/
|
||||
public boolean addTeacher(Teacher teacher) {
|
||||
// 检查工号是否已存在
|
||||
if (teacherDAO.findByTeacherId(teacher.getTeacherId()) != null) {
|
||||
return false;
|
||||
}
|
||||
return teacherDAO.insert(teacher) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新教师信息
|
||||
* @param teacher 教师信息
|
||||
@ -43,15 +30,6 @@ public class TeacherService {
|
||||
return teacherDAO.update(teacher) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除教师
|
||||
* @param id 教师ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
public boolean deleteTeacher(int id) {
|
||||
return teacherDAO.deleteById(id) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询教师
|
||||
* @param id 教师ID
|
||||
@ -78,24 +56,6 @@ public class TeacherService {
|
||||
return teacherDAO.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门查询教师
|
||||
* @param department 部门名称
|
||||
* @return 教师列表
|
||||
*/
|
||||
public List<Teacher> getTeachersByDepartment(String department) {
|
||||
return teacherDAO.findByDepartment(department);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据姓名模糊查询教师
|
||||
* @param name 教师姓名
|
||||
* @return 教师列表
|
||||
*/
|
||||
public List<Teacher> searchTeachersByName(String name) {
|
||||
return teacherDAO.findByNameLike(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 教师登录
|
||||
* @param teacherId 教师工号
|
||||
|
Loading…
x
Reference in New Issue
Block a user