|
|
@@ -2,6 +2,7 @@ package cn.tr.module.sys.tenant.service.impl;
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.tr.core.annotation.TenantIgnore;
|
|
|
import cn.tr.core.exception.ServiceException;
|
|
|
@@ -21,6 +22,7 @@ import cn.tr.module.sys.user.service.*;
|
|
|
import cn.tr.module.sys.tenant.service.ISysTenantService;
|
|
|
import cn.tr.plugin.biz.tenant.context.TenantContextHolder;
|
|
|
import cn.tr.plugin.biz.tenant.utils.TenantUtils;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
@@ -82,12 +84,14 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
|
|
|
@Override
|
|
|
public boolean updateSysTenantById(SysTenantCommonDTO source) {
|
|
|
+ validateSource(source);
|
|
|
return tenantRepository.updateById(SysTenantMapper.INSTANCE.toPO(source))!=0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean insertSysTenant(SysTenantAddDTO source) {
|
|
|
+ validateSource(source);
|
|
|
String orgId= IdWorker.getIdStr();
|
|
|
String userId= IdWorker.getIdStr();
|
|
|
String roleId= IdWorker.getIdStr();
|
|
|
@@ -149,6 +153,22 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
return tenantPackageMenuService.findMenuIdByPackageId(tenant.getPackageId());
|
|
|
}
|
|
|
|
|
|
+ private void validateSource(SysTenantAddDTO source){
|
|
|
+ SysTenantPO sysTenantPO = tenantRepository.selectOne(new LambdaQueryWrapper<SysTenantPO>()
|
|
|
+ .eq(SysTenantPO::getName, source.getName()));
|
|
|
+ if(ObjectUtil.isNotNull(sysTenantPO)){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"租户名称不能重复");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validateSource(SysTenantCommonDTO source){
|
|
|
+ SysTenantPO sysTenantPO = tenantRepository.selectOne(new LambdaQueryWrapper<SysTenantPO>()
|
|
|
+ .ne(StrUtil.isNotEmpty(source.getId()),SysTenantPO::getId,source.getId())
|
|
|
+ .eq(SysTenantPO::getName, source.getName()));
|
|
|
+ if(ObjectUtil.isNotNull(sysTenantPO)){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"租户名称不能重复");
|
|
|
+ }
|
|
|
+ }
|
|
|
private SysPortalDTO buildPortal(String portalId){
|
|
|
SysPortalDTO org = new SysPortalDTO();
|
|
|
org.setId(portalId);
|