动态枚举内容功能增加
This commit is contained in:
@@ -103,12 +103,18 @@ public enum CommonResponseEnum {
|
||||
|
||||
ADVANCE_RESPONSE_ENUM("A00105", "终端响应枚举类型"),
|
||||
|
||||
DYNAMIC_RESPONSE_ENUM("A00002", "动态枚举内容"),
|
||||
|
||||
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
private final String message;
|
||||
private String message;
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
CommonResponseEnum(String code, String message) {
|
||||
this.code = code;
|
||||
|
||||
@@ -51,7 +51,13 @@ public class FeignConfig {
|
||||
//对结果进行转换
|
||||
HttpResult<Object> result = PubUtils.json2obj(bodyStr, type);
|
||||
//如果返回错误,且为内部错误,则直接抛出异常
|
||||
CommonResponseEnum commonResponseEnum = EnumUtils.getCommonResponseEnumByCode(result.getCode());
|
||||
CommonResponseEnum commonResponseEnum;
|
||||
if(result.getCode().equals(CommonResponseEnum.DYNAMIC_RESPONSE_ENUM.getCode())){
|
||||
commonResponseEnum = CommonResponseEnum.DEVICE_RESPONSE_ENUM;
|
||||
commonResponseEnum.setMessage(result.getMessage());
|
||||
}else{
|
||||
commonResponseEnum = EnumUtils.getCommonResponseEnumByCode(result.getCode());
|
||||
}
|
||||
switch (commonResponseEnum) {
|
||||
case SUCCESS:
|
||||
return result;
|
||||
|
||||
@@ -117,61 +117,64 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
||||
@Override
|
||||
public void judgeUserStatus(String loginName) {
|
||||
User user = getUserByLoginName(loginName);
|
||||
if (Objects.isNull(user)) {
|
||||
throw new BusinessException(UserResponseEnum.LOGIN_WRONG_PWD);
|
||||
}
|
||||
//超级管理员则不做任何逻辑判断
|
||||
if (user.getType() == 0) {
|
||||
//更新用户登录时间,以及错误登录记录的信息归零。
|
||||
user.setState(UserState.ENABLE);
|
||||
user.setLoginErrorTimes(0);
|
||||
user.setLoginTime(LocalDateTime.now());
|
||||
user.setFirstErrorTime(null);
|
||||
user.setLockTime(null);
|
||||
this.baseMapper.updateById(user);
|
||||
return;
|
||||
}
|
||||
//根据用户类型获取对应用户策略
|
||||
UserStrategy userStrategy = userStrategyService.lambdaQuery()
|
||||
.eq(UserStrategy::getType, user.getCasualUser())
|
||||
.eq(UserStrategy::getState, DataStateEnum.ENABLE.getCode())
|
||||
.one();
|
||||
switch (user.getState()) {
|
||||
case UserState.LOCKED:
|
||||
LocalDateTime lockTime = user.getLockTime();
|
||||
lockTime = lockTime.plusMinutes(userStrategy.getLockPwdTime());
|
||||
LocalDateTime nowTime = LocalDateTime.now();
|
||||
//判断是否满足锁定时间
|
||||
if (nowTime.isBefore(lockTime)) {
|
||||
throw new BusinessException(UserResponseEnum.LOGIN_USER_LOCKED);
|
||||
}
|
||||
break;
|
||||
case UserState.DELETE:
|
||||
//用户已注销
|
||||
throw new BusinessException(UserResponseEnum.LOGIN_USER_DELETE);
|
||||
case UserState.UNCHECK:
|
||||
//用户未审核
|
||||
throw new BusinessException(UserResponseEnum.LOGIN_USER_UNAUDITED);
|
||||
case UserState.SLEEP:
|
||||
//用户已休眠
|
||||
throw new BusinessException(UserResponseEnum.LOGIN_USER_SLEEP);
|
||||
case UserState.OVERDUE:
|
||||
//用户密码已过期
|
||||
throw new BusinessException(UserResponseEnum.LOGIN_USER_PASSWORD_EXPIRED);
|
||||
default:
|
||||
if (user.getPwdState() == 1) {
|
||||
throw new BusinessException(UserResponseEnum.NEED_MODIFY_PWD);
|
||||
}
|
||||
//用户状态正常,判断其他细节
|
||||
judgeFirstLogin(user, userStrategy);
|
||||
}
|
||||
//所有验证通过后,更新用户登录时间,以及错误登录记录的信息归零。
|
||||
user.setState(UserState.ENABLE);
|
||||
user.setLoginErrorTimes(0);
|
||||
user.setLoginTime(LocalDateTime.now());
|
||||
user.setFirstErrorTime(null);
|
||||
user.setLockTime(null);
|
||||
this.baseMapper.updateById(user);
|
||||
CommonResponseEnum testEnum = CommonResponseEnum.DYNAMIC_RESPONSE_ENUM;
|
||||
testEnum.setMessage("测试自定义等于失败");
|
||||
throw new BusinessException(testEnum);
|
||||
// if (Objects.isNull(user)) {
|
||||
// throw new BusinessException(UserResponseEnum.LOGIN_WRONG_PWD);
|
||||
// }
|
||||
// //超级管理员则不做任何逻辑判断
|
||||
// if (user.getType() == 0) {
|
||||
// //更新用户登录时间,以及错误登录记录的信息归零。
|
||||
// user.setState(UserState.ENABLE);
|
||||
// user.setLoginErrorTimes(0);
|
||||
// user.setLoginTime(LocalDateTime.now());
|
||||
// user.setFirstErrorTime(null);
|
||||
// user.setLockTime(null);
|
||||
// this.baseMapper.updateById(user);
|
||||
// return;
|
||||
// }
|
||||
// //根据用户类型获取对应用户策略
|
||||
// UserStrategy userStrategy = userStrategyService.lambdaQuery()
|
||||
// .eq(UserStrategy::getType, user.getCasualUser())
|
||||
// .eq(UserStrategy::getState, DataStateEnum.ENABLE.getCode())
|
||||
// .one();
|
||||
// switch (user.getState()) {
|
||||
// case UserState.LOCKED:
|
||||
// LocalDateTime lockTime = user.getLockTime();
|
||||
// lockTime = lockTime.plusMinutes(userStrategy.getLockPwdTime());
|
||||
// LocalDateTime nowTime = LocalDateTime.now();
|
||||
// //判断是否满足锁定时间
|
||||
// if (nowTime.isBefore(lockTime)) {
|
||||
// throw new BusinessException(UserResponseEnum.LOGIN_USER_LOCKED);
|
||||
// }
|
||||
// break;
|
||||
// case UserState.DELETE:
|
||||
// //用户已注销
|
||||
// throw new BusinessException(UserResponseEnum.LOGIN_USER_DELETE);
|
||||
// case UserState.UNCHECK:
|
||||
// //用户未审核
|
||||
// throw new BusinessException(UserResponseEnum.LOGIN_USER_UNAUDITED);
|
||||
// case UserState.SLEEP:
|
||||
// //用户已休眠
|
||||
// throw new BusinessException(UserResponseEnum.LOGIN_USER_SLEEP);
|
||||
// case UserState.OVERDUE:
|
||||
// //用户密码已过期
|
||||
// throw new BusinessException(UserResponseEnum.LOGIN_USER_PASSWORD_EXPIRED);
|
||||
// default:
|
||||
// if (user.getPwdState() == 1) {
|
||||
// throw new BusinessException(UserResponseEnum.NEED_MODIFY_PWD);
|
||||
// }
|
||||
// //用户状态正常,判断其他细节
|
||||
// judgeFirstLogin(user, userStrategy);
|
||||
// }
|
||||
// //所有验证通过后,更新用户登录时间,以及错误登录记录的信息归零。
|
||||
// user.setState(UserState.ENABLE);
|
||||
// user.setLoginErrorTimes(0);
|
||||
// user.setLoginTime(LocalDateTime.now());
|
||||
// user.setFirstErrorTime(null);
|
||||
// user.setLockTime(null);
|
||||
// this.baseMapper.updateById(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user