Merge pull request 'fix : 路由关键key改为登录uuid' (#5) from clay into master
Reviewed-on: http://git.feashow.cn/clay/fateverse/pulls/5
This commit is contained in:
@@ -72,6 +72,7 @@ public class OnlineUserServiceImpl implements OnlineUserService {
|
||||
@Override
|
||||
public void force(String tokenId) {
|
||||
redisTemplate.delete(CacheConstants.LOGIN_TOKEN_KEY + tokenId);
|
||||
redisTemplate.delete(CacheConstants.ROUTE_CACHE_KEY + tokenId);
|
||||
}
|
||||
|
||||
private OnlineUser toOnlineUser(LoginUser user) {
|
||||
|
||||
@@ -307,6 +307,7 @@ public class UserServiceImpl implements UserService {
|
||||
batchUserPost(dto, Boolean.TRUE);
|
||||
dto.setPassword(null);
|
||||
UserBase user = dto.toUser();
|
||||
|
||||
return userMapper.update(user);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
@@ -156,11 +157,15 @@ public class LoginServiceImpl implements LoginService {
|
||||
|
||||
@Override
|
||||
public List<RouterVo> getMenuRouterByUserId() {
|
||||
List<RouterVo> result = (List<RouterVo>) redisTemplate.opsForValue().get(CacheConstants.ROUTE_CACHE_KEY + SecurityUtils.getUserId());
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
if (ObjectUtils.isEmpty(loginUser)){
|
||||
throw new CustomException("获取用户信息失败!");
|
||||
}
|
||||
List<RouterVo> result = (List<RouterVo>) redisTemplate.opsForValue().get(CacheConstants.ROUTE_CACHE_KEY + loginUser.getUuid());
|
||||
if (result == null || result.isEmpty()) {
|
||||
RLock lock = redissonClient.getLock(CacheConstants.ROUTE_CACHE_KEY + "lock:" + SecurityUtils.getUserId());
|
||||
RLock lock = redissonClient.getLock(CacheConstants.ROUTE_CACHE_KEY + "lock:" + loginUser.getUuid());
|
||||
try {
|
||||
result = (List<RouterVo>) redisTemplate.opsForValue().get(CacheConstants.ROUTE_CACHE_KEY + SecurityUtils.getUserId());
|
||||
result = (List<RouterVo>) redisTemplate.opsForValue().get(CacheConstants.ROUTE_CACHE_KEY + loginUser.getUuid());
|
||||
if (result == null || result.isEmpty()) {
|
||||
result = menuService.selectMenuRouterByUserId(SecurityUtils.getUserId());
|
||||
if (result == null || result.isEmpty()) {
|
||||
@@ -168,7 +173,7 @@ public class LoginServiceImpl implements LoginService {
|
||||
// throw new CustomException("获取路由异常!");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
redisTemplate.opsForValue().set(CacheConstants.ROUTE_CACHE_KEY + SecurityUtils.getUserId(),result,30, TimeUnit.MINUTES);
|
||||
redisTemplate.opsForValue().set(CacheConstants.ROUTE_CACHE_KEY + loginUser.getUuid(), result, 30, TimeUnit.MINUTES);
|
||||
}
|
||||
} finally {
|
||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||
|
||||
@@ -14,7 +14,7 @@ public class CacheConstants {
|
||||
/**
|
||||
* 路由缓存地址
|
||||
*/
|
||||
public static final String ROUTE_CACHE_KEY = "router_key:";
|
||||
public static final String ROUTE_CACHE_KEY = "router:key:";
|
||||
/**
|
||||
* 登录用户 redis key
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user