|
|
@@ -17,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* @author Kunduin
|
|
|
@@ -60,7 +61,7 @@ public class UserService {
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
|
|
- public User updateUserEmail (Long userId, String email) {
|
|
|
+ public User updateUserEmail(Long userId, String email) {
|
|
|
return userRepository.findById(userId)
|
|
|
.map(user -> {
|
|
|
user.setEmail(email);
|
|
|
@@ -69,7 +70,7 @@ public class UserService {
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = RuntimeException.class)
|
|
|
- public User updateUserSignature (Long userId, String signature) {
|
|
|
+ public User updateUserSignature(Long userId, String signature) {
|
|
|
return userRepository.findById(userId)
|
|
|
.map(user -> {
|
|
|
user.setSignature(signature);
|
|
|
@@ -100,18 +101,21 @@ public class UserService {
|
|
|
checkPhoneMessageOrThrowError(userVO.getPhone(), phoneCode);
|
|
|
userVO.setUsername(userVO.getUsername());
|
|
|
userRepository.findByPhone(userVO.getPhone()).ifPresent(user -> {
|
|
|
- throw CustomErrorException.phoneAlreadyExist(); });
|
|
|
- userRepository.findByUsername(userVO.getUsername()).ifPresent(user->{
|
|
|
- throw CustomErrorException.usernameAlreadyExist(); });
|
|
|
+ throw CustomErrorException.phoneAlreadyExist();
|
|
|
+ });
|
|
|
+ userRepository.findByUsername(userVO.getUsername()).ifPresent(user -> {
|
|
|
+ throw CustomErrorException.usernameAlreadyExist();
|
|
|
+ });
|
|
|
userRepository.findByEmail(userVO.getEmail()).ifPresent(user -> {
|
|
|
- throw CustomErrorException.emailAlreadyExist(); });
|
|
|
+ throw CustomErrorException.emailAlreadyExist();
|
|
|
+ });
|
|
|
User user = userMapper.userVOToUser(userVO);
|
|
|
String encodedPassword = passwordEncoder.encode(password);
|
|
|
System.out.println(encodedPassword);
|
|
|
user.setPassword(encodedPassword);
|
|
|
System.out.println(1);
|
|
|
System.out.println(userVO.getUsername());
|
|
|
- User savedUser=userRepository.save(user);
|
|
|
+ User savedUser = userRepository.save(user);
|
|
|
//Optional<User> resultUser=userRepository.findByPhone(user.getPhone());
|
|
|
System.out.println(2);
|
|
|
System.out.println(savedUser.getUsername());
|
|
|
@@ -122,7 +126,7 @@ public class UserService {
|
|
|
userRepository.delete(savedUser);
|
|
|
throw new CustomErrorException("gitlab 创建异常");
|
|
|
}
|
|
|
- log.debug("Created Information for User: {}",savedUser);
|
|
|
+ log.debug("Created Information for User: {}", savedUser);
|
|
|
return savedUser;
|
|
|
}
|
|
|
|
|
|
@@ -153,19 +157,29 @@ public class UserService {
|
|
|
.orElseThrow(CustomErrorException::userIdNotFound);
|
|
|
}
|
|
|
|
|
|
- public UserVO findUserById(Long id){
|
|
|
+ public UserVO findUserById(Long id) {
|
|
|
User user = userRepository.findById(id).orElseThrow(CustomErrorException::userIdNotFound);
|
|
|
return userMapper.userToUserVO(user);
|
|
|
}
|
|
|
|
|
|
- public Boolean isTeacher(UserRole role){
|
|
|
+ public String findNameByUserName(String username) {
|
|
|
+ User user;
|
|
|
+ if (username.length() == 11 && Pattern.matches("^1[3-9]\\d{9}$", username)) {
|
|
|
+ user = userRepository.findByPhone(username).orElseThrow(CustomErrorException::userIdNotFound);
|
|
|
+ } else {
|
|
|
+ user = userRepository.findByUsername(username).orElseThrow(CustomErrorException::userIdNotFound);
|
|
|
+ }
|
|
|
+ return userMapper.userToUserVO(user).getName();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean isTeacher(UserRole role) {
|
|
|
List<UserRole> teacherRoles = new ArrayList<>();
|
|
|
teacherRoles.add(UserRole.TEACHER);
|
|
|
teacherRoles.add(UserRole.ADMIN);
|
|
|
return teacherRoles.contains(role);
|
|
|
}
|
|
|
|
|
|
- public Boolean isStudent(UserRole role){
|
|
|
+ public Boolean isStudent(UserRole role) {
|
|
|
List<UserRole> studentRoles = new ArrayList<>();
|
|
|
studentRoles.add(UserRole.STUDENT);
|
|
|
studentRoles.add(UserRole.SEEC);
|