|
@@ -19,6 +19,7 @@ import com.zanxiang.game.module.sdk.pojo.vo.CpTokenCheckVO;
|
|
import com.zanxiang.game.module.sdk.service.*;
|
|
import com.zanxiang.game.module.sdk.service.*;
|
|
import com.zanxiang.game.module.sdk.util.RedisUtil;
|
|
import com.zanxiang.game.module.sdk.util.RedisUtil;
|
|
import com.zanxiang.game.module.sdk.util.SignUtil;
|
|
import com.zanxiang.game.module.sdk.util.SignUtil;
|
|
|
|
+import com.zanxiang.module.redis.service.IDistributedLockComponent;
|
|
import com.zanxiang.module.util.DateUtil;
|
|
import com.zanxiang.module.util.DateUtil;
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
import com.zanxiang.module.util.bean.BeanUtil;
|
|
import com.zanxiang.module.util.bean.BeanUtil;
|
|
@@ -35,6 +36,7 @@ import reactor.util.function.Tuples;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author : lingfeng
|
|
* @author : lingfeng
|
|
@@ -57,6 +59,9 @@ public class UserTokenServiceImpl extends ServiceImpl<UserTokenMapper, UserToken
|
|
@Autowired
|
|
@Autowired
|
|
private IUserService userService;
|
|
private IUserService userService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IDistributedLockComponent distributedLockComponent;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private IUserLoginLogService userLoginLogService;
|
|
private IUserLoginLogService userLoginLogService;
|
|
|
|
|
|
@@ -248,15 +253,7 @@ public class UserTokenServiceImpl extends ServiceImpl<UserTokenMapper, UserToken
|
|
.eq(UserToken::getDeviceType, deviceType));
|
|
.eq(UserToken::getDeviceType, deviceType));
|
|
//不存在token数据, 直接创建
|
|
//不存在token数据, 直接创建
|
|
if (userToken == null) {
|
|
if (userToken == null) {
|
|
- userToken = UserToken.builder()
|
|
|
|
- .userId(userId)
|
|
|
|
- .token(token)
|
|
|
|
- .deviceType(deviceType)
|
|
|
|
- .createTime(LocalDateTime.now())
|
|
|
|
- .updateTime(LocalDateTime.now())
|
|
|
|
- .expireTime(DateUtils.localDateTimeToSecond(LocalDateTime.now()) + ExpireTimeEnum.ONE_WEEK.getTime())
|
|
|
|
- .build();
|
|
|
|
- super.save(userToken);
|
|
|
|
|
|
+ userToken = this.tokenSave(userId, token, deviceType);
|
|
} else {
|
|
} else {
|
|
//更新数据库
|
|
//更新数据库
|
|
userToken.setToken(token);
|
|
userToken.setToken(token);
|
|
@@ -274,6 +271,23 @@ public class UserTokenServiceImpl extends ServiceImpl<UserTokenMapper, UserToken
|
|
return token;
|
|
return token;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private UserToken tokenSave(Long userId, String token, Integer deviceType) {
|
|
|
|
+ //上锁
|
|
|
|
+ if (!distributedLockComponent.doLock(RedisKeyConstant.TOKEN_CREATE_LOCK + userId + "_" + deviceType, 0L, 3L, TimeUnit.MINUTES)) {
|
|
|
|
+ throw new BaseException("token创建中, 请勿重复请求!");
|
|
|
|
+ }
|
|
|
|
+ UserToken userToken = UserToken.builder()
|
|
|
|
+ .userId(userId)
|
|
|
|
+ .token(token)
|
|
|
|
+ .deviceType(deviceType)
|
|
|
|
+ .createTime(LocalDateTime.now())
|
|
|
|
+ .updateTime(LocalDateTime.now())
|
|
|
|
+ .expireTime(DateUtils.localDateTimeToSecond(LocalDateTime.now()) + ExpireTimeEnum.ONE_WEEK.getTime())
|
|
|
|
+ .build();
|
|
|
|
+ super.save(userToken);
|
|
|
|
+ return userToken;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void deleteUserToken(Long userId, Integer deviceType) {
|
|
public void deleteUserToken(Long userId, Integer deviceType) {
|
|
UserToken userToken = super.getOne(new LambdaQueryWrapper<UserToken>()
|
|
UserToken userToken = super.getOne(new LambdaQueryWrapper<UserToken>()
|