diff --git a/src/main/java/com/rymcu/vertical/mapper/UserMapper.java b/src/main/java/com/rymcu/vertical/mapper/UserMapper.java index aa2ed61..88b22c2 100644 --- a/src/main/java/com/rymcu/vertical/mapper/UserMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/UserMapper.java @@ -23,4 +23,6 @@ public interface UserMapper extends Mapper { Integer updateUserRole(@Param("idUser") Integer idUser, @Param("idRole") Integer idRole); Integer updateStatus(@Param("idUser") Integer idUser, @Param("status") String status); + + Integer selectCountByNickName(@Param("nickname") String nickname); } \ No newline at end of file diff --git a/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java index efda0cc..48f99e9 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java @@ -58,7 +58,9 @@ public class UserServiceImpl extends AbstractService implements UserServic } else { user = new User(); user.setAccount(email); - user.setNickname(email.split("@")[0]); + String nickname = email.split("@")[0]; + nickname = checkNickname(nickname); + user.setNickname(nickname); user.setEmail(email); user.setPassword(Utils.entryptPassword(password)); user.setCreatedTime(new Date()); @@ -76,6 +78,14 @@ public class UserServiceImpl extends AbstractService implements UserServic return map; } + private String checkNickname(String nickname) { + Integer result = userMapper.selectCountByNickName(nickname); + if (result > 0) { + return checkNickname(nickname + System.currentTimeMillis()); + } + return nickname; + } + @Override public Map login(String account, String password) { Map map = new HashMap(1); diff --git a/src/main/java/mapper/UserMapper.xml b/src/main/java/mapper/UserMapper.xml index 7d43f1a..5e84986 100644 --- a/src/main/java/mapper/UserMapper.xml +++ b/src/main/java/mapper/UserMapper.xml @@ -63,5 +63,8 @@ + \ No newline at end of file