From b0e0c1cfaf3de0bc402241a1aedbd51d66ff0840 Mon Sep 17 00:00:00 2001 From: Parker Date: Thu, 25 Feb 2021 13:15:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=9F=E6=88=B7=E6=AD=A3=E5=9C=A8=E8=A2=AB?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E7=94=A8=E6=88=B7=E7=BB=91=E5=AE=9A=EF=BC=8C?= =?UTF-8?q?=E7=A6=81=E6=AD=A2=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/TenantServiceImpl.java | 62 ++++++++----------- 1 file changed, 26 insertions(+), 36 deletions(-) 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); + } + } + // ============