调整格式

pull/652/head
dante 2021-06-27 00:14:38 +08:00
parent b1a3064cc8
commit 721bbe2cbc
1 changed files with 38 additions and 34 deletions

View File

@ -57,6 +57,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
final static Map<String, Future<JwtUserDto>> userDtoCache = new ConcurrentHashMap<>(); final static Map<String, Future<JwtUserDto>> userDtoCache = new ConcurrentHashMap<>();
public static ExecutorService executor = newThreadPool(); public static ExecutorService executor = newThreadPool();
@Override @Override
public JwtUserDto loadUserByUsername(String username) { public JwtUserDto loadUserByUsername(String username) {
JwtUserDto jwtUserDto = null; JwtUserDto jwtUserDto = null;
@ -84,17 +85,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
return jwtUserDto; return jwtUserDto;
} }
if (future!=null) { if (future==null) {
try {
jwtUserDto=future.get();
}catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e.getMessage());
}
// 检查dataScope是否修改
List<Long> dataScopes = jwtUserDto.getDataScopes();
dataScopes.clear();
dataScopes.addAll(dataService.getDeptIds(jwtUserDto.getUser()));
}else{
Callable<JwtUserDto> call=()->getJwtBySearchDB(username); Callable<JwtUserDto> call=()->getJwtBySearchDB(username);
FutureTask<JwtUserDto> ft=new FutureTask<>(call); FutureTask<JwtUserDto> ft=new FutureTask<>(call);
future=userDtoCache.putIfAbsent(username,ft); future=userDtoCache.putIfAbsent(username,ft);
@ -109,10 +100,23 @@ public class UserDetailsServiceImpl implements UserDetailsService {
}catch (InterruptedException | ExecutionException e) { }catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(e.getMessage());
} }
}else{
try {
jwtUserDto=future.get();
}catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e.getMessage());
}
// 检查dataScope是否修改
List<Long> dataScopes = jwtUserDto.getDataScopes();
dataScopes.clear();
dataScopes.addAll(dataService.getDeptIds(jwtUserDto.getUser()));
} }
return jwtUserDto; return jwtUserDto;
} }
private JwtUserDto getJwtBySearchDB(String username) { private JwtUserDto getJwtBySearchDB(String username) {
UserDto user; UserDto user;
try { try {
@ -153,7 +157,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
return thread; return thread;
} }
}; };
return new ThreadPoolExecutor(8, 200, return new ThreadPoolExecutor(10, 200,
0L, TimeUnit.MILLISECONDS, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(1024), new LinkedBlockingQueue<>(1024),
namedThreadFactory, namedThreadFactory,