代码优化

This commit is contained in:
2025-10-13 10:43:08 +08:00
parent b6818b179c
commit bc3ed2d872
40 changed files with 3189 additions and 788 deletions
@@ -245,6 +245,69 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
return this.updateById(user);
}
@Override
public User getByAccount(String account) {
if (!StringUtils.hasText(account)) {
return null;
}
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(User::getAccount, account)
.eq(User::getIsDeleted, 0);
return this.getOne(wrapper);
}
@Override
public User getByEmail(String email) {
if (!StringUtils.hasText(email)) {
return null;
}
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(User::getEmail, email)
.eq(User::getIsDeleted, 0);
return this.getOne(wrapper);
}
@Override
public User getByPhone(String phone) {
if (!StringUtils.hasText(phone)) {
return null;
}
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(User::getPhone, phone)
.eq(User::getIsDeleted, 0);
return this.getOne(wrapper);
}
@Override
public User createUser(String account, String username, String password, String email, String phone) {
User user = new User();
user.setAccount(account);
user.setUsername(username);
user.setNickname(username); // 默认昵称与用户名相同
user.setPassword(passwordEncoder.encode(password)); // 加密密码
user.setEmail(email);
user.setPhone(phone);
user.setMemberLevel("free"); // 默认免费会员
user.setStatus(1); // 默认启用
user.setIsVerified(0); // 默认未验证
user.setLastActiveTime(LocalDateTime.now());
this.save(user);
return user;
}
@Override
public void updateLastActiveTime(String userId, LocalDateTime lastActiveTime) {
if (!StringUtils.hasText(userId) || lastActiveTime == null) {
return;
}
User user = this.getById(userId);
if (user != null && user.getIsDeleted() == 0) {
user.setLastActiveTime(lastActiveTime);
this.updateById(user);
}
}
/**
* 转换为响应对象
*/