diff --git a/.idea/libraries/mysql_connector_java_8_0_25.xml b/.idea/libraries/mysql_connector_java_8_0_25.xml new file mode 100644 index 0000000..964b2b5 --- /dev/null +++ b/.idea/libraries/mysql_connector_java_8_0_25.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/slf4j_simple.xml b/.idea/libraries/slf4j_simple.xml new file mode 100644 index 0000000..17c0eba --- /dev/null +++ b/.idea/libraries/slf4j_simple.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/zaxxer_HikariCP.xml b/.idea/libraries/zaxxer_HikariCP.xml new file mode 100644 index 0000000..c8c41d5 --- /dev/null +++ b/.idea/libraries/zaxxer_HikariCP.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..1e1334b --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Library/src/main/ClassroomInteraction.Library.main.iml b/Library/src/main/ClassroomInteraction.Library.main.iml index b18ed62..310ceb5 100644 --- a/Library/src/main/ClassroomInteraction.Library.main.iml +++ b/Library/src/main/ClassroomInteraction.Library.main.iml @@ -11,5 +11,8 @@ + + + \ No newline at end of file diff --git a/Library/src/main/java/com/cfive/classroom/library/database/PoolHelper.java b/Library/src/main/java/com/cfive/classroom/library/database/PoolHelper.java new file mode 100644 index 0000000..7a8a7d1 --- /dev/null +++ b/Library/src/main/java/com/cfive/classroom/library/database/PoolHelper.java @@ -0,0 +1,76 @@ +package com.cfive.classroom.library.database; + +import com.cfive.classroom.library.database.util.NoConfigException; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.*; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Properties; + +public class PoolHelper { + private static final Logger LOGGER = LogManager.getLogger(); + private static HikariDataSource hikariDataSource; + private static String JDBC_URL = "jdbc:mysql://%s:%s/%s?useSSL=false&characterEncoding=utf8"; + private static String JDBC_USERNAME; + private static String JDBC_PASSWORD; + private static final String CACHE_PREP_STMTS = "true"; + private static final String PREP_STMT_CACHE_SIZE = "100"; + private static final String MAXIMUM_POOL_SIZE = "10"; + + public static void init() throws NoConfigException { + loadProperties(); + + HikariConfig config = new HikariConfig(); + config.setJdbcUrl(JDBC_URL); + config.setUsername(JDBC_USERNAME); + config.setPassword(JDBC_PASSWORD); + config.addDataSourceProperty("cachePrepStmts", CACHE_PREP_STMTS); + config.addDataSourceProperty("prepStmtCacheSize", PREP_STMT_CACHE_SIZE); + config.addDataSourceProperty("maximumPoolSize", MAXIMUM_POOL_SIZE); + hikariDataSource = new HikariDataSource(config); + } + + private static void loadProperties() throws NoConfigException { + Properties properties = new Properties(); + try { + properties.load(new FileReader("mysql.properties")); + if (properties.getProperty("ip").isEmpty() || properties.getProperty("port").isEmpty() || properties.getProperty("database").isEmpty() || properties.getProperty("username").isEmpty() || properties.getProperty("password").isEmpty()) { + LOGGER.error("配置有误,请重新配置或删除配置文件重新生成"); + throw new NoConfigException(); + } else { + JDBC_URL = String.format(JDBC_URL, properties.getProperty("ip"), properties.getProperty("port"), properties.getProperty("database")); + JDBC_USERNAME = properties.getProperty("username"); + JDBC_PASSWORD = properties.getProperty("password"); + } + } catch (IOException e) { + properties.setProperty("ip", ""); + properties.setProperty("port", ""); + properties.setProperty("database", ""); + properties.setProperty("username", ""); + properties.setProperty("password", ""); + try { + properties.store(new FileWriter("mysql.properties"), "MySQL Configuration"); + LOGGER.info("已创建配置文件“mysql.properties”"); + } catch (IOException ioException) { + LOGGER.error("无法创建配置文件“mysql.properties”,请手动配置:创建配置文件并添加以下内容\nip=[数据库IP]\nport=[数据库端口]\ndatabase=[数据库名]\nusername=[数据用户名]\npassword=[数据库密码]", e); + } + throw new NoConfigException(); + } + + } + + public static void close() { + hikariDataSource.close(); + } + + public static Connection getConnection() throws SQLException, NoConfigException { + if (hikariDataSource == null) { + init(); + } + return hikariDataSource.getConnection(); + } +} diff --git a/Library/src/main/java/com/cfive/classroom/library/database/bean/AttStatus.java b/Library/src/main/java/com/cfive/classroom/library/database/bean/AttStatus.java new file mode 100644 index 0000000..81523b2 --- /dev/null +++ b/Library/src/main/java/com/cfive/classroom/library/database/bean/AttStatus.java @@ -0,0 +1,22 @@ +package com.cfive.classroom.library.database.bean; + +/** + * 考勤状态枚举类 + * + * @author FatttSnake + * @version 1.0 + */ +public enum AttStatus { + not_signed("未签"), signed("已签"), absence("缺勤"), personal_leave("事假"), sick_leave("病假"), public_holiday("公假"), late("迟到"), leave_early("早退"); + + private final String string; + + AttStatus(String string) { + this.string = string; + } + + @Override + public String toString() { + return string; + } +} diff --git a/Library/src/main/java/com/cfive/classroom/library/database/bean/Attendance.java b/Library/src/main/java/com/cfive/classroom/library/database/bean/Attendance.java new file mode 100644 index 0000000..3d5b57a --- /dev/null +++ b/Library/src/main/java/com/cfive/classroom/library/database/bean/Attendance.java @@ -0,0 +1,137 @@ +package com.cfive.classroom.library.database.bean; + +import java.time.LocalDateTime; + +/** + * 考勤类,用于考勤信息封装 + * + * @author FatttSnake + * @version 1.0 + */ +public class Attendance { + private final String attID; + private Course course; + private Student student; + private LocalDateTime attTime; + private AttStatus attStatus; + + /** + * 构造考勤对象 + * + * @param attID 考勤编号,用于识别唯一考勤 + * @param course 隶属课程 + * @param student 隶属学生 + * @param attTime 考勤时间 + * @param attStatus 考勤状态 + */ + public Attendance(String attID, Course course, Student student, LocalDateTime attTime, AttStatus attStatus) { + this.attID = attID; + this.course = course; + this.student = student; + this.attTime = attTime; + this.attStatus = attStatus; + } + + /** + * 获取考勤编号 + * + * @return String 考勤编号,UUID字符串 + */ + public String getAttID() { + return attID; + } + + /** + * 获取隶属课程 + * + * @return Course 隶属课程 + * @see Course + */ + public Course getCourse() { + return course; + } + + /** + * 设置隶属课程 + * + * @param course 隶属课程 + * @see Course + */ + public void setCourse(Course course) { + this.course = course; + } + + /** + * 获取隶属学生 + * + * @return Student 隶属学生 + * @see Student + */ + public Student getStudent() { + return student; + } + + /** + * 设置隶属学生 + * + * @param student 隶属学生 + * @see Student + */ + public void setStudent(Student student) { + this.student = student; + } + + /** + * 获取考勤时间 + * + * @return LocalDateTime 考勤时间 + */ + public LocalDateTime getAttTime() { + return attTime; + } + + /** + * 设置考勤时间 + * + * @param attTime 考勤时间 + */ + public void setAttTime(LocalDateTime attTime) { + this.attTime = attTime; + } + + /** + * 获取考勤状态 + * + * @return AttStatus 考勤状态 + * @see AttStatus + */ + public AttStatus getAttStatus() { + return attStatus; + } + + /** + * 设置考勤状态 + * + * @param attStatus 考勤状态 + * @see AttStatus + */ + public void setAttStatus(AttStatus attStatus) { + this.attStatus = attStatus; + } + + /** + * 仅用于测试使用 + * + * @return String 包含所有属性的字符串 + */ + @Override + public String toString() { + return "Attendance{" + + "attID='" + attID + '\'' + + ", course=" + course + + ", student=" + student + + ", attTime=" + attTime + + ", attStatus=" + attStatus + + '}'; + } +} diff --git a/Library/src/main/java/com/cfive/classroom/library/database/bean/Class.java b/Library/src/main/java/com/cfive/classroom/library/database/bean/Class.java new file mode 100644 index 0000000..8a9cc94 --- /dev/null +++ b/Library/src/main/java/com/cfive/classroom/library/database/bean/Class.java @@ -0,0 +1,112 @@ +package com.cfive.classroom.library.database.bean; + +import com.sun.istack.internal.NotNull; + +/** + * 班级类,用于班级信息封装 + * + * @author FatttSnake + * @version 1.0 + */ + +public class Class { + private final long classID; + private Major major; + private int grade; + private int classNum; + + /** + * 构造班级对象 + * + * @param classID 班级编号,用于识别唯一班级 + * @param major 隶属专业 + * @param grade 年级 + * @param classNum 班号 + */ + public Class(@NotNull long classID, @NotNull Major major, @NotNull int grade, @NotNull int classNum) { + this.classID = classID; + this.major = major; + this.grade = grade; + this.classNum = classNum; + } + + /** + * 获取班级编号,用于识别唯一班级 + * + * @return long 班级编号 + */ + public long getClassID() { + return classID; + } + + /** + * 获取隶属专业 + * + * @return Major 隶属专业 + * @see Major + */ + public Major getMajor() { + return major; + } + + /** + * 设置隶属专业 + * + * @param major 隶属专业 + * @see Major + */ + public void setMajor(@NotNull Major major) { + this.major = major; + } + + /** + * 获取年级 + * + * @return int 年级 + */ + public int getGrade() { + return grade; + } + + /** + * 设置年级 + * + * @param grade 年级 + */ + public void setGrade(@NotNull int grade) { + this.grade = grade; + } + + /** + * 获取班号 + * + * @return int 班号 + */ + public int getClassNum() { + return classNum; + } + + /** + * 设置班号 + * + * @param classNum 班号 + */ + public void setClassNum(@NotNull int classNum) { + this.classNum = classNum; + } + + /** + * 仅用于测试使用 + * + * @return String 包含所有属性的字符串 + */ + @Override + public String toString() { + return "Class{" + + "classID=" + classID + + ", major=" + major + + ", grade=" + grade + + ", classNum=" + classNum + + '}'; + } +} diff --git a/Library/src/main/java/com/cfive/classroom/library/database/bean/Course.java b/Library/src/main/java/com/cfive/classroom/library/database/bean/Course.java new file mode 100644 index 0000000..c7ac890 --- /dev/null +++ b/Library/src/main/java/com/cfive/classroom/library/database/bean/Course.java @@ -0,0 +1,139 @@ +package com.cfive.classroom.library.database.bean; + +import java.time.LocalDateTime; + +/** + * 课程类,用于课程信息封装 + * + * @author FatttSnake + * @version 1.0 + */ +public class Course { + private final long courID; + private Subject subject; + private Teacher teacher; + private LocalDateTime courTimeFrom; + private LocalDateTime courTimeEnd; + + /** + * 构造课程对象 + * + * @param courID 课程编号,用于识别唯一课程 + * @param subject 隶属科目 + * @param teacher 隶属教师 + * @param courTimeFrom 开始时间 + * @param courTimeEnd 结束时间 + */ + public Course(long courID, Subject subject, Teacher teacher, LocalDateTime courTimeFrom, LocalDateTime courTimeEnd) { + this.courID = courID; + this.subject = subject; + this.teacher = teacher; + this.courTimeFrom = courTimeFrom; + this.courTimeEnd = courTimeEnd; + } + + /** + * 获取课程编号,用于识别唯一课程 + * + * @return long 课程编号 + */ + public long getCourID() { + return courID; + } + + /** + * 获取隶属科目 + * + * @return Subject 隶属科目 + * @see Subject + */ + public Subject getSubject() { + return subject; + } + + /** + * 设置隶属科目 + * + * @param subject 隶属科目 + * @see Subject + */ + public void setSubject(Subject subject) { + this.subject = subject; + } + + /** + * 获取隶属教师 + * + * @return Teacher 隶属教师 + * @see Teacher + */ + public Teacher getTeacher() { + return teacher; + } + + /** + * 设置隶属教师 + * + * @param teacher 隶属教师 + * @see Teacher + */ + public void setTeacher(Teacher teacher) { + this.teacher = teacher; + } + + /** + * 获取开始时间 + * + * @return LocalDateTime 开始时间 + * @see LocalDateTime + */ + public LocalDateTime getCourTimeFrom() { + return courTimeFrom; + } + + /** + * 设置开始时间 + * + * @param courTimeFrom 开始时间 + * @see LocalDateTime + */ + public void setCourTimeFrom(LocalDateTime courTimeFrom) { + this.courTimeFrom = courTimeFrom; + } + + /** + * 获取结束时间 + * + * @return LocalDateTime 结束时间 + * @see LocalDateTime + */ + public LocalDateTime getCourTimeEnd() { + return courTimeEnd; + } + + /** + * 设置结束时间 + * + * @param courTimeEnd 结束时间 + * @see LocalDateTime + */ + public void setCourTimeEnd(LocalDateTime courTimeEnd) { + this.courTimeEnd = courTimeEnd; + } + + /** + * 仅用于测试使用 + * + * @return String 包含所有属性的字符串 + */ + @Override + public String toString() { + return "Course{" + + "courID=" + courID + + ", subject=" + subject + + ", teacher=" + teacher + + ", courTimeFrom=" + courTimeFrom + + ", courTimeEnd=" + courTimeEnd + + '}'; + } +} diff --git a/Library/src/main/java/com/cfive/classroom/library/database/bean/Faculty.java b/Library/src/main/java/com/cfive/classroom/library/database/bean/Faculty.java new file mode 100644 index 0000000..9bc8980 --- /dev/null +++ b/Library/src/main/java/com/cfive/classroom/library/database/bean/Faculty.java @@ -0,0 +1,65 @@ +package com.cfive.classroom.library.database.bean; + +import com.sun.istack.internal.NotNull; + +/** + * 院系类,用于院系信息封装 + * + * @author FatttSnake + * @version 1.0 + */ +public class Faculty { + private final int facID; + private String facName; + + /** + * 构造院系对象 + * + * @param facID 院系编号,用于识别唯一院系 + * @param facName 院系名 + */ + public Faculty(@NotNull int facID, @NotNull String facName) { + this.facID = facID; + this.facName = facName; + } + + /** + * 获取院系编号,用于识别唯一院系 + * + * @return 院系编号 + */ + public int getFacID() { + return facID; + } + + /** + * 获取院系名 + * + * @return 院系名 + */ + public String getFacName() { + return facName; + } + + /** + * 设置院系名 + * + * @param facName String 院系名 + */ + public void setFacName(@NotNull String facName) { + this.facName = facName; + } + + /** + * 仅用于测试使用 + * + * @return String 包含所有属性的字符串 + */ + @Override + public String toString() { + return "Faculty{" + + "facID=" + facID + + ", facName='" + facName + '\'' + + '}'; + } +} diff --git a/Library/src/main/java/com/cfive/classroom/library/database/bean/Gender.java b/Library/src/main/java/com/cfive/classroom/library/database/bean/Gender.java new file mode 100644 index 0000000..c2e305e --- /dev/null +++ b/Library/src/main/java/com/cfive/classroom/library/database/bean/Gender.java @@ -0,0 +1,27 @@ +package com.cfive.classroom.library.database.bean; + +/** + * 性别枚举类 + * + * @author FatttSnake + * @version 1.0 + */ +public enum Gender { + m("男"), f("女"); + + private final String string; + + Gender(String string) { + this.string = string; + } + + /** + * 转换成中文 + * + * @return String 中文 + */ + @Override + public String toString() { + return string; + } +} diff --git a/Library/src/main/java/com/cfive/classroom/library/database/bean/Major.java b/Library/src/main/java/com/cfive/classroom/library/database/bean/Major.java new file mode 100644 index 0000000..fa7cbf2 --- /dev/null +++ b/Library/src/main/java/com/cfive/classroom/library/database/bean/Major.java @@ -0,0 +1,89 @@ +package com.cfive.classroom.library.database.bean; + +import com.sun.istack.internal.NotNull; + +/** + * 专业类,用于专业信息封装 + * + * @author FatttSnake + * @version 1.0 + */ +public class Major { + private final int majorID; + private String majorName; + private Faculty faculty; + + /** + * 构造专业对象 + * + * @param majorID 专业编号,用于识别唯一专业 + * @param majorName 专业名 + * @param faculty 隶属院系 + */ + public Major(@NotNull int majorID, @NotNull String majorName, @NotNull Faculty faculty) { + this.majorID = majorID; + this.majorName = majorName; + this.faculty = faculty; + } + + /** + * 获取专业编号,用于识别唯一专业 + * + * @return int 专业编号 + */ + public int getMajorID() { + return majorID; + } + + /** + * 获取专业名 + * + * @return String 专业名 + */ + public String getMajorName() { + return majorName; + } + + /** + * 设置专业名 + * + * @param majorName 专业名 + */ + public void setMajorName(@NotNull String majorName) { + this.majorName = majorName; + } + + /** + * 获取隶属院系 + * + * @return Faculty 隶属院系 + * @see Faculty + */ + public Faculty getFaculty() { + return faculty; + } + + /** + * 设置隶属院系 + * + * @param faculty 隶属院系 + * @see Faculty + */ + public void setFaculty(@NotNull Faculty faculty) { + this.faculty = faculty; + } + + /** + * 仅用于测试使用 + * + * @return String 包含所有属性的字符串 + */ + @Override + public String toString() { + return "Major{" + + "majorID=" + majorID + + ", majorName='" + majorName + '\'' + + ", faculty=" + faculty + + '}'; + } +} diff --git a/Library/src/main/java/com/cfive/classroom/library/database/bean/Student.java b/Library/src/main/java/com/cfive/classroom/library/database/bean/Student.java new file mode 100644 index 0000000..23d41a4 --- /dev/null +++ b/Library/src/main/java/com/cfive/classroom/library/database/bean/Student.java @@ -0,0 +1,157 @@ +package com.cfive.classroom.library.database.bean; + +import com.sun.istack.internal.NotNull; + +/** + * 学生类,用于学生信息封装 + * + * @author FatttSnake + * @version 1.0 + */ +public class Student { + private final long stuID; + private String stuName; + private Gender gender; + private Class aClass; + private String password; + private String salt; + + /** + * 构造学生对象 + * + * @param stuID 学号,用于识别唯一学生 + * @param stuName 学生姓名 + * @param gender 性别 + * @param aClass 隶属班级 + * @param password 密码 + * @param salt 加盐 + */ + public Student(@NotNull long stuID, @NotNull String stuName, @NotNull Gender gender, @NotNull Class aClass, @NotNull String password, @NotNull String salt) { + this.stuID = stuID; + this.stuName = stuName; + this.gender = gender; + this.aClass = aClass; + this.password = password; + this.salt = salt; + } + + /** + * 获取学生编号,用于识别唯一学生 + * + * @return long 学号 + */ + public long getStuID() { + return stuID; + } + + /** + * 获取学生姓名 + * + * @return String 学生姓名 + */ + public String getStuName() { + return stuName; + } + + /** + * 设置学生姓名 + * + * @param stuName 学生姓名 + */ + public void setStuName(@NotNull String stuName) { + this.stuName = stuName; + } + + /** + * 获取性别 + * + * @return Gender 性别 + * @see Gender + */ + public Gender getGender() { + return gender; + } + + /** + * 设置性别 + * + * @param gender 性别 + * @see Gender + */ + public void setGender(@NotNull Gender gender) { + this.gender = gender; + } + + /** + * 获取隶属班级 + * + * @return Class 隶属班级 + * @see Class + */ + public Class getaClass() { + return aClass; + } + + /** + * 设置隶属班级 + * + * @param aClass 隶属班级 + * @see Class + */ + public void setaClass(@NotNull Class aClass) { + this.aClass = aClass; + } + + /** + * 获取密码 + * + * @return String 密码 + */ + public String getPassword() { + return password; + } + + /** + * 设置密码 + * + * @param password 密码 + */ + public void setPassword(@NotNull String password) { + this.password = password; + } + + /** + * 获取加盐 + * + * @return String 加盐 + */ + public String getSalt() { + return salt; + } + + /** + * 设置加盐 + * + * @param salt 加盐 + */ + public void setSalt(@NotNull String salt) { + this.salt = salt; + } + + /** + * 仅用于测试使用 + * + * @return String 包含所有属性的字符串 + */ + @Override + public String toString() { + return "Student{" + + "stuID=" + stuID + + ", stuName='" + stuName + '\'' + + ", gender=" + gender + + ", aClass=" + aClass + + ", password='" + password + '\'' + + ", salt='" + salt + '\'' + + '}'; + } +} diff --git a/Library/src/main/java/com/cfive/classroom/library/database/bean/Subject.java b/Library/src/main/java/com/cfive/classroom/library/database/bean/Subject.java new file mode 100644 index 0000000..087cf62 --- /dev/null +++ b/Library/src/main/java/com/cfive/classroom/library/database/bean/Subject.java @@ -0,0 +1,65 @@ +package com.cfive.classroom.library.database.bean; + +import com.sun.istack.internal.NotNull; + +/** + * 科目类,用于科目信息封装 + * + * @author FatttSnake + * @version 1.0 + */ +public class Subject { + private final int subID; + private String subName; + + /** + * 构造科目对象 + * + * @param subID 科目编号,用于识别唯一科目 + * @param subName 科目名 + */ + public Subject(@NotNull int subID, @NotNull String subName) { + this.subID = subID; + this.subName = subName; + } + + /** + * 获取科目编号,用于识别唯一科目 + * + * @return int 科目编号 + */ + public int getSubID() { + return subID; + } + + /** + * 获取科目名 + * + * @return String 科目名 + */ + public String getSubName() { + return subName; + } + + /** + * 设置科目名 + * + * @param subName 科目名 + */ + public void setSubName(@NotNull String subName) { + this.subName = subName; + } + + /** + * 仅用于测试使用 + * + * @return String 包含所有属性的字符串 + */ + @Override + public String toString() { + return "Subject{" + + "subID=" + subID + + ", subName='" + subName + '\'' + + '}'; + } +} diff --git a/Library/src/main/java/com/cfive/classroom/library/database/bean/Teacher.java b/Library/src/main/java/com/cfive/classroom/library/database/bean/Teacher.java new file mode 100644 index 0000000..19afd82 --- /dev/null +++ b/Library/src/main/java/com/cfive/classroom/library/database/bean/Teacher.java @@ -0,0 +1,156 @@ +package com.cfive.classroom.library.database.bean; + +import com.sun.istack.internal.NotNull; + +/** + * 教师类,用于教师信息封装 + * + * @author FatttSnake + * @version 1.0 + */ +public class Teacher { + private final long tchID; + private String tchName; + private Gender gender; + private Faculty faculty; + private String password; + private String salt; + + /** + * 构造教师对象 + * + * @param tchID 工号,用于识别唯一教师 + * @param tchName 教师姓名 + * @param gender 性别 + * @param faculty 隶属院系 + * @param password 密码 + * @param salt 加盐 + */ + public Teacher(@NotNull long tchID, @NotNull String tchName, @NotNull Gender gender, @NotNull Faculty faculty, @NotNull String password, @NotNull String salt) { + this.tchID = tchID; + this.tchName = tchName; + this.gender = gender; + this.faculty = faculty; + this.password = password; + this.salt = salt; + } + + /** + * 获取工号,用于识别唯一教师 + * + * @return long 教师编号 + */ + public long getTchID() { + return tchID; + } + + /** + * 获取教师姓名 + * + * @return String 教师姓名 + */ + public String getTchName() { + return tchName; + } + + /** + * 设置教师姓名 + * @param tchName 教师姓名 + */ + public void setTchName(@NotNull String tchName) { + this.tchName = tchName; + } + + /** + * 获取性别 + * + * @return Gender 性别 + * @see Gender + */ + public Gender getGender() { + return gender; + } + + /** + * 设置性别 + * + * @param gender 性别 + * @see Gender + */ + public void setGender(@NotNull Gender gender) { + this.gender = gender; + } + + /** + * 获取隶属院系 + * + * @return Faculty 隶属院系 + * @see Faculty + */ + public Faculty getFaculty() { + return faculty; + } + + /** + * 设置隶属院系 + * + * @param faculty 隶属院系 + * @see Faculty + */ + public void setFaculty(@NotNull Faculty faculty) { + this.faculty = faculty; + } + + /** + * 获取密码 + * + * @return String 密码 + */ + public String getPassword() { + return password; + } + + /** + * 设置密码 + * + * @param password 密码 + */ + public void setPassword(@NotNull String password) { + this.password = password; + } + + /** + * 获取加盐 + * + * @return String 加盐 + */ + public String getSalt() { + return salt; + } + + /** + * 设置加盐 + * + * @param salt 加盐 + */ + public void setSalt(@NotNull String salt) { + this.salt = salt; + } + + /** + * 仅用于测试使用 + * + * @return String 包含所有属性的字符串 + */ + @Override + public String toString() { + return "Teacher{" + + "tchID=" + tchID + + ", tchName='" + tchName + '\'' + + ", gender=" + gender + + ", faculty=" + faculty + + ", password='" + password + '\'' + + ", salt='" + salt + '\'' + + '}'; + } +} diff --git a/Library/src/test/mysql.properties b/Library/src/test/mysql.properties new file mode 100644 index 0000000..806a4a6 --- /dev/null +++ b/Library/src/test/mysql.properties @@ -0,0 +1,7 @@ +#MySQL Configuration +#Mon Jun 06 15:29:23 CST 2022 +port=3306 +password=class_five +database=class +ip=10.14.0.7 +username=class diff --git a/MySQL.sql b/MySQL.sql new file mode 100644 index 0000000..1b48e84 --- /dev/null +++ b/MySQL.sql @@ -0,0 +1,154 @@ +SHOW DATABASES; +SHOW TABLES; + +USE class; + +create table Faculty +( + facID int auto_increment comment '院系编号', + facName varchar(20) not null comment '学院名称', + constraint Faculty_pk + primary key (facID) +) + comment '院系'; + +create unique index Faculty_facID_uindex + on Faculty (facID); + +create unique index Faculty_facName_uindex + on Faculty (facName); + +create table Major +( + majorID int auto_increment comment '专业编号', + majorName varchar(20) not null comment '专业名称', + facID int not null comment '隶属院系', + constraint Major_pk + primary key (majorID), + constraint Major_facID_fk + foreign key (facID) references faculty (facID) +) + comment '专业'; + +create unique index Major_majorID_uindex + on Major (majorID); + +create unique index Major_majorName_uindex + on Major (majorName); + +create table Class +( + classID bigint auto_increment comment '班级编号', + majorID int not null comment '隶属专业', + grade int not null comment '年级', + classNum int not null comment '班号', + constraint Class_pk + primary key (classID), + constraint Class_majorID_fk + foreign key (majorID) references major (majorID) +) + comment '班级'; + +create unique index Class_classID_uindex + on Class (classID); + +create table Student +( + stuID bigint auto_increment comment '学号', + stuName varchar(10) not null comment '学生姓名', + stuGender enum ('m', 'f') not null comment '性别', + classID bigint not null comment '隶属班级', + passwd char(128) not null comment '学生密码', + salt char(32) not null comment '加盐', + constraint Student_pk + primary key (stuID), + constraint Student_classID_fk + foreign key (classID) references class (classID) +) + comment '学生'; + +create unique index Student_stuID_uindex + on Student (stuID); + +create table Teacher +( + tchID bigint auto_increment comment '工号', + tchName varchar(20) not null comment '教师姓名', + tchGender enum ('m', 'f') not null comment '教师性别', + facID int not null comment '隶属院系', + passwd char(128) not null comment '教师密码', + salt char(32) not null comment '加盐', + constraint Teacher_pk + primary key (tchID), + constraint Teacher_facID_fk + foreign key (facID) references faculty (facID) +) + comment '教师'; + +create unique index Teacher_tchID_uindex + on Teacher (tchID); + +create table Subject +( + subID int auto_increment comment '科目编号', + subName varchar(40) not null comment '科目名', + constraint Subject_pk + primary key (subID) +) + comment '科目'; + +create unique index Subject_subID_uindex + on Subject (subID); + +create unique index Subject_subName_uindex + on Subject (subName); + +create table Course +( + courID bigint auto_increment comment '课程编号', + subID int not null comment '隶属科目', + tchID bigint not null comment '授课教师', + courTimeFrom timestamp not null, + courTimeEnd timestamp not null, + constraint Course_pk + primary key (courID), + constraint Course_subID_fk + foreign key (subID) references Subject(subID), + constraint Course_tchID_fk + foreign key (tchID) references Teacher(tchID) +) + comment '课程'; + +create unique index Course_courID_uindex + on Course (courID); + +create table Attendance +( + attID char(36) not null comment '考勤编号', + courID bigint not null comment '隶属课程', + stuID int not null comment '隶属学生', + attTie timestamp null comment '考勤时间', + attStatus enum ('not_signed', 'signed', 'absence', 'personal_leave', 'sick_leave', 'public_holiday', 'late', 'leave_early') default 'not_signed' not null comment '考勤状态', + constraint Attendance_pk + primary key (attID) +) + comment '考勤'; + +create unique index Attendance_courID_uindex + on Attendance (attID); + +select * +from faculty; + +ALTER TABLE faculty + AUTO_INCREMENT = 19; + +delete +from faculty; + +INSERT INTO faculty +values (2, '计算机学院'), + (18, '工程训练中心'); + + +SELECT EXISTS(SELECT 1 FROM faculty WHERE facName = '信息学院') \ No newline at end of file diff --git a/Student/src/main/mysql.properties b/Student/src/main/mysql.properties new file mode 100644 index 0000000..806a4a6 --- /dev/null +++ b/Student/src/main/mysql.properties @@ -0,0 +1,7 @@ +#MySQL Configuration +#Mon Jun 06 15:29:23 CST 2022 +port=3306 +password=class_five +database=class +ip=10.14.0.7 +username=class diff --git a/Student/src/test/mysql.properties b/Student/src/test/mysql.properties new file mode 100644 index 0000000..806a4a6 --- /dev/null +++ b/Student/src/test/mysql.properties @@ -0,0 +1,7 @@ +#MySQL Configuration +#Mon Jun 06 15:29:23 CST 2022 +port=3306 +password=class_five +database=class +ip=10.14.0.7 +username=class diff --git a/Teacher/src/main/mysql.properties b/Teacher/src/main/mysql.properties new file mode 100644 index 0000000..806a4a6 --- /dev/null +++ b/Teacher/src/main/mysql.properties @@ -0,0 +1,7 @@ +#MySQL Configuration +#Mon Jun 06 15:29:23 CST 2022 +port=3306 +password=class_five +database=class +ip=10.14.0.7 +username=class diff --git a/Teacher/src/test/mysql.properties b/Teacher/src/test/mysql.properties new file mode 100644 index 0000000..806a4a6 --- /dev/null +++ b/Teacher/src/test/mysql.properties @@ -0,0 +1,7 @@ +#MySQL Configuration +#Mon Jun 06 15:29:23 CST 2022 +port=3306 +password=class_five +database=class +ip=10.14.0.7 +username=class diff --git a/lib/HikariCP-2.7.6.jar b/lib/HikariCP-2.7.6.jar new file mode 100644 index 0000000..2ae8aa6 Binary files /dev/null and b/lib/HikariCP-2.7.6.jar differ diff --git a/lib/mysql-connector-java-8.0.25.jar b/lib/mysql-connector-java-8.0.25.jar new file mode 100644 index 0000000..3db626b Binary files /dev/null and b/lib/mysql-connector-java-8.0.25.jar differ diff --git a/lib/slf4j-api-1.7.25.jar b/lib/slf4j-api-1.7.25.jar new file mode 100644 index 0000000..0143c09 Binary files /dev/null and b/lib/slf4j-api-1.7.25.jar differ diff --git a/lib/slf4j-api-1.7.36.jar b/lib/slf4j-api-1.7.36.jar new file mode 100644 index 0000000..7d3ce68 Binary files /dev/null and b/lib/slf4j-api-1.7.36.jar differ diff --git a/lib/slf4j-simple-1.7.36.jar b/lib/slf4j-simple-1.7.36.jar new file mode 100644 index 0000000..ef831a8 Binary files /dev/null and b/lib/slf4j-simple-1.7.36.jar differ