From d82d78697ed4780b6e77cdb8aef82b563fee05c2 Mon Sep 17 00:00:00 2001 From: gxwebsoft <170083662@qq.com> Date: Fri, 12 Dec 2025 14:31:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(tenant):=20=E6=B7=BB=E5=8A=A0=E7=A7=9F?= =?UTF-8?q?=E6=88=B7=E5=90=8D=E7=A7=B0=E9=87=8D=E5=A4=8D=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在创建租户时检查名称是否已存在 - 确保租户名称不为空 - 防止重复租户名称导致的数据冲突 --- .../system/controller/MainController.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/com/gxwebsoft/common/system/controller/MainController.java b/src/main/java/com/gxwebsoft/common/system/controller/MainController.java index 155c75e..9ee9e7c 100644 --- a/src/main/java/com/gxwebsoft/common/system/controller/MainController.java +++ b/src/main/java/com/gxwebsoft/common/system/controller/MainController.java @@ -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() + .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() + .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);