// 根据学界获取年级名称 private String getGrade(int y) { Date now = new Date(); int pastHalf = isPastHalf(now) ? 1 : 0; int currentYear = DateUtil.getYear(now); int year = currentYear + pastHalf - y; return NumberUtil.getSimpleNumber(year) + "年级"; }
/** 导出学生信息 */ @Override public List<ExcelInfo> queryExcelInfo(StudentPageRequest studentPageRequest) { Map<Integer, ExcelInfo> map = new TreeMap<>(); String schoolId = studentPageRequest.getSchoolId(); if (schoolId == null) { schoolId = userService.getSchoolId(studentPageRequest.getUserId()); studentPageRequest.setSchoolId(schoolId); } // 获取学生信息的总条数 MStudentManager studentManager = new MStudentManager(); BeanUtils.copyProperties(studentPageRequest, studentManager); List<MStudentManager> mStudentList = studentMapper.selectStudents_export(studentManager); for (MStudentManager students : mStudentList) { List<List<Object>> data; List<Object> row = new ArrayList<>(); row.add(students.getRealName()); if (students.getYears() != null) { int grade = ClassNameUtil.getGradeNum(students.getYears()); ExcelInfo excelInfo = map.get(grade); if (excelInfo == null) { excelInfo = new ExcelInfo(); data = new ArrayList<>(); excelInfo.setData(data); excelInfo.setSheetName(grade + "年级"); excelInfo.setHeaders(new String[] {"学生姓名", "所在班级", "登录账号", "上线情况"}); excelInfo.setColumnWidth(20); map.put(grade, excelInfo); } else { data = excelInfo.getData(); } row.add(grade + "年级" + students.getClassAliasName()); } else { ExcelInfo excelInfo = map.get(0); if (excelInfo == null) { excelInfo = new ExcelInfo(); data = new ArrayList<>(); excelInfo.setData(data); excelInfo.setSheetName("无班级"); excelInfo.setColumnWidth(20); excelInfo.setHeaders(new String[] {"学生姓名", "所在班级", "登录账号", "上线情况"}); map.put(0, excelInfo); } else { data = excelInfo.getData(); } row.add("无班级"); } row.add(students.getUserId()); row.add(DateUtil.getLogin_date(students.getLastLoginDate())); data.add(row); } return new ArrayList<>(map.values()); }
// 根据年份获取年级号 private int getGradeNum(int year) { Date now = new Date(); int pastHalf = isPastHalf(now) ? 1 : 0; int currentYear = DateUtil.getYear(now); return currentYear + pastHalf - year; }