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 172dec8e..76ff976e 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 201e49d3..e158da2d 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){ // 清除缓存