|
@@ -1,20 +1,29 @@
|
|
package com.usky.system.service.impl;
|
|
package com.usky.system.service.impl;
|
|
|
|
|
|
import com.usky.common.core.bean.CommonPage;
|
|
import com.usky.common.core.bean.CommonPage;
|
|
|
|
+import com.usky.common.core.exception.BusinessException;
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
import com.usky.system.domain.SysDept;
|
|
import com.usky.system.domain.SysDept;
|
|
import com.usky.system.domain.SysTenant;
|
|
import com.usky.system.domain.SysTenant;
|
|
|
|
+import com.usky.system.domain.SysUser;
|
|
|
|
+import com.usky.system.domain.SysUserTenant;
|
|
import com.usky.system.mapper.SysTenantMapper;
|
|
import com.usky.system.mapper.SysTenantMapper;
|
|
|
|
+import com.usky.system.mapper.SysUserTenantMapper;
|
|
import com.usky.system.service.ISysDeptService;
|
|
import com.usky.system.service.ISysDeptService;
|
|
|
|
+import com.usky.system.service.SysTenantPlatformService;
|
|
import com.usky.system.service.SysTenantService;
|
|
import com.usky.system.service.SysTenantService;
|
|
import com.usky.system.service.vo.SysTenantOneVo;
|
|
import com.usky.system.service.vo.SysTenantOneVo;
|
|
import com.usky.system.service.vo.SysTenantTwoVo;
|
|
import com.usky.system.service.vo.SysTenantTwoVo;
|
|
import com.usky.system.service.vo.SysTenantVo;
|
|
import com.usky.system.service.vo.SysTenantVo;
|
|
|
|
+import com.usky.system.service.vo.TenantPlatformVo;
|
|
|
|
+import io.swagger.models.auth.In;
|
|
|
|
+import org.apache.ibatis.annotations.Select;
|
|
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 java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
|
|
|
@@ -31,6 +40,12 @@ public class SysTenantServiceImpl extends AbstractCrudService<SysTenantMapper, S
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private ISysDeptService iSysDeptService;
|
|
private ISysDeptService iSysDeptService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysUserTenantMapper sysUserTenantMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysTenantMapper sysTenantMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysTenantPlatformService sysTenantPlatformService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public List<SysTenantVo> getUserData() {
|
|
public List<SysTenantVo> getUserData() {
|
|
@@ -110,6 +125,54 @@ public class SysTenantServiceImpl extends AbstractCrudService<SysTenantMapper, S
|
|
iSysDeptService.insertDept(sysDept);
|
|
iSysDeptService.insertDept(sysDept);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void cloneTenantData(SysTenant sysTenant) {
|
|
|
|
+ Integer originalTenantId = sysTenant.getOriginalTenantId();
|
|
|
|
+
|
|
|
|
+ String uuid = UUID.randomUUID().toString();
|
|
|
|
+ uuid = uuid.replace("-", "");
|
|
|
|
+ sysTenant.setTenantCode(uuid);
|
|
|
|
+ sysTenant.setCreateBy(SecurityUtils.getUsername());
|
|
|
|
+ sysTenant.setCreateTime(LocalDateTime.now());
|
|
|
|
+ this.save(sysTenant);
|
|
|
|
+ Integer tenantId = sysTenant.getId();
|
|
|
|
+
|
|
|
|
+ SysDept sysDept = new SysDept();
|
|
|
|
+ sysDept.setTenantId(tenantId);
|
|
|
|
+ sysDept.setDeptName(sysTenant.getTenantName());
|
|
|
|
+ sysDept.setOrderNum("0");
|
|
|
|
+ sysDept.setEmail(sysTenant.getEmail());
|
|
|
|
+ sysDept.setPhone(sysTenant.getPhoneNumber());
|
|
|
|
+ sysDept.setCreateBy(SecurityUtils.getUsername());
|
|
|
|
+ iSysDeptService.insertDept(sysDept);
|
|
|
|
+
|
|
|
|
+ //在用户租户表中添加克隆账号id与租户id绑定关系
|
|
|
|
+ SysUserTenant sysUserTenant = new SysUserTenant();
|
|
|
|
+ sysUserTenant.setUserId(SecurityUtils.getUserId());
|
|
|
|
+ sysUserTenant.setTenantId(tenantId);
|
|
|
|
+ int userCount = sysUserTenantMapper.checkUserIdUnique(sysUserTenant.getTenantId(), sysUserTenant.getUserId());
|
|
|
|
+ if (userCount > 0){
|
|
|
|
+ throw new BusinessException("用户已绑定,无法重复绑定!");
|
|
|
|
+ }else {
|
|
|
|
+ sysUserTenantMapper.insert(sysUserTenant);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //克隆系统配置
|
|
|
|
+ sysTenantMapper.cloneSysTenantConfig(originalTenantId,tenantId,SecurityUtils.getUsername());
|
|
|
|
+ sysTenantMapper.cloneSysTenantMenu(originalTenantId,tenantId);
|
|
|
|
+ sysTenantMapper.cloneSysMobileTenantConfig(originalTenantId,tenantId,SecurityUtils.getUsername());
|
|
|
|
+ sysTenantMapper.cloneSysMobileBanner(originalTenantId,tenantId,SecurityUtils.getUsername());
|
|
|
|
+ //克隆应用授权和权限配置
|
|
|
|
+ sysTenantMapper.cloneSysTenantPlatform(originalTenantId,tenantId);
|
|
|
|
+ sysTenantMapper.cloneSysMobileTenantMenu(originalTenantId,tenantId);
|
|
|
|
+
|
|
|
|
+ //更新默认应用
|
|
|
|
+ TenantPlatformVo tenantPlatformVo = new TenantPlatformVo();
|
|
|
|
+ tenantPlatformVo.setPlatformIds(new Integer[]{Integer.parseInt(sysTenant.getSystemName())});
|
|
|
|
+ tenantPlatformVo.setRequestId(0);
|
|
|
|
+ tenantPlatformVo.setTenantId(tenantId);
|
|
|
|
+ sysTenantPlatformService.updateTenantPlatform(tenantPlatformVo);
|
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void updateTenantData(SysTenant sysTenant) {
|
|
public void updateTenantData(SysTenant sysTenant) {
|