コード例 #1
1
 @Override
 public StudentManagerDTO saveStudent(String name, String classId, String schoolId) {
   UserDTO userDTO = new UserDTO();
   userDTO.setRealName(name);
   userDTO.setIdentityId(IdentityIdConstants.STUDENT);
   userDTO.setIdentityDescription("学生");
   userDTO.setSchoolId(schoolId);
   userDTO.setArea(mSchoolMapper.selectByPrimaryKey(schoolId).getArea());
   UserDTO users = userService.saveUser(userDTO);
   MClass mclass = classMapper.selectByPrimaryKey(classId, schoolId);
   StudentDTO studentDTO = new StudentDTO();
   studentDTO.setUserId(users.getUserId());
   studentDTO.setSchoolId(mclass.getSchoolId());
   studentDTO.setSchoolName(mclass.getSchoolName());
   studentDTO.setClassName(mclass.getName());
   studentDTO.setClassId(classId);
   studentDTO.setClassAliasName(mclass.getAliasName());
   studentDTO.setJoinClass(new Date());
   MStudent mStudent = new MStudent();
   BeanUtils.copyProperties(studentDTO, mStudent);
   studentMapper.insert(mStudent);
   MStudentManager studentManager =
       studentMapper.selectStudentByUserId(mStudent.getUserId(), schoolId);
   StudentManagerDTO studentManagerDTO = new StudentManagerDTO();
   BeanUtils.copyProperties(studentManager, studentManagerDTO);
   studentManagerDTO.setClassAliasName(
       ClassNameUtil.getFullName(studentManager.getYears(), studentManager.getClassAliasName()));
   return studentManagerDTO;
 }
コード例 #2
0
  @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;
  }