refactor: remove unused database columns

This commit is contained in:
seahi 2024-12-17 10:57:00 +08:00
parent 5877055879
commit 7b70a03666
5 changed files with 7 additions and 30 deletions

View File

@ -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='请假申请表';

View File

@ -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"));
// 设置学生信息

View File

@ -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<String> userTypeComboBox;

View File

@ -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());

View File

@ -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;
}