|
@@ -11,6 +11,7 @@ import cn.iocoder.byzs.framework.common.util.collection.CollectionUtils;
|
|
|
import cn.iocoder.byzs.framework.common.util.object.BeanUtils;
|
|
import cn.iocoder.byzs.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.byzs.framework.common.util.validation.ValidationUtils;
|
|
import cn.iocoder.byzs.framework.common.util.validation.ValidationUtils;
|
|
|
import cn.iocoder.byzs.framework.datapermission.core.util.DataPermissionUtils;
|
|
import cn.iocoder.byzs.framework.datapermission.core.util.DataPermissionUtils;
|
|
|
|
|
+import cn.iocoder.byzs.framework.tenant.core.context.TenantContextHolder;
|
|
|
import cn.iocoder.byzs.framework.tenant.core.util.TenantUtils;
|
|
import cn.iocoder.byzs.framework.tenant.core.util.TenantUtils;
|
|
|
import cn.iocoder.byzs.module.infra.api.config.ConfigApi;
|
|
import cn.iocoder.byzs.module.infra.api.config.ConfigApi;
|
|
|
import cn.iocoder.byzs.module.system.controller.admin.auth.vo.AuthRegisterReqVO;
|
|
import cn.iocoder.byzs.module.system.controller.admin.auth.vo.AuthRegisterReqVO;
|
|
@@ -92,9 +93,17 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
public Long createUser(UserSaveReqVO createReqVO) {
|
|
public Long createUser(UserSaveReqVO createReqVO) {
|
|
|
// 1.1 校验账户配合
|
|
// 1.1 校验账户配合
|
|
|
tenantService.handleTenantInfo(tenant -> {
|
|
tenantService.handleTenantInfo(tenant -> {
|
|
|
- long count = userMapper.selectCount();
|
|
|
|
|
- if (count >= tenant.getAccountCount()) {
|
|
|
|
|
- throw exception(USER_COUNT_MAX, tenant.getAccountCount());
|
|
|
|
|
|
|
+ // 设置拼接租户,确保只查询当前租户的用户数量
|
|
|
|
|
+ boolean oldSplice = TenantContextHolder.isSplice();
|
|
|
|
|
+ try {
|
|
|
|
|
+ TenantContextHolder.setSplice(true);
|
|
|
|
|
+ long count = userMapper.selectCount();
|
|
|
|
|
+ if (count >= tenant.getAccountCount()) {
|
|
|
|
|
+ throw exception(USER_COUNT_MAX, tenant.getAccountCount());
|
|
|
|
|
+ }
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ // 恢复原始状态
|
|
|
|
|
+ TenantContextHolder.setSplice(oldSplice);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
// 1.2 校验正确性
|
|
// 1.2 校验正确性
|
|
@@ -124,9 +133,17 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
}
|
|
}
|
|
|
// 1.2 校验账户配合
|
|
// 1.2 校验账户配合
|
|
|
tenantService.handleTenantInfo(tenant -> {
|
|
tenantService.handleTenantInfo(tenant -> {
|
|
|
- long count = userMapper.selectCount();
|
|
|
|
|
- if (count >= tenant.getAccountCount()) {
|
|
|
|
|
- throw exception(USER_COUNT_MAX, tenant.getAccountCount());
|
|
|
|
|
|
|
+ // 设置拼接租户,确保只查询当前租户的用户数量
|
|
|
|
|
+ boolean oldSplice = TenantContextHolder.isSplice();
|
|
|
|
|
+ try {
|
|
|
|
|
+ TenantContextHolder.setSplice(true);
|
|
|
|
|
+ long count = userMapper.selectCount();
|
|
|
|
|
+ if (count >= tenant.getAccountCount()) {
|
|
|
|
|
+ throw exception(USER_COUNT_MAX, tenant.getAccountCount());
|
|
|
|
|
+ }
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ // 恢复原始状态
|
|
|
|
|
+ TenantContextHolder.setSplice(oldSplice);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
// 1.3 校验正确性
|
|
// 1.3 校验正确性
|
|
@@ -545,4 +562,4 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
return passwordEncoder.encode(password);
|
|
return passwordEncoder.encode(password);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
+}
|