From 23ec63ef0be218512f6b1a6544e8bbc4c83e20d6 Mon Sep 17 00:00:00 2001 From: xiongxiaoyang <1179705413@qq.com> Date: Wed, 21 Oct 2026 12:26:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(novel-front):=20=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E9=9A=8F=E6=9C=BA=E6=98=B5=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java2nb/novel/service/impl/UserServiceImpl.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/novel-front/src/main/java/com/java2nb/novel/service/impl/UserServiceImpl.java b/novel-front/src/main/java/com/java2nb/novel/service/impl/UserServiceImpl.java index 98418fb..1f7978f 100644 --- a/novel-front/src/main/java/com/java2nb/novel/service/impl/UserServiceImpl.java +++ b/novel-front/src/main/java/com/java2nb/novel/service/impl/UserServiceImpl.java @@ -29,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; import static com.java2nb.novel.mapper.BookDynamicSqlSupport.id; import static com.java2nb.novel.mapper.UserBookshelfDynamicSqlSupport.userBookshelf; @@ -77,7 +78,8 @@ public class UserServiceImpl implements UserService { //数据库生成注册记录 Long id = idWorker.nextId(); entity.setId(id); - entity.setNickName(entity.getUsername()); + //注册时生成随机昵称,避免直接展示手机号 + entity.setNickName(generateRandomNickName()); Date currentDate = new Date(); entity.setCreateTime(currentDate); entity.setUpdateTime(currentDate); @@ -91,6 +93,15 @@ public class UserServiceImpl implements UserService { return userDetails; } + /** + * 生成随机昵称,格式:书友 + 6 位随机数字。 + * 用户后续可在账号设置里修改昵称。 + */ + private String generateRandomNickName() { + int random = ThreadLocalRandom.current().nextInt(100000, 1000000); + return "书友" + random; + } + @Override public UserDetails login(User user) { //根据用户名密码查询记录