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); } }