文章目录
- 一、项目演示
- 二、项目介绍
- 三、运行截图
- 四、主要代码
- 1.查询课程表代码
- 2.保存学生信息代码
- 3.用户登录代码
一、项目演示
项目演示地址: 视频地址
二、项目介绍
项目描述:这是一个基于SpringBoot+Electron框架开发的教务管理系统。首先,这是一个前后端分离的项目,前端采用Vue+Electron框架,支持以Web界面访问,也支持以桌面应用的形式访问。然后这项目代码简洁规范,注释说明详细,易于理解和学习。其次,这项目功能丰富,具有一个教务管理系统该有的所有功能。
项目功能:此项目分为三个角色:学生、老师和管理员。学生有管理个人信息、查看所有学期信息、查看个人课程和上课信息、查看个人成绩信息、查看公告信息和查看并支付个人缴费信息等等功能。老师有查看所有学生、老师和管理员信息、查看所有学院、专业和班级信息、查看所有学期信息、查看所有课程信息和查询上课信息、管理自己课程的成绩信息、查看公告信息和管理个人信息等等功能。管理员有管理所有学生、老师和管理员信息、管理所有学院、专业和班级信息、管理所有学期信息、管理所有课程信息和日程信息、查询上课信息、管理所有成绩信息、管理公告信息和管理所有缴费信息等等功能。
应用技术:SpringBoot + Electron + Vue3 + MySQL + MyBatis + Redis + ElementUI-Plus + Vite
运行环境:IntelliJ IDEA2019.3.5 + MySQL5.7(项目压缩包中自带) + Redis5.0.5(项目压缩包中自带) + JDK1.8 + Maven3.6.3(项目压缩包中自带)+ Node20.18.0(项目压缩包中自带)+ Visual Studio Code(项目压缩包中自带)
三、运行截图
四、主要代码
1.查询课程表代码
@Overridepublic ResponseDTO<List<CourseItemDTO>> getCourseTableList(CourseDTO courseDTO) {if(CommonUtil.isEmpty(courseDTO.getClassesId()) || CommonUtil.isEmpty(courseDTO.getSemesterId())) {return ResponseDTO.errorByMsg(CodeMsg.DATA_ERROR);}CourseClassesExample courseClassesExample = new CourseClassesExample();courseClassesExample.createCriteria().andClassesIdEqualTo(courseDTO.getClassesId());List<String> courseIdList = courseClassesMapper.selectByExample(courseClassesExample).stream().map(CourseClasses::getCourseId).collect(Collectors.toList());if(courseIdList.size() == 0) {return ResponseDTO.errorByMsg(CodeMsg.COURSE_CLASSES_EMPTY);}CourseExample courseExample = new CourseExample();courseExample.createCriteria().andIdIn(courseIdList).andSemesterIdEqualTo(courseDTO.getSemesterId());courseIdList = courseMapper.selectByExample(courseExample).stream().map(Course::getId).collect(Collectors.toList());if(courseIdList.size() == 0) {return ResponseDTO.errorByMsg(CodeMsg.COURSE_CLASSES_EMPTY);}CourseItemExample courseItemExample = new CourseItemExample();courseItemExample.createCriteria().andCourseIdIn(courseIdList);List<CourseItem> courseItemList = courseItemMapper.selectByExample(courseItemExample);List<CourseItemDTO> courseItemDTOList = CopyUtil.copyList(courseItemList, CourseItemDTO.class);for(CourseItemDTO courseItemDTO : courseItemDTOList) {Course course = courseMapper.selectByPrimaryKey(courseItemDTO.getCourseId());CourseDTO courseDTODB = CopyUtil.copy(Optional.ofNullable(course).orElse(new Course()), CourseDTO.class);Teacher teacher = teacherMapper.selectByPrimaryKey(courseDTODB.getTeacherId());courseDTODB.setTeacherDTO(CopyUtil.copy(Optional.ofNullable(teacher).orElse(new Teacher()), TeacherDTO.class));courseItemDTO.setCourseDTO(courseDTODB);}return ResponseDTO.success(courseItemDTOList);}
2.保存学生信息代码
@Overridepublic ResponseDTO<Boolean> saveStudent(StudentDTO studentDTO) {// 进行统一表单验证CodeMsg validate = ValidateEntityUtil.validate(studentDTO);if (!validate.getCode().equals(CodeMsg.SUCCESS.getCode())) {return ResponseDTO.errorByMsg(validate);}Student student = CopyUtil.copy(studentDTO, Student.class);if(CommonUtil.isEmpty(student.getId())) {// 添加操作// 判断学号/学工号是否存在if(isNoExist(student, "")){return ResponseDTO.errorByMsg(CodeMsg.NO_EXIST);}student.setId(UuidUtil.getShortUuid());if(studentMapper.insertSelective(student) == 0) {return ResponseDTO.errorByMsg(CodeMsg.USER_ADD_ERROR);}} else {// 修改操作// 判断学号/学工号是否存在if(isNoExist(student, student.getId())){return ResponseDTO.errorByMsg(CodeMsg.NO_EXIST);}ResponseDTO<UserDTO> loginUserResp = userService.getLoginUser(studentDTO.getToken());if(loginUserResp.getCode() != 0) {return ResponseDTO.errorByMsg(CodeMsg.USER_SESSION_EXPIRED);}if(studentMapper.updateByPrimaryKeySelective(student) == 0) {return ResponseDTO.errorByMsg(CodeMsg.USER_EDIT_ERROR);}UserDTO loginUserDTO = loginUserResp.getData();if(student.getId().equals(loginUserDTO.getId())) {// 如果是修改个人信息 则更新redis中数据loginUserDTO = CopyUtil.copy(studentMapper.selectByPrimaryKey(student.getId()), UserDTO.class);stringRedisTemplate.opsForValue().set("USER_" + studentDTO.getToken(), JSON.toJSONString(loginUserDTO), 3600, TimeUnit.SECONDS);}}return ResponseDTO.successByMsg(true, "保存成功!");}
3.用户登录代码
@Overridepublic ResponseDTO<UserDTO> login(UserDTO userDTO) {// 进行是否为空判断if(CommonUtil.isEmpty(userDTO.getNo())){return ResponseDTO.errorByMsg(CodeMsg.NO_EMPTY);}if(CommonUtil.isEmpty(userDTO.getPassword())){return ResponseDTO.errorByMsg(CodeMsg.PASSWORD_EMPTY);}if(userDTO.getRoleId() == null){return ResponseDTO.errorByMsg(CodeMsg.ROLE_EMPTY);}UserDTO loginUserDTO = new UserDTO();// 对比学号/学工号和密码是否正确if(RoleEnum.STUDENT.getCode().equals(userDTO.getRoleId())) {StudentExample studentExample = new StudentExample();studentExample.createCriteria().andNoEqualTo(userDTO.getNo()).andPasswordEqualTo(userDTO.getPassword());List<Student> studentList = studentMapper.selectByExample(studentExample);if(studentList == null || studentList.size() != 1){return ResponseDTO.errorByMsg(CodeMsg.NO_PASSWORD_ERROR);}loginUserDTO = CopyUtil.copy(studentList.get(0), UserDTO.class);} else if (RoleEnum.TEACHER.getCode().equals(userDTO.getRoleId())) {TeacherExample teacherExample = new TeacherExample();teacherExample.createCriteria().andNoEqualTo(userDTO.getNo()).andPasswordEqualTo(userDTO.getPassword());List<Teacher> teacherList = teacherMapper.selectByExample(teacherExample);if(teacherList == null || teacherList.size() != 1){return ResponseDTO.errorByMsg(CodeMsg.NO_PASSWORD_ERROR);}loginUserDTO = CopyUtil.copy(teacherList.get(0), UserDTO.class);} else if (RoleEnum.ADMIN.getCode().equals(userDTO.getRoleId())) {AdminExample adminExample = new AdminExample();adminExample.createCriteria().andNoEqualTo(userDTO.getNo()).andPasswordEqualTo(userDTO.getPassword());List<Admin> adminList = adminMapper.selectByExample(adminExample);if(adminList == null || adminList.size() != 1){return ResponseDTO.errorByMsg(CodeMsg.NO_PASSWORD_ERROR);}loginUserDTO = CopyUtil.copy(adminList.get(0), UserDTO.class);}loginUserDTO.setRoleId(userDTO.getRoleId());// 生成登录token并存入Redis中String token = UuidUtil.getShortUuid();loginUserDTO.setToken(token);//把token存入redis中 有效期1小时stringRedisTemplate.opsForValue().set("USER_" + token, JSON.toJSONString(loginUserDTO), 3600, TimeUnit.SECONDS);return ResponseDTO.successByMsg(loginUserDTO, "登录成功!");}