@Override public StudentDTO queryStudentForAPP(String userId, String schoolId) { UserDTO mUsers = userService.getByUserId(userId); if (mUsers == null) { logger.debug("未找到学乐号为" + userId + "的学生用户"); return null; } MStudent mStudent = studentMapper.selectByPrimaryKey(userId, schoolId); if (mStudent == null) { logger.debug("未找到学生id为" + userId + "的学生"); throw new MemberException("未找到学生id为" + userId + "的学生"); } // 学生信息 StudentDTO studentDTO = new StudentDTO(); studentDTO.setUserId(userId); studentDTO.setRealName(mUsers.getRealName()); studentDTO.setSchoolId(mStudent.getSchoolId()); studentDTO.setSchoolName(mStudent.getSchoolName()); studentDTO.setClassId(mStudent.getClassId()); studentDTO.setClassName(mStudent.getClassName()); studentDTO.setMobile(mUsers.getMobile()); studentDTO.setEmail(mUsers.getEmail()); // 学校所在区域信息 MSchool mSchool = mSchoolMapper.selectByPrimaryKey(mUsers.getSchoolId()); if (mSchool == null) { logger.debug("未找到学乐号为" + userId + "的学生用户所在的学校"); return null; } studentDTO.setAreaCode(mSchool.getArea()); studentDTO.setAreaName(mSchool.getAreaName()); // 班级信息 MClass mClass = classMapper.selectByPrimaryKey(mStudent.getClassId(), schoolId); if (mClass == null) { logger.debug("未找到学乐号为" + userId + "的学生用户所在的班级"); return null; } studentDTO.setGradeNum(getGradeNum(mClass.getYears())); studentDTO.setYear(mClass.getYears()); return studentDTO; }
@Override public StudentDTO updateStudentForAPP(StudentDTO studentDTO) { // 更新联系方式 UserDTO userDTO = new UserDTO(); boolean isAllNot = true; // 学生姓名 String name = studentDTO.getRealName(); if (!StringUtils.isEmpty(name)) { userDTO.setRealName(name); isAllNot = false; } String school = studentDTO.getSchoolId(); if (school != null) { userDTO.setSchoolId(school); isAllNot = false; } else { logger.warn("schoolId不能为空"); return null; } String userId = studentDTO.getUserId(); if (!StringUtils.isEmpty(userId)) { userDTO.setUserId(userId); } else { logger.warn("userId不能为空"); return null; } String mobile = studentDTO.getMobile(); if (!StringUtils.isEmpty(mobile)) { userDTO.setMobile(mobile); isAllNot = false; } String email = studentDTO.getEmail(); if (!StringUtils.isEmpty(email)) { userDTO.setEmail(email); isAllNot = false; } if (!isAllNot) { userService.updateByUserId(userDTO); } // 更新班级 String schoolId = userService.getSchoolId(userId); if (StringUtils.isEmpty(schoolId)) { throw new MemberException("该学生没有学校"); } MSchool mSchool = mSchoolMapper.selectByPrimaryKey(schoolId); String classId = studentDTO.getClassId(); if (!StringUtils.isEmpty(classId)) { MClass mClass = classMapper.selectByPrimaryKey(classId, schoolId); if (mClass == null) { logger.warn("找不到班级号为" + classId + "的班级"); return null; } MStudent mStudent = new MStudent(); mStudent.setUserId(studentDTO.getUserId()); mStudent.setClassName(mClass.getName()); mStudent.setClassId(classId); mStudent.setSchoolId(schoolId); studentMapper.updateByPrimaryKey(mStudent); } studentDTO.setClassId(classId); studentDTO.setSchoolId(schoolId); studentDTO.setSchoolName(mSchool.getName()); return studentDTO; }