|
|
@@ -1,12 +1,11 @@
|
|
|
package cn.reghao.tnb.account.app.db.repository;
|
|
|
|
|
|
-import cn.reghao.jutil.web.ServletUtil;
|
|
|
import cn.reghao.tnb.account.api.dto.AccountInfo;
|
|
|
import cn.reghao.tnb.account.app.db.mapper.UserAccountMapper;
|
|
|
-import cn.reghao.tnb.account.app.db.mapper.UserAccountRoleMapper;
|
|
|
+import cn.reghao.tnb.account.app.db.mapper.UserRoleMapper;
|
|
|
import cn.reghao.tnb.account.app.db.mapper.UserRegistryMapper;
|
|
|
import cn.reghao.tnb.account.app.model.po.UserAccount;
|
|
|
-import cn.reghao.tnb.account.app.model.po.UserAccountRole;
|
|
|
+import cn.reghao.tnb.account.app.model.po.UserRole;
|
|
|
import cn.reghao.tnb.account.app.model.po.UserAuthority;
|
|
|
import cn.reghao.tnb.account.app.model.po.UserRegistry;
|
|
|
import cn.reghao.tnb.common.auth.AccountRole;
|
|
|
@@ -29,24 +28,24 @@ import java.util.stream.Collectors;
|
|
|
public class AccountRepository {
|
|
|
private final UserAccountMapper userAccountMapper;
|
|
|
private final UserRegistryMapper userRegistryMapper;
|
|
|
- private final UserAccountRoleMapper userAccountRoleMapper;
|
|
|
+ private final UserRoleMapper userRoleMapper;
|
|
|
|
|
|
public AccountRepository(UserAccountMapper userAccountMapper, UserRegistryMapper userRegistryMapper,
|
|
|
- UserAccountRoleMapper userAccountRoleMapper) {
|
|
|
+ UserRoleMapper userRoleMapper) {
|
|
|
this.userAccountMapper = userAccountMapper;
|
|
|
this.userRegistryMapper = userRegistryMapper;
|
|
|
- this.userAccountRoleMapper = userAccountRoleMapper;
|
|
|
+ this.userRoleMapper = userRoleMapper;
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void saveAccount(UserAccount userAccount) {
|
|
|
long userId = userAccount.getUserId();
|
|
|
- Set<UserAccountRole> set = userAccount.getAuthorities().stream()
|
|
|
- .map(role -> new UserAccountRole(userId, role.getAuthority()))
|
|
|
+ Set<UserRole> set = userAccount.getAuthorities().stream()
|
|
|
+ .map(role -> new UserRole(userId, role.getAuthority()))
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
userAccountMapper.save(userAccount);
|
|
|
- userAccountRoleMapper.saveAll(new ArrayList<>(set));
|
|
|
+ userRoleMapper.saveAll(new ArrayList<>(set));
|
|
|
}
|
|
|
|
|
|
@CacheEvict(cacheNames = "tnb:account:info", key = "#userId")
|
|
|
@@ -60,8 +59,8 @@ public class AccountRepository {
|
|
|
}
|
|
|
|
|
|
private void addUserRole(long userId, String role) {
|
|
|
- UserAccountRole userAccountRole = new UserAccountRole(userId, role);
|
|
|
- userAccountRoleMapper.save(userAccountRole);
|
|
|
+ UserRole userRole = new UserRole(userId, role);
|
|
|
+ userRoleMapper.save(userRole);
|
|
|
}
|
|
|
|
|
|
@CacheEvict(cacheNames = "tnb:account:registry", key = "'account-registry'")
|
|
|
@@ -95,8 +94,8 @@ public class AccountRepository {
|
|
|
* @date 2025-10-17 11:30:05
|
|
|
*/
|
|
|
public Set<String> getUserRoles(long userId) {
|
|
|
- return userAccountRoleMapper.findRolesByUserId(userId).stream()
|
|
|
- .map(UserAccountRole::getName)
|
|
|
+ return userRoleMapper.findRolesByUserId(userId).stream()
|
|
|
+ .map(UserRole::getName)
|
|
|
.collect(Collectors.toSet());
|
|
|
}
|
|
|
|
|
|
@@ -105,7 +104,7 @@ public class AccountRepository {
|
|
|
String role1 = accountRole.getValue();
|
|
|
}
|
|
|
|
|
|
- List<Long> userIds = userAccountRoleMapper.findUserIdsByRole(role);
|
|
|
+ List<Long> userIds = userRoleMapper.findUserIdsByRole(role);
|
|
|
return userIds;
|
|
|
}
|
|
|
|
|
|
@@ -157,8 +156,8 @@ public class AccountRepository {
|
|
|
}
|
|
|
|
|
|
private UserAccount setAccountAuthorities(UserAccount userAccount) {
|
|
|
- Set<UserAuthority> set = userAccountRoleMapper.findRolesByUserId(userAccount.getUserId()).stream()
|
|
|
- .map(userAccountRole -> new UserAuthority(userAccountRole.getName()))
|
|
|
+ Set<UserAuthority> set = userRoleMapper.findRolesByUserId(userAccount.getUserId()).stream()
|
|
|
+ .map(userRole -> new UserAuthority(userRole.getName()))
|
|
|
.collect(Collectors.toSet());
|
|
|
userAccount.setAuthorities(set);
|
|
|
return userAccount;
|