mirror of
https://github.com/FatttSnake/ClassroomInteraction.git
synced 2026-04-06 05:01:27 +08:00
Added selectFromAttendance(long stuID, long courID)
This commit is contained in:
@@ -726,6 +726,18 @@ public class DatabaseHelper {
|
|||||||
return AttendanceOA.select(attID);
|
return AttendanceOA.select(attID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过学生编号和课程编号查询考勤
|
||||||
|
*
|
||||||
|
* @param stuID 学生编号
|
||||||
|
* @param courID 课程编号
|
||||||
|
* @return <code>Attendance</code> 考勤类
|
||||||
|
* @see Attendance
|
||||||
|
*/
|
||||||
|
public static Attendance selectFromAttendance(long stuID, long courID) throws NoConfigException, SQLException {
|
||||||
|
return AttendanceOA.select(stuID, courID);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插入考勤
|
* 插入考勤
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -60,6 +60,29 @@ public class AttendanceOA {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Attendance select(long stuID, long courID) throws SQLException, NoConfigException {
|
||||||
|
String sql = "SELECT attID,attTime,attStatus,student.stuID,stuName,stuGender,student.passwd,student.salt,class.classID,grade,classNum,major.majorID,majorName,course.courID,courTimeFrom,courTimeEnd,subject.subID,subName,teacher.tchID,tchName,tchGender,teacher.passwd,teacher.salt,faculty.facID,facName FROM attendance,student,class,major,course,subject,teacher,faculty where attendance.courID=course.courID AND attendance.stuID=student.stuID AND class.classID=student.classID AND class.majorID=major.majorID AND major.facID=faculty.facID AND course.subID=subject.subID AND course.tchID=teacher.tchID AND teacher.facID=faculty.facID AND attendance.stuID=? AND attendance.courID=?";
|
||||||
|
try (Connection connection = PoolHelper.getConnection()) {
|
||||||
|
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||||
|
preparedStatement.setLong(1, stuID);
|
||||||
|
preparedStatement.setLong(2, courID);
|
||||||
|
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
||||||
|
if (resultSet.next()) {
|
||||||
|
Subject subject = new Subject(resultSet.getInt("subID"), resultSet.getString("subName"));
|
||||||
|
Faculty faculty = new Faculty(resultSet.getInt("facID"), resultSet.getString("facName"));
|
||||||
|
Teacher teacher = new Teacher(resultSet.getLong("tchID"), resultSet.getString("tchName"), resultSet.getString("tchGender").equals("m") ? Gender.m : Gender.f, faculty, resultSet.getString("teacher.passwd"), resultSet.getString("teacher.salt"));
|
||||||
|
Course course = new Course(resultSet.getLong("courID"), subject, teacher, LocalDateTime.ofEpochSecond(resultSet.getTimestamp("courTimeFrom").getTime() / 1000, 0, ZoneOffset.of("+8")), LocalDateTime.ofEpochSecond(resultSet.getTimestamp("courTimeEnd").getTime() / 1000, 0, ZoneOffset.of("+8")));
|
||||||
|
Major major = new Major(resultSet.getInt("majorID"), resultSet.getString("majorName"), faculty);
|
||||||
|
AClass aClass = new AClass(resultSet.getLong("classID"), major, resultSet.getInt("grade"), resultSet.getInt("classNum"));
|
||||||
|
Student student = new Student(resultSet.getLong("stuID"), resultSet.getString("stuName"), resultSet.getString("stuGender").equals("m") ? Gender.m : Gender.f, aClass, resultSet.getString("student.passwd"), resultSet.getString("student.salt"));
|
||||||
|
return new Attendance(resultSet.getString("attID"), course, student, resultSet.getTimestamp("attTime") == null ? null : LocalDateTime.ofEpochSecond(resultSet.getTimestamp("attTime").getTime() / 1000, 0, ZoneOffset.of("+8")), AttStatus.fromString(resultSet.getString("attStatus")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static Attendance insert(long courID, long stuID, @Nullable LocalDateTime attTime, AttStatus attStatus) throws NoConfigException, SQLException, AlreadyExistsException, DependenciesNotFoundException, InsertException {
|
public static Attendance insert(long courID, long stuID, @Nullable LocalDateTime attTime, AttStatus attStatus) throws NoConfigException, SQLException, AlreadyExistsException, DependenciesNotFoundException, InsertException {
|
||||||
if (!CourseOA.isExists(courID) || !StudentOA.isExists(stuID)) throw new DependenciesNotFoundException();
|
if (!CourseOA.isExists(courID) || !StudentOA.isExists(stuID)) throw new DependenciesNotFoundException();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user