Commit c963186e authored by muhong's avatar muhong

修改 用户

parent 3f579804
...@@ -100,7 +100,7 @@ public class UserServiceImpl implements UserService { ...@@ -100,7 +100,7 @@ public class UserServiceImpl implements UserService {
User user = userDao.queryByMobile(mobile); User user = userDao.queryByMobile(mobile);
if (Objects.isNull(user)) { if (Objects.isNull(user)) {
user = new User(); user = new User();
user.setUsername("user" + mobile); user.setUsername(UUID.randomUUID().toString().replace("-", ""));
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
user.setPassword(bCryptPasswordEncoder.encode("Aa123456")); user.setPassword(bCryptPasswordEncoder.encode("Aa123456"));
user.setWeixinOpenid(""); user.setWeixinOpenid("");
...@@ -109,7 +109,13 @@ public class UserServiceImpl implements UserService { ...@@ -109,7 +109,13 @@ public class UserServiceImpl implements UserService {
user.setWechatId(""); user.setWechatId("");
user.setMobile(mobile); user.setMobile(mobile);
user.setAvatar(avatarUrl); user.setAvatar(avatarUrl);
user.setNickname("收藏家" + StringUtil.generateRandomString(10)); while (true) {
String nickname = "收藏家" + StringUtil.generateRandomString(10);
if (!userDao.isExistedByNickname(0L, nickname)) {
user.setNickname(nickname);
break;
}
}
user.setGender((byte) 0); user.setGender((byte) 0);
user.setUserLevel((byte) 0); user.setUserLevel((byte) 0);
user.setStatus((byte) 0); user.setStatus((byte) 0);
...@@ -168,6 +174,10 @@ public class UserServiceImpl implements UserService { ...@@ -168,6 +174,10 @@ public class UserServiceImpl implements UserService {
userInfo.setUserLevelDesc(UserTypeEnum.getInstance(user.getUserLevel()).getDesc()); userInfo.setUserLevelDesc(UserTypeEnum.getInstance(user.getUserLevel()).getDesc());
result.put("userInfo", userInfo); result.put("userInfo", userInfo);
// 缓存用户信息
String userKey = MessageFormat.format(CacheCodeConstants.USER_INFO_KEY, user.getId());
redisUtil.set(userKey, user, 2 * 60 * 60);
logger.info("【请求结束】手机号登录,响应结果:{}", JSONObject.toJSONString(result)); logger.info("【请求结束】手机号登录,响应结果:{}", JSONObject.toJSONString(result));
return Result.success(result); return Result.success(result);
} catch (Exception e) { } catch (Exception e) {
...@@ -234,7 +244,7 @@ public class UserServiceImpl implements UserService { ...@@ -234,7 +244,7 @@ public class UserServiceImpl implements UserService {
User user = userDao.queryByMobile(dto.getMobile()); User user = userDao.queryByMobile(dto.getMobile());
if (Objects.isNull(user)) { if (Objects.isNull(user)) {
user = new User(); user = new User();
user.setUsername("user" + dto.getMobile()); user.setUsername(UUID.randomUUID().toString().replace("-", ""));
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
user.setPassword(bCryptPasswordEncoder.encode("Aa123456")); user.setPassword(bCryptPasswordEncoder.encode("Aa123456"));
user.setWeixinOpenid(""); user.setWeixinOpenid("");
...@@ -243,7 +253,13 @@ public class UserServiceImpl implements UserService { ...@@ -243,7 +253,13 @@ public class UserServiceImpl implements UserService {
user.setWechatId(""); user.setWechatId("");
user.setMobile(dto.getMobile()); user.setMobile(dto.getMobile());
user.setAvatar(avatarUrl); user.setAvatar(avatarUrl);
user.setNickname("收藏家" + StringUtil.generateRandomString(10)); while (true) {
String nickname = "收藏家" + StringUtil.generateRandomString(10);
if (!userDao.isExistedByNickname(0L, nickname)) {
user.setNickname(nickname);
break;
}
}
user.setGender((byte) 0); user.setGender((byte) 0);
user.setUserLevel((byte) 0); user.setUserLevel((byte) 0);
user.setStatus((byte) 0); user.setStatus((byte) 0);
...@@ -302,6 +318,10 @@ public class UserServiceImpl implements UserService { ...@@ -302,6 +318,10 @@ public class UserServiceImpl implements UserService {
userInfo.setUserLevelDesc(UserTypeEnum.getInstance(user.getUserLevel()).getDesc()); userInfo.setUserLevelDesc(UserTypeEnum.getInstance(user.getUserLevel()).getDesc());
result.put("userInfo", userInfo); result.put("userInfo", userInfo);
// 缓存用户信息
String userKey = MessageFormat.format(CacheCodeConstants.USER_INFO_KEY, user.getId());
redisUtil.set(userKey, user, 2 * 60 * 60);
logger.info("【请求结束】手机号登录,响应结果:{}", JSONObject.toJSONString(result)); logger.info("【请求结束】手机号登录,响应结果:{}", JSONObject.toJSONString(result));
// 清除验证码缓存 // 清除验证码缓存
redisUtil.del(key); redisUtil.del(key);
...@@ -323,6 +343,10 @@ public class UserServiceImpl implements UserService { ...@@ -323,6 +343,10 @@ public class UserServiceImpl implements UserService {
} }
user.setProfile(dto.getProfile()); user.setProfile(dto.getProfile());
userDao.updateById(user); userDao.updateById(user);
// 更新用户缓存
User resultUser = userDao.queryById(user.getId());
String userKey = MessageFormat.format(CacheCodeConstants.USER_INFO_KEY, user.getId());
redisUtil.set(userKey, resultUser, 2 * 60 * 60);
logger.info("【请求结束】用户修改个性签名成功"); logger.info("【请求结束】用户修改个性签名成功");
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
...@@ -342,6 +366,10 @@ public class UserServiceImpl implements UserService { ...@@ -342,6 +366,10 @@ public class UserServiceImpl implements UserService {
} }
user.setBackground(dto.getBackground()); user.setBackground(dto.getBackground());
userDao.updateById(user); userDao.updateById(user);
// 更新用户缓存
User resultUser = userDao.queryById(user.getId());
String userKey = MessageFormat.format(CacheCodeConstants.USER_INFO_KEY, user.getId());
redisUtil.set(userKey, resultUser, 2 * 60 * 60);
logger.info("【请求结束】用户修改背景成功"); logger.info("【请求结束】用户修改背景成功");
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
...@@ -364,6 +392,10 @@ public class UserServiceImpl implements UserService { ...@@ -364,6 +392,10 @@ public class UserServiceImpl implements UserService {
} }
user.setNickname(dto.getNickname()); user.setNickname(dto.getNickname());
userDao.updateById(user); userDao.updateById(user);
// 更新用户缓存
User resultUser = userDao.queryById(user.getId());
String userKey = MessageFormat.format(CacheCodeConstants.USER_INFO_KEY, user.getId());
redisUtil.set(userKey, resultUser, 2 * 60 * 60);
logger.info("【请求结束】用户修改昵称成功"); logger.info("【请求结束】用户修改昵称成功");
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
...@@ -383,6 +415,10 @@ public class UserServiceImpl implements UserService { ...@@ -383,6 +415,10 @@ public class UserServiceImpl implements UserService {
} }
user.setAvatar(dto.getAvatarUrl()); user.setAvatar(dto.getAvatarUrl());
userDao.updateById(user); userDao.updateById(user);
// 更新用户缓存
User resultUser = userDao.queryById(user.getId());
String userKey = MessageFormat.format(CacheCodeConstants.USER_INFO_KEY, user.getId());
redisUtil.set(userKey, resultUser, 2 * 60 * 60);
logger.info("【请求结束】用户修改头像成功"); logger.info("【请求结束】用户修改头像成功");
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
...@@ -416,6 +452,11 @@ public class UserServiceImpl implements UserService { ...@@ -416,6 +452,11 @@ public class UserServiceImpl implements UserService {
} }
user.setMobile(dto.getAfterMobile()); user.setMobile(dto.getAfterMobile());
userDao.updateById(user); userDao.updateById(user);
// 更新用户缓存
User resultUser = userDao.queryById(user.getId());
String userKey = MessageFormat.format(CacheCodeConstants.USER_INFO_KEY, user.getId());
redisUtil.set(userKey, resultUser, 2 * 60 * 60);
logger.info("【请求结束】用户修改手机号成功"); logger.info("【请求结束】用户修改手机号成功");
// 清除验证码缓存 // 清除验证码缓存
redisUtil.del(key); redisUtil.del(key);
...@@ -441,12 +482,14 @@ public class UserServiceImpl implements UserService { ...@@ -441,12 +482,14 @@ public class UserServiceImpl implements UserService {
return Result.failed("查询不到当前登录用户信息"); return Result.failed("查询不到当前登录用户信息");
} }
User user = null; User user = null;
// String key = MessageFormat.format(CacheCodeConstants.USER_INFO_KEY, dto.getUserId().toString()); String key = MessageFormat.format(CacheCodeConstants.USER_INFO_KEY, userId);
// if (redisUtil.hasKey(key)) { if (redisUtil.hasKey(key)) {
// user = (User) redisUtil.get(key); user = (User) redisUtil.get(key);
// } else { } else {
user = userDao.queryById(userId); user = userDao.queryById(userId);
// } // 缓存用户信息
redisUtil.set(key, user, 2 * 60 * 60);
}
logger.info("【请求结束】查询用户信息成功"); logger.info("【请求结束】查询用户信息成功");
return Result.success(user); return Result.success(user);
} catch (Exception e) { } catch (Exception e) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment