|
|
@@ -1,5 +1,6 @@
|
|
|
package cn.reghao.tnb.auth.app.db.repository;
|
|
|
|
|
|
+import cn.reghao.jutil.jdk.string.IDObfuscation;
|
|
|
import cn.reghao.tnb.auth.api.dto.AccountInfo;
|
|
|
import cn.reghao.tnb.auth.app.db.mapper.UserAccountMapper;
|
|
|
import cn.reghao.tnb.auth.app.db.mapper.UserRoleMapper;
|
|
|
@@ -31,12 +32,14 @@ public class AccountRepository {
|
|
|
private final UserAccountMapper userAccountMapper;
|
|
|
private final UserRegistryMapper userRegistryMapper;
|
|
|
private final UserRoleMapper userRoleMapper;
|
|
|
+ private final IDObfuscation userIdObfuscation;
|
|
|
|
|
|
public AccountRepository(UserAccountMapper userAccountMapper, UserRegistryMapper userRegistryMapper,
|
|
|
- UserRoleMapper userRoleMapper) {
|
|
|
+ UserRoleMapper userRoleMapper, IDObfuscation userIdObfuscation) {
|
|
|
this.userAccountMapper = userAccountMapper;
|
|
|
this.userRegistryMapper = userRegistryMapper;
|
|
|
this.userRoleMapper = userRoleMapper;
|
|
|
+ this.userIdObfuscation = userIdObfuscation;
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@@ -87,9 +90,12 @@ public class AccountRepository {
|
|
|
return userId;
|
|
|
}
|
|
|
|
|
|
+ // redis 中的 key 格式为 tnb:account:info:10002
|
|
|
@Cacheable(cacheNames = "tnb:account:info", key = "#userId", unless = "#result == null")
|
|
|
public AccountInfo getAccountInfo(long userId) {
|
|
|
AccountInfo accountInfo = userAccountMapper.findAccountInfo(userId);
|
|
|
+ String userIdStr = userIdObfuscation.obfuscate(accountInfo.getUserId());
|
|
|
+ accountInfo.setUserIdStr(userIdStr);
|
|
|
return accountInfo;
|
|
|
}
|
|
|
|
|
|
@@ -172,7 +178,10 @@ public class AccountRepository {
|
|
|
|
|
|
private UserAccount setAccountAuthorities(UserAccount userAccount) {
|
|
|
Set<UserAuthority> set = userRoleMapper.findRolesByUserId(userAccount.getUserId()).stream()
|
|
|
- .map(userRole -> new UserAuthority(userRole.getName()))
|
|
|
+ .map(userRole -> {
|
|
|
+ String role = AccountRole.getByDesc(userRole.getName()).name();
|
|
|
+ return new UserAuthority(role);
|
|
|
+ })
|
|
|
.collect(Collectors.toSet());
|
|
|
userAccount.setAuthorities(set);
|
|
|
return userAccount;
|