优化用户状态交互逻辑.

This commit is contained in:
lijiahang
2024-04-16 12:01:44 +08:00
parent e3fd75e570
commit a3e354cea9
19 changed files with 78 additions and 133 deletions

View File

@@ -43,7 +43,7 @@ public class SystemUserDTO implements Serializable {
@Schema(description = "邮箱")
private String email;
@Schema(description = "用户状态 0停用 1启用 2锁定")
@Schema(description = "用户状态 0停用 1启用")
private Integer status;
@Schema(description = "最后登录时间")

View File

@@ -56,7 +56,7 @@ public class SystemUserDO extends BaseDO {
@TableField("email")
private String email;
@Schema(description = "用户状态 0停用 1启用 2锁定")
@Schema(description = "用户状态 0停用 1启用")
@TableField("status")
private Integer status;

View File

@@ -43,7 +43,7 @@ public class UserInfoDTO implements LongCacheIdModel, Serializable {
@Schema(description = "邮箱")
private String email;
@Schema(description = "用户状态 0停用 1启用 2锁定")
@Schema(description = "用户状态 0停用 1启用")
private Integer status;
}

View File

@@ -40,7 +40,7 @@ public class SystemUserQueryRequest extends PageRequest {
@Schema(description = "邮箱")
private String email;
@Schema(description = "用户状态 0停用 1启用 2锁定")
@Schema(description = "用户状态 0停用 1启用")
private Integer status;
}

View File

@@ -28,7 +28,7 @@ public class SystemUserUpdateStatusRequest implements Serializable {
private Long id;
@NotNull
@Schema(description = "用户状态 0停用 1启用 2锁定")
@Schema(description = "用户状态 0停用 1启用")
private Integer status;
}

View File

@@ -43,7 +43,7 @@ public class SystemUserVO implements Serializable {
@Schema(description = "邮箱")
private String email;
@Schema(description = "用户状态 0停用 1启用 2锁定")
@Schema(description = "用户状态 0停用 1启用")
private Integer status;
@Schema(description = "最后登录时间")

View File

@@ -32,7 +32,7 @@ public enum LoginTokenStatusEnum {
@Override
public RuntimeException toException(LoginTokenDTO token) {
LoginTokenIdentityDTO override = token.getOverride();
return ErrorCode.OTHER_DEVICE_LOGIN.exception(
return ErrorCode.USER_OTHER_DEVICE_LOGIN.exception(
Dates.format(new Date(override.getLoginTime()), Dates.MD_HM),
override.getAddress(),
override.getLocation());
@@ -47,7 +47,7 @@ public enum LoginTokenStatusEnum {
@Override
public RuntimeException toException(LoginTokenDTO token) {
LoginTokenIdentityDTO override = token.getOverride();
return ErrorCode.SESSION_OFFLINE.exception(
return ErrorCode.USER_OFFLINE.exception(
Dates.format(new Date(override.getLoginTime()), Dates.MD_HM),
override.getAddress(),
override.getLocation());

View File

@@ -25,11 +25,6 @@ public enum UserStatusEnum {
*/
ENABLED(1),
/**
* 2 锁定
*/
LOCKED(2),
;
private final Integer status;
@@ -55,9 +50,6 @@ public enum UserStatusEnum {
if (UserStatusEnum.DISABLED.getStatus().equals(status)) {
// 禁用状态
throw ErrorCode.USER_DISABLED.exception();
} else if (UserStatusEnum.LOCKED.getStatus().equals(status)) {
// 锁定状态
throw ErrorCode.USER_LOCKED.exception();
}
}

View File

@@ -242,22 +242,6 @@ public class AuthenticationServiceImpl implements AuthenticationService {
String failedCountKey = UserCacheKeyDefine.LOGIN_FAILED_COUNT.format(request.getUsername());
Long failedLoginCount = redisTemplate.opsForValue().increment(failedCountKey);
RedisUtils.setExpire(failedCountKey, appAuthenticationConfig.getLoginFailedLockTime(), TimeUnit.MINUTES);
// // 锁定用户
// if (failedLoginCount >= appAuthenticationConfig.getLoginFailedLockCount()) {
// // 更新用户表
// SystemUserDO updateUser = new SystemUserDO();
// updateUser.setId(user.getId());
// updateUser.setStatus(UserStatusEnum.LOCKED.getStatus());
// systemUserDAO.updateById(updateUser);
// // 修改缓存状态
// String userInfoKey = UserCacheKeyDefine.USER_INFO.format(user.getId());
// String userInfoCache = redisTemplate.opsForValue().get(userInfoKey);
// if (userInfoCache != null) {
// LoginUser loginUser = JSON.parseObject(userInfoCache, LoginUser.class);
// loginUser.setStatus(UserStatusEnum.LOCKED.getStatus());
// RedisStrings.setJson(userInfoKey, UserCacheKeyDefine.USER_INFO, loginUser);
// }
// }
return false;
}

View File

@@ -130,11 +130,7 @@ public class SystemUserServiceImpl implements SystemUserService {
if (id.equals(SecurityUtils.getLoginUserId())) {
throw ErrorCode.UNSUPPOETED.exception();
}
// 检查状态
UserStatusEnum status = Valid.valid(UserStatusEnum::of, request.getStatus());
if (!status.equals(UserStatusEnum.DISABLED) && !status.equals(UserStatusEnum.ENABLED)) {
throw ErrorCode.BAD_REQUEST.exception();
}
// 查询用户
SystemUserDO record = systemUserDAO.selectById(id);
Valid.notNull(record, ErrorMessage.USER_ABSENT);
@@ -146,8 +142,8 @@ public class SystemUserServiceImpl implements SystemUserService {
// 更新用户
int effect = systemUserDAO.updateById(updateRecord);
log.info("SystemUserService-updateUserStatus effect: {}, updateRecord: {}", effect, JSON.toJSONString(updateRecord));
// 如果之前是锁定则删除登录失败次数缓存
if (UserStatusEnum.LOCKED.getStatus().equals(record.getStatus())) {
// 改为启用则删除登录失败次数缓存
if (UserStatusEnum.ENABLED.equals(status)) {
RedisUtils.delete(UserCacheKeyDefine.LOGIN_FAILED_COUNT.format(record.getUsername()));
}
// 更新用户缓存中的 status