From 92cf4b9e636ba4868d4b0325719607d2da33eebc Mon Sep 17 00:00:00 2001 From: shizhong <124974919@qq.com> Date: Mon, 3 Apr 2023 12:55:06 +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=EF=BC=8C=E6=8C=89=E8=A7=84=E8=8C=83=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/system/dal/mysql/tenant/TenantMapper.java | 6 ++++++ .../module/system/service/tenant/TenantServiceImpl.java | 7 +------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java index 8731e4628..92a0f9975 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java @@ -38,6 +38,12 @@ public interface TenantMapper extends BaseMapperX { .orderByDesc(TenantDO::getId)); } + default Long selectCountByName(String name, Long id) { + return selectCount(new LambdaQueryWrapperX() + .eqIfPresent(TenantDO::getName, name) + .neIfPresent(TenantDO::getId, id)); + } + default TenantDO selectByName(String name) { return selectOne(TenantDO::getName, name); } 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 5df583bde..ad1fa180f 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 @@ -160,12 +160,7 @@ 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) { + if (tenantMapper.selectCountByName(tenantName, id) > 0) { throw exception(TENANT_NAME_DUPLICATE); } }