From 55358aa170c2f641cdb63c12a04c8939b8d232bb Mon Sep 17 00:00:00 2001 From: shizhong <124974919@qq.com> Date: Thu, 30 Mar 2023 16:00:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=9F=E6=88=B7=E6=B7=BB=E5=8A=A0=E6=88=96?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=B6=E7=A7=9F=E6=88=B7=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E4=B8=8D=E5=8F=AF=E4=BB=A5=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=EF=BC=8C=E5=90=A6=E5=88=99=E4=BC=9A=E9=80=A0=E6=88=90=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=90=8D=E7=A7=B0=E7=9A=84=E7=A7=9F=E6=88=B7=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E5=B8=B8=E7=99=BB=E5=BD=95=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/enums/ErrorCodeConstants.java | 1 + .../service/tenant/TenantServiceImpl.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 8a54ba92e..693c9b8ef 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -103,6 +103,7 @@ public interface ErrorCodeConstants { ErrorCode TENANT_DISABLE = new ErrorCode(1002015001, "名字为【{}】的租户已被禁用"); ErrorCode TENANT_EXPIRE = new ErrorCode(1002015002, "名字为【{}】的租户已过期"); ErrorCode TENANT_CAN_NOT_UPDATE_SYSTEM = new ErrorCode(1002015003, "系统租户不能进行修改、删除等操作!"); + ErrorCode TENANT_NAME_DUPLICATE = new ErrorCode(1002015004, "已经存在该名称的租户"); // ========== 租户套餐 1002016000 ========== ErrorCode TENANT_PACKAGE_NOT_EXISTS = new ErrorCode(1002016000, "租户套餐不存在"); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java index 3a70d31b9..5df583bde 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java @@ -29,6 +29,7 @@ import cn.iocoder.yudao.module.system.service.permission.RoleService; import cn.iocoder.yudao.module.system.service.tenant.handler.TenantInfoHandler; import cn.iocoder.yudao.module.system.service.tenant.handler.TenantMenuHandler; import cn.iocoder.yudao.module.system.service.user.AdminUserService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; @@ -97,6 +98,9 @@ public class TenantServiceImpl implements TenantService { @Override @Transactional(rollbackFor = Exception.class) public Long createTenant(TenantCreateReqVO createReqVO) { + // 校验租户名称是否重复 + validTenantName(createReqVO.getName(), null); + // 校验套餐被禁用 TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(createReqVO.getPackageId()); @@ -139,6 +143,10 @@ public class TenantServiceImpl implements TenantService { public void updateTenant(TenantUpdateReqVO updateReqVO) { // 校验存在 TenantDO tenant = validateUpdateTenant(updateReqVO.getId()); + + // 校验租户名称是否重复 + validTenantName(updateReqVO.getName(), updateReqVO.getId()); + // 校验套餐被禁用 TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(updateReqVO.getPackageId()); @@ -151,6 +159,17 @@ public class TenantServiceImpl implements TenantService { } } + protected void validTenantName(String tenantName, Long id) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(TenantDO::getName, tenantName); + if (id != null) { + wrapper.ne(TenantDO::getId, id); + } + if (tenantMapper.selectCount(wrapper) > 0) { + throw exception(TENANT_NAME_DUPLICATE); + } + } + @Override @Transactional(rollbackFor = Exception.class) public void updateTenantRoleMenu(Long tenantId, Set menuIds) {