feat(tenant): 添加租户名称重复验证
- 在创建租户时检查名称是否已存在 - 确保租户名称不为空 - 防止重复租户名称导致的数据冲突
This commit is contained in:
@@ -673,6 +673,21 @@ public class MainController extends BaseController {
|
||||
if (userService.getAdminByPhone(param) != null) {
|
||||
throw new BusinessException("该手机号码已注册");
|
||||
}
|
||||
|
||||
// 验证租户名称是否重复
|
||||
if (StrUtil.isNotBlank(tenantName)) {
|
||||
long existingTenantCount = tenantService.count(
|
||||
new LambdaQueryWrapper<Tenant>()
|
||||
.eq(Tenant::getTenantName, tenantName)
|
||||
.eq(Tenant::getDeleted, 0)
|
||||
);
|
||||
if (existingTenantCount > 0) {
|
||||
throw new BusinessException("租户名称已存在,请使用其他名称");
|
||||
}
|
||||
} else {
|
||||
throw new BusinessException("租户名称不能为空");
|
||||
}
|
||||
|
||||
// 添加租户
|
||||
Tenant tenant = new Tenant();
|
||||
tenant.setTenantName(tenantName);
|
||||
@@ -823,6 +838,21 @@ public class MainController extends BaseController {
|
||||
if (userService.getAdminByPhone(param) != null) {
|
||||
throw new BusinessException("该手机号码已注册");
|
||||
}
|
||||
|
||||
// 验证租户名称是否重复
|
||||
if (StrUtil.isNotBlank(tenantName)) {
|
||||
long existingTenantCount = tenantService.count(
|
||||
new LambdaQueryWrapper<Tenant>()
|
||||
.eq(Tenant::getTenantName, tenantName)
|
||||
.eq(Tenant::getDeleted, 0)
|
||||
);
|
||||
if (existingTenantCount > 0) {
|
||||
throw new BusinessException("租户名称已存在,请使用其他名称");
|
||||
}
|
||||
} else {
|
||||
throw new BusinessException("租户名称不能为空");
|
||||
}
|
||||
|
||||
// 添加租户
|
||||
Tenant tenant = new Tenant();
|
||||
tenant.setTenantName(tenantName);
|
||||
|
||||
Reference in New Issue
Block a user