|
@@ -301,20 +301,27 @@ public class UserTokenServiceImpl extends ServiceImpl<UserTokenMapper, UserToken
|
|
}
|
|
}
|
|
|
|
|
|
private UserToken tokenSave(Long userId, String token, Integer deviceType) {
|
|
private UserToken tokenSave(Long userId, String token, Integer deviceType) {
|
|
|
|
+ String lockKey = RedisKeyConstant.TOKEN_CREATE_LOCK + userId + "_" + deviceType;
|
|
//上锁
|
|
//上锁
|
|
- if (!distributedLockComponent.doLock(RedisKeyConstant.TOKEN_CREATE_LOCK + userId + "_" + deviceType, 0L, 3L, TimeUnit.MINUTES)) {
|
|
|
|
|
|
+ if (!distributedLockComponent.doLock(lockKey, 0L, 3L, TimeUnit.MINUTES)) {
|
|
throw new BaseException("token创建中, 请勿重复请求!");
|
|
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;
|
|
|
|
|
|
+ try {
|
|
|
|
+ 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;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new BaseException("创建token异常!");
|
|
|
|
+ } finally {
|
|
|
|
+ distributedLockComponent.unlock(lockKey);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|