commit 2e741987bf228388220d553c75b4cf69e8fb9229 Author: yang <3396822982@qq.com> Date: Tue Dec 24 14:00:56 2024 +0800 完成Day2 diff --git a/.idea/1 b/.idea/1 new file mode 100644 index 0000000..e0844bc --- /dev/null +++ b/.idea/1 @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib.xml b/.idea/libraries/lib.xml new file mode 100644 index 0000000..fa8838a --- /dev/null +++ b/.idea/libraries/lib.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e0844bc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b8556e0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..11f316c --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1734415810914 + + + + + + \ No newline at end of file diff --git a/AbsenceManager.iml b/AbsenceManager.iml new file mode 100644 index 0000000..fb8e866 --- /dev/null +++ b/AbsenceManager.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/hamcrest-core-1.3.jar b/lib/hamcrest-core-1.3.jar new file mode 100644 index 0000000..9d5fe16 Binary files /dev/null and b/lib/hamcrest-core-1.3.jar differ diff --git a/lib/junit-4.13.2.jar b/lib/junit-4.13.2.jar new file mode 100644 index 0000000..6da55d8 Binary files /dev/null and b/lib/junit-4.13.2.jar differ diff --git a/lib/mysql-connector-java-8.0.11.jar b/lib/mysql-connector-java-8.0.11.jar new file mode 100644 index 0000000..c3b5f70 Binary files /dev/null and b/lib/mysql-connector-java-8.0.11.jar differ diff --git a/out/production/AbsenceManager/model/ApprovalStatus.class b/out/production/AbsenceManager/model/ApprovalStatus.class new file mode 100644 index 0000000..cfeede6 Binary files /dev/null and b/out/production/AbsenceManager/model/ApprovalStatus.class differ diff --git a/out/production/AbsenceManager/model/LeaveRequest.class b/out/production/AbsenceManager/model/LeaveRequest.class new file mode 100644 index 0000000..01952c7 Binary files /dev/null and b/out/production/AbsenceManager/model/LeaveRequest.class differ diff --git a/out/production/AbsenceManager/model/Student.class b/out/production/AbsenceManager/model/Student.class new file mode 100644 index 0000000..a169c3f Binary files /dev/null and b/out/production/AbsenceManager/model/Student.class differ diff --git a/out/production/AbsenceManager/model/Teacher.class b/out/production/AbsenceManager/model/Teacher.class new file mode 100644 index 0000000..fcc0bbb Binary files /dev/null and b/out/production/AbsenceManager/model/Teacher.class differ diff --git a/out/production/AbsenceManager/test/model/TeacherTest.class b/out/production/AbsenceManager/test/model/TeacherTest.class new file mode 100644 index 0000000..f1b3c20 Binary files /dev/null and b/out/production/AbsenceManager/test/model/TeacherTest.class differ diff --git a/out/production/AbsenceManager/test/util/TestDatabaseUtil.class b/out/production/AbsenceManager/test/util/TestDatabaseUtil.class new file mode 100644 index 0000000..b57760c Binary files /dev/null and b/out/production/AbsenceManager/test/util/TestDatabaseUtil.class differ diff --git a/out/production/AbsenceManager/util/DatabaseUtil.class b/out/production/AbsenceManager/util/DatabaseUtil.class new file mode 100644 index 0000000..ae4d74f Binary files /dev/null and b/out/production/AbsenceManager/util/DatabaseUtil.class differ diff --git a/sql/init.sql b/sql/init.sql new file mode 100644 index 0000000..05b8626 --- /dev/null +++ b/sql/init.sql @@ -0,0 +1,68 @@ +-- 创建数据库 +CREATE DATABASE IF NOT EXISTS absence_manager DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +USE absence_manager; + +-- 创建学生表 +CREATE TABLE IF NOT EXISTS students ( + id INT PRIMARY KEY AUTO_INCREMENT, + student_id VARCHAR(20) UNIQUE NOT NULL, -- 学号 + name VARCHAR(50) NOT NULL, -- 姓名 + class_name VARCHAR(50) NOT NULL, -- 班级 + contact VARCHAR(20), -- 联系方式 + college VARCHAR(50) NOT NULL, -- 学院 + major VARCHAR(50) NOT NULL, -- 专业 + password VARCHAR(50) NOT NULL -- 密码 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学生信息表'; + +-- 创建教师表 +CREATE TABLE IF NOT EXISTS teachers ( + id INT PRIMARY KEY AUTO_INCREMENT, + teacher_id VARCHAR(20) UNIQUE NOT NULL, -- 工号 + name VARCHAR(50) NOT NULL, -- 姓名 + department VARCHAR(50) NOT NULL, -- 部门 + contact VARCHAR(20), -- 联系方式 + password VARCHAR(50) NOT NULL -- 密码 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='教师信息表'; + +-- 创建请假申请表 +CREATE TABLE IF NOT EXISTS leave_requests ( + id INT PRIMARY KEY AUTO_INCREMENT, + student_id INT NOT NULL, -- 关联学生ID + start_time DATETIME NOT NULL, -- 开始时间 + end_time DATETIME NOT NULL, -- 结束时间 + duration DECIMAL(5,2) NOT NULL, -- 时长 + location VARCHAR(100) NOT NULL, -- 外出地址 + reason_type VARCHAR(50) NOT NULL, -- 外出事由类型 + reason_detail TEXT, -- 详细事由 + is_leaving_city BOOLEAN DEFAULT FALSE, -- 是否离津 + status VARCHAR(20) NOT NULL DEFAULT 'PENDING', -- 审批状态 + approver_id INT, -- 审批人ID + approval_comment TEXT, -- 审批意见 + request_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- 申请时间 + approval_time TIMESTAMP NULL, -- 审批时间 + FOREIGN KEY (student_id) REFERENCES students(id), + FOREIGN KEY (approver_id) REFERENCES teachers(id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='请假申请表'; + +-- 插入示例数据 +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'), +('2023002', '李老师', '信息工程学院', '13912345679', '123456'); + +-- 插入请假申请示例数据 +INSERT INTO leave_requests (student_id, start_time, end_time, duration, location, reason_type, reason_detail, is_leaving_city, status, approver_id, approval_comment, request_time) VALUES +(1, '2024-01-15 08:00:00', '2024-01-15 17:00:00', 9.00, '天津市河西区图书馆', '学习', '去图书馆学习准备考试', false, 'APPROVED', 1, '同意', '2024-01-14 10:00:00'), +(2, '2024-01-16 13:00:00', '2024-01-16 17:30:00', 4.50, '天津市南开医院', '就医', '牙科复诊', false, 'APPROVED', 1, '注意安全', '2024-01-15 09:30:00'), +(1, '2024-01-17 09:00:00', '2024-01-17 12:00:00', 3.00, '天津市档案馆', '办事', '办理个人档案', false, 'PENDING', null, null, '2024-01-16 16:20:00'), +(2, '2024-01-18 14:00:00', '2024-01-18 18:00:00', 4.00, '和平区文化中心', '活动', '参加志愿者活动', false, 'REJECTED', 2, '活动时间与课程冲突', '2024-01-17 11:15:00'), +(1, '2024-01-19 10:00:00', '2024-01-19 16:00:00', 6.00, '天津站', '返乡', '购买返乡车票', true, 'APPROVED', 2, '请注意防疫', '2024-01-18 14:40:00'), +(2, '2024-01-20 09:30:00', '2024-01-20 11:30:00', 2.00, '河西区人才市场', '求职', '参加招聘会', false, 'PENDING', null, null, '2024-01-19 17:00:00'), +(1, '2024-01-21 13:00:00', '2024-01-21 17:00:00', 4.00, '天津市第一中心医院', '就医', '例行体检', false, 'APPROVED', 1, '准假', '2024-01-20 10:25:00'), +(2, '2024-01-22 08:00:00', '2024-01-22 18:00:00', 10.00, '滨海新区图书馆', '实习', '企业实地考察', false, 'PENDING', null, null, '2024-01-21 15:30:00'), +(1, '2024-01-23 14:00:00', '2024-01-23 16:00:00', 2.00, '南开区政务中心', '办事', '办理身份证', false, 'APPROVED', 2, '同意', '2024-01-22 09:45:00'), +(2, '2024-01-24 09:00:00', '2024-01-24 18:00:00', 9.00, '天津市人民医院', '就医', '陪同父亲做检查', false, 'PENDING', null, null, '2024-01-23 16:50:00'); diff --git a/src/model/ApprovalStatus.java b/src/model/ApprovalStatus.java new file mode 100644 index 0000000..09c2e77 --- /dev/null +++ b/src/model/ApprovalStatus.java @@ -0,0 +1,21 @@ + +package model; + +/** + * 请假审批状态枚举类 + */ +public enum ApprovalStatus { + PENDING("待审批"), // 等待审批 + APPROVED("已批准"), // 已经批准 + REJECTED("已驳回"); // 已经驳回 + + private final String description; // 状态描述 + + ApprovalStatus(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } +} \ No newline at end of file diff --git a/src/model/LeaveRequest.java b/src/model/LeaveRequest.java new file mode 100644 index 0000000..77ececa --- /dev/null +++ b/src/model/LeaveRequest.java @@ -0,0 +1,155 @@ + +package model; + +import java.util.Date; + +public class LeaveRequest { + private int id; // 数据库主键ID + private Student student; // 学生信息 + private Date startTime; // 开始时间 + private Date endTime; // 结束时间 + private double duration; // 时长 + private String location; // 外出地址 + private String reasonType; // 外出事由类型 + private String reasonDetail; // 详细事由 + private boolean isLeavingCity; // 是否离津 + private ApprovalStatus status; // 审批状态 + private Teacher approver; // 审批人 + private String approvalComment; // 审批意见 + private Date requestTime; // 申请时间 + private Date approvalTime; // 审批时间 + + // 构造方法 + + public LeaveRequest(int id, Student student, Date startTime, Date endTime, double duration, String location, + String reasonType, String reasonDetail, boolean isLeavingCity, ApprovalStatus status, + Teacher approver, String approvalComment, Date requestTime, Date approvalTime) { + this.id = id; + this.student = student; + this.startTime = startTime; + this.endTime = endTime; + this.duration = duration; + this.location = location; + this.reasonType = reasonType; + this.reasonDetail = reasonDetail; + this.isLeavingCity = isLeavingCity; + this.status = status; + this.approver = approver; + this.approvalComment = approvalComment; + this.requestTime = requestTime; + this.approvalTime = approvalTime; + } + // getter和setter方法 + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Student getStudent() { + return student; + } + + public void setStudent(Student student) { + this.student = student; + } + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public Date getEndTime() { + return endTime; + } + + public void setEndTime(Date endTime) { + this.endTime = endTime; + } + + public double getDuration() { + return duration; + } + + public void setDuration(double duration) { + this.duration = duration; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getReasonType() { + return reasonType; + } + + public void setReasonType(String reasonType) { + this.reasonType = reasonType; + } + + public String getReasonDetail() { + return reasonDetail; + } + + public void setReasonDetail(String reasonDetail) { + this.reasonDetail = reasonDetail; + } + + public boolean isLeavingCity() { + return isLeavingCity; + } + + public void setLeavingCity(boolean leavingCity) { + isLeavingCity = leavingCity; + } + + public ApprovalStatus getStatus() { + return status; + } + + public void setStatus(ApprovalStatus status) { + this.status = status; + } + + public Teacher getApprover() { + return approver; + } + + public void setApprover(Teacher approver) { + this.approver = approver; + } + + public String getApprovalComment() { + return approvalComment; + } + + public void setApprovalComment(String approvalComment) { + this.approvalComment = approvalComment; + } + + public Date getRequestTime() { + return requestTime; + } + + public void setRequestTime(Date requestTime) { + this.requestTime = requestTime; + } + + public Date getApprovalTime() { + return approvalTime; + } + + public void setApprovalTime(Date approvalTime) { + this.approvalTime = approvalTime; + } +} \ No newline at end of file diff --git a/src/model/Student.java b/src/model/Student.java new file mode 100644 index 0000000..ce1d2fe --- /dev/null +++ b/src/model/Student.java @@ -0,0 +1,92 @@ +package model; + +public class Student { + private int id; // 数据库主键ID + private String studentId; // 学号 + private String name; // 学生姓名 + private String className; // 班级 + private String contact; // 联系方式 + private String college; // 学院 + private String major; // 专业 + private String password; // 登录密码 + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getStudentId() { + return studentId; + } + + public void setStudentId(String studentId) { + this.studentId = studentId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + public String getContact() { + return contact; + } + + public void setContact(String contact) { + this.contact = contact; + } + + public String getCollege() { + return college; + } + + public void setCollege(String college) { + this.college = college; + } + + public String getMajor() { + return major; + } + + public void setMajor(String major) { + this.major = major; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public Student(int id, String studentId, String name, String className, String contact, String college, String major, String password) { + this.id = id; + this.studentId = studentId; + this.name = name; + this.className = className; + this.contact = contact; + this.college = college; + this.major = major; + this.password = password; + } +// 构造方法 + + + + // getter和setter方法 +} diff --git a/src/model/Teacher.java b/src/model/Teacher.java new file mode 100644 index 0000000..01bfb66 --- /dev/null +++ b/src/model/Teacher.java @@ -0,0 +1,79 @@ +package model; + +/** + * 教师实体类 + */ +public class Teacher { + private int id; // 数据库主键ID + private String teacherId; // 教师工号 + private String name; // 教师姓名 + private String department; // 所属部门 + private String contact; // 联系方式 + private String password; // 登录密码 + + // 使用 IDE 自动生成以下内容: + public Teacher( String teacherId, String name, String department, String contact, + String password) { + + this.teacherId = teacherId; + this.name = name; + this.department = department; + this.contact = contact; + this.password = password; + } + + public Teacher() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getTeacherId() { + return teacherId; + } + + public void setTeacherId(String teacherId) { + this.teacherId = teacherId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDepartment() { + return department; + } + + public void setDepartment(String department) { + this.department = department; + } + + public String getContact() { + return contact; + } + + public void setContact(String contact) { + this.contact = contact; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + + // 构造方法 + // getter 和 setter 方法 +} \ No newline at end of file diff --git a/src/test/model/TeacherTest.java b/src/test/model/TeacherTest.java new file mode 100644 index 0000000..64c7de7 --- /dev/null +++ b/src/test/model/TeacherTest.java @@ -0,0 +1,50 @@ +package test.model; + +import model.Teacher; +import org.junit.Test; +import static org.junit.Assert.*; + +public class TeacherTest { + + @Test + public void testConstructorAndGetters() { + String teacherId = "T001"; + String name = "张老师"; + String department = "计算机系"; + String contact = "13800138000"; + String password = "password123"; + + Teacher teacher = new Teacher(teacherId, name, department, contact, password); + + assertEquals("教师工号应匹配", teacherId, teacher.getTeacherId()); + assertEquals("教师姓名应匹配", name, teacher.getName()); + assertEquals("所属部门应匹配", department, teacher.getDepartment()); + assertEquals("联系方式应匹配", contact, teacher.getContact()); + assertEquals("密码应匹配", password, teacher.getPassword()); + } + + @Test + public void testSetters() { + Teacher teacher = new Teacher(); + + String teacherId = "T002"; + String name = "李老师"; + String department = "数学系"; + String contact = "13900139000"; + String password = "newpass123"; + + + teacher.setTeacherId(teacherId); + teacher.setName(name); + teacher.setDepartment(department); + teacher.setContact(contact); + teacher.setPassword(password); + + + assertEquals("教师工号应匹配", teacherId, teacher.getTeacherId()); + assertEquals("教师姓名应匹配", name, teacher.getName()); + assertEquals("所属部门应匹配", department, teacher.getDepartment()); + assertEquals("联系方式应匹配", contact, teacher.getContact()); + assertEquals("密码应匹配", password, teacher.getPassword()); + } +} \ No newline at end of file diff --git a/src/test/util/TestDatabaseUtil.java b/src/test/util/TestDatabaseUtil.java new file mode 100644 index 0000000..8126b72 --- /dev/null +++ b/src/test/util/TestDatabaseUtil.java @@ -0,0 +1,19 @@ +package test.util; +import org.junit.Test; +import java.sql.Connection; +import util.DatabaseUtil; +import static org.junit.Assert.*; +import java.sql.SQLException; + +public class TestDatabaseUtil { + @Test + public void testGetConnection() { + try (Connection connection = DatabaseUtil.getConnection()) { + + assertNotNull("数据库连接不应该为空", connection); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/util/DatabaseUtil.java b/src/util/DatabaseUtil.java new file mode 100644 index 0000000..d2804b1 --- /dev/null +++ b/src/util/DatabaseUtil.java @@ -0,0 +1,24 @@ +package util; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class DatabaseUtil { + private static final String URL = + "jdbc:mysql://localhost:8200/absence_manager?useSSL=false&serverTimezone=UTC" + + "&characterEncoding=UTF-8"; + private static final String USERNAME = "root"; + private static final String PASSWORD = "admin"; + + static { + try { + Class.forName("com.mysql.cj.jdbc.Driver"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + + public static Connection getConnection() throws SQLException { + return DriverManager.getConnection(URL, USERNAME, PASSWORD); + } +}