diff --git a/.idea/misc.xml b/.idea/misc.xml
index 58918f5..031fcf3 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,10 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Library/src/main/java/com/cfive/classroom/library/database/DatabaseHelper.java b/Library/src/main/java/com/cfive/classroom/library/database/DatabaseHelper.java
index 55ccc9b..15fa7b8 100644
--- a/Library/src/main/java/com/cfive/classroom/library/database/DatabaseHelper.java
+++ b/Library/src/main/java/com/cfive/classroom/library/database/DatabaseHelper.java
@@ -10,273 +10,766 @@ import com.sun.istack.internal.Nullable;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import java.sql.*;
import java.time.LocalDateTime;
+import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;
+/**
+ * 数据库操作集合类
+ * 所有数据库操作方法全部在这里
+ *
+ * @author FatttSnake
+ * @version 2.1
+ */
public class DatabaseHelper {
+ /**
+ * 查询所有院系
+ *
+ * @return List 包含 Faculty 类型的数组
+ * @see List
+ */
public static List selectAllFromFaculty() throws NoConfigException, SQLException {
return FacultyOA.selectAll();
}
+ /**
+ * 通过院系编号查询院系
+ *
+ * @param facID 院系编号
+ * @return Faculty 院系类
+ * @see Faculty
+ */
public static Faculty selectFromFaculty(int facID) throws NoConfigException, SQLException {
return FacultyOA.select(facID);
}
+ /**
+ * 通过院系名查询院系
+ *
+ * @param facName 院系名
+ * @return Faculty 院系类
+ * @see Faculty
+ */
public static Faculty selectFromFaculty(String facName) throws NoConfigException, SQLException {
return FacultyOA.select(facName);
}
+ /**
+ * 插入院系
+ *
+ * @param facName 院系名
+ * @return Faculty 院系类
+ * @see Faculty
+ */
public static Faculty insertIntoFaculty(String facName) throws NoConfigException, SQLException, InsertException, AlreadyExistsException {
return FacultyOA.insert(facName);
}
+ /**
+ * 插入院系(指定院系编号)
+ *
+ * @param facID 院系编号
+ * @param facName 院系名
+ * @return Faculty 院系类
+ * @see Faculty
+ */
public static Faculty insertIntoFaculty(int facID, String facName) throws NoConfigException, InsertException, SQLException, AlreadyExistsException {
return FacultyOA.insert(facID, facName);
}
+ /**
+ * 通过院系编号查询院系是否存在
+ *
+ * @param facID 院系编号
+ * @return true 存在
+ * false 不存在
+ */
public static boolean isExistsInFaculty(int facID) throws NoConfigException, SQLException {
return FacultyOA.isExists(facID);
}
+ /**
+ * 通过院系名查询院系是否存在
+ *
+ * @param facName 院系名
+ * @return true 存在
+ * false 不存在
+ */
public static boolean isExistsInFaculty(String facName) throws NoConfigException, SQLException {
return FacultyOA.isExists(facName);
}
+ /**
+ * 通过院系编号删除院系
+ *
+ * @param facID 院系编号
+ * @return true 成功
+ * false 失败
+ */
public static boolean deleteFromFaculty(int facID) throws NoConfigException, SQLException {
return FacultyOA.delete(facID);
}
+ /**
+ * 通过院系名删除院系
+ *
+ * @param facName 院系名
+ * @return true 成功
+ * false 失败
+ */
public static boolean deleteFromFaculty(String facName) throws NoConfigException, SQLException {
return FacultyOA.delete(facName);
}
+ /**
+ * 查询所有科目
+ *
+ * @return List 包含 Subject 类型的数组
+ * @see List
+ */
public static List selectAllFromSubject() throws NoConfigException, SQLException {
return SubjectOA.selectAll();
}
+ /**
+ * 通过科目编号查询科目
+ *
+ * @param subID 科目编号
+ * @return Subject 科目类
+ * @see Subject
+ */
public static Subject selectFromSubject(int subID) throws NoConfigException, SQLException {
return SubjectOA.select(subID);
}
+ /**
+ * 通过科目名查询科目
+ *
+ * @param subName 科目名
+ * @return Subject 科目类
+ * @see Subject
+ */
public static Subject selectFromSubject(String subName) throws NoConfigException, SQLException {
return SubjectOA.select(subName);
}
+ /**
+ * 插入科目
+ *
+ * @param subName 科目名
+ * @return Subject 科目类
+ * @see Subject
+ */
public static Subject insertIntoSubject(String subName) throws NoConfigException, SQLException, InsertException, AlreadyExistsException {
return SubjectOA.insert(subName);
}
+ /**
+ * 插入科目(指定科目编号)
+ *
+ * @param subID 科目编号
+ * @param subName 科目名
+ * @return Subject 科目类
+ * @see Subject
+ */
public static Subject insertIntoSubject(int subID, String subName) throws NoConfigException, SQLException, InsertException, AlreadyExistsException {
return SubjectOA.insert(subID, subName);
}
+ /**
+ * 通过科目编号查询科目是否存在
+ *
+ * @param subID 科目编号
+ * @return true 存在
+ * false 不存在
+ */
public static boolean isExistsInSubject(int subID) throws NoConfigException, SQLException {
return SubjectOA.isExists(subID);
}
+ /**
+ * 通过科目名查询科目是否存在
+ *
+ * @param subName 科目名
+ * @return true 存在
+ * false 不存在
+ */
public static boolean isExistsInSubject(String subName) throws NoConfigException, SQLException {
return SubjectOA.isExists(subName);
}
+ /**
+ * 通过科目编号删除科目
+ *
+ * @param subID 科目编号
+ * @return true 成功
+ * false 失败
+ */
public static boolean deleteFromSubject(int subID) throws NoConfigException, SQLException {
return SubjectOA.delete(subID);
}
+ /**
+ * 通过科目名删除科目
+ *
+ * @param subName 科目名
+ * @return true 成功
+ * false 失败
+ */
public static boolean deleteFromSubject(String subName) throws NoConfigException, SQLException {
return SubjectOA.delete(subName);
}
+ /**
+ * 查询所有专业
+ *
+ * @return List 包含 Major 类型的数组
+ * @see List
+ */
public static List selectAllFromMajor() throws NoConfigException, SQLException {
return MajorOA.selectAll();
}
+ /**
+ * 通过专业编号查询专业
+ *
+ * @param majorID 专业编号
+ * @return Major 专业类
+ * @see Major
+ */
public static Major selectFromMajor(int majorID) throws NoConfigException, SQLException {
return MajorOA.select(majorID);
}
+ /**
+ * 通过专业名查询专业
+ *
+ * @param majorName 专业名
+ * @return Major 专业类
+ * @see Major
+ */
public static Major selectFromMajor(String majorName) throws NoConfigException, SQLException {
return MajorOA.select(majorName);
}
+ /**
+ * 插入专业
+ *
+ * @param majorName 专业名
+ * @param facID 隶属院系编号
+ * @return Major 专业类
+ * @see Major
+ */
public static Major insertIntoMajor(String majorName, int facID) throws NoConfigException, SQLException, InsertException, AlreadyExistsException, DependenciesNotFoundException {
return MajorOA.insert(majorName, facID);
}
+ /**
+ * 插入专业
+ *
+ * @param majorName 专业名
+ * @param facName 隶属院系名
+ * @return Major 专业
+ * @see Major
+ */
public static Major insertIntoMajor(String majorName, String facName) throws NoConfigException, AlreadyExistsException, SQLException, InsertException, DependenciesNotFoundException {
return MajorOA.insert(majorName, facName);
}
+ /**
+ * 插入专业(指定专业编号)
+ *
+ * @param majorID 专业编号
+ * @param majorName 专业名
+ * @param facID 隶属院系
+ * @return Major 专业类
+ * @see Major
+ */
public static Major insertIntoMajor(int majorID, String majorName, int facID) throws NoConfigException, SQLException, InsertException, AlreadyExistsException, DependenciesNotFoundException {
return MajorOA.insert(majorID, majorName, facID);
}
+ /**
+ * 插入专业(指定专业编号)
+ *
+ * @param majorID 专业编号
+ * @param majorName 专业名
+ * @param facName 隶属院系
+ * @return Major 专业类
+ * @see Major
+ */
public static Major insertIntoMajor(int majorID, String majorName, String facName) throws NoConfigException, AlreadyExistsException, SQLException, InsertException, DependenciesNotFoundException {
return MajorOA.insert(majorID, majorName, facName);
}
+ /**
+ * 通过专业编号查询专业是否存在
+ *
+ * @param majorID 专业编号
+ * @return true 存在
+ * false 不存在
+ */
public static boolean isExistsInMajor(int majorID) throws NoConfigException, SQLException {
return MajorOA.isExists(majorID);
}
+ /**
+ * 通过专业名查询专业是否存在
+ *
+ * @param majorName 专业名
+ * @return true 存在
+ * false 不存在
+ */
public static boolean isExistsInMajor(String majorName) throws NoConfigException, SQLException {
return MajorOA.isExists(majorName);
}
+ /**
+ * 通过专业编号删除专业
+ *
+ * @param majorID 专业编号
+ * @return true 成功
+ * false 失败
+ */
public static boolean deleteFromMajor(int majorID) throws NoConfigException, SQLException {
return MajorOA.delete(majorID);
}
+ /**
+ * 通过专业名删除专业
+ *
+ * @param majorName 专业名
+ * @return true 成功
+ * false 失败
+ */
public static boolean deleteFromMajor(String majorName) throws NoConfigException, SQLException {
return MajorOA.delete(majorName);
}
+ /**
+ * 查询所有班级
+ *
+ * @return List 包含 AClass 类型的数组
+ * @see List
+ */
public static List selectAllFromClass() throws NoConfigException, SQLException {
return ClassOA.selectAll();
}
+ /**
+ * 通过班级编号查询班级
+ *
+ * @param classID 班级编号
+ * @return AClass 班级类
+ * @see AClass
+ */
public static AClass selectFromClass(long classID) throws NoConfigException, SQLException {
return ClassOA.select(classID);
}
+ /**
+ * 通过专业ID,年级,班号查询班级
+ *
+ * @param majorID 专业编号
+ * @param grade 年级
+ * @param classNum 班号
+ * @return AClass 班级类
+ * @see AClass
+ */
public static AClass selectFromClass(int majorID, int grade, int classNum) throws NoConfigException, SQLException {
return ClassOA.select(majorID, grade, classNum);
}
+ /**
+ * 插入班级
+ *
+ * @param majorID 隶属专业
+ * @param grade 年级
+ * @param classNum 班号
+ * @return AClass 班级类
+ * @see AClass
+ */
public static AClass insertIntoClass(int majorID, int grade, int classNum) throws NoConfigException, SQLException, InsertException, AlreadyExistsException, DependenciesNotFoundException {
return ClassOA.insert(majorID, grade, classNum);
}
+ /**
+ * 插入班级
+ *
+ * @param majorName 隶属专业
+ * @param grade 年级
+ * @param classNum 班号
+ * @return AClass 班级类
+ * @see AClass
+ */
public static AClass insertIntoClass(String majorName, int grade, int classNum) throws NoConfigException, SQLException, InsertException, AlreadyExistsException, DependenciesNotFoundException {
return ClassOA.insert(majorName, grade, classNum);
}
+ /**
+ * 插入班级(指定班级编号)
+ *
+ * @param classID 班级编号
+ * @param majorID 隶属专业
+ * @param grade 年级
+ * @param classNum 班号
+ * @return AClass 班级类
+ * @see AClass
+ */
public static AClass insertIntoClass(long classID, int majorID, int grade, int classNum) throws NoConfigException, AlreadyExistsException, SQLException, InsertException, DependenciesNotFoundException {
return ClassOA.insert(classID, majorID, grade, classNum);
}
+ /**
+ * 插入班级(指定班级编号)
+ *
+ * @param classID 班级编号
+ * @param majorName 隶属专业
+ * @param grade 年级
+ * @param classNum 班号
+ * @return AClass 班级类
+ * @see AClass
+ */
public static AClass insertIntoClass(long classID, String majorName, int grade, int classNum) throws NoConfigException, AlreadyExistsException, SQLException, InsertException, DependenciesNotFoundException {
return ClassOA.insert(classID, majorName, grade, classNum);
}
+ /**
+ * 通过班级编号查询班级是否存在
+ *
+ * @param classID 班级编号
+ * @return true 存在
+ * false 不存在
+ */
public static boolean isExistsInClass(long classID) throws NoConfigException, SQLException {
return ClassOA.isExists(classID);
}
+ /**
+ * 通过隶属专业编号,年级,班号查询班级是否存在
+ * @param majorID 专业编号
+ * @param grade 年级
+ * @param classNum 班号
+ * @return true 存在
+ * false 不存在
+ */
public static boolean isExistsInClass(int majorID, int grade, int classNum) throws NoConfigException, SQLException {
return ClassOA.isExists(majorID, grade, classNum);
}
+ /**
+ * 通过班级编号删除班级
+ *
+ * @param classID 班级编号
+ * @return true 成功
+ * false 失败
+ */
public static boolean deleteFromClass(long classID) throws NoConfigException, SQLException {
return ClassOA.delete(classID);
}
+ /**
+ * 通过隶属专业编号,年级,班号
+ *
+ * @param majorID 隶属专业
+ * @param grade 年级
+ * @param classNum 班号
+ * @return true 成功
+ * false 失败
+ */
public static boolean deleteFromClass(int majorID, int grade, int classNum) throws NoConfigException, SQLException {
return ClassOA.delete(majorID, grade, classNum);
}
+ /**
+ * 查询所有学生
+ *
+ * @return List 包含 Student 类型的数组
+ * @see List
+ */
public static List selectAllFromStudent() throws NoConfigException, SQLException {
return StudentOA.selectAll();
}
+ /**
+ * 通过学生编号查询学生
+ *
+ * @param stuID 学生编号
+ * @return Student 学生类
+ * @see Student
+ */
public static Student selectFromStudent(long stuID) throws NoConfigException, SQLException {
return StudentOA.select(stuID);
}
+ /**
+ * 学生检验密码
+ *
+ * @param stuID 学生编号
+ * @param passwd 密码
+ * @return true 成功
+ * false 失败
+ */
public static boolean checkPasswdInStudent(long stuID, String passwd) throws NoConfigException, SQLException, DependenciesNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
return StudentOA.checkPasswd(stuID, passwd);
}
+ /**
+ * 学生更改密码
+ *
+ * @param stuID 学生编号
+ * @param passwd 密码
+ * @return true 成功
+ * false 失败
+ */
public static boolean changePasswdInStudent(long stuID, String passwd) throws NoConfigException, SQLException, DependenciesNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
return StudentOA.changePasswd(stuID, passwd);
}
+ /**
+ * 插入学生
+ *
+ * @param stuID 学号
+ * @param stuName 学生姓名
+ * @param gender 性别
+ * @param classID 隶属班级
+ * @param passwd 密码
+ * @return Student 学生类
+ * @see Student
+ */
public static Student insertIntoStudent(long stuID, String stuName, Gender gender, long classID, String passwd) throws NoConfigException, SQLException, InsertException, AlreadyExistsException, DependenciesNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
return StudentOA.insert(stuID, stuName, gender, classID, passwd);
}
+ /**
+ * 通过学生编号查询学生是否存在
+ *
+ * @param stuID 学生编号
+ * @return true 存在
+ * false 不存在
+ */
public static boolean isExistsInStudent(long stuID) throws NoConfigException, SQLException {
return StudentOA.isExists(stuID);
}
+ /**
+ * 通过学生编号删除学生
+ *
+ * @param stuID 学生编号
+ * @return true 成功
+ * false 失败
+ */
public static boolean deleteFromStudent(long stuID) throws NoConfigException, SQLException {
return StudentOA.delete(stuID);
}
+ /**
+ * 查询所有教师
+ *
+ * @return List 包含 Teacher 类型的数组
+ * @see List
+ */
public static List selectAllFromTeacher() throws NoConfigException, SQLException {
return TeacherOA.selectAll();
}
+ /**
+ * 通过教师编号查询教师
+ *
+ * @param tchID 教师编号
+ * @return Teacher 教师类
+ * @see Teacher
+ */
public static Teacher selectFromTeacher(int tchID) throws NoConfigException, SQLException {
return TeacherOA.select(tchID);
}
+ /**
+ * 教师检验密码
+ *
+ * @param tchID 教师编号
+ * @param passwd 密码
+ * @return true 成功
+ * false 失败
+ */
public static boolean checkPasswdInTeacher(long tchID, String passwd) throws NoConfigException, SQLException, DependenciesNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
return TeacherOA.checkPasswd(tchID, passwd);
}
+ /**
+ * 教师更改密码
+ *
+ * @param tchID 教师编号
+ * @param passwd 密码
+ * @return true 成功
+ * false 失败
+ */
public static boolean changePasswdInTeacher(long tchID, String passwd) throws NoConfigException, SQLException, DependenciesNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
return TeacherOA.changePasswd(tchID, passwd);
}
+ /**
+ * 插入教师
+ *
+ * @param tchID 教师编号
+ * @param tchName 教师姓名
+ * @param gender 性别
+ * @param facID 隶属院系
+ * @param passwd 密码
+ * @return Teacher 教师类
+ * @see Teacher
+ */
public static Teacher insertIntoTeacher(long tchID, String tchName, Gender gender, int facID, String passwd) throws NoConfigException, SQLException, InsertException, AlreadyExistsException, DependenciesNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
return TeacherOA.insert(tchID, tchName, gender, facID, passwd);
}
+ /**
+ * 通过教师编号查询教师是否存在
+ *
+ * @param tchID 教师编号
+ * @return true 存在
+ * false 不存在
+ */
public static boolean isExistsInTeacher(long tchID) throws NoConfigException, SQLException {
return TeacherOA.isExists(tchID);
}
+ /**
+ * 通过教师编号删除教师
+ *
+ * @param tchID 教师编号
+ * @return true 成功
+ * false 失败
+ */
public static boolean deleteFromTeacher(long tchID) throws NoConfigException, SQLException {
return TeacherOA.delete(tchID);
}
+ /**
+ * 查询所有课程
+ *
+ * @return List 包含 Course 类型的数组
+ * @see List
+ */
public static List selectAllFromCourse() throws NoConfigException, SQLException {
return CourseOA.selectAll();
}
+ /**
+ * 通过课程编号查询课程
+ *
+ * @param courID 课程编号
+ * @return Course 课程类
+ * @see Course
+ */
public static Course selectFromCourse(long courID) throws NoConfigException, SQLException {
return CourseOA.select(courID);
}
+ /**
+ * 插入课程
+ *
+ * @param courID 课程编号
+ * @param subID 隶属专业
+ * @param tchID 隶属教师
+ * @param courTimeStart 课程开始时间
+ * @param courTimeEnd 课程结束时间
+ * @return Course 课程类
+ * @see Course
+ */
public static Course insertIntoCourse(long courID, int subID, long tchID, LocalDateTime courTimeStart, LocalDateTime courTimeEnd) throws NoConfigException, SQLException, InsertException, AlreadyExistsException, DependenciesNotFoundException {
return CourseOA.insert(courID, subID, tchID, courTimeStart, courTimeEnd);
}
+ /**
+ * 通过课程编号查询课程是否存在
+ *
+ * @param courID 课程编号
+ * @return true 存在
+ * false 不存在
+ */
public static boolean isExistsInCourse(long courID) throws NoConfigException, SQLException {
return CourseOA.isExists(courID);
}
+ /**
+ * 通过课程编号删除课程
+ *
+ * @param courID 课程编号
+ * @return true 成功
+ * false 失败
+ */
public static boolean deleteFromCourse(long courID) throws NoConfigException, SQLException {
return CourseOA.delete(courID);
}
+ /**
+ * 查询所有考勤
+ *
+ * @return List 包含 Attendance 类型的数组
+ * @see List
+ */
public static List selectAllFromAttendance() throws NoConfigException, SQLException {
return AttendanceOA.selectAll();
}
+ /**
+ * 通过考勤编号查询考勤
+ *
+ * @param attID 考勤编号
+ * @return Attendance 考勤类
+ * @see Attendance
+ */
public static Attendance selectFromAttendance(String attID) throws NoConfigException, SQLException {
return AttendanceOA.select(attID);
}
+ /**
+ * 插入考勤
+ *
+ * @param courID 隶属课程
+ * @param stuID 隶属学生
+ * @param attTime 考勤时间
+ * @param attStatus 考勤状态
+ * @return Attendance 考勤类
+ * @see Attendance
+ */
public static Attendance insertIntoAttendance(long courID, long stuID, @Nullable LocalDateTime attTime, AttStatus attStatus) throws NoConfigException, SQLException, InsertException, AlreadyExistsException, DependenciesNotFoundException {
return AttendanceOA.insert(courID, stuID, attTime, attStatus);
}
+ /**
+ * 通过考勤编号查询考勤是否存在
+ * @param attID 考勤编号
+ * @return true 存在
+ * false 不存在
+ */
public static boolean isExistsInAttendance(String attID) throws NoConfigException, SQLException {
return AttendanceOA.isExists(attID);
}
+ /**
+ * 通过考勤编号删除考勤
+ *
+ * @param attID 考勤编号
+ * @return true 成功
+ * false 失败
+ */
public static boolean deleteFromAttendance(String attID) throws NoConfigException, SQLException {
return AttendanceOA.delete(attID);
}
+ /**
+ * 查询教师所授课程
+ *
+ * @param tchID 教师编号
+ * @return List 包含 Course 类型的数组
+ * @see List
+ */
public static List queryCourses(long tchID) throws NoConfigException, SQLException, DependenciesNotFoundException {
- if (!isExistsInTeacher(tchID)) throw new DependenciesNotFoundException();
+ if (!TeacherOA.isExists(tchID)) throw new DependenciesNotFoundException();
ArrayList courses = new ArrayList<>();
String sql = "SELECT courID FROM course,teacher WHERE course.tchID=teacher.tchID AND course.tchID=?";
try (Connection connection = PoolHelper.getConnection()) {
@@ -284,7 +777,7 @@ public class DatabaseHelper {
preparedStatement.setLong(1, tchID);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
- courses.add(selectFromCourse(resultSet.getLong("courID")));
+ courses.add(CourseOA.select(resultSet.getLong("courID")));
}
}
}
@@ -292,8 +785,15 @@ public class DatabaseHelper {
return courses;
}
+ /**
+ * 查询课程所有学生
+ *
+ * @param courID 课程编号
+ * @return List 包含 Student 类型的数组
+ * @see List
+ */
public static List selectStudentsFromCourse(long courID) throws DependenciesNotFoundException, NoConfigException, SQLException {
- if (!isExistsInCourse(courID)) throw new DependenciesNotFoundException();
+ if (!CourseOA.isExists(courID)) throw new DependenciesNotFoundException();
ArrayList students = new ArrayList<>();
String sql = "SELECT stuID FROM attendance WHERE courID=?";
@@ -310,21 +810,41 @@ public class DatabaseHelper {
return students;
}
- public static boolean updateAttendance(String attID, AttStatus attStatus) throws NoConfigException, SQLException, DependenciesNotFoundException {
- if (!isExistsInAttendance(attID)) throw new DependenciesNotFoundException();
+ /**
+ * 更新考勤状态
+ *
+ * @param attID 考勤编号
+ * @param attStatus 考勤状态
+ * @param attTime 考勤时间(可空)
+ * @return true 成功
+ * false 失败
+ */
+ public static boolean updateAttendance(String attID, AttStatus attStatus, @Nullable LocalDateTime attTime) throws NoConfigException, SQLException, DependenciesNotFoundException {
+ if (!AttendanceOA.isExists(attID)) throw new DependenciesNotFoundException();
- String sql = "UPDATE attendance SET attStatus=? WHERE attID=?";
+ String sql = "UPDATE attendance SET attStatus=?,attTime=? WHERE attID=?";
try (Connection connection = PoolHelper.getConnection()) {
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
preparedStatement.setString(1, attStatus.name());
- preparedStatement.setString(2, attID);
+ if (attTime == null) {
+ preparedStatement.setTimestamp(2, null);
+ } else {
+ preparedStatement.setTimestamp(2, new Timestamp(attTime.toEpochSecond(ZoneOffset.of("+8")) * 1000));
+ }
+ preparedStatement.setString(3, attID);
return preparedStatement.executeUpdate() == 1;
}
}
}
+ /**
+ * 查询课程考勤
+ * @param courID 课程编号
+ * @return List 包含 Attendance 类型的数组
+ * @see List
+ */
public static List selectAttendanceByCourse(long courID) throws NoConfigException, SQLException, DependenciesNotFoundException {
- if (!isExistsInCourse(courID)) throw new DependenciesNotFoundException();
+ if (!CourseOA.isExists(courID)) throw new DependenciesNotFoundException();
ArrayList attendances = new ArrayList<>();
String sql = "SELECT attID FROM attendance WHERE courID=?";
@@ -341,6 +861,9 @@ public class DatabaseHelper {
return attendances;
}
+ /**
+ * 关闭数据库
+ */
public static void close() {
PoolHelper.close();
}
diff --git a/Library/src/main/java/com/cfive/classroom/library/database/util/AlreadyExistsException.java b/Library/src/main/java/com/cfive/classroom/library/database/util/AlreadyExistsException.java
index 8b37f69..3360f35 100644
--- a/Library/src/main/java/com/cfive/classroom/library/database/util/AlreadyExistsException.java
+++ b/Library/src/main/java/com/cfive/classroom/library/database/util/AlreadyExistsException.java
@@ -1,5 +1,11 @@
package com.cfive.classroom.library.database.util;
+/**
+ * 项目已存在异常
+ *
+ * @author FatttSnake
+ * @version 1.0
+ */
public class AlreadyExistsException extends Exception {
public AlreadyExistsException() {
super("This item already exists");
diff --git a/Library/src/main/java/com/cfive/classroom/library/database/util/DependenciesNotFoundException.java b/Library/src/main/java/com/cfive/classroom/library/database/util/DependenciesNotFoundException.java
index 70ab93c..3787823 100644
--- a/Library/src/main/java/com/cfive/classroom/library/database/util/DependenciesNotFoundException.java
+++ b/Library/src/main/java/com/cfive/classroom/library/database/util/DependenciesNotFoundException.java
@@ -1,5 +1,11 @@
package com.cfive.classroom.library.database.util;
+/**
+ * 依赖项不存在异常
+ *
+ * @author FatttSnake
+ * @version 1.0
+ */
public class DependenciesNotFoundException extends Exception {
public DependenciesNotFoundException() {
super("Could not found dependencies");
diff --git a/Library/src/main/java/com/cfive/classroom/library/database/util/InsertException.java b/Library/src/main/java/com/cfive/classroom/library/database/util/InsertException.java
index f1e247a..0d4986f 100644
--- a/Library/src/main/java/com/cfive/classroom/library/database/util/InsertException.java
+++ b/Library/src/main/java/com/cfive/classroom/library/database/util/InsertException.java
@@ -1,5 +1,11 @@
package com.cfive.classroom.library.database.util;
+/**
+ * 插入异常
+ *
+ * @author FatttSnake
+ * @version 1.0
+ */
public class InsertException extends Exception {
public InsertException() {
super("Could not insert the data into database");
diff --git a/Library/src/main/java/com/cfive/classroom/library/database/util/NoConfigException.java b/Library/src/main/java/com/cfive/classroom/library/database/util/NoConfigException.java
index 262520f..fb7670b 100644
--- a/Library/src/main/java/com/cfive/classroom/library/database/util/NoConfigException.java
+++ b/Library/src/main/java/com/cfive/classroom/library/database/util/NoConfigException.java
@@ -1,5 +1,11 @@
package com.cfive.classroom.library.database.util;
+/**
+ * 无配置文件异常
+ *
+ * @author FatttSnake
+ * @version 1.0
+ */
public class NoConfigException extends Exception {
public NoConfigException() {
super("Could not load configuration file");
diff --git a/Library/src/main/java/com/cfive/classroom/library/database/util/PBKDF2Util.java b/Library/src/main/java/com/cfive/classroom/library/database/util/PBKDF2Util.java
index 3fcb522..243f56d 100644
--- a/Library/src/main/java/com/cfive/classroom/library/database/util/PBKDF2Util.java
+++ b/Library/src/main/java/com/cfive/classroom/library/database/util/PBKDF2Util.java
@@ -8,6 +8,12 @@ import java.security.SecureRandom;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
+/**
+ * PBKDF2 密码加密工具类
+ *
+ * @author FatttSnake
+ * @version 1.0
+ */
public class PBKDF2Util {
public static final String PBKDF2_ALGORITHM = "PBKDF2WithHmacSHA1";