Now we can read excel file:
public void ReadMajorExcel(MultipartFile file) throws IOException { Integer status = statusMapper.getStatus(); majorMapper.resetTable(); studentMapper.resetStudent(); if (status != null && (status == EnrollStatus.PRE_ENROLL.ordinal() || status >= EnrollStatus.READY.ordinal())){ throw new RuntimeException("现在不能导入文件"); } EasyExcel.read(file.getInputStream(), ExcelMajor.class, new ReadMajorListener(majorMapper, departmentMapper)).sheet().doRead(); if (status == null){ statusMapper.addLog("导入专业招生计划文件", EnrollStatus.WITHOUT_STUDENT.ordinal()); } else if (status == EnrollStatus.WITHOUT_MAJOR.ordinal()){ statusMapper.addLog("导入专业招生计划文件", EnrollStatus.FILE_READY.ordinal()); } else if (status == EnrollStatus.WITHOUT_STUDENT.ordinal()){ statusMapper.addLog("重新导入专业招生计划文件", EnrollStatus.WITHOUT_STUDENT.ordinal()); } else { statusMapper.addLog("重新导入专业招生计划文件", EnrollStatus.FILE_READY.ordinal()); } }
Then the data is loaded into ExcelMajor.class
public class ExcelMajor { @ExcelProperty("专业代号") private String majorId; @ExcelProperty("专业代码") private String majorCode; private int departmentId; @ExcelProperty("学院") private String departmentName; @ExcelProperty("专业名称") private String majorName; @ExcelProperty("备注") private String comment; @ExcelProperty("学制年限") private int period; @ExcelProperty("招生计划数") private int planStudentCount; private int realisticStudentCount; public String getMajorId() { return majorId; } public int getPlanStudentCount() { return planStudentCount; } public int getRealisticStudentCount() { return realisticStudentCount; } public void setRealisticStudentCount(int realisticStudentCount) { this.realisticStudentCount = realisticStudentCount; }
Then we map the data from two excel file
List<ExcelMajor> majors = majorMapper.getMajorPlanForEnroll(); Map<String,ExcelMajor> map = new HashMap<>(); for (ExcelMajor major : majors) { map.put(major.getMajorId(),major); }
Now we can run the enrollment code
int current = 0, size = 200; while(true){ List<ExcelStudent> students = studentMapper.getStudentRawForEnroll(current, size); if (students.size() == 0) break; for (ExcelStudent student : students) { if(doEnroll(map.get(student.getWill1()))){ student.setAcceptedType(1); student.setAcceptedMajorId(student.getWill1()); } else if(doEnroll(map.get(student.getWill2()))){ student.setAcceptedType(2); student.setAcceptedMajorId(student.getWill2()); } else if(doEnroll(map.get(student.getWill3()))){ student.setAcceptedType(3); student.setAcceptedMajorId(student.getWill3()); }else if(doEnroll(map.get(student.getWill4()))){ student.setAcceptedType(4); student.setAcceptedMajorId(student.getWill4()); }else if(doEnroll(map.get(student.getWill5()))){ student.setAcceptedType(5); student.setAcceptedMajorId(student.getWill5()); }else if(doEnroll(map.get(student.getWill6()))){ student.setAcceptedType(6); student.setAcceptedMajorId(student.getWill6()); } else { if(student.getAdjust() != 1) student.setAcceptedType(-1); else { student.setAcceptedType(0); } } } studentMapper.updateAccepted(students); current = current + size; } majorMapper.updateStudentCount(majors); if (status == EnrollStatus.FILE_READY.ordinal()){ statusMapper.addLog("预录取完成", EnrollStatus.PRE_ENROLL.ordinal()); } else { statusMapper.addLog("录取完成", EnrollStatus.ENROLLED.ordinal()); }
If a student’s application can’t be fulfilled, doAdjust() will be in action
public void doAdjust(){ Integer status = statusMapper.getStatus(); if (status == null || status != EnrollStatus.PRE_ENROLL.ordinal() && status != EnrollStatus.ENROLLED.ordinal()){ throw new RuntimeException("这个状态不能调剂"); } List<ExcelMajor> majors = majorMapper.getMajorPlanForAdjust(); int start = 0, size = 100, index = 0; while(true){ List<ExcelStudent> students = studentMapper.getStudentRawForAdjust(start, size); if(students.size() == 0) break; for (int i = 0;i<students.size();) { ExcelStudent student = students.get(i); if(index < majors.size()){ ExcelMajor major = majors.get(index); if (major.getRealisticStudentCount() < major.getPlanStudentCount()){ student.setAcceptedType(7); student.setAcceptedMajorId(major.getMajorId()); major.setRealisticStudentCount(major.getRealisticStudentCount()+1); i++; } else { index++; } } else { student.setAcceptedType(-1); i++; } } studentMapper.updateAdjust(students); //不能改变start } majorMapper.updateStudentCount(majors); if (status == EnrollStatus.PRE_ENROLL.ordinal()){ statusMapper.addLog("预调剂完成", EnrollStatus.PRE_ADJUST.ordinal()); } else { statusMapper.addLog("调剂完成", EnrollStatus.ADJUSTED.ordinal()); } }
4.项目效果图:(项目出来的效果,功能,以及其他相关图片,数据等)
Project demonstration:
- Login Page
After entering the system
If we take a look at the database now, we can find that the database is empty.
Now we upload the data stored in excel files
Upload success and we can now either reupload the data or just run the pre-enrollment.
Run pre enrollment
Run pre adjust, we can reset the enrollment plan is needed or continue the enrollment process.
Start the enrollment (may takes some time)
Start adjust
Now we can take a look at the data analysis page, all the data is sorted and be listed in different graphs