From e8b51b82f96c20abdb8e55ee195fb213679cc130 Mon Sep 17 00:00:00 2001 From: hechanggeng Date: Fri, 12 Jan 2024 01:56:28 +0800 Subject: [PATCH] 1.add more attribute for user profile --- .../luoo/user/controller/UserController.java | 1 + .../java/com/luoo/user/enumerate/Gender.java | 14 ++++++++++ .../com/luoo/user/service/UserService.java | 18 ++++++++++-- .../main/java/com/luoo/user/vo/UserVO.java | 8 ++++-- .../luoo/user/service/UserServiceTest.java | 28 +++++++++++++++++++ 5 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 luoo_user/src/main/java/com/luoo/user/enumerate/Gender.java create mode 100644 luoo_user/src/test/java/com/luoo/user/service/UserServiceTest.java diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserController.java index 268c794..c879de6 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/UserController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserController.java @@ -117,6 +117,7 @@ public class UserController { // 得到缓存中的验证码 String checkcodeRedis = (String) redisTemplate.opsForValue().get("checkcode_"+user.getMobile()); if (checkcodeRedis.isEmpty()){ + //单独定义一个请重新获取验证码的code? 2024.01.12 by he,changgeng return new Result(false,StatusCode.ERROR,"请先获取手机验证码"); } if (!checkcodeRedis.equals(code)) { diff --git a/luoo_user/src/main/java/com/luoo/user/enumerate/Gender.java b/luoo_user/src/main/java/com/luoo/user/enumerate/Gender.java new file mode 100644 index 0000000..f4a3525 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/enumerate/Gender.java @@ -0,0 +1,14 @@ +package com.luoo.user.enumerate; + +public enum Gender { + Male("0"), Female("1"); + private String code; + + private Gender(String code) { + this.code = code; + } + + public String getCode() { + return code; + } +} diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserService.java b/luoo_user/src/main/java/com/luoo/user/service/UserService.java index 823524b..9f2fa9d 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserService.java @@ -15,6 +15,7 @@ import entity.Result; import entity.StatusCode; import io.jsonwebtoken.Claims; import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.RandomUtils; import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.BeanUtils; @@ -32,6 +33,7 @@ import util.IdWorker; import com.apifan.common.random.RandomSource; import com.luoo.user.dao.UserDao; +import com.luoo.user.enumerate.Gender; import com.luoo.user.pojo.User; import com.luoo.user.vo.UserVO; @@ -259,8 +261,10 @@ public class UserService { user=new User(); user.setId(String.valueOf(idWorker.nextId())); user.setMobile(mobile); - user.setNickname(RandomSource.personInfoSource().randomChineseNickName(8)); + user.setNickname("雀乐"+getRandomNickName()); + user.setSex(Gender.Male.getCode()); user.setAvatar("default"); + user.setPersonality("无签名"); userDao.save(user); } @@ -279,10 +283,20 @@ public class UserService { public UserVO touristLogin() { UserVO userVO=new UserVO(); userVO.setId(String.valueOf(idWorker.nextId())); - userVO.setNickname(RandomSource.personInfoSource().randomChineseNickName(8)); + userVO.setNickname("游客"+getRandomNickName()); + userVO.setSex(Gender.Male.getCode()); userVO.setAvatar("default"); + userVO.setPersonality("无签名"); String token = jwtUtil.createJWT(userVO.getId(),"tourist","tourist"); userVO.setToken(token); return userVO; } + + private String getRandomNickName() { + String rawNickName=RandomSource.personInfoSource().randomChineseNickName(3); + if(rawNickName.length()>3) { + return rawNickName.substring(0, 3); + } + return rawNickName; + } } diff --git a/luoo_user/src/main/java/com/luoo/user/vo/UserVO.java b/luoo_user/src/main/java/com/luoo/user/vo/UserVO.java index 849d7fb..e4b4c62 100644 --- a/luoo_user/src/main/java/com/luoo/user/vo/UserVO.java +++ b/luoo_user/src/main/java/com/luoo/user/vo/UserVO.java @@ -8,10 +8,14 @@ import lombok.Data; public class UserVO { @ApiModelProperty(value = "ID") private String id;//ID - @ApiModelProperty(value = "昵称",notes="初次登录,随机生成") + @ApiModelProperty(value = "昵称,首次注册登录,登录用户随机为“雀乐XXX”,游客为“游客XXX”",example="雀乐XXX") private String nickname;//昵称 - @ApiModelProperty(value = "头像",notes="初次登录,默认头像") + @ApiModelProperty(value = "性别,0为男,1 为女,首次注册登录,默认为0",example="0") + private String sex;//性别 + @ApiModelProperty(value = "头像,首次注册登录,默认头像",example="default") private String avatar;//头像 + @ApiModelProperty(value = "个性签名,首次注册登录,默认为“无签名”",example="无签名") + private String personality;//个性 @ApiModelProperty(value = "TOKEN") private String token; } diff --git a/luoo_user/src/test/java/com/luoo/user/service/UserServiceTest.java b/luoo_user/src/test/java/com/luoo/user/service/UserServiceTest.java new file mode 100644 index 0000000..f19d8fb --- /dev/null +++ b/luoo_user/src/test/java/com/luoo/user/service/UserServiceTest.java @@ -0,0 +1,28 @@ +package com.luoo.user.service; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.apifan.common.random.RandomSource; + +public class UserServiceTest { + + @Test + public void testRandomNickName() { + for(int i=0;i<100;i++) { + String nickName=getRandomNickName(); + assertTrue(nickName.length()<=3); + } + + } + + private String getRandomNickName() { + String rawNickName=RandomSource.personInfoSource().randomChineseNickName(3); + if(rawNickName.length()>3) { + return rawNickName.substring(0, 3); + } + return rawNickName; + } + +}