From 7b70a0366653abe167141f7bafaf88ac3596066a Mon Sep 17 00:00:00 2001 From: seahi Date: Tue, 17 Dec 2024 10:57:00 +0800 Subject: [PATCH] refactor: remove unused database columns --- sql/init.sql | 11 ++--------- src/dao/impl/LeaveRequestDAOImpl.java | 13 +++++-------- src/gui/LoginFrame.java | 2 -- src/gui/RequestDetailDialog.java | 2 -- src/model/LeaveRequest.java | 9 --------- 5 files changed, 7 insertions(+), 30 deletions(-) diff --git a/sql/init.sql b/sql/init.sql index 5a656f7..44bc164 100644 --- a/sql/init.sql +++ b/sql/init.sql @@ -13,9 +13,7 @@ CREATE TABLE IF NOT EXISTS students ( college VARCHAR(50) NOT NULL, -- 学院 major VARCHAR(50) NOT NULL, -- 专业 is_graduating BOOLEAN DEFAULT FALSE, -- 是否毕业班 - password VARCHAR(50) NOT NULL, -- 密码 - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + password VARCHAR(50) NOT NULL -- 密码 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学生信息表'; -- 创建教师表 @@ -25,9 +23,7 @@ CREATE TABLE IF NOT EXISTS teachers ( name VARCHAR(50) NOT NULL, -- 姓名 department VARCHAR(50) NOT NULL, -- 部门 contact VARCHAR(20), -- 联系方式 - password VARCHAR(50) NOT NULL, -- 密码 - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + password VARCHAR(50) NOT NULL -- 密码 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='教师信息表'; -- 创建请假申请表 @@ -41,14 +37,11 @@ CREATE TABLE IF NOT EXISTS leave_requests ( reason_type VARCHAR(50) NOT NULL, -- 外出事由类型 reason_detail TEXT, -- 详细事由 is_leaving_city BOOLEAN DEFAULT FALSE, -- 是否离津 - special_situation TEXT, -- 其他特殊情况 status VARCHAR(20) NOT NULL DEFAULT 'PENDING', -- 审批状态 approver_id INT, -- 审批人ID approval_comment TEXT, -- 审批意见 request_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- 申请时间 approval_time TIMESTAMP NULL, -- 审批时间 - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (student_id) REFERENCES students(id), FOREIGN KEY (approver_id) REFERENCES teachers(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='请假申请表'; diff --git a/src/dao/impl/LeaveRequestDAOImpl.java b/src/dao/impl/LeaveRequestDAOImpl.java index f88de5e..756298e 100644 --- a/src/dao/impl/LeaveRequestDAOImpl.java +++ b/src/dao/impl/LeaveRequestDAOImpl.java @@ -19,7 +19,7 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO { public int insert(LeaveRequest request) { String sql = "INSERT INTO leave_requests (student_id, start_time, end_time, status, " + "duration, location, reason_type, reason_detail, is_leaving_city, " + - "special_situation, request_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + "request_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; try (Connection conn = DatabaseUtil.getConnection(); PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { @@ -33,8 +33,7 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO { stmt.setString(7, request.getReasonType()); stmt.setString(8, request.getReasonDetail()); stmt.setBoolean(9, request.isLeavingCity()); - stmt.setString(10, request.getSpecialSituation()); - stmt.setTimestamp(11, new Timestamp(request.getRequestTime().getTime())); + stmt.setTimestamp(10, new Timestamp(request.getRequestTime().getTime())); int affectedRows = stmt.executeUpdate(); if (affectedRows == 0) { @@ -72,7 +71,7 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO { String sql = "UPDATE leave_requests SET student_id = ?, start_time = ?, " + "end_time = ?, status = ?, duration = ?, location = ?, " + "reason_type = ?, reason_detail = ?, is_leaving_city = ?, " + - "special_situation = ?, request_time = ? WHERE id = ?"; + "request_time = ? WHERE id = ?"; try (Connection conn = DatabaseUtil.getConnection(); PreparedStatement stmt = conn.prepareStatement(sql)) { @@ -85,9 +84,8 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO { stmt.setString(7, request.getReasonType()); stmt.setString(8, request.getReasonDetail()); stmt.setBoolean(9, request.isLeavingCity()); - stmt.setString(10, request.getSpecialSituation()); - stmt.setTimestamp(11, new Timestamp(request.getRequestTime().getTime())); - stmt.setInt(12, request.getId()); + stmt.setTimestamp(10, new Timestamp(request.getRequestTime().getTime())); + stmt.setInt(11, request.getId()); return stmt.executeUpdate(); } catch (SQLException e) { @@ -213,7 +211,6 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO { request.setReasonType(rs.getString("reason_type")); request.setReasonDetail(rs.getString("reason_detail")); request.setLeavingCity(rs.getBoolean("is_leaving_city")); - request.setSpecialSituation(rs.getString("special_situation")); request.setRequestTime(rs.getTimestamp("request_time")); // 设置学生信息 diff --git a/src/gui/LoginFrame.java b/src/gui/LoginFrame.java index 0383a7c..982ce10 100644 --- a/src/gui/LoginFrame.java +++ b/src/gui/LoginFrame.java @@ -8,8 +8,6 @@ import service.ServiceFactory; import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; public class LoginFrame extends JFrame { private JComboBox userTypeComboBox; diff --git a/src/gui/RequestDetailDialog.java b/src/gui/RequestDetailDialog.java index e2a60d9..a94717f 100644 --- a/src/gui/RequestDetailDialog.java +++ b/src/gui/RequestDetailDialog.java @@ -63,8 +63,6 @@ public class RequestDetailDialog extends JDialog { addInfoField(mainPanel, gbc, "外出事由:", currentRequest.getReasonType()); addInfoField(mainPanel, gbc, "详细事由:", currentRequest.getReasonDetail()); addInfoField(mainPanel, gbc, "是否离津:", currentRequest.isLeavingCity() ? "是" : "否"); - addInfoField(mainPanel, gbc, "其他特殊情况:", - currentRequest.getSpecialSituation() == null ? "" : currentRequest.getSpecialSituation()); addInfoField(mainPanel, gbc, "发起时间:", dateFormat.format(currentRequest.getRequestTime())); addInfoField(mainPanel, gbc, "审批状态:", currentRequest.getStatus().getDescription()); diff --git a/src/model/LeaveRequest.java b/src/model/LeaveRequest.java index 8b64866..94de8a3 100644 --- a/src/model/LeaveRequest.java +++ b/src/model/LeaveRequest.java @@ -15,7 +15,6 @@ public class LeaveRequest { private String reasonType; // 外出事由类型 private String reasonDetail; // 详细事由 private boolean isLeavingCity; // 是否离津 - private String specialSituation; // 其他特殊情况 private ApprovalStatus status; // 审批状态 private Teacher approver; // 审批人 private String approvalComment; // 审批意见 @@ -101,14 +100,6 @@ public class LeaveRequest { isLeavingCity = leavingCity; } - public String getSpecialSituation() { - return specialSituation; - } - - public void setSpecialSituation(String specialSituation) { - this.specialSituation = specialSituation; - } - public ApprovalStatus getStatus() { return status; }