|
@@ -1,7 +1,6 @@
|
|
|
package com.abi.qms.platform.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
-import com.abi.base.foundation.util.RedisClient;
|
|
|
import com.abi.qms.platform.dao.entity.UserInfo;
|
|
|
import com.abi.qms.platform.dao.entity.UserRole;
|
|
|
import com.abi.qms.platform.dao.mapper.UserInfoMapper;
|
|
@@ -13,6 +12,7 @@ import com.abi.qms.platform.dto.req.UpdatePasswordReq;
|
|
|
import com.abi.qms.platform.dto.res.LoginRes;
|
|
|
import com.abi.qms.platform.infrastructure.constant.BaseFinal;
|
|
|
import com.abi.qms.platform.infrastructure.constant.RedisKey;
|
|
|
+import com.abi.qms.platform.infrastructure.util.RedisUtils;
|
|
|
import com.abi.qms.platform.infrastructure.util.UUIDutils;
|
|
|
import com.abi.qms.platform.infrastructure.util.UserUtil;
|
|
|
import com.abi.qms.platform.service.LoginService;
|
|
@@ -46,7 +46,7 @@ public class LoginServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> impl
|
|
|
private UserRoleMapper userRoleMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- private RedisClient redisClient;
|
|
|
+ private RedisUtils redisUtils;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -65,20 +65,20 @@ public class LoginServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> impl
|
|
|
UserUtil.setUser(userInfo);
|
|
|
String uuid = UUIDutils.getUUID();
|
|
|
//token为key,id为value。过期时间30天
|
|
|
- redisClient.set(RedisKey.USER_TOKEN_ID + ":" + uuid, one.getId(), BaseFinal.REDIS_USER_EXPIRE_TIME, TimeUnit.SECONDS);
|
|
|
+ redisUtils.set(RedisKey.USER_TOKEN_ID + ":" + uuid, one.getId(), BaseFinal.REDIS_USER_EXPIRE_TIME, TimeUnit.SECONDS);
|
|
|
//异地登录状态
|
|
|
- if (redisClient.hasKey(RedisKey.USER_ID_TOKEN + ":" + one.getId())) {
|
|
|
+ if (redisUtils.exists(RedisKey.USER_ID_TOKEN + ":" + one.getId())) {
|
|
|
//有key,value为null的情况;就把key删掉
|
|
|
- Object loginkey = redisClient.get(RedisKey.USER_ID_TOKEN + ":" + one.getId());
|
|
|
+ Object loginkey = redisUtils.get(RedisKey.USER_ID_TOKEN + ":" + one.getId());
|
|
|
if (Objects.nonNull(loginkey)) {
|
|
|
- redisClient.delete(RedisKey.USER_TOKEN_ID + ":" + loginkey.toString());
|
|
|
+ redisUtils.del(RedisKey.USER_TOKEN_ID + ":" + loginkey.toString());
|
|
|
} else {
|
|
|
- redisClient.delete(RedisKey.USER_ID_TOKEN + ":" + one.getId());
|
|
|
+ redisUtils.del(RedisKey.USER_ID_TOKEN + ":" + one.getId());
|
|
|
}
|
|
|
}
|
|
|
;
|
|
|
//登录状态
|
|
|
- redisClient.set(RedisKey.USER_ID_TOKEN + ":" + one.getId(), uuid, BaseFinal.REDIS_USER_EXPIRE_TIME, TimeUnit.SECONDS);
|
|
|
+ redisUtils.set(RedisKey.USER_ID_TOKEN + ":" + one.getId(), uuid, BaseFinal.REDIS_USER_EXPIRE_TIME, TimeUnit.SECONDS);
|
|
|
LoginRes build = LoginRes.builder()
|
|
|
.token(uuid)
|
|
|
.id(one.getId())
|
|
@@ -99,13 +99,13 @@ public class LoginServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> impl
|
|
|
userInfoMapper.updateById(userInfo);
|
|
|
UserUtil.releaseUser();
|
|
|
//删除redis用户token信息
|
|
|
- if (redisClient.hasKey(RedisKey.USER_ID_TOKEN + ":" + req.getId())) {
|
|
|
+ if (redisUtils.exists(RedisKey.USER_ID_TOKEN + ":" + req.getId())) {
|
|
|
//有key,value为null的情况;就把key删掉
|
|
|
- Object loginkey = redisClient.get(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
+ Object loginkey = redisUtils.get(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
if (Objects.nonNull(loginkey)) {
|
|
|
- redisClient.delete(RedisKey.USER_TOKEN_ID + ":" + loginkey.toString());
|
|
|
+ redisUtils.del(RedisKey.USER_TOKEN_ID + ":" + loginkey.toString());
|
|
|
}
|
|
|
- redisClient.delete(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
+ redisUtils.del(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -119,13 +119,13 @@ public class LoginServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> impl
|
|
|
userInfo.setPassword(req.getNewPassword());
|
|
|
userInfoMapper.updateById(userInfo);
|
|
|
//删除redis用户token信息
|
|
|
- if (redisClient.hasKey(RedisKey.USER_ID_TOKEN + ":" + req.getId())) {
|
|
|
+ if (redisUtils.exists(RedisKey.USER_ID_TOKEN + ":" + req.getId())) {
|
|
|
//有key,value为null的情况;就把key删掉
|
|
|
- Object loginkey = redisClient.get(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
+ Object loginkey = redisUtils.get(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
if (Objects.nonNull(loginkey)) {
|
|
|
- redisClient.delete(RedisKey.USER_TOKEN_ID + ":" + loginkey.toString());
|
|
|
+ redisUtils.del(RedisKey.USER_TOKEN_ID + ":" + loginkey.toString());
|
|
|
}
|
|
|
- redisClient.delete(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
+ redisUtils.del(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
}
|
|
|
} else {
|
|
|
throw new BusinessException("请输入正确的密码");
|
|
@@ -134,13 +134,13 @@ public class LoginServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> impl
|
|
|
|
|
|
@Override
|
|
|
public UserInfo validateToken(TokenReq req) {
|
|
|
- Object uid = redisClient.get(RedisKey.USER_TOKEN_ID + ":" + req.getToken());
|
|
|
+ Object uid = redisUtils.get(RedisKey.USER_TOKEN_ID + ":" + req.getToken());
|
|
|
if (Objects.nonNull(uid)) {
|
|
|
UserInfo userInfo = getById(uid.toString());
|
|
|
if (userInfo != null) {
|
|
|
//刷新token
|
|
|
- redisClient.set(RedisKey.USER_TOKEN_ID + ":" + req.getToken(), userInfo.getId(), BaseFinal.REDIS_USER_EXPIRE_TIME, TimeUnit.SECONDS);
|
|
|
- redisClient.set(RedisKey.USER_ID_TOKEN + ":" + userInfo.getId(), req.getToken(), BaseFinal.REDIS_USER_EXPIRE_TIME, TimeUnit.SECONDS);
|
|
|
+ redisUtils.set(RedisKey.USER_TOKEN_ID + ":" + req.getToken(), userInfo.getId(), BaseFinal.REDIS_USER_EXPIRE_TIME, TimeUnit.SECONDS);
|
|
|
+ redisUtils.set(RedisKey.USER_ID_TOKEN + ":" + userInfo.getId(), req.getToken(), BaseFinal.REDIS_USER_EXPIRE_TIME, TimeUnit.SECONDS);
|
|
|
}
|
|
|
return userInfo;
|
|
|
}
|