验收通用功能并进行修改

grs
yjxx 1 month ago
parent bdaec402ed
commit 0bfdba7e35

@ -5,7 +5,7 @@ import jakarta.validation.constraints.Pattern;
import lombok.Data;
@Data
public class UserModifyMessageDTO {
public class UserModifyInfoDTO {
@NotBlank(message = "用户名不能为空")
private String userName;

@ -8,7 +8,7 @@ import lombok.Data;
public class UserModifyPasswordDTO {
@NotBlank(message = "旧密码不能为空")
@Pattern(regexp = "^.+$")
private String OldPassword;
private String oldPassword;
@NotBlank(message = "新密码不能为空")
@Pattern(regexp = "^.+$")

@ -8,24 +8,15 @@ import java.time.LocalDateTime;
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
private static final ThreadLocal<Boolean> skipUpdateFill = new ThreadLocal<>();
public static void setSkipUpdateFill(boolean skip) {
skipUpdateFill.set(skip);
}
@Override
public void insertFill(MetaObject metaObject) {
this.strictInsertFill(metaObject, "createTime", LocalDateTime::now, LocalDateTime.class);
if (skipUpdateFill.get() == null || !skipUpdateFill.get()) {
this.strictInsertFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class);
}
this.strictInsertFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class);
}
@Override
public void updateFill(MetaObject metaObject) {
if (skipUpdateFill.get() == null || !skipUpdateFill.get()) {
this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class);
}
this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class);
}
}

@ -13,6 +13,6 @@ public class WebConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loginInterceptor).excludePathPatterns("/user/login", "/user/register");
registry.addInterceptor(loginInterceptor).excludePathPatterns("/user/login", "/user/loginByAccount");
}
}

@ -50,11 +50,7 @@ public class AdminController {
return new Result<>(200, "删除成功", "");
}
}
// 禁用自动填充
MyMetaObjectHandler.setSkipUpdateFill(true);
userService.updateById(user);
// 开启自动填充
MyMetaObjectHandler.setSkipUpdateFill(false);
return new Result<>(200, "操作成功", "");
}

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

@ -60,9 +60,9 @@ public class User implements Serializable {
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
@TableField(value = "login_time", fill = FieldFill.UPDATE)
@TableField(value = "login_time")
private LocalDateTime loginTime;
@TableField(value = "update_time", fill = FieldFill.INSERT)
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
}

Loading…
Cancel
Save