五、核心代码
5.1 查询课程
@RequestMapping(value = "/getByPage", method = RequestMethod.GET) @ApiOperation(value = "查询课程") public Result<IPage<Curriculum>> getByPage(@ModelAttribute Curriculum curriculum ,@ModelAttribute PageVo page){ QueryWrapper<Curriculum> qw = new QueryWrapper<>(); if(!ZwzNullUtils.isNull(curriculum.getTitle())) { qw.like("title",curriculum.getTitle()); } if(!ZwzNullUtils.isNull(curriculum.getStatus())) { qw.like("status",curriculum.getStatus()); } IPage<Curriculum> data = iCurriculumService.page(PageUtil.initMpPage(page),qw); return new ResultUtil<IPage<Curriculum>>().setData(data); }
5.2 新增课程
@RequestMapping(value = "/insert", method = RequestMethod.POST) @ApiOperation(value = "新增课程") public Result<Curriculum> insert(Curriculum curriculum){ iCurriculumService.saveOrUpdate(curriculum); return new ResultUtil<Curriculum>().setData(curriculum); }
5.3 查询全部排课
@RequestMapping(value = "/getCardList", method = RequestMethod.GET) @ApiOperation(value = "查询全部排课") public Result<List<TeachingScheduleVo>> getCardList(){ List<TeachingScheduleVo> ans = new ArrayList<>(); QueryWrapper<TeachingSchedule> qw1 = new QueryWrapper<>(); qw1.eq("x",1); qw1.orderByAsc("y"); ans.add(new TeachingScheduleVo(1,iTeachingScheduleService.list(qw1))); QueryWrapper<TeachingSchedule> qw2 = new QueryWrapper<>(); qw2.eq("x",2); qw2.orderByAsc("y"); ans.add(new TeachingScheduleVo(2,iTeachingScheduleService.list(qw2))); QueryWrapper<TeachingSchedule> qw3 = new QueryWrapper<>(); qw3.eq("x",3); qw3.orderByAsc("y"); ans.add(new TeachingScheduleVo(3,iTeachingScheduleService.list(qw3))); QueryWrapper<TeachingSchedule> qw4 = new QueryWrapper<>(); qw4.eq("x",4); qw4.orderByAsc("y"); ans.add(new TeachingScheduleVo(4,iTeachingScheduleService.list(qw4))); QueryWrapper<TeachingSchedule> qw5 = new QueryWrapper<>(); qw5.eq("x",5); qw5.orderByAsc("y"); ans.add(new TeachingScheduleVo(5,iTeachingScheduleService.list(qw5))); QueryWrapper<TeachingSchedule> qw6 = new QueryWrapper<>(); qw6.eq("x",6); qw6.orderByAsc("y"); ans.add(new TeachingScheduleVo(6,iTeachingScheduleService.list(qw6))); QueryWrapper<TeachingSchedule> qw7 = new QueryWrapper<>(); qw7.eq("x",7); qw7.orderByAsc("y"); ans.add(new TeachingScheduleVo(7,iTeachingScheduleService.list(qw7))); return new ResultUtil<List<TeachingScheduleVo>>().setData(ans); }
5.4 查询排课申请
@RequestMapping(value = "/getByPage", method = RequestMethod.GET) @ApiOperation(value = "查询排课申请") public Result<IPage<TeachingApply>> getByPage(@ModelAttribute TeachingApply teachingApply ,@ModelAttribute PageVo page){ QueryWrapper<TeachingApply> qw = new QueryWrapper<>(); User currUser = securityUtil.getCurrUser(); QueryWrapper<User> userQw = new QueryWrapper<>(); userQw.eq("id",currUser.getId()); userQw.inSql("id","SELECT user_id FROM a_user_role WHERE del_flag = 0 AND role_id = '496138616573952'"); if(iUserService.count(userQw) < 1L) { qw.eq("user_id",currUser.getId()); } if(!ZwzNullUtils.isNull(teachingApply.getUserName())) { qw.like("user_name",teachingApply.getUserName()); } if(!ZwzNullUtils.isNull(teachingApply.getCurriculumName())) { qw.like("curriculum_name",teachingApply.getCurriculumName()); } if(!ZwzNullUtils.isNull(teachingApply.getScheduleName())) { qw.like("schedule_name",teachingApply.getScheduleName()); } IPage<TeachingApply> data = iTeachingApplyService.page(PageUtil.initMpPage(page),qw); return new ResultUtil<IPage<TeachingApply>>().setData(data); }
5.5 自动排课算法
@RequestMapping(value = "/work", method = RequestMethod.GET) @ApiOperation(value = "自动排课") public Result<Object> work(){ List<TeachingApply> applyList = iTeachingApplyService.list(); List<TeachingApplyVo> ans = new ArrayList<>(); // 分离用户的排课申请 for (TeachingApply a : applyList) { boolean flag = true; for (TeachingApplyVo vo : ans) { if(Objects.equals(a.getUserId(),vo.getUserId())) { vo.getList().add(a); flag = false; break; } } if(flag) { TeachingApplyVo vo = new TeachingApplyVo(); vo.setUserId(a.getUserId()); vo.setUserName(a.getUserName()); List<TeachingApply> aList = new ArrayList<>(); aList.add(a); vo.setList(aList); vo.setFlag(0); ans.add(vo); } } // 课位初始化 List<TeachingSchedule> scheduleList = iTeachingScheduleService.list(); for (TeachingSchedule s : scheduleList) { s.setCurId(""); s.setCurName(""); s.setTeacherName(""); } // 根据排课申请数量升序排列,尽可能满足多的教师完成排课 Collections.sort(ans, new Comparator<TeachingApplyVo>() { @Override public int compare(TeachingApplyVo o1, TeachingApplyVo o2) { return o1.getList().size() - o2.getList().size(); } }); for(int i = 0; i < ans.size(); i ++) { List<TeachingSchedule> tempList = new ArrayList<>(); for (TeachingSchedule s : scheduleList) { tempList.add(s); } // 判断能否满足排课 boolean flagSum = true; for (TeachingApply a : ans.get(i).getList()) { boolean flag = true; for (TeachingSchedule teachingSchedule : tempList) { if(Objects.equals(a.getScheduleId(),teachingSchedule.getId()) && ZwzNullUtils.isNull(teachingSchedule.getCurId())) { // 排课成功 teachingSchedule.setCurId(a.getCurriculumId()); teachingSchedule.setCurName(a.getCurriculumName()); teachingSchedule.setTeacherName(a.getUserName()); a.setStatus("排课成功"); flag = false; break; } } if(flag) { // 排课失败,下一位 flagSum = false; break; } } if(flagSum) { // 如果全部课程可以排课,则保存 scheduleList = new ArrayList<>(); for (TeachingSchedule vo : tempList) { scheduleList.add(vo); } ans.get(i).setFlag(1); } else { // 否则不保存 } } // 未完成排课的,按顺序能排上的排上 for (TeachingApplyVo vo : ans) { if(Objects.equals(1,vo.getFlag())) { continue; } for (TeachingApply a : vo.getList()) { for (TeachingSchedule teachingSchedule : scheduleList) { if(Objects.equals(a.getScheduleId(),teachingSchedule.getId()) && ZwzNullUtils.isNull(teachingSchedule.getCurId())) { // 补排课成功 teachingSchedule.setCurId(a.getCurriculumId()); teachingSchedule.setCurName(a.getCurriculumName()); teachingSchedule.setTeacherName(a.getUserName()); a.setStatus("排课成功"); break; } } } } // 保存排课数据 for (TeachingSchedule teachingSchedule : scheduleList) { iTeachingScheduleService.saveOrUpdate(teachingSchedule); } // 保存申请数据 for (TeachingApplyVo vo : ans) { for (TeachingApply a : vo.getList()) { if(!Objects.equals("排课成功",a.getStatus())) { a.setStatus("排课失败"); } iTeachingApplyService.saveOrUpdate(a); } } return ResultUtil.success(); }
六、免责说明
- 本项目仅供个人学习使用,商用授权请联系博主,否则后果自负。
- 博主拥有本软件构建后的应用系统全部内容所有权及独立的知识产权,拥有最终解释权。
- 如有问题,欢迎在仓库 Issue 留言,看到后会第一时间回复,相关意见会酌情考虑,但没有一定被采纳的承诺或保证。
下载本系统代码或使用本系统的用户,必须同意以下内容,否则请勿下载!
- 出于自愿而使用/开发本软件,了解使用本软件的风险,且同意自己承担使用本软件的风险。
- 利用本软件构建的网站的任何信息内容以及导致的任何版权纠纷和法律争议及后果和博主无关,博主对此不承担任何责任。
- 在任何情况下,对于因使用或无法使用本软件而导致的任何难以合理预估的损失(包括但不仅限于商业利润损失、业务中断与业务信息丢失),博主概不承担任何责任。
- 必须了解使用本软件的风险,博主不承诺提供一对一的技术支持、使用担保,也不承担任何因本软件而产生的难以预料的问题的相关责任。