|
@@ -1,6 +1,7 @@
|
|
|
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;
|
|
@@ -12,12 +13,9 @@ 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.exception.ErrorCodeEnum;
|
|
|
-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;
|
|
|
-import com.abi.task.common.api.base.BaseResponse;
|
|
|
import com.abi.task.common.api.exception.BusinessException;
|
|
|
import com.abi.task.common.utils.AESEncodeTwoUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -27,8 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -47,8 +45,8 @@ public class LoginServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> impl
|
|
|
@Autowired
|
|
|
private UserRoleMapper userRoleMapper;
|
|
|
|
|
|
- @Resource
|
|
|
- private RedisUtils redisUtil;
|
|
|
+ @Autowired
|
|
|
+ private RedisClient redisClient;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -67,20 +65,20 @@ public class LoginServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> impl
|
|
|
UserUtil.setUser(userInfo);
|
|
|
String uuid = UUIDutils.getUUID();
|
|
|
//token为key,id为value。过期时间30天
|
|
|
- redisUtil.set(RedisKey.USER_TOKEN_ID + ":" + uuid, one.getId(), BaseFinal.REDIS_USER_EXPIRE_TIME);
|
|
|
+ redisClient.set(RedisKey.USER_TOKEN_ID + ":" + uuid, one.getId(), BaseFinal.REDIS_USER_EXPIRE_TIME, TimeUnit.MILLISECONDS);
|
|
|
//异地登录状态
|
|
|
- if (redisUtil.exists(RedisKey.USER_ID_TOKEN + ":" + one.getId())) {
|
|
|
+ if (redisClient.hasKey(RedisKey.USER_ID_TOKEN + ":" + one.getId())) {
|
|
|
//有key,value为null的情况;就把key删掉
|
|
|
- Object loginkey = redisUtil.get(RedisKey.USER_ID_TOKEN + ":" + one.getId());
|
|
|
+ Object loginkey = redisClient.get(RedisKey.USER_ID_TOKEN + ":" + one.getId());
|
|
|
if (Objects.nonNull(loginkey)) {
|
|
|
- redisUtil.del(RedisKey.USER_TOKEN_ID + ":" + loginkey.toString());
|
|
|
+ redisClient.delete(RedisKey.USER_TOKEN_ID + ":" + loginkey.toString());
|
|
|
} else {
|
|
|
- redisUtil.del(RedisKey.USER_ID_TOKEN + ":" + one.getId());
|
|
|
+ redisClient.delete(RedisKey.USER_ID_TOKEN + ":" + one.getId());
|
|
|
}
|
|
|
}
|
|
|
;
|
|
|
//登录状态
|
|
|
- redisUtil.set(RedisKey.USER_ID_TOKEN + ":" + one.getId(), uuid, BaseFinal.REDIS_USER_EXPIRE_TIME);
|
|
|
+ redisClient.set(RedisKey.USER_ID_TOKEN + ":" + one.getId(), uuid, BaseFinal.REDIS_USER_EXPIRE_TIME, TimeUnit.MILLISECONDS);
|
|
|
LoginRes build = LoginRes.builder()
|
|
|
.token(uuid)
|
|
|
.id(one.getId())
|
|
@@ -101,13 +99,13 @@ public class LoginServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> impl
|
|
|
userInfoMapper.updateById(userInfo);
|
|
|
UserUtil.releaseUser();
|
|
|
//删除redis用户token信息
|
|
|
- if (redisUtil.exists(RedisKey.USER_ID_TOKEN + ":" + req.getId())) {
|
|
|
+ if (redisClient.hasKey(RedisKey.USER_ID_TOKEN + ":" + req.getId())) {
|
|
|
//有key,value为null的情况;就把key删掉
|
|
|
- Object loginkey = redisUtil.get(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
+ Object loginkey = redisClient.get(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
if (Objects.nonNull(loginkey)) {
|
|
|
- redisUtil.del(RedisKey.USER_TOKEN_ID + ":" + loginkey.toString());
|
|
|
+ redisClient.delete(RedisKey.USER_TOKEN_ID + ":" + loginkey.toString());
|
|
|
}
|
|
|
- redisUtil.del(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
+ redisClient.delete(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -121,13 +119,13 @@ public class LoginServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> impl
|
|
|
userInfo.setPassword(req.getNewPassword());
|
|
|
userInfoMapper.updateById(userInfo);
|
|
|
//删除redis用户token信息
|
|
|
- if (redisUtil.exists(RedisKey.USER_ID_TOKEN + ":" + req.getId())) {
|
|
|
+ if (redisClient.hasKey(RedisKey.USER_ID_TOKEN + ":" + req.getId())) {
|
|
|
//有key,value为null的情况;就把key删掉
|
|
|
- Object loginkey = redisUtil.get(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
+ Object loginkey = redisClient.get(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
if (Objects.nonNull(loginkey)) {
|
|
|
- redisUtil.del(RedisKey.USER_TOKEN_ID + ":" + loginkey.toString());
|
|
|
+ redisClient.delete(RedisKey.USER_TOKEN_ID + ":" + loginkey.toString());
|
|
|
}
|
|
|
- redisUtil.del(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
+ redisClient.delete(RedisKey.USER_ID_TOKEN + ":" + req.getId());
|
|
|
}
|
|
|
} else {
|
|
|
throw new BusinessException("请输入正确的密码");
|
|
@@ -136,13 +134,13 @@ public class LoginServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> impl
|
|
|
|
|
|
@Override
|
|
|
public UserInfo validateToken(TokenReq req) {
|
|
|
- Object uid = redisUtil.get(RedisKey.USER_TOKEN_ID + ":" + req.getToken());
|
|
|
+ Object uid = redisClient.get(RedisKey.USER_TOKEN_ID + ":" + req.getToken());
|
|
|
if (Objects.nonNull(uid)) {
|
|
|
UserInfo userInfo = getById(uid.toString());
|
|
|
if (userInfo != null) {
|
|
|
//刷新token
|
|
|
- redisUtil.set(RedisKey.USER_TOKEN_ID + ":" + req.getToken(), userInfo.getId(), BaseFinal.REDIS_USER_EXPIRE_TIME);
|
|
|
- redisUtil.set(RedisKey.USER_ID_TOKEN + ":" + userInfo.getId(), req.getToken(), BaseFinal.REDIS_USER_EXPIRE_TIME);
|
|
|
+ redisClient.set(RedisKey.USER_TOKEN_ID + ":" + req.getToken(), userInfo.getId(), BaseFinal.REDIS_USER_EXPIRE_TIME, TimeUnit.MILLISECONDS);
|
|
|
+ redisClient.set(RedisKey.USER_ID_TOKEN + ":" + userInfo.getId(), req.getToken(), BaseFinal.REDIS_USER_EXPIRE_TIME, TimeUnit.MILLISECONDS);
|
|
|
}
|
|
|
return userInfo;
|
|
|
}
|