|
|
@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
import jty.expressdistributionsystem.DTO.UserLoginByAccountDTO;
|
|
|
|
import jty.expressdistributionsystem.DTO.UserLoginByAccountDTO;
|
|
|
|
import jty.expressdistributionsystem.DTO.UserModifyMessageDTO;
|
|
|
|
import jty.expressdistributionsystem.DTO.UserModifyInfoDTO;
|
|
|
|
import jty.expressdistributionsystem.DTO.UserModifyPasswordDTO;
|
|
|
|
import jty.expressdistributionsystem.DTO.UserModifyPasswordDTO;
|
|
|
|
import jty.expressdistributionsystem.config.MyMetaObjectHandler;
|
|
|
|
import jty.expressdistributionsystem.config.MyMetaObjectHandler;
|
|
|
|
import jty.expressdistributionsystem.entity.Result;
|
|
|
|
import jty.expressdistributionsystem.entity.Result;
|
|
|
@ -14,9 +14,11 @@ import jty.expressdistributionsystem.utils.GetIdUtil;
|
|
|
|
import jty.expressdistributionsystem.utils.JwtUtil;
|
|
|
|
import jty.expressdistributionsystem.utils.JwtUtil;
|
|
|
|
import jty.expressdistributionsystem.utils.Md5Util;
|
|
|
|
import jty.expressdistributionsystem.utils.Md5Util;
|
|
|
|
import jty.expressdistributionsystem.utils.ThreadLocalUtil;
|
|
|
|
import jty.expressdistributionsystem.utils.ThreadLocalUtil;
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
import org.springframework.data.redis.core.ValueOperations;
|
|
|
|
import org.springframework.data.redis.core.ValueOperations;
|
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
@ -28,6 +30,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/user")
|
|
|
|
@RequestMapping("/user")
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
public class UserController {
|
|
|
|
public class UserController {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private UserService userService;
|
|
|
|
private UserService userService;
|
|
|
@ -67,8 +70,6 @@ public class UserController {
|
|
|
|
if(user.getDisabled() == 1){
|
|
|
|
if(user.getDisabled() == 1){
|
|
|
|
return new Result<>(403, "该账号已被禁用, 请联系管理员", "");
|
|
|
|
return new Result<>(403, "该账号已被禁用, 请联系管理员", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 禁用自动填充
|
|
|
|
|
|
|
|
MyMetaObjectHandler.setSkipUpdateFill(true);
|
|
|
|
|
|
|
|
user.setLoginTime(LocalDateTime.now());
|
|
|
|
user.setLoginTime(LocalDateTime.now());
|
|
|
|
userService.update(user, new UpdateWrapper<User>().eq("id", user.getId()));
|
|
|
|
userService.update(user, new UpdateWrapper<User>().eq("id", user.getId()));
|
|
|
|
// 校验通过
|
|
|
|
// 校验通过
|
|
|
@ -81,40 +82,39 @@ public class UserController {
|
|
|
|
ValueOperations<String, String> stringStringValueOperations = stringRedisTemplate.opsForValue();
|
|
|
|
ValueOperations<String, String> stringStringValueOperations = stringRedisTemplate.opsForValue();
|
|
|
|
// 设置过期时间(1天)
|
|
|
|
// 设置过期时间(1天)
|
|
|
|
stringStringValueOperations.set(token, token, 1, TimeUnit.DAYS);
|
|
|
|
stringStringValueOperations.set(token, token, 1, TimeUnit.DAYS);
|
|
|
|
// 开启自动填充
|
|
|
|
|
|
|
|
MyMetaObjectHandler.setSkipUpdateFill(false);
|
|
|
|
|
|
|
|
// 返回token给前端
|
|
|
|
// 返回token给前端
|
|
|
|
return new Result<>(200, "登录成功", token);
|
|
|
|
return new Result<>(200, "登录成功", token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 修改个人信息
|
|
|
|
// 修改个人信息
|
|
|
|
@PutMapping("/modify")
|
|
|
|
@PutMapping("/modify")
|
|
|
|
public Result<Object> modifyMessage(@RequestBody @Validated @NotNull UserModifyMessageDTO userModifyMessageDTO) {
|
|
|
|
public Result<Object> modifyInfo(@RequestBody @Validated @NotNull UserModifyInfoDTO userModifyInfoDTO) {
|
|
|
|
// 获取登录用户id
|
|
|
|
// 获取登录用户id
|
|
|
|
Long id = GetIdUtil.getId();
|
|
|
|
Long id = GetIdUtil.getId();
|
|
|
|
User user = userService.getById(id);
|
|
|
|
User user = userService.getById(id);
|
|
|
|
// 检查phone和userName是否与当前用户信息一致
|
|
|
|
// 检查phone和userName是否与当前用户信息一致
|
|
|
|
boolean isPhoneSame = user.getPhone().equals(userModifyMessageDTO.getPhone());
|
|
|
|
boolean isPhoneSame = user.getPhone().equals(userModifyInfoDTO.getPhone());
|
|
|
|
boolean isUserNameSame = user.getUserName().equals(userModifyMessageDTO.getUserName());
|
|
|
|
boolean isUserNameSame = user.getUserName().equals(userModifyInfoDTO.getUserName());
|
|
|
|
if (isPhoneSame && isUserNameSame) {
|
|
|
|
if (isPhoneSame && isUserNameSame) {
|
|
|
|
return new Result<>(400, "请修改您的信息", "");
|
|
|
|
return new Result<>(400, "请修改您的信息", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
|
|
|
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
|
|
|
if (!isPhoneSame) {
|
|
|
|
if (!isPhoneSame) {
|
|
|
|
queryWrapper.eq("phone", userModifyMessageDTO.getPhone());
|
|
|
|
queryWrapper.eq("phone", userModifyInfoDTO.getPhone());
|
|
|
|
if (userService.getOne(queryWrapper) != null) {
|
|
|
|
if (userService.getOne(queryWrapper) != null) {
|
|
|
|
return new Result<>(400, "该手机号已被注册", "");
|
|
|
|
return new Result<>(400, "该手机号已被注册", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
user.setPhone(userModifyMessageDTO.getPhone());
|
|
|
|
user.setPhone(userModifyInfoDTO.getPhone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
queryWrapper.clear();
|
|
|
|
queryWrapper.clear();
|
|
|
|
if (!isUserNameSame) {
|
|
|
|
if (!isUserNameSame) {
|
|
|
|
queryWrapper.eq("user_name", userModifyMessageDTO.getUserName());
|
|
|
|
queryWrapper.eq("user_name", userModifyInfoDTO.getUserName());
|
|
|
|
if (userService.getOne(queryWrapper) != null) {
|
|
|
|
if (userService.getOne(queryWrapper) != null) {
|
|
|
|
return new Result<>(400, "该用户名已被使用", "");
|
|
|
|
return new Result<>(400, "该用户名已被使用", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
user.setUserName(userModifyMessageDTO.getUserName());
|
|
|
|
user.setUserName(userModifyInfoDTO.getUserName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
user.setUpdateTime(null);
|
|
|
|
userService.updateById(user);
|
|
|
|
userService.updateById(user);
|
|
|
|
return new Result<>(200, "用户信息修改成功", user);
|
|
|
|
return new Result<>(200, "用户信息修改成功", user);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -133,9 +133,10 @@ public class UserController {
|
|
|
|
Long id = GetIdUtil.getId();
|
|
|
|
Long id = GetIdUtil.getId();
|
|
|
|
User user = userService.getById(id);
|
|
|
|
User user = userService.getById(id);
|
|
|
|
if (!user.getIdentity().equals(userModifyPasswordDTO.getIdentity())) {
|
|
|
|
if (!user.getIdentity().equals(userModifyPasswordDTO.getIdentity())) {
|
|
|
|
return new Result<>(409, "请输入您的身份证", "");
|
|
|
|
return new Result<>(409, "身份证有误", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
user.setPassword(Md5Util.getMD5String(userModifyPasswordDTO.getNewPassword()));
|
|
|
|
user.setPassword(Md5Util.getMD5String(userModifyPasswordDTO.getNewPassword()));
|
|
|
|
|
|
|
|
user.setUpdateTime(null);
|
|
|
|
userService.updateById(user);
|
|
|
|
userService.updateById(user);
|
|
|
|
// 删除redis当中的token
|
|
|
|
// 删除redis当中的token
|
|
|
|
stringRedisTemplate.delete(token);
|
|
|
|
stringRedisTemplate.delete(token);
|
|
|
|