赞
踩
基于javaweb+mysql的springboot基于遗传算法学校排课系统(java+springboot+maven+mybatis+vue+mysql)
运行环境
Java≥8、MySQL≥5.7、Node.js≥10
开发工具
后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot基于遗传算法学校排课系统(java+springboot+maven+mybatis+vue+mysql)
一、项目简述本系统功能包括: 排课管理,课程管理,讲师管理,班级管理,学生管理,教学资料,学习文档,在线测试,教材列表,教学设计,帮助中心等等功能。
二、项目运行 环境配置:
Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。
项目技术:
Springboot + Maven + mybatis+ Vue 等等组成,B/S模式 + Maven管理等等。
/** * @Descripe: 文件上传,读取文件 */ @RestController public class UploadController { private Logger log = LoggerFactory.getLogger(UploadController.class); @Autowired private UploadService uploadService; /** * 上传课程计划Excel文件 * @return */ @PostMapping("/upload") public ServerResponse uploadClassTaskFile(MultipartFile file) { log.info("文件上传被调用。。。"); return uploadService.upload(file); } /** * 下载系统提供的Excel导入模板 * @return */ @GetMapping(value = "/download", consumes = MediaType.ALL_VALUE) public void downloadTemplate(final HttpServletResponse response) { // 获取文件 File file = new File("D:/arrange/excel/课程任务导入模板.xls"); if (!file.exists()) { // 没有该模板文件就调用创建模板文件方法 log.info("创建模板文件"); createTemplate(); } // 获取文件名字 String fileName = file.getName(); response.reset(); // 设置ContentType,响应内容为二进制数据流,编码为utf-8,此处设定的编码是文件内容的编码 response.setContentType("application/octet-stream;charset=utf-8"); // 以(Content-Disposition: attachment; filename="filename.jpg")格式设定默认文件名,设定utf编码,此处的编码是文件名的编码,使能正确显示中文文件名 try { response.setHeader("Content-Disposition", "attachment;fileName="+ fileName +";filename*=utf-8''"+ URLEncoder.encode(fileName,"utf-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace();
} } /** */ @RestController @RequestMapping("/teacher") public class TeacherController { @Autowired private TeacherService teacherService; @Autowired private TokenService tokenService; /**
/** * @Descripe: 获取系统相关的数据 */ @RestController public class SystemController { @Autowired private TeacherService teacherService; @Autowired private StudentService studentService; @Autowired private CourseInfoService courseInfoService; @Autowired private ClassInfoService classInfoService; @Autowired private ClassTaskService classTaskService; @Autowired private TeachbuildInfoService teachbuildInfoService; @Autowired private DocService docService; @Autowired private ExerciseService exerciseService; @Autowired private ClassroomService classroomService; @Autowired private StudentDao studentDao; @Autowired private OnlineCourseService onlineCourseService; @Autowired private TeacherDao teacherDao; @GetMapping("/systemdata") public ServerResponse systemData() { Map<String, Object> map = new HashMap<>(); // 讲师人数 int teachers = teacherService.count();
QueryWrapper wrapper = new QueryWrapper(); wrapper.orderByDesc("update_time"); Page<OnlineCourse> pages = new Page<>(page, limit); IPage<OnlineCourse> iPage = ocs.page(pages, wrapper); if (page != null) { return ServerResponse.ofSuccess(iPage); } return ServerResponse.ofError("查询不到数据"); } /** * 添加网课 * @param on * @return */ @PostMapping("/add") public ServerResponse addCourse(@RequestBody OnlineCourseAddVO on) { OnlineCourse onlineCourse = new OnlineCourse(); // 获取网课编号 String no = getCourseNo(); if(!StringUtils.isEmpty(no)) { onlineCourse.setOnlineNo(no); } onlineCourse.setOnlineName(on.getOnlineName()); onlineCourse.setDescription(on.getDescription()); onlineCourse.setCover(on.getCover()); onlineCourse.setOnlineCategoryId(on.getOnlineCategoryId()); onlineCourse.setOnlineCategoryName(on.getOnlineCategoryName()); onlineCourse.setFromUserId(on.getFromUserId()); onlineCourse.setFromUserType(on.getFromUserType()); onlineCourse.setFromUserName(on.getFromUserName()); boolean b = ocs.save(onlineCourse); if (b) { return ServerResponse.ofSuccess("添加网课成功"); } return ServerResponse.ofError("添加网课失败"); } /** * 根据id删除网课 * @param id * @return */ @DeleteMapping("/delete/{id}") public ServerResponse delete(@PathVariable("id") Integer id) { boolean b = ocs.removeById(id); if (b) { return ServerResponse.ofSuccess("删除网课成功"); }
* * @param c * @return */ @PostMapping("/addclasstask") public ServerResponse addClassTask(@RequestBody() ClassTaskDTO c) { System.out.println(c); ClassTask classTask = new ClassTask(); classTask.setSemester(c.getSemester()); classTask.setGradeNo(c.getGradeNo()); classTask.setClassNo(c.getClassNo()); classTask.setCourseNo(c.getCourseNo()); classTask.setCourseName(c.getCourseName()); classTask.setTeacherNo(c.getTeacherNo()); classTask.setRealname(c.getRealname()); classTask.setCourseAttr(c.getCourseAttr()); classTask.setStudentNum(c.getStudentNum()); classTask.setWeeksNumber(c.getWeeksNumber()); classTask.setWeeksSum(c.getWeeksSum()); classTask.setIsFix(c.getIsFix()); classTask.setClassTime(c.getClassTime()); boolean b = classTaskService.save(classTask); if (b) { return ServerResponse.ofSuccess("添加课程任务成功"); } return ServerResponse.ofError("添加课程任务失败"); } /** * 删除开课任务 * @param id * @return */ @DeleteMapping("/deleteclasstask/{id}") public ServerResponse deleteClassTask(@PathVariable("id") Integer id) { boolean b = classTaskService.removeById(id); if (b) { return ServerResponse.ofSuccess("删除成功"); } return ServerResponse.ofError("删除失败"); }
@Autowired private ClassTaskService classTaskService; @Autowired private TeachbuildInfoService teachbuildInfoService; @Autowired private DocService docService; @Autowired private ExerciseService exerciseService; @Autowired private ClassroomService classroomService; @Autowired private StudentDao studentDao; @Autowired private OnlineCourseService onlineCourseService; @Autowired private TeacherDao teacherDao; @GetMapping("/systemdata") public ServerResponse systemData() { Map<String, Object> map = new HashMap<>(); // 讲师人数 int teachers = teacherService.count(); // 学生人数 int students = studentService.count(); // 教材数量 int courses = courseInfoService.count(); // 班级数量 int classes = classInfoService.count(); // 教学楼数量 int teachbuilds = teachbuildInfoService.count(); // 教室数量 int classrooms = classroomService.count(); // 当前课程任务数量 int classtasks = classTaskService.count(); // 学习文档数 int docs = docService.count(); // 题库数量 int exercises = exerciseService.count(); // 网课数量 int onlineCourse = onlineCourseService.count(); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE,-1); Date d = cal.getTime(); SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");
/** */ @RestController @RequestMapping("/category") public class OnlineCategoryController { @Autowired private OnlineCategoryService ocs; /** * 添加类别 * @param categoryNo * @param categoryName * @return */ @PostMapping("/add") public ServerResponse addCategory(@RequestParam(name = "categoryNo") String categoryNo, @RequestParam(name = "categoryName") String categoryName, @RequestParam(name = "parentId") Integer parentId) { OnlineCategory onlineCategory = new OnlineCategory(); onlineCategory.setCategoryNo(categoryNo); onlineCategory.setCategoryName(categoryName); onlineCategory.setParentId(parentId); boolean b = ocs.save(onlineCategory); if (b) { return ServerResponse.ofSuccess("添加成功"); } return ServerResponse.ofError("添加失败"); } /**
System.out.println("666666"); // 如果查不到该学号,则学号可用,跳出循环 if (student == null) { return ServerResponse.ofSuccess(str3); } } while(true); } /** * 获取所有学生,带分页 * @param page * @param limit * @return */ @GetMapping("/students/{page}") public ServerResponse queryStudent(@PathVariable("page") Integer page, @RequestParam(defaultValue = "10") Integer limit) { Page<Student> pages = new Page<>(page, limit); QueryWrapper<Student> wrapper = new QueryWrapper<Student>().orderByDesc("student_no"); IPage<Student> iPage = studentService.page(pages, wrapper); return ServerResponse.ofSuccess(iPage); } /** * 根据姓名关键字搜学生 * @return */ @GetMapping("/search/{keyword}") public ServerResponse searchTeacher(@PathVariable("keyword") String keyword, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) { QueryWrapper<Student> wrapper = new QueryWrapper<>(); wrapper.orderByDesc("update_time"); wrapper.like(!StringUtils.isEmpty(keyword), "realname", keyword); Page<Student> pages = new Page<>(page, limit); IPage<Student> iPage = studentService.page(pages, wrapper); if (page != null) { return ServerResponse.ofSuccess(iPage); } return ServerResponse.ofError("查询不到数据!"); }
* * @return */ @GetMapping("/semester") public ServerResponse queryAllSemester() { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.select("semester"); wrapper.groupBy("semester"); List<ClassTask> list = classTaskService.list(wrapper); Set set = new HashSet(); for (ClassTask c : list) { set.add(c.getSemester()); } return ServerResponse.ofSuccess(set); } /** * 排课算法接口,传入学期开始去查对应学期的开课任务,进行排课,排完课程后添加到course_plan表 * * @param semester * @return */ @PostMapping("/arrange/{semester}") public ServerResponse arrange(@PathVariable("semester") String semester) { return classTaskService.classScheduling(semester); } }
/** * @Descripe: 拦截器 */ public class AuthenticationInterceptor implements HandlerInterceptor { @Autowired private AdminService adminService; @Autowired private StudentService studentService; @Autowired private TeacherService teacherService; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { // 从 http 请求头中取出 token String token = request.getHeader("token"); // 如果不是映射到方法直接通过 if(!(handler instanceof HandlerMethod)){ return true; } HandlerMethod handlerMethod = (HandlerMethod)handler; Method method = handlerMethod.getMethod(); //检查是否有passtoken注释,有则跳过认证 if (method.isAnnotationPresent(PassToken.class)) { PassToken passToken = method.getAnnotation(PassToken.class); if (passToken.required()) { return true; } } //检查有没有需要用户权限的注解 if (method.isAnnotationPresent(UserLoginToken.class)) { UserLoginToken userLoginToken = method.getAnnotation(UserLoginToken.class); if (userLoginToken.required()) { // 执行认证 if (token == null) { throw new RuntimeException("无token,请重新登录"); } // 获取 token 中的 user id String userId; try { userId = JWT.decode(token).getAudience().get(0); } catch (JWTDecodeException j) { throw new RuntimeException("401");
*/ @PostMapping("/upload") public ServerResponse upload(MultipartFile file) { Map<String, Object> map = AliyunUtil.upload(file, null); if (map != null) { return ServerResponse.ofSuccess(map); } return ServerResponse.ofError("视频上传失败"); } /** * 上传新视频 * @param * @return */ @PostMapping("/add") public ServerResponse addVideo(MultipartFile file, @RequestBody UserInfoVO u) { Map<String, Object> map = new HashMap(); // map = AliyunUtil.upload(file, null); OnlineVideo onlineVideo = new OnlineVideo(); // 所属课程的id onlineVideo.setOnlineCourseId(u.getCourseId()); onlineVideo.setVideoName(u.getVideoName()); onlineVideo.setVideoUrl(u.getVideoUrl()); onlineVideo.setCover(u.getCover()); // onlineVideo.setVideoUrl(map.get("url").toString()); // onlineVideo.setVideoName(map.get("name").toString()); onlineVideo.setVideoNo(u.getVideoNo()); // 视频编号 onlineVideo.setFromUserType(u.getUserType()); onlineVideo.setFromUserId(u.getId()); onlineVideo.setFromUserName(u.getRealname()); boolean b = ovs.save(onlineVideo); if (b) { return ServerResponse.ofSuccess("添加视频成功"); } return ServerResponse.ofError("添加视频失败"); } /** * 根据id删除视频 * @param id * @return */ @DeleteMapping("/delete/{id}") public ServerResponse deleteVideo(@PathVariable("id") Integer id) { boolean b = ovs.removeById(id); if (b) {
/** * @Descripe: 文件上传,读取文件 */ @RestController public class UploadController { private Logger log = LoggerFactory.getLogger(UploadController.class); @Autowired private UploadService uploadService; /** * 上传课程计划Excel文件 * @return */ @PostMapping("/upload") public ServerResponse uploadClassTaskFile(MultipartFile file) { log.info("文件上传被调用。。。"); return uploadService.upload(file); } /** * 下载系统提供的Excel导入模板 * @return */ @GetMapping(value = "/download", consumes = MediaType.ALL_VALUE) public void downloadTemplate(final HttpServletResponse response) { // 获取文件 File file = new File("D:/arrange/excel/课程任务导入模板.xls"); if (!file.exists()) { // 没有该模板文件就调用创建模板文件方法 log.info("创建模板文件"); createTemplate(); } // 获取文件名字 String fileName = file.getName();
/** */ @RestController @RequestMapping("/teacher") public class TeacherController { @Autowired private TeacherService teacherService; @Autowired private TokenService tokenService; /** * 上传讲师证件 * @param id * @param file * @return */ @PostMapping("/upload/{id}") public ServerResponse uploadLicense(@PathVariable("id") Integer id, MultipartFile file) { Map<String, Object> map = AliyunUtil.upload(file, "license"); String license = (String) map.get("url"); Teacher t = teacherService.getById(id); t.setLicense(license); boolean b = teacherService.updateById(t); if (b) { return ServerResponse.ofSuccess("上传证件成功"); } return ServerResponse.ofError("上传证件失败"); } /** * 讲师登录
* @return */ @PostMapping("/upload/{id}") public ServerResponse uploadLicense(@PathVariable("id") Integer id, MultipartFile file) { Map<String, Object> map = AliyunUtil.upload(file, "license"); String license = (String) map.get("url"); Teacher t = teacherService.getById(id); t.setLicense(license); boolean b = teacherService.updateById(t); if (b) { return ServerResponse.ofSuccess("上传证件成功"); } return ServerResponse.ofError("上传证件失败"); } /** * 讲师登录 * @param userLoginRequest * @return */ @PostMapping("/login") public ServerResponse teacherLogin(@RequestBody UserLoginRequest userLoginRequest) { Map<String, Object> map = new HashMap<>(); QueryWrapper<Teacher> wrapper = new QueryWrapper<>(); wrapper.eq("teacher_no", userLoginRequest.getUsername()); // 先查询是否有该账号 Teacher teacher2 = teacherService.getOne(wrapper); if (teacher2 == null) { return ServerResponse.ofError("账号不存在"); } else if (teacher2.getStatus() != 0) { return ServerResponse.ofError("账号状态异常,请联系管理员"); } // 登录,使用编号登录 Teacher teacher = teacherService.teacherLogin(userLoginRequest.getUsername(), userLoginRequest.getPassword()); if (teacher != null) { // 允许登录 String token = tokenService.getToken(teacher); map.put("teacher", teacher); map.put("token", token); return ServerResponse.ofSuccess(map); } // 否则一律视为密码错误 return ServerResponse.ofError("密码错误"); } /** * 根据id查询讲师,用于更新操作 * @param id
@Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception { } } /** */ @RestController @RequestMapping("/admin") public class AdminController { @Autowired private AdminService adminService; @Autowired
*/ @GetMapping("/locations/{page}") public ServerResponse queryLocationInfo(@PathVariable("page") Integer page, @RequestParam(defaultValue = "10") Integer limit) { Map<String, Object> map = new HashMap<>(); List<LocationVO> list = lid.locations((page - 1) * limit, limit); int total = lid.count(); map.put("records", list); map.put("total", total); return ServerResponse.ofSuccess(map); } /** * 根据id删除教学区域信息 * @param id * @return */ @DeleteMapping("/location/delete/{id}") public ServerResponse delete(@PathVariable("id") Integer id) { boolean b = lis.removeById(id); if (b) { return ServerResponse.ofSuccess("删除成功"); } return ServerResponse.ofError("删除失败"); } } /** */ @RestController
@RequestParam(defaultValue = "10") Integer limit) { Page<TeachbuildInfo> pages = new Page<>(page, limit); QueryWrapper<TeachbuildInfo> wrapper = new QueryWrapper<TeachbuildInfo>().orderByDesc("update_time"); IPage<TeachbuildInfo> ipage = teachBuildInfoService.page(pages, wrapper); if (ipage != null) { return ServerResponse.ofSuccess(ipage); } return ServerResponse.ofError("查询失败"); } /** * 查询所有教学楼 * @return */ @GetMapping("/list") public ServerResponse queryallTeachbuilding() { List<TeachbuildInfo> list = teachBuildInfoService.list(); return ServerResponse.ofSuccess(list); } /** * 根据id删除教学楼 * @param id * @return */ @DeleteMapping("/delete/{id}") public ServerResponse deleteTeachbuilding(@PathVariable("id") Integer id) { boolean b = teachBuildInfoService.removeById(id); if (b) { return ServerResponse.ofSuccess("删除成功"); } return ServerResponse.ofError("删除失败"); } /** * 添加教学楼 * @param t * @return
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。