diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/impl/TenantServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/impl/TenantServiceImpl.java index e158da2d..0a60f219 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/impl/TenantServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/impl/TenantServiceImpl.java @@ -19,6 +19,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.google.common.collect.Lists; + import org.apache.commons.lang3.StringUtils; import org.opsli.api.wrapper.system.tenant.TenantModel; import org.opsli.common.constants.MyBatisConstants; @@ -113,15 +114,7 @@ public class TenantServiceImpl extends CrudServiceImpl queryWrapper = new QueryWrapper<>(); - queryWrapper.in(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT), - id - ); - int count = iUserService.count(queryWrapper); - if(count >= 0){ - // 该租户正在被其他用户绑定,无法删除 - throw new ServiceException(SystemMsg.EXCEPTION_TENANT_USED_DEL); - } + this.validationUsedByDel(Collections.singletonList(id)); boolean ret = super.delete(id); @@ -147,15 +140,7 @@ public class TenantServiceImpl extends CrudServiceImpl queryWrapper = new QueryWrapper<>(); - queryWrapper.in(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT), - model.getId() - ); - int count = iUserService.count(queryWrapper); - if(count >= 0){ - // 该租户正在被其他用户绑定,无法删除 - throw new ServiceException(SystemMsg.EXCEPTION_TENANT_USED_DEL); - } + this.validationUsedByDel(Collections.singletonList(model.getId())); boolean ret = super.delete(model); @@ -178,15 +163,7 @@ public class TenantServiceImpl extends CrudServiceImpl idList = Convert.toList(String.class, ids); // 如果有租户还在被引用 则不允许删除该租户 - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.in(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT), - idList - ); - int count = iUserService.count(queryWrapper); - if(count >= 0){ - // 该租户正在被其他用户绑定,无法删除 - throw new ServiceException(SystemMsg.EXCEPTION_TENANT_USED_DEL); - } + this.validationUsedByDel(idList); boolean ret = super.deleteAll(ids); if(ret){ @@ -211,15 +188,7 @@ public class TenantServiceImpl extends CrudServiceImpl queryWrapper = new QueryWrapper<>(); - queryWrapper.in(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT), - idList - ); - int count = iUserService.count(queryWrapper); - if(count >= 0){ - // 该租户正在被其他用户绑定,无法删除 - throw new ServiceException(SystemMsg.EXCEPTION_TENANT_USED_DEL); - } + this.validationUsedByDel(idList); boolean ret = super.deleteAll(models); if(ret){ @@ -254,6 +223,27 @@ public class TenantServiceImpl extends CrudServiceImpl tenantIdList){ + if(CollUtil.isEmpty(tenantIdList)){ + return; + } + + // 如果有租户还在被引用 则不允许删除该租户 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT), + tenantIdList + ); + int count = iUserService.count(queryWrapper); + if(count > 0){ + // 该租户正在被其他用户绑定,无法删除 + throw new ServiceException(SystemMsg.EXCEPTION_TENANT_USED_DEL); + } + } + // ============