diff --git a/sql/v2.0.0.sql b/sql/v2.0.0.sql new file mode 100644 index 0000000..8333a2c --- /dev/null +++ b/sql/v2.0.0.sql @@ -0,0 +1,53 @@ +create database if not exists education_administration_system default character set utf8mb4 collate utf8mb4_0900_ai_ci; + +use education_administration_system; + +create table if not exists Faculty( + id char(15) primary key comment '职工号', + name varchar(15) not null comment '姓名', + password varchar(40) not null comment '密码(SHA加密)', + sex char(5) not null comment '性别', + birth date comment '出生年月日', + department varchar(30) not null comment '部门/所在系', + title varchar(15) comment '职称' +); + +create table if not exists Student( + id char(15) primary key comment '学号', + name varchar(15) not null comment '姓名', + password varchar(40) not null comment '密码(SHA加密)', + sex char(5) not null comment '性别', + birth date comment '出生年月日', + department varchar(30) not null comment '所在系', + grade int not null comment '年级', + stuClass varchar(20) not null comment '班级' +); + +create table if not exists Course( + id char(8) primary key comment '课程号', + name varchar(30) not null comment '课程名', + credit int not null comment '学分', + cnt int not null comment '选课人数' +); + +create table if not exists SelectCourse( + courseId char(8) comment '课程号', + studentId char(15) comment '学生学号', + grade decimal(5,2) comment '成绩', + PRIMARY KEY(courseId,studentId), + foreign key(courseId) references Course(id), + foreign key(studentId) references Student(id) + on update cascade + on delete cascade +); + +create table if not exists TeachCourse( + courseId char(8) comment '课程号', + facultyId char(15) comment '教师工号', + location varchar(40) comment '授课地点', + primary key(courseId,facultyId), + foreign key(courseId) references Course(id), + foreign key(facultyId) references Faculty(id) + on update cascade + on delete cascade +); diff --git a/src/main/java/cn/czyx007/eas_gui/bean/Course.java b/src/main/java/cn/czyx007/eas_gui/bean/Course.java new file mode 100644 index 0000000..60de2e2 --- /dev/null +++ b/src/main/java/cn/czyx007/eas_gui/bean/Course.java @@ -0,0 +1,64 @@ +package cn.czyx007.eas_gui.bean; + +/** + * @author : 张宇轩 + * @createTime : 2022/6/25 - 20:19 + */ +public class Course { + private String id;//课程号 + private String name;//课程名 + private Integer credit;//学分 + private Integer cnt;//选科人数 + + public Course() { + } + + public Course(String id, String name, Integer credit, Integer cnt) { + this.id = id; + this.name = name; + this.credit = credit; + this.cnt = cnt; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getCredit() { + return credit; + } + + public void setCredit(Integer credit) { + this.credit = credit; + } + + public Integer getCnt() { + return cnt; + } + + public void setCnt(Integer cnt) { + this.cnt = cnt; + } + + @Override + public String toString() { + return "Course{" + + "id='" + id + '\'' + + ", name='" + name + '\'' + + ", credit=" + credit + + ", cnt=" + cnt + + '}'; + } +} diff --git a/src/main/java/cn/czyx007/eas_gui/bean/Faculty.java b/src/main/java/cn/czyx007/eas_gui/bean/Faculty.java index b795550..346dd20 100644 --- a/src/main/java/cn/czyx007/eas_gui/bean/Faculty.java +++ b/src/main/java/cn/czyx007/eas_gui/bean/Faculty.java @@ -1,5 +1,7 @@ package cn.czyx007.eas_gui.bean; +import java.time.LocalDate; + /** * @author : 张宇轩 * @createTime : 2022/6/24 - 22:05 @@ -8,16 +10,20 @@ public class Faculty { private String id;//职工号 private String name;//姓名 private String password;//密码 + private String sex;//性别 + private LocalDate birth;//出生年月日 private String department;// 部门 / 所在系 private String title;//职称 public Faculty() { } - public Faculty(String id, String name, String password, String department, String title) { + public Faculty(String id, String name, String password, String sex, LocalDate birth, String department, String title) { this.id = id; this.name = name; this.password = password; + this.sex = sex; + this.birth = birth; this.department = department; this.title = title; } @@ -62,12 +68,30 @@ public class Faculty { this.title = title; } + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public LocalDate getBirth() { + return birth; + } + + public void setBirth(LocalDate birth) { + this.birth = birth; + } + @Override public String toString() { return "Faculty{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", password='" + password + '\'' + + ", sex='" + sex + '\'' + + ", birth=" + birth + ", department='" + department + '\'' + ", title='" + title + '\'' + '}'; diff --git a/src/main/java/cn/czyx007/eas_gui/bean/SelectCourse.java b/src/main/java/cn/czyx007/eas_gui/bean/SelectCourse.java new file mode 100644 index 0000000..8fc20ac --- /dev/null +++ b/src/main/java/cn/czyx007/eas_gui/bean/SelectCourse.java @@ -0,0 +1,53 @@ +package cn.czyx007.eas_gui.bean; + +/** + * @author : 张宇轩 + * @createTime : 2022/6/25 - 20:20 + */ +public class SelectCourse { + private String courseId;//课程号 + private String studentId;//学生学号 + private Double grade;//成绩 + + public SelectCourse() { + } + + public SelectCourse(String courseId, String studentId, Double grade) { + this.courseId = courseId; + this.studentId = studentId; + this.grade = grade; + } + + public String getCourseId() { + return courseId; + } + + public void setCourseId(String courseId) { + this.courseId = courseId; + } + + public String getStudentId() { + return studentId; + } + + public void setStudentId(String studentId) { + this.studentId = studentId; + } + + public Double getGrade() { + return grade; + } + + public void setGrade(Double grade) { + this.grade = grade; + } + + @Override + public String toString() { + return "SelectCourse{" + + "courseId='" + courseId + '\'' + + ", studentId='" + studentId + '\'' + + ", grade=" + grade + + '}'; + } +} diff --git a/src/main/java/cn/czyx007/eas_gui/bean/Student.java b/src/main/java/cn/czyx007/eas_gui/bean/Student.java index 2e7981b..0393e25 100644 --- a/src/main/java/cn/czyx007/eas_gui/bean/Student.java +++ b/src/main/java/cn/czyx007/eas_gui/bean/Student.java @@ -1,5 +1,7 @@ package cn.czyx007.eas_gui.bean; +import java.time.LocalDate; + /** * @author : 张宇轩 * @createTime : 2022/6/24 - 22:07 @@ -8,6 +10,8 @@ public class Student { private String id;//学号 private String name;//姓名 private String password;//密码 + private String sex;//性别 + private LocalDate birth;//出生年月日 private String department;//所在系 private Integer grade;//年级 private String stuClass;//班级 @@ -15,10 +19,12 @@ public class Student { public Student() { } - public Student(String id, String name, String password, String department, Integer grade, String stuClass) { + public Student(String id, String name, String password, String sex, LocalDate birth, String department, Integer grade, String stuClass) { this.id = id; this.name = name; this.password = password; + this.sex = sex; + this.birth = birth; this.department = department; this.grade = grade; this.stuClass = stuClass; @@ -72,12 +78,30 @@ public class Student { this.stuClass = stuClass; } + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public LocalDate getBirth() { + return birth; + } + + public void setBirth(LocalDate birth) { + this.birth = birth; + } + @Override public String toString() { return "Student{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", password='" + password + '\'' + + ", sex='" + sex + '\'' + + ", birth=" + birth + ", department='" + department + '\'' + ", grade=" + grade + ", stuClass='" + stuClass + '\'' + diff --git a/src/main/java/cn/czyx007/eas_gui/bean/TeachCourse.java b/src/main/java/cn/czyx007/eas_gui/bean/TeachCourse.java new file mode 100644 index 0000000..7657f1b --- /dev/null +++ b/src/main/java/cn/czyx007/eas_gui/bean/TeachCourse.java @@ -0,0 +1,53 @@ +package cn.czyx007.eas_gui.bean; + +/** + * @author : 张宇轩 + * @createTime : 2022/6/25 - 20:21 + */ +public class TeachCourse { + private String courseId;//课程号 + private String facultyId;//教师工号 + private String location;//授课地点 + + public TeachCourse() { + } + + public TeachCourse(String courseId, String facultyId, String location) { + this.courseId = courseId; + this.facultyId = facultyId; + this.location = location; + } + + public String getCourseId() { + return courseId; + } + + public void setCourseId(String courseId) { + this.courseId = courseId; + } + + public String getFacultyId() { + return facultyId; + } + + public void setFacultyId(String facultyId) { + this.facultyId = facultyId; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + @Override + public String toString() { + return "TeachCourse{" + + "courseId='" + courseId + '\'' + + ", facultyId='" + facultyId + '\'' + + ", location='" + location + '\'' + + '}'; + } +} diff --git a/src/main/java/cn/czyx007/eas_gui/dao/BaseDAO.java b/src/main/java/cn/czyx007/eas_gui/dao/BaseDAO.java index bc8d943..08f6fd5 100644 --- a/src/main/java/cn/czyx007/eas_gui/dao/BaseDAO.java +++ b/src/main/java/cn/czyx007/eas_gui/dao/BaseDAO.java @@ -5,7 +5,10 @@ import cn.czyx007.eas_gui.dbc.JDBCUtils; import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; +import java.math.BigDecimal; import java.sql.*; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.ArrayList; import java.util.List; import java.sql.Connection; @@ -78,6 +81,12 @@ public abstract class BaseDAO { T t = clazz.newInstance(); for (int i = 0; i < columnCount; i++) { Object columnValue = resultSet.getObject(i + 1); + if (columnValue instanceof BigDecimal){ + columnValue = Double.parseDouble(columnValue.toString()); + } + if (columnValue instanceof LocalDateTime){ + columnValue = Date.from(((LocalDateTime) columnValue).atZone(ZoneId.systemDefault()).toInstant()); + } //获取列的别名(没有起别名时默认就是列名) String columnLabel = metaData.getColumnLabel(i + 1); diff --git a/src/main/java/cn/czyx007/eas_gui/dao/CourseDAO.java b/src/main/java/cn/czyx007/eas_gui/dao/CourseDAO.java new file mode 100644 index 0000000..8a9dee0 --- /dev/null +++ b/src/main/java/cn/czyx007/eas_gui/dao/CourseDAO.java @@ -0,0 +1,27 @@ +package cn.czyx007.eas_gui.dao; + +import cn.czyx007.eas_gui.bean.Course; + +import java.sql.Connection; +import java.util.List; + +/** + * @author : 张宇轩 + * @createTime : 2022/6/25 - 20:47 + */ +public interface CourseDAO { + //添加一门课程 + boolean addCourse(Connection connection, Course course); + //删除一门课程 + boolean deleteCourse(Connection connection,String id); + //修改课程学分 + boolean updateCourseCredit(Connection connection,String id,Integer credit); + //修改选课人数 + boolean updateCourseChooseCnt(Connection connection,String id,int change); + //根据课程号查询课程 + Course searchCourseById(Connection connection,String id); + //根据课程名查询课程 + List searchCourseByName(Connection connection,String name); + //查询所有课程 + List searchAllCourse(Connection connection); +} diff --git a/src/main/java/cn/czyx007/eas_gui/dao/FacultyDAO.java b/src/main/java/cn/czyx007/eas_gui/dao/FacultyDAO.java index da07ed6..c4a82c4 100644 --- a/src/main/java/cn/czyx007/eas_gui/dao/FacultyDAO.java +++ b/src/main/java/cn/czyx007/eas_gui/dao/FacultyDAO.java @@ -16,11 +16,15 @@ public interface FacultyDAO { //根据职工号删除一名教职工 boolean deleteFaculty(Connection connection,String id); //根据职工号更新一名教职工的信息 - boolean updateFaculty(Connection connection,String id,String password,String department,String title); + boolean updateFaculty(Connection connection,String id,String department,String title); //根据职工号查找一名教职工 Faculty getFacultyById(Connection connection,String id); //根据姓名查找匹配的教职工 List getFacultyByName(Connection connection,String name); + //查询所有教职工 + List getAllFaculty(Connection connection); //检查职工号与密码是否匹配 Long checkPassword(Connection connection,String id,String password); + //根据工号修改密码 + boolean changePassword(Connection connection,String id,String newPassword); } diff --git a/src/main/java/cn/czyx007/eas_gui/dao/SelectCourseDAO.java b/src/main/java/cn/czyx007/eas_gui/dao/SelectCourseDAO.java new file mode 100644 index 0000000..b9a0ab4 --- /dev/null +++ b/src/main/java/cn/czyx007/eas_gui/dao/SelectCourseDAO.java @@ -0,0 +1,32 @@ +package cn.czyx007.eas_gui.dao; + +import cn.czyx007.eas_gui.bean.Course; +import cn.czyx007.eas_gui.bean.SelectCourse; + +import java.sql.Connection; +import java.util.List; + +/** + * @author : 张宇轩 + * @createTime : 2022/6/25 - 21:24 + */ +public interface SelectCourseDAO { + //添加一条选课信息 + boolean addSelectCourse(Connection connection, SelectCourse selectcourse); + //删除一条选课信息 + boolean deleteSelectCourse(Connection connection,String courseId,String studentId); + //删除某课程选课信息 + boolean deleteSelectCourseByCourse(Connection connection,String courseId); + //删除某学生选课信息 + boolean deleteSelectCourseByStudent(Connection connection,String studentId); + //修改课程成绩 + boolean updateSelectCourseGrade(Connection connection,String courseId,String studentId,Integer grade); + //查询某人某科成绩 + SelectCourse searchOnesSelectCourse(Connection connection,String courseId,String studentId); + //根据课程号查询课程 + List searchSelectCourseByCourseId(Connection connection,String courseId); + //根据学名查询课程 + List searchSelectCourseByStudentId(Connection connection, String studentId); + //查询所有课程 + List searchAllSelectCourse(Connection connection); +} diff --git a/src/main/java/cn/czyx007/eas_gui/dao/StudentDAO.java b/src/main/java/cn/czyx007/eas_gui/dao/StudentDAO.java index 93029ed..187127e 100644 --- a/src/main/java/cn/czyx007/eas_gui/dao/StudentDAO.java +++ b/src/main/java/cn/czyx007/eas_gui/dao/StudentDAO.java @@ -16,11 +16,15 @@ public interface StudentDAO { //根据学号删除一名学生 boolean deleteStudent(Connection connection,String id); //根据学号更新一名学生的信息 - boolean updateStudent(Connection connection,String id,String password,String department,Integer grade,String stuClass); + boolean updateStudent(Connection connection,String id,String department,Integer grade,String stuClass); //根据学号查找一名学生 Student getStudentById(Connection connection, String id); //根据姓名查找匹配的学生 List getStudentByName(Connection connection, String name); + //查询所有学生 + List getAllStudent(Connection connection); //检查学号与密码是否匹配 Long checkPassword(Connection connection,String id,String password); + //根据学号修改密码 + boolean changePassword(Connection connection,String id,String newPassword); } diff --git a/src/main/java/cn/czyx007/eas_gui/dao/TeachCourseDAO.java b/src/main/java/cn/czyx007/eas_gui/dao/TeachCourseDAO.java new file mode 100644 index 0000000..3f94094 --- /dev/null +++ b/src/main/java/cn/czyx007/eas_gui/dao/TeachCourseDAO.java @@ -0,0 +1,32 @@ +package cn.czyx007.eas_gui.dao; + +import cn.czyx007.eas_gui.bean.SelectCourse; +import cn.czyx007.eas_gui.bean.TeachCourse; + +import java.sql.Connection; +import java.util.List; + +/** + * @author : 张宇轩 + * @createTime : 2022/6/25 - 21:39 + */ +public interface TeachCourseDAO { + //添加一条授课信息 + boolean addTeachCourse(Connection connection, TeachCourse teachCourse); + //删除一条授课信息 + boolean deleteTeachCourse(Connection connection,String courseId,String facultyId); + //删除某课程授课信息 + boolean deleteTeachCourseByCourse(Connection connection,String courseId); + //删除某老师授课信息 + boolean deleteTeachCourseByFaculty(Connection connection,String facultyId); + //修改授课地点 + boolean updateTeachCourseLocation(Connection connection,String courseId,String facultyId,String location); + //查询某老师某课授课地点 + TeachCourse searchOnesTeachCourse(Connection connection,String courseId,String facultyId); + //根据课程号查询授课信息 + List searchTeachCourseByCourseId(Connection connection, String courseId); + //根据教师工号查询授课信息 + List searchTeachCourseByFacultyId(Connection connection, String facultyId); + //查询所有授课信息 + List searchAllTeachCourse(Connection connection); +} diff --git a/src/main/java/cn/czyx007/eas_gui/dao/impl/CourseDAOImpl.java b/src/main/java/cn/czyx007/eas_gui/dao/impl/CourseDAOImpl.java new file mode 100644 index 0000000..643fbba --- /dev/null +++ b/src/main/java/cn/czyx007/eas_gui/dao/impl/CourseDAOImpl.java @@ -0,0 +1,63 @@ +package cn.czyx007.eas_gui.dao.impl; + +import cn.czyx007.eas_gui.bean.Course; +import cn.czyx007.eas_gui.dao.BaseDAO; +import cn.czyx007.eas_gui.dao.CourseDAO; + +import java.sql.Connection; +import java.util.List; + +/** + * @author : 张宇轩 + * @createTime : 2022/6/25 - 21:14 + */ +public class CourseDAOImpl extends BaseDAO implements CourseDAO { + @Override + public boolean addCourse(Connection connection, Course course) { + //language=MySQL + String sql = "insert into education_administration_system.course values (?,?,?,?)"; + return update(connection,sql,course.getId(),course.getName(),course.getCredit(),course.getCnt()) > 0; + } + + @Override + public boolean deleteCourse(Connection connection, String id) { + //language=MySQL + String sql = "delete from education_administration_system.course where id = ?"; + return update(connection,sql,id) > 0; + } + + @Override + public boolean updateCourseCredit(Connection connection, String id, Integer credit) { + //language=MySQL + String sql = "update education_administration_system.course set credit = ? where id = ?"; + return update(connection,sql,credit,id) > 0; + } + + @Override + public boolean updateCourseChooseCnt(Connection connection, String id, int change) { + //language=MySQL + String sql = "update education_administration_system.course set cnt = cnt + ? where id = ?"; + return update(connection,sql,change,id) > 0; + } + + @Override + public Course searchCourseById(Connection connection, String id) { + //language=MySQL + String sql = "select * from education_administration_system.course where id = ?"; + return search(connection,sql,id).get(0); + } + + @Override + public List searchCourseByName(Connection connection, String name) { + //language=MySQL + String sql = "select * from education_administration_system.course where name = ?"; + return search(connection,sql,name); + } + + @Override + public List searchAllCourse(Connection connection) { + //language=MySQL + String sql = "select * from education_administration_system.course"; + return search(connection,sql); + } +} diff --git a/src/main/java/cn/czyx007/eas_gui/dao/impl/FacultyDAOImpl.java b/src/main/java/cn/czyx007/eas_gui/dao/impl/FacultyDAOImpl.java index d246eb1..5c44dc9 100644 --- a/src/main/java/cn/czyx007/eas_gui/dao/impl/FacultyDAOImpl.java +++ b/src/main/java/cn/czyx007/eas_gui/dao/impl/FacultyDAOImpl.java @@ -15,8 +15,8 @@ public class FacultyDAOImpl extends BaseDAO implements FacultyDAO { @Override public boolean addFaculty(Connection connection, Faculty faculty) { //language=MySQL - String sql = "insert into education_administration_system.faculty values (?,?,sha1(?),?,?)"; - return update(connection, sql, faculty.getId(), faculty.getName(), faculty.getPassword(), faculty.getDepartment(), faculty.getTitle()) > 0; + String sql = "insert into education_administration_system.faculty values (?,?,sha1(?),?,?,?,?)"; + return update(connection, sql, faculty.getId(), faculty.getName(), faculty.getPassword(), faculty.getSex(),faculty.getBirth(), faculty.getDepartment(), faculty.getTitle()) > 0; } @Override @@ -27,13 +27,10 @@ public class FacultyDAOImpl extends BaseDAO implements FacultyDAO { } @Override - public boolean updateFaculty(Connection connection, String id,String password,String department,String title) { + public boolean updateFaculty(Connection connection, String id,String department,String title) { //language=MySQL String sql; - if (password != null){ - sql = "update education_administration_system.faculty set password = sha1(?) where id = ?"; - return update(connection,sql,password,id) > 0; - }else if (department != null){ + if (department != null){ sql = "update education_administration_system.faculty set department = ? where id = ?"; return update(connection,sql,department,id) > 0; }else if (title != null){ @@ -57,10 +54,24 @@ public class FacultyDAOImpl extends BaseDAO implements FacultyDAO { return search(connection,sql,name); } + @Override + public List getAllFaculty(Connection connection) { + //language=MySQL + String sql = "select * from education_administration_system.faculty"; + return search(connection,sql); + } + @Override public Long checkPassword(Connection connection, String id, String password) { //language=MySQL String sql = "select password = sha1(?) from education_administration_system.faculty where id = ?"; return getValue(connection,sql,password,id); } + + @Override + public boolean changePassword(Connection connection, String id, String newPassword) { + //language=MySQL + String sql = "update education_administration_system.faculty set password = sha1(?) where id = ?"; + return update(connection,newPassword,id) > 0; + } } diff --git a/src/main/java/cn/czyx007/eas_gui/dao/impl/SelectCourseDAOImpl.java b/src/main/java/cn/czyx007/eas_gui/dao/impl/SelectCourseDAOImpl.java new file mode 100644 index 0000000..e368bb1 --- /dev/null +++ b/src/main/java/cn/czyx007/eas_gui/dao/impl/SelectCourseDAOImpl.java @@ -0,0 +1,78 @@ +package cn.czyx007.eas_gui.dao.impl; + +import cn.czyx007.eas_gui.bean.Course; +import cn.czyx007.eas_gui.bean.SelectCourse; +import cn.czyx007.eas_gui.dao.BaseDAO; +import cn.czyx007.eas_gui.dao.SelectCourseDAO; + +import java.sql.Connection; +import java.util.List; + +/** + * @author : 张宇轩 + * @createTime : 2022/6/25 - 21:27 + */ +public class SelectCourseDAOImpl extends BaseDAO implements SelectCourseDAO { + @Override + public boolean addSelectCourse(Connection connection, SelectCourse selectCourse) { + //language=MySQL + String sql = "insert into education_administration_system.selectcourse values (?,?,?)"; + return update(connection,sql,selectCourse.getCourseId(),selectCourse.getStudentId(),selectCourse.getGrade()) > 0; + } + + @Override + public boolean deleteSelectCourse(Connection connection, String courseId,String studentId) { + //language=MySQL + String sql = "delete from education_administration_system.selectcourse where courseId = ? and studentId = ?"; + return update(connection,sql,courseId,studentId) > 0; + } + + @Override + public boolean deleteSelectCourseByCourse(Connection connection, String courseId) { + //language=MySQL + String sql = "delete from education_administration_system.selectcourse where courseId = ?"; + return update(connection,sql,courseId) > 0; + } + + @Override + public boolean deleteSelectCourseByStudent(Connection connection, String studentId) { + //language=MySQL + String sql = "delete from education_administration_system.selectcourse where studentId = ?"; + return update(connection,sql,studentId) > 0; + } + + @Override + public boolean updateSelectCourseGrade(Connection connection, String courseId, String studentId,Integer grade) { + //language=MySQL + String sql = "update education_administration_system.selectcourse set grade = ? where courseId = ? and studentId = ?"; + return update(connection,sql,grade,courseId,studentId) > 0; + } + + @Override + public SelectCourse searchOnesSelectCourse(Connection connection, String courseId, String studentId) { + //language=MySQL + String sql = "select * from education_administration_system.selectcourse where courseId = ? and studentId = ?"; + return search(connection,sql,courseId,studentId).get(0); + } + + @Override + public List searchSelectCourseByCourseId(Connection connection, String courseId) { + //language=MySQL + String sql = "select * from education_administration_system.selectcourse where courseId = ?"; + return search(connection,sql,courseId); + } + + @Override + public List searchSelectCourseByStudentId(Connection connection, String studentId) { + //language=MySQL + String sql = "select * from education_administration_system.selectcourse where studentId = ?"; + return search(connection,sql,studentId); + } + + @Override + public List searchAllSelectCourse(Connection connection) { + //language=MySQL + String sql = "select * from education_administration_system.selectcourse"; + return search(connection,sql); + } +} diff --git a/src/main/java/cn/czyx007/eas_gui/dao/impl/StudentDAOImpl.java b/src/main/java/cn/czyx007/eas_gui/dao/impl/StudentDAOImpl.java index 3a6e9c3..7dd095c 100644 --- a/src/main/java/cn/czyx007/eas_gui/dao/impl/StudentDAOImpl.java +++ b/src/main/java/cn/czyx007/eas_gui/dao/impl/StudentDAOImpl.java @@ -15,8 +15,8 @@ public class StudentDAOImpl extends BaseDAO implements StudentDAO { @Override public boolean addStudent(Connection connection, Student student) { //language=MySQL - String sql = "insert into education_administration_system.student values (?,?,sha1(?),?,?,?)"; - return update(connection,sql,student.getId(),student.getName(),student.getPassword(),student.getDepartment(),student.getGrade(),student.getStuClass()) > 0; + String sql = "insert into education_administration_system.student values (?,?,sha1(?),?,?,?,?,?)"; + return update(connection,sql,student.getId(),student.getName(),student.getPassword(),student.getSex(),student.getBirth(),student.getDepartment(),student.getGrade(),student.getStuClass()) > 0; } @Override @@ -27,13 +27,10 @@ public class StudentDAOImpl extends BaseDAO implements StudentDAO { } @Override - public boolean updateStudent(Connection connection, String id, String password, String department, Integer grade, String stuClass) { + public boolean updateStudent(Connection connection, String id, String department, Integer grade, String stuClass) { //language=MySQL String sql; - if (password != null){ - sql = "update education_administration_system.student set password = sha1(?) where id = ?"; - return update(connection,sql,password,id) > 0; - }else if (department != null){ + if (department != null){ sql = "update education_administration_system.student set department = ? where id = ?"; return update(connection,sql,department,id) > 0; }else if (grade != null){ @@ -60,10 +57,24 @@ public class StudentDAOImpl extends BaseDAO implements StudentDAO { return search(connection,sql,name); } + @Override + public List getAllStudent(Connection connection) { + //language=MySQL + String sql = "select * from education_administration_system.student"; + return search(connection,sql); + } + @Override public Long checkPassword(Connection connection, String id, String password) { //language=MySQL String sql = "select password = sha1(?) from education_administration_system.student where id = ?"; return getValue(connection,sql,password,id); } + + @Override + public boolean changePassword(Connection connection, String id, String newPassword) { + //language=MySQL + String sql = "update education_administration_system.student set password = sha1(?) where id = ?"; + return update(connection,newPassword,id) > 0; + } } diff --git a/src/main/java/cn/czyx007/eas_gui/dao/impl/TeachCourseDAOImpl.java b/src/main/java/cn/czyx007/eas_gui/dao/impl/TeachCourseDAOImpl.java new file mode 100644 index 0000000..1fa6158 --- /dev/null +++ b/src/main/java/cn/czyx007/eas_gui/dao/impl/TeachCourseDAOImpl.java @@ -0,0 +1,77 @@ +package cn.czyx007.eas_gui.dao.impl; + +import cn.czyx007.eas_gui.bean.TeachCourse; +import cn.czyx007.eas_gui.dao.BaseDAO; +import cn.czyx007.eas_gui.dao.TeachCourseDAO; + +import java.sql.Connection; +import java.util.List; + +/** + * @author : 张宇轩 + * @createTime : 2022/6/25 - 21:43 + */ +public class TeachCourseDAOImpl extends BaseDAO implements TeachCourseDAO { + @Override + public boolean addTeachCourse(Connection connection, TeachCourse teachCourse) { + //language=MySQL + String sql = "insert into education_administration_system.teachcourse values (?,?,?)"; + return update(connection,sql,teachCourse.getCourseId(),teachCourse.getFacultyId(),teachCourse.getLocation()) > 0; + } + + @Override + public boolean deleteTeachCourse(Connection connection, String courseId, String facultyId) { + //language=MySQL + String sql = "delete from education_administration_system.teachcourse where courseId = ? and facultyId = ?"; + return update(connection,sql,courseId,facultyId) > 0; + } + + @Override + public boolean deleteTeachCourseByCourse(Connection connection, String courseId) { + //language=MySQL + String sql = "delete from education_administration_system.teachcourse where courseId = ?"; + return update(connection,sql,courseId) > 0; + } + + @Override + public boolean deleteTeachCourseByFaculty(Connection connection, String facultyId) { + //language=MySQL + String sql = "delete from education_administration_system.teachcourse where facultyId = ?"; + return update(connection,sql,facultyId) > 0; + } + + @Override + public boolean updateTeachCourseLocation(Connection connection, String courseId, String facultyId, String location) { + //language=MySQL + String sql = "update education_administration_system.teachcourse set location = ? where courseId = ? and facultyId = ?"; + return update(connection,sql,location,courseId,facultyId) > 0; + } + + @Override + public TeachCourse searchOnesTeachCourse(Connection connection, String courseId, String facultyId) { + //language=MySQL + String sql = "select * from education_administration_system.teachcourse where courseId = ? and facultyId = ?"; + return search(connection,sql,courseId,facultyId).get(0); + } + + @Override + public List searchTeachCourseByCourseId(Connection connection, String courseId) { + //language=MySQL + String sql = "select * from education_administration_system.teachcourse where courseId = ?"; + return search(connection,sql,courseId); + } + + @Override + public List searchTeachCourseByFacultyId(Connection connection, String facultyId) { + //language=MySQL + String sql = "select * from education_administration_system.teachcourse where facultyId = ?"; + return search(connection,sql,facultyId); + } + + @Override + public List searchAllTeachCourse(Connection connection) { + //language=MySQL + String sql = "select * from education_administration_system.teachcourse"; + return search(connection,sql); + } +}