/** 查询无班级学生信息 */
 @Override
 public List<StudentManagerDTO> queryStudentsWithoutClassId(String schoolId) {
   List<MStudentManager> usersList = studentMapper.selectStudentsWithoutClassId(null, schoolId);
   List<StudentManagerDTO> userDTOList = new ArrayList<>();
   for (MStudentManager user : usersList) {
     StudentManagerDTO userDTO = new StudentManagerDTO();
     BeanUtils.copyProperties(user, userDTO);
     userDTOList.add(userDTO);
   }
   return userDTOList;
 }
 // 学生换班,管理员修改名称,删除该家长的缓存信息
 private void deleteRedis(List<MFamilyRelation> frList) {
   List<String> keyList = new ArrayList<>();
   for (MFamilyRelation fr : frList) {
     keyList.add(MessageFormat.format(CacheConstants.KEY_KID_OF_PARENT, fr.getUserId()));
     keyList.add(MessageFormat.format(CacheConstants.KEY_FAMILY_RELATION, fr.getUserId()));
     keyList.add(MessageFormat.format(CacheConstants.KEY_KID_NAME_OF_PARENT, fr.getUserId()));
   }
   if (CollectionUtils.isNotEmpty(keyList)) {
     cacheService.delete(keyList);
   }
 }
 /** APP接口、WEB平台:根据班级ID查询该班级所有学生 */
 @Override
 public List<StudentManagerDTO> queryClassStudents(String classId) {
   String schoolId = classService.getSchoolId(classId);
   List<MStudentManager> userList = studentMapper.selectClassStudents(classId, schoolId);
   List<StudentManagerDTO> userDTOList = new ArrayList<>();
   for (MStudentManager u : userList) {
     StudentManagerDTO userDTO = new StudentManagerDTO();
     BeanUtils.copyProperties(u, userDTO);
     userDTOList.add(userDTO);
   }
   return userDTOList;
 }
 /** APP接口、WEB平台:根据学生名称查询学生信息 */
 @Override
 public List<StudentManagerDTO> queryStudentByRealName(String realName, String userId) {
   if (StringUtils.isEmpty(userId)) {
     logger.debug("userId 不能为空");
     return null;
   }
   String schoolId = userService.getSchoolId(userId);
   List<MStudentManager> userList = studentMapper.selectStudentByRealName(realName, schoolId);
   List<StudentManagerDTO> userDTOList = new ArrayList<>();
   for (MStudentManager u : userList) {
     StudentManagerDTO userDTO = new StudentManagerDTO();
     BeanUtils.copyProperties(u, userDTO);
     userDTOList.add(userDTO);
   }
   return userDTOList;
 }
 /** 通知用 根据学生Id查询家庭成员 */
 @Override
 public List<FamilyRelationDTO> queryFamilyByStudent(String userId) {
   String key = MessageFormat.format(CacheConstants.KEY_PARENT_OF_KID, userId);
   List<FamilyRelationDTO> list = cacheService.get(key);
   if (list != null) {
     return list;
   }
   List<FamilyRelationDTO> familyRelationDTOs = new ArrayList<>();
   List<MFamilyRelation> mFamilyRelations =
       famillyRelationMapper.queryFamilyByStudent(userId, userService.getSchoolId(userId));
   for (MFamilyRelation fr : mFamilyRelations) {
     FamilyRelationDTO familyRelationDTO = new FamilyRelationDTO();
     BeanUtils.copyProperties(fr, familyRelationDTO);
     familyRelationDTOs.add(familyRelationDTO);
   }
   cacheService.set(key, familyRelationDTOs, CacheConstants.CACHE_SEVEN_DAY, TimeUnit.DAYS);
   return familyRelationDTOs;
 }
  /** 查询学生信息分页 */
  @Override
  public PageResponse<StudentManagerDTO> queryStudentPage(StudentPageRequest studentPageRequest) {
    String schoolId = studentPageRequest.getSchoolId();
    if (schoolId == null) {
      schoolId = userService.getSchoolId(studentPageRequest.getUserId());
      studentPageRequest.setSchoolId(schoolId);
    }
    // 获取学生信息的总条数
    MStudentManager studentManager = new MStudentManager();
    BeanUtils.copyProperties(studentPageRequest, studentManager);
    long count = studentMapper.selectCount(studentManager);
    // 获取当前页的信息
    Page page = PageUtils.buildPage(studentPageRequest);
    List<MStudentManager> mStudentList =
        studentMapper.selectMStudentManagerPage(page, studentManager);
    /*
    给返回接口赋值
     */
    List<StudentManagerDTO> studentManagerDTOs = new ArrayList<>();
    for (MStudentManager mstudents : mStudentList) {
      StudentManagerDTO studentManagerDTO = new StudentManagerDTO();
      BeanUtils.copyProperties(mstudents, studentManagerDTO);
      studentManagerDTO.setLastLoginDate(
          mstudents.getLastLoginDate() == null
              ? "从未登录"
              : DateFormatUtils.format(mstudents.getLastLoginDate(), "yyyy-MM-dd HH:mm"));
      if (mstudents.getYears() != null) {
        studentManagerDTO.setClassAliasName(
            getGrade(mstudents.getYears()) + studentManagerDTO.getClassAliasName());
      } else {
        studentManagerDTO.setClassAliasName("无班级");
      }
      studentManagerDTOs.add(studentManagerDTO);
    }

    // 返回对象
    PageResponse<StudentManagerDTO> pageResponse = new PageResponse<>();
    PageUtils.buldPageResponse(studentPageRequest, pageResponse);
    pageResponse.setRows(studentManagerDTOs);
    pageResponse.setRecords(count);
    return pageResponse;
  }
 /** 导出学生信息 */
 @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());
 }