租户正在被其他用户绑定,禁止删除

v1.4.1
Parker 4 years ago
parent b5177157be
commit cc81014a0d

@ -67,6 +67,7 @@ public enum SystemMsg implements BaseMsg {
* *
*/ */
EXCEPTION_TENANT_UNIQUE(20400,"租户名称重复,该租户已存在"), EXCEPTION_TENANT_UNIQUE(20400,"租户名称重复,该租户已存在"),
EXCEPTION_TENANT_USED_DEL(20401,"该租户正在被其他用户绑定,无法删除"),
/** /**
* *

@ -24,6 +24,7 @@ import org.opsli.api.wrapper.system.tenant.TenantModel;
import org.opsli.common.constants.MyBatisConstants; import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.enums.DictType; import org.opsli.common.enums.DictType;
import org.opsli.common.exception.ServiceException; import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.HumpUtil;
import org.opsli.core.base.service.impl.CrudServiceImpl; import org.opsli.core.base.service.impl.CrudServiceImpl;
import org.opsli.core.msg.CoreMsg; import org.opsli.core.msg.CoreMsg;
import org.opsli.core.utils.TenantUtil; 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.entity.SysTenant;
import org.opsli.modulars.system.tenant.mapper.TenantMapper; import org.opsli.modulars.system.tenant.mapper.TenantMapper;
import org.opsli.modulars.system.tenant.service.ITenantService; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -53,6 +56,9 @@ public class TenantServiceImpl extends CrudServiceImpl<TenantMapper, SysTenant,
@Autowired(required = false) @Autowired(required = false)
private TenantMapper mapper; private TenantMapper mapper;
@Autowired
private IUserService iUserService;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public TenantModel insert(TenantModel model) { public TenantModel insert(TenantModel model) {
@ -106,6 +112,17 @@ public class TenantServiceImpl extends CrudServiceImpl<TenantMapper, SysTenant,
return false; return false;
} }
// 如果有租户还在被引用 则不允许删除该租户
QueryWrapper<SysUser> 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); boolean ret = super.delete(id);
if(ret){ if(ret){
@ -129,6 +146,17 @@ public class TenantServiceImpl extends CrudServiceImpl<TenantMapper, SysTenant,
return false; return false;
} }
// 如果有租户还在被引用 则不允许删除该租户
QueryWrapper<SysUser> 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); boolean ret = super.delete(model);
if(ret){ if(ret){
@ -149,6 +177,17 @@ public class TenantServiceImpl extends CrudServiceImpl<TenantMapper, SysTenant,
public boolean deleteAll(String[] ids) { public boolean deleteAll(String[] ids) {
List<String> idList = Convert.toList(String.class, ids); List<String> idList = Convert.toList(String.class, ids);
// 如果有租户还在被引用 则不允许删除该租户
QueryWrapper<SysUser> 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); boolean ret = super.deleteAll(ids);
if(ret){ if(ret){
// 清除缓存 // 清除缓存
@ -171,6 +210,17 @@ public class TenantServiceImpl extends CrudServiceImpl<TenantMapper, SysTenant,
idList.add(model.getId()); idList.add(model.getId());
} }
// 如果有租户还在被引用 则不允许删除该租户
QueryWrapper<SysUser> 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); boolean ret = super.deleteAll(models);
if(ret){ if(ret){
// 清除缓存 // 清除缓存

Loading…
Cancel
Save