mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 20:49:00 +08:00
fix(pigx-upms-biz): 修复租户用户移除时的租户切换问题
- 在removeTenantUser方法添加@Transactional注解确保事务性 - 增加用户当前租户检查逻辑 - 当用户当前租户是被移除租户时自动切换到其他可用租户 - 更新用户租户信息后清除用户缓存
This commit is contained in:
1 parent
a44319f898
commit
4868f0d213
1 file changed
+25
+25
@@ -357,6 +357,7 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
|
||||
* @return 是否移除成功
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean removeTenantUser(SysTenantUserDTO tenantUserDTO) {
|
||||
ArrayList<Long> userIdList = CollUtil.toList(tenantUserDTO.getUserIds());
|
||||
|
||||
@@ -373,6 +374,30 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
|
||||
// 删除用户部门
|
||||
sysUserDeptMapper.delete(Wrappers.<SysUserDept>lambdaQuery().in(SysUserDept::getUserId, userIdList));
|
||||
}));
|
||||
|
||||
// 检查用户当前租户是否为被移除的租户,若是则自动切换到其他租户
|
||||
TenantBroker.noneAs(() -> {
|
||||
for (Long userId : userIdList) {
|
||||
SysUser sysUser = sysUserMapper.selectById(userId);
|
||||
if (Objects.nonNull(sysUser) && tenantUserDTO.getTenantId().equals(sysUser.getTenantId())) {
|
||||
// 查询用户的其他租户
|
||||
SysTenantUser otherTenantUser = sysTenantUserMapper.selectOne(
|
||||
Wrappers.<SysTenantUser>lambdaQuery()
|
||||
.eq(SysTenantUser::getUserId, userId)
|
||||
.ne(SysTenantUser::getTenantId, tenantUserDTO.getTenantId()),
|
||||
false);
|
||||
if (otherTenantUser != null) {
|
||||
// 切换到其他租户
|
||||
sysUserMapper.update(Wrappers.<SysUser>lambdaUpdate()
|
||||
.set(SysUser::getTenantId, otherTenantUser.getTenantId())
|
||||
.eq(SysUser::getUserId, userId));
|
||||
// 清除用户缓存
|
||||
cacheManager.getCache(CacheConstants.USER_DETAILS).evict(sysUser.getUsername());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user