fix: 教师无法审批错误
This commit is contained in:
parent
be0b49b3d1
commit
7fde34d238
@ -98,7 +98,9 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO {
|
||||
|
||||
@Override
|
||||
public LeaveRequest findById(int id) {
|
||||
String sql = "SELECT lr.*, s.* FROM leave_requests lr " +
|
||||
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 " +
|
||||
"FROM leave_requests lr " +
|
||||
"JOIN students s ON lr.student_id = s.id " +
|
||||
"WHERE lr.id = ?";
|
||||
try (Connection conn = DatabaseUtil.getConnection();
|
||||
@ -119,7 +121,9 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO {
|
||||
@Override
|
||||
public List<LeaveRequest> findAll() {
|
||||
List<LeaveRequest> requests = new ArrayList<>();
|
||||
String sql = "SELECT lr.*, s.* FROM leave_requests lr " +
|
||||
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 " +
|
||||
"FROM leave_requests lr " +
|
||||
"JOIN students s ON lr.student_id = s.id";
|
||||
try (Connection conn = DatabaseUtil.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
@ -137,7 +141,9 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO {
|
||||
@Override
|
||||
public List<LeaveRequest> findByStudentId(int studentId) {
|
||||
List<LeaveRequest> requests = new ArrayList<>();
|
||||
String sql = "SELECT lr.*, s.* FROM leave_requests lr " +
|
||||
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 " +
|
||||
"FROM leave_requests lr " +
|
||||
"JOIN students s ON lr.student_id = s.id " +
|
||||
"WHERE lr.student_id = ? ORDER BY lr.request_time DESC";
|
||||
try (Connection conn = DatabaseUtil.getConnection();
|
||||
@ -158,7 +164,9 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO {
|
||||
@Override
|
||||
public List<LeaveRequest> findByStatus(ApprovalStatus status) {
|
||||
List<LeaveRequest> requests = new ArrayList<>();
|
||||
String sql = "SELECT lr.*, s.* FROM leave_requests lr " +
|
||||
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 " +
|
||||
"FROM leave_requests lr " +
|
||||
"JOIN students s ON lr.student_id = s.id " +
|
||||
"WHERE lr.status = ? ORDER BY lr.request_time DESC";
|
||||
try (Connection conn = DatabaseUtil.getConnection();
|
||||
@ -211,10 +219,13 @@ public class LeaveRequestDAOImpl implements LeaveRequestDAO {
|
||||
// 设置学生信息
|
||||
Student student = new Student();
|
||||
student.setId(rs.getInt("student_id"));
|
||||
student.setStudentId(rs.getString("student_id"));
|
||||
student.setStudentId(rs.getString("student_number"));
|
||||
student.setName(rs.getString("name"));
|
||||
student.setClassName(rs.getString("class_name"));
|
||||
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");
|
||||
|
@ -13,17 +13,15 @@ import java.util.List;
|
||||
public class RequestDetailDialog extends JDialog {
|
||||
private final LeaveRequestService leaveRequestService;
|
||||
private LeaveRequest currentRequest;
|
||||
private Runnable onApprovalComplete; // 添加回调接口
|
||||
|
||||
public RequestDetailDialog(JFrame parent, String studentName) {
|
||||
public RequestDetailDialog(JFrame parent, int requestId, Runnable onApprovalComplete) {
|
||||
super(parent, "请假详情", true);
|
||||
this.leaveRequestService = ServiceFactory.getLeaveRequestService();
|
||||
this.onApprovalComplete = onApprovalComplete;
|
||||
|
||||
// 根据学生姓名获取请假信息
|
||||
List<LeaveRequest> requests = leaveRequestService.getAllLeaveRequests();
|
||||
this.currentRequest = requests.stream()
|
||||
.filter(r -> r.getStudent().getName().equals(studentName))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
// 根据ID获取请假信息
|
||||
this.currentRequest = leaveRequestService.getLeaveRequestById(requestId);
|
||||
|
||||
if (currentRequest == null) {
|
||||
JOptionPane.showMessageDialog(parent, "未找到请假信息!", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
@ -31,7 +29,7 @@ public class RequestDetailDialog extends JDialog {
|
||||
return;
|
||||
}
|
||||
|
||||
setSize(500, 700);
|
||||
setSize(350, 550);
|
||||
setLocationRelativeTo(parent);
|
||||
setResizable(false);
|
||||
|
||||
@ -49,13 +47,11 @@ public class RequestDetailDialog extends JDialog {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
// 学生基本信息
|
||||
addInfoField(mainPanel, gbc, "审核进度:", "班主任");
|
||||
addInfoField(mainPanel, gbc, "学院:", currentRequest.getStudent().getCollege());
|
||||
addInfoField(mainPanel, gbc, "专业:", currentRequest.getStudent().getMajor());
|
||||
addInfoField(mainPanel, gbc, "班级:", currentRequest.getStudent().getClassName());
|
||||
addInfoField(mainPanel, gbc, "姓名:", currentRequest.getStudent().getName());
|
||||
addInfoField(mainPanel, gbc, "学号:", currentRequest.getStudent().getStudentId());
|
||||
addInfoField(mainPanel, gbc, "手机号:", currentRequest.getStudent().getPhone());
|
||||
|
||||
// 请假信息
|
||||
addInfoField(mainPanel, gbc, "申请外出时间:", dateFormat.format(currentRequest.getStartTime()));
|
||||
@ -68,10 +64,10 @@ public class RequestDetailDialog extends JDialog {
|
||||
addInfoField(mainPanel, gbc, "其他特殊情况:",
|
||||
currentRequest.getSpecialSituation() == null ? "" : currentRequest.getSpecialSituation());
|
||||
addInfoField(mainPanel, gbc, "发起时间:", dateFormat.format(currentRequest.getRequestTime()));
|
||||
addInfoField(mainPanel, gbc, "审批状态:", currentRequest.getStatus().getDescription());
|
||||
|
||||
// 如果已经审批过,显示审批信息
|
||||
if (currentRequest.getStatus() != ApprovalStatus.PENDING) {
|
||||
addInfoField(mainPanel, gbc, "审批状态:", currentRequest.getStatus().getDescription());
|
||||
if (currentRequest.getApprovalComment() != null) {
|
||||
addInfoField(mainPanel, gbc, "审批意见:", currentRequest.getApprovalComment());
|
||||
}
|
||||
@ -81,7 +77,7 @@ public class RequestDetailDialog extends JDialog {
|
||||
}
|
||||
|
||||
// 审批按钮
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
|
||||
JPanel actionButtonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
|
||||
JButton approveButton = new JButton("通过");
|
||||
JButton rejectButton = new JButton("驳回");
|
||||
|
||||
@ -94,52 +90,116 @@ public class RequestDetailDialog extends JDialog {
|
||||
approveButton.setPreferredSize(new Dimension(100, 30));
|
||||
rejectButton.setPreferredSize(new Dimension(100, 30));
|
||||
|
||||
// 设置按钮颜色
|
||||
// 设置按钮样式
|
||||
approveButton.setBackground(new Color(39, 174, 96));
|
||||
approveButton.setForeground(Color.WHITE);
|
||||
rejectButton.setBackground(new Color(231, 76, 60));
|
||||
rejectButton.setForeground(Color.WHITE);
|
||||
// approveButton.setForeground(Color.WHITE);
|
||||
|
||||
buttonPanel.add(approveButton);
|
||||
buttonPanel.add(rejectButton);
|
||||
rejectButton.setBackground(new Color(231, 76, 60));
|
||||
// rejectButton.setForeground(Color.WHITE);
|
||||
|
||||
actionButtonPanel.add(approveButton);
|
||||
actionButtonPanel.add(rejectButton);
|
||||
|
||||
// 添加按钮面板
|
||||
gbc.insets = new Insets(20, 10, 10, 10);
|
||||
mainPanel.add(buttonPanel, gbc);
|
||||
mainPanel.add(actionButtonPanel, gbc);
|
||||
|
||||
// 添加事件监听
|
||||
approveButton.addActionListener(e -> {
|
||||
int result = JOptionPane.showConfirmDialog(
|
||||
this,
|
||||
"确定通过该请假申请吗?",
|
||||
"确认",
|
||||
JOptionPane.YES_NO_OPTION
|
||||
);
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
leaveRequestService.approveLeaveRequest(
|
||||
currentRequest.getId(),
|
||||
ApprovalStatus.APPROVED,
|
||||
"已通过"
|
||||
);
|
||||
dispose();
|
||||
}
|
||||
// 创建一个自定义对话框
|
||||
JDialog approveDialog = new JDialog(this, "审批意见", true);
|
||||
approveDialog.setLayout(new BorderLayout());
|
||||
approveDialog.setSize(300, 200);
|
||||
approveDialog.setLocationRelativeTo(this);
|
||||
|
||||
JPanel inputPanel = new JPanel(new BorderLayout(10, 10));
|
||||
inputPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
|
||||
JLabel label = new JLabel("请输入审批意见:");
|
||||
JTextArea commentArea = new JTextArea(4, 20);
|
||||
commentArea.setLineWrap(true);
|
||||
commentArea.setWrapStyleWord(true);
|
||||
commentArea.setText("同意");
|
||||
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
JButton confirmButton = new JButton("确定");
|
||||
JButton cancelButton = new JButton("取消");
|
||||
|
||||
confirmButton.addActionListener(event -> {
|
||||
String comment = commentArea.getText().trim();
|
||||
if (!comment.isEmpty()) {
|
||||
leaveRequestService.approveLeaveRequest(
|
||||
currentRequest.getId(),
|
||||
ApprovalStatus.APPROVED,
|
||||
comment
|
||||
);
|
||||
approveDialog.dispose();
|
||||
dispose();
|
||||
if (onApprovalComplete != null) {
|
||||
onApprovalComplete.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cancelButton.addActionListener(event -> approveDialog.dispose());
|
||||
|
||||
buttonPanel.add(confirmButton);
|
||||
buttonPanel.add(cancelButton);
|
||||
|
||||
inputPanel.add(label, BorderLayout.NORTH);
|
||||
inputPanel.add(new JScrollPane(commentArea), BorderLayout.CENTER);
|
||||
inputPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
approveDialog.add(inputPanel);
|
||||
approveDialog.setVisible(true);
|
||||
});
|
||||
|
||||
rejectButton.addActionListener(e -> {
|
||||
String reason = JOptionPane.showInputDialog(
|
||||
this,
|
||||
"请输入驳回原因:",
|
||||
"驳回原因",
|
||||
JOptionPane.QUESTION_MESSAGE
|
||||
);
|
||||
if (reason != null && !reason.trim().isEmpty()) {
|
||||
leaveRequestService.approveLeaveRequest(
|
||||
currentRequest.getId(),
|
||||
ApprovalStatus.REJECTED,
|
||||
reason
|
||||
);
|
||||
dispose();
|
||||
}
|
||||
// 创建一个自定义对话框
|
||||
JDialog rejectDialog = new JDialog(this, "驳回原因", true);
|
||||
rejectDialog.setLayout(new BorderLayout());
|
||||
rejectDialog.setSize(300, 200);
|
||||
rejectDialog.setLocationRelativeTo(this);
|
||||
|
||||
JPanel inputPanel = new JPanel(new BorderLayout(10, 10));
|
||||
inputPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
|
||||
JLabel label = new JLabel("请输入驳回原因:");
|
||||
JTextArea commentArea = new JTextArea(4, 20);
|
||||
commentArea.setLineWrap(true);
|
||||
commentArea.setWrapStyleWord(true);
|
||||
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
JButton confirmButton = new JButton("确定");
|
||||
JButton cancelButton = new JButton("取消");
|
||||
|
||||
confirmButton.addActionListener(event -> {
|
||||
String comment = commentArea.getText().trim();
|
||||
if (!comment.isEmpty()) {
|
||||
leaveRequestService.approveLeaveRequest(
|
||||
currentRequest.getId(),
|
||||
ApprovalStatus.REJECTED,
|
||||
comment
|
||||
);
|
||||
rejectDialog.dispose();
|
||||
dispose();
|
||||
if (onApprovalComplete != null) {
|
||||
onApprovalComplete.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cancelButton.addActionListener(event -> rejectDialog.dispose());
|
||||
|
||||
buttonPanel.add(confirmButton);
|
||||
buttonPanel.add(cancelButton);
|
||||
|
||||
inputPanel.add(label, BorderLayout.NORTH);
|
||||
inputPanel.add(new JScrollPane(commentArea), BorderLayout.CENTER);
|
||||
inputPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
rejectDialog.add(inputPanel);
|
||||
rejectDialog.setVisible(true);
|
||||
});
|
||||
|
||||
// 添加滚动面板
|
||||
|
@ -11,6 +11,8 @@ import javax.swing.table.TableColumnModel;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
@ -46,7 +48,9 @@ public class TeacherMainFrame extends JFrame {
|
||||
|
||||
// 状态过滤器
|
||||
JPanel filterPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
String[] statuses = {"全部", "待审批", "已通过", "已驳回"};
|
||||
String[] statuses = {"全部", ApprovalStatus.PENDING.getDescription(),
|
||||
ApprovalStatus.APPROVED.getDescription(),
|
||||
ApprovalStatus.REJECTED.getDescription()};
|
||||
statusFilter = new JComboBox<>(statuses);
|
||||
statusFilter.addActionListener(e -> loadLeaveRequests());
|
||||
filterPanel.add(statusFilter);
|
||||
@ -62,7 +66,7 @@ public class TeacherMainFrame extends JFrame {
|
||||
topPanel.add(filterPanel, BorderLayout.SOUTH);
|
||||
|
||||
// 表格
|
||||
String[] columnNames = {"姓名", "班级", "状态", "申请时间", "外出事由"};
|
||||
String[] columnNames = {"ID", "姓名", "班级", "状态", "申请时间", "外出事由"};
|
||||
tableModel = new DefaultTableModel(columnNames, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
@ -79,11 +83,12 @@ public class TeacherMainFrame extends JFrame {
|
||||
|
||||
// 设置列宽
|
||||
TableColumnModel columnModel = requestTable.getColumnModel();
|
||||
columnModel.getColumn(0).setPreferredWidth(50); // 姓名
|
||||
columnModel.getColumn(1).setPreferredWidth(90); // 班级
|
||||
columnModel.getColumn(2).setPreferredWidth(50); // 状态
|
||||
columnModel.getColumn(3).setPreferredWidth(100); // 申请时间
|
||||
columnModel.getColumn(4).setPreferredWidth(60); // 外出事由
|
||||
columnModel.getColumn(0).setPreferredWidth(40); // ID
|
||||
columnModel.getColumn(1).setPreferredWidth(50); // 姓名
|
||||
columnModel.getColumn(2).setPreferredWidth(90); // 班级
|
||||
columnModel.getColumn(3).setPreferredWidth(50); // 状态
|
||||
columnModel.getColumn(4).setPreferredWidth(100); // 申请时间
|
||||
columnModel.getColumn(5).setPreferredWidth(60); // 外出事由
|
||||
|
||||
// 分页控制
|
||||
JPanel pagePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
@ -94,18 +99,73 @@ public class TeacherMainFrame extends JFrame {
|
||||
pagePanel.add(pageLabel);
|
||||
pagePanel.add(nextButton);
|
||||
|
||||
// 操作按钮
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
JButton approveButton = new JButton("通过");
|
||||
JButton rejectButton = new JButton("驳回");
|
||||
|
||||
approveButton.setPreferredSize(new Dimension(80, 30));
|
||||
rejectButton.setPreferredSize(new Dimension(80, 30));
|
||||
|
||||
// 设置按钮颜色
|
||||
approveButton.setBackground(new Color(39, 174, 96));
|
||||
approveButton.setForeground(Color.WHITE);
|
||||
rejectButton.setBackground(new Color(231, 76, 60));
|
||||
rejectButton.setForeground(Color.WHITE);
|
||||
|
||||
buttonPanel.add(approveButton);
|
||||
buttonPanel.add(rejectButton);
|
||||
|
||||
// 默认禁用按钮
|
||||
approveButton.setEnabled(false);
|
||||
rejectButton.setEnabled(false);
|
||||
|
||||
// 表格选择监听器
|
||||
requestTable.getSelectionModel().addListSelectionListener(e -> {
|
||||
if (!e.getValueIsAdjusting() && requestTable.getSelectedRow() != -1) {
|
||||
String statusText = (String) tableModel.getValueAt(requestTable.getSelectedRow(), 3);
|
||||
boolean isPending = false;
|
||||
for (ApprovalStatus s : ApprovalStatus.values()) {
|
||||
if (s.getDescription().equals(statusText)) {
|
||||
isPending = (s == ApprovalStatus.PENDING);
|
||||
break;
|
||||
}
|
||||
}
|
||||
approveButton.setEnabled(isPending);
|
||||
rejectButton.setEnabled(isPending);
|
||||
}
|
||||
});
|
||||
|
||||
// 按钮点击事件
|
||||
approveButton.addActionListener(e -> {
|
||||
if (requestTable.getSelectedRow() != -1) {
|
||||
showRequestDetails(requestTable.getSelectedRow());
|
||||
}
|
||||
});
|
||||
|
||||
rejectButton.addActionListener(e -> {
|
||||
if (requestTable.getSelectedRow() != -1) {
|
||||
showRequestDetails(requestTable.getSelectedRow());
|
||||
}
|
||||
});
|
||||
|
||||
// 添加到主面板
|
||||
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||
mainPanel.add(topPanel, BorderLayout.NORTH);
|
||||
mainPanel.add(new JScrollPane(requestTable), BorderLayout.CENTER);
|
||||
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
mainPanel.add(pagePanel, BorderLayout.SOUTH);
|
||||
|
||||
// 添加事件监听
|
||||
searchButton.addActionListener(e -> loadLeaveRequests());
|
||||
|
||||
requestTable.getSelectionModel().addListSelectionListener(e -> {
|
||||
if (!e.getValueIsAdjusting() && requestTable.getSelectedRow() != -1) {
|
||||
showRequestDetails(requestTable.getSelectedRow());
|
||||
// 使用鼠标监听器替代选择监听器,实现双击打开详情
|
||||
requestTable.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() == 2 && requestTable.getSelectedRow() != -1) {
|
||||
showRequestDetails(requestTable.getSelectedRow());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -134,16 +194,11 @@ public class TeacherMainFrame extends JFrame {
|
||||
requests = leaveRequestService.getAllLeaveRequests();
|
||||
} else {
|
||||
ApprovalStatus status = null;
|
||||
switch (statusText) {
|
||||
case "待审批":
|
||||
status = ApprovalStatus.PENDING;
|
||||
break;
|
||||
case "已通过":
|
||||
status = ApprovalStatus.APPROVED;
|
||||
break;
|
||||
case "已驳回":
|
||||
status = ApprovalStatus.REJECTED;
|
||||
for (ApprovalStatus s : ApprovalStatus.values()) {
|
||||
if (s.getDescription().equals(statusText)) {
|
||||
status = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
requests = leaveRequestService.getLeaveRequestsByStatus(status);
|
||||
}
|
||||
@ -158,6 +213,7 @@ public class TeacherMainFrame extends JFrame {
|
||||
// 添加到表格
|
||||
for (LeaveRequest request : requests) {
|
||||
Object[] row = {
|
||||
request.getId(),
|
||||
request.getStudent().getName(),
|
||||
request.getStudent().getClassName(),
|
||||
request.getStatus().getDescription(),
|
||||
@ -170,7 +226,11 @@ public class TeacherMainFrame extends JFrame {
|
||||
|
||||
private void showRequestDetails(int row) {
|
||||
// 创建详情对话框
|
||||
RequestDetailDialog dialog = new RequestDetailDialog(this, tableModel.getValueAt(row, 0).toString());
|
||||
RequestDetailDialog dialog = new RequestDetailDialog(
|
||||
this,
|
||||
((Number)tableModel.getValueAt(row, 0)).intValue(), // 获取ID
|
||||
() -> loadLeaveRequests() // 添加刷新列表的回调
|
||||
);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,6 @@ public class LeaveRequestService {
|
||||
return leaveRequestDAO.findByStatus(status);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有请假申请
|
||||
* @return 请假申请列表
|
||||
@ -88,6 +87,15 @@ public class LeaveRequestService {
|
||||
return leaveRequestDAO.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取请假申请
|
||||
* @param requestId 请假申请ID
|
||||
* @return 请假申请信息
|
||||
*/
|
||||
public LeaveRequest getLeaveRequestById(int requestId) {
|
||||
return leaveRequestDAO.findById(requestId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查请假时间是否合理
|
||||
* @param startTime 开始时间
|
||||
|
Loading…
x
Reference in New Issue
Block a user