租户添加或修改时租户名称改为不可以重复,否则会造成重复名称的租户无法正常登录的问题,按规范优化代码

This commit is contained in:
shizhong 2023-04-03 12:55:06 +08:00
parent 64cd19f7db
commit 92cf4b9e63
2 changed files with 7 additions and 6 deletions

View File

@ -38,6 +38,12 @@ public interface TenantMapper extends BaseMapperX<TenantDO> {
.orderByDesc(TenantDO::getId));
}
default Long selectCountByName(String name, Long id) {
return selectCount(new LambdaQueryWrapperX<TenantDO>()
.eqIfPresent(TenantDO::getName, name)
.neIfPresent(TenantDO::getId, id));
}
default TenantDO selectByName(String name) {
return selectOne(TenantDO::getName, name);
}

View File

@ -160,12 +160,7 @@ public class TenantServiceImpl implements TenantService {
}
protected void validTenantName(String tenantName, Long id) {
LambdaQueryWrapper<TenantDO> 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);
}
}