个人资料修改
This commit is contained in:
@@ -51,7 +51,9 @@ public class AuthInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
|
||||
Long userId = jwtUtil.getUserIdFromToken(token);
|
||||
String account = jwtUtil.getAccountFromToken(token);
|
||||
request.setAttribute("userId", userId);
|
||||
request.setAttribute("account", account);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+16
-2
@@ -179,11 +179,25 @@ public class UserController {
|
||||
* @return 用户VO
|
||||
*/
|
||||
@GetMapping("/info")
|
||||
public Result<UserVO> getCurrentUserInfo() {
|
||||
UserVO userVO = userService.getCurrentUserInfo();
|
||||
public Result<UserVO> getCurrentUserInfo(HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
UserVO userVO = userService.getUserById(userId);
|
||||
return Result.success(userVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新当前用户信息
|
||||
*
|
||||
* @param userDTO 用户DTO
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public Result<Boolean> updateCurrentUserInfo(HttpServletRequest request, @RequestBody UserDTO userDTO) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
boolean success = userService.updateUser(userId, userDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定手机号
|
||||
*
|
||||
|
||||
@@ -32,6 +32,11 @@ public class UserDTO {
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 用户头像URL
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 用户签名
|
||||
*/
|
||||
|
||||
@@ -66,6 +66,12 @@ public class UserDO extends BaseEntity {
|
||||
@TableField("password")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 用户头像URL
|
||||
*/
|
||||
@TableField("avatar")
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 用户签名
|
||||
*/
|
||||
|
||||
+39
-8
@@ -9,10 +9,12 @@ import com.xiaowang.yuminailcore.dto.RegisterRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.service.ShopService;
|
||||
import com.xiaowang.yuminailcore.service.UserService;
|
||||
import com.xiaowang.yuminailcore.utils.JwtUtil;
|
||||
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||
import com.xiaowang.yuminailcore.vo.ShopVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -33,6 +35,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
|
||||
private final UserMapper userMapper;
|
||||
private final JwtUtil jwtUtil;
|
||||
private final ShopService shopService;
|
||||
|
||||
@Override
|
||||
public Long createUser(UserDTO userDTO) {
|
||||
@@ -56,14 +59,34 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
if (userDO == null) {
|
||||
return false;
|
||||
}
|
||||
userDO.setShopId(userDTO.getShopId());
|
||||
userDO.setNickname(userDTO.getNickname());
|
||||
userDO.setAccount(userDTO.getAccount());
|
||||
userDO.setPassword(userDTO.getPassword());
|
||||
userDO.setSignature(userDTO.getSignature());
|
||||
userDO.setLevel(userDTO.getLevel());
|
||||
userDO.setType(userDTO.getType());
|
||||
userDO.setVipId(userDTO.getVipId());
|
||||
if (userDTO.getShopId() != null) {
|
||||
userDO.setShopId(userDTO.getShopId());
|
||||
}
|
||||
if (userDTO.getNickname() != null) {
|
||||
userDO.setNickname(userDTO.getNickname());
|
||||
}
|
||||
if (userDTO.getAccount() != null) {
|
||||
userDO.setAccount(userDTO.getAccount());
|
||||
}
|
||||
if (userDTO.getPassword() != null) {
|
||||
userDO.setPassword(userDTO.getPassword());
|
||||
}
|
||||
if (userDTO.getAvatar() != null) {
|
||||
userDO.setAvatar(userDTO.getAvatar());
|
||||
}
|
||||
if (userDTO.getSignature() != null) {
|
||||
userDO.setSignature(userDTO.getSignature());
|
||||
}
|
||||
if (userDTO.getLevel() != null) {
|
||||
userDO.setLevel(userDTO.getLevel());
|
||||
}
|
||||
if (userDTO.getType() != null) {
|
||||
userDO.setType(userDTO.getType());
|
||||
}
|
||||
if (userDTO.getVipId() != null) {
|
||||
userDO.setVipId(userDTO.getVipId());
|
||||
}
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
return userMapper.updateById(userDO) > 0;
|
||||
}
|
||||
|
||||
@@ -138,8 +161,16 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
UserVO userVO = new UserVO();
|
||||
userVO.setId(userDO.getId());
|
||||
userVO.setShopId(userDO.getShopId());
|
||||
if (userDO.getShopId() != null && userDO.getShopId() > 0) {
|
||||
ShopVO shopVO = shopService.getShopById(userDO.getShopId());
|
||||
if (shopVO != null) {
|
||||
userVO.setShopName(shopVO.getShopName());
|
||||
}
|
||||
}
|
||||
userVO.setNickname(userDO.getNickname());
|
||||
userVO.setAccount(userDO.getAccount());
|
||||
String defaultAvatar = "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png";
|
||||
userVO.setAvatar(userDO.getAvatar() != null && !userDO.getAvatar().isEmpty() ? userDO.getAvatar() : defaultAvatar);
|
||||
userVO.setSignature(userDO.getSignature());
|
||||
userVO.setLevel(userDO.getLevel());
|
||||
userVO.setType(userDO.getType());
|
||||
|
||||
@@ -39,6 +39,11 @@ public class UserVO {
|
||||
*/
|
||||
private String account;
|
||||
|
||||
/**
|
||||
* 用户头像URL
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 用户签名
|
||||
*/
|
||||
|
||||
@@ -10,3 +10,8 @@ server.servlet.encoding.enabled=true
|
||||
|
||||
# MyBatis编码配置
|
||||
mybatis.configuration.map-underscore-to-camel-case=true
|
||||
|
||||
# 时区配置
|
||||
spring.jackson.time-zone=Asia/Shanghai
|
||||
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
|
||||
server.timezone=Asia/Shanghai
|
||||
|
||||
Reference in New Issue
Block a user