From cc81014a0d8d4dfa8cb4f474b59d28c778d9fecb Mon Sep 17 00:00:00 2001 From: Parker Date: Thu, 25 Feb 2021 13:08:34 +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 --- .../org/opsli/modulars/system/SystemMsg.java | 1 + .../service/impl/TenantServiceImpl.java | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java index 172dec8..76ff976 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java @@ -67,6 +67,7 @@ public enum SystemMsg implements BaseMsg { * 租户 */ EXCEPTION_TENANT_UNIQUE(20400,"租户名称重复,该租户已存在"), + EXCEPTION_TENANT_USED_DEL(20401,"该租户正在被其他用户绑定,无法删除"), /** * 组织机构 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 201e49d..e158da2 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 @@ -24,6 +24,7 @@ import org.opsli.api.wrapper.system.tenant.TenantModel; import org.opsli.common.constants.MyBatisConstants; import org.opsli.common.enums.DictType; import org.opsli.common.exception.ServiceException; +import org.opsli.common.utils.HumpUtil; import org.opsli.core.base.service.impl.CrudServiceImpl; import org.opsli.core.msg.CoreMsg; import org.opsli.core.utils.TenantUtil; @@ -31,6 +32,8 @@ import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.tenant.entity.SysTenant; import org.opsli.modulars.system.tenant.mapper.TenantMapper; import org.opsli.modulars.system.tenant.service.ITenantService; +import org.opsli.modulars.system.user.entity.SysUser; +import org.opsli.modulars.system.user.service.IUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -53,6 +56,9 @@ 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); + } + boolean ret = super.delete(id); if(ret){ @@ -129,6 +146,17 @@ 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); + } + boolean ret = super.delete(model); if(ret){ @@ -149,6 +177,17 @@ 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); + } + boolean ret = super.deleteAll(ids); if(ret){ // 清除缓存 @@ -171,6 +210,17 @@ 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); + } + boolean ret = super.deleteAll(models); if(ret){ // 清除缓存