|
@@ -9,10 +9,8 @@ import cn.tr.core.enums.CreateEnum;
|
|
|
import cn.tr.core.exception.ServiceException;
|
|
import cn.tr.core.exception.ServiceException;
|
|
|
import cn.tr.core.exception.TRExcCode;
|
|
import cn.tr.core.exception.TRExcCode;
|
|
|
import cn.tr.core.tenant.TenantContextHolder;
|
|
import cn.tr.core.tenant.TenantContextHolder;
|
|
|
-import cn.tr.core.tenant.TenantUtils;
|
|
|
|
|
import cn.tr.module.sys.config.SysConfigManager;
|
|
import cn.tr.module.sys.config.SysConfigManager;
|
|
|
import cn.tr.module.sys.tenant.dto.SysTenantAddDTO;
|
|
import cn.tr.module.sys.tenant.dto.SysTenantAddDTO;
|
|
|
-import cn.tr.module.sys.tenant.dto.SysTenantCommonDTO;
|
|
|
|
|
import cn.tr.module.sys.tenant.dto.SysTenantQueryDTO;
|
|
import cn.tr.module.sys.tenant.dto.SysTenantQueryDTO;
|
|
|
import cn.tr.module.sys.tenant.mapper.SysTenantMapper;
|
|
import cn.tr.module.sys.tenant.mapper.SysTenantMapper;
|
|
|
import cn.tr.module.sys.tenant.po.SysInviteCodePO;
|
|
import cn.tr.module.sys.tenant.po.SysInviteCodePO;
|
|
@@ -24,9 +22,12 @@ import cn.tr.module.sys.tenant.service.ISysTenantService;
|
|
|
import cn.tr.module.sys.tenant.vo.SysTenantCommonVO;
|
|
import cn.tr.module.sys.tenant.vo.SysTenantCommonVO;
|
|
|
import cn.tr.module.sys.user.dto.*;
|
|
import cn.tr.module.sys.user.dto.*;
|
|
|
import cn.tr.module.sys.user.enums.UserStatusEnum;
|
|
import cn.tr.module.sys.user.enums.UserStatusEnum;
|
|
|
|
|
+import cn.tr.module.sys.user.po.SysUserPO;
|
|
|
|
|
+import cn.tr.module.sys.user.po.SysUserTenantPO;
|
|
|
|
|
+import cn.tr.module.sys.user.repository.SysUserRepository;
|
|
|
|
|
+import cn.tr.module.sys.user.repository.SysUserTenantRepository;
|
|
|
import cn.tr.module.sys.user.service.*;
|
|
import cn.tr.module.sys.user.service.*;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
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.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
@@ -80,6 +81,11 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private SysInviteCodeRepository inviteCodeRepository;
|
|
private SysInviteCodeRepository inviteCodeRepository;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysUserRepository userRepository;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysUserTenantRepository userTenantRepository;
|
|
|
@Override
|
|
@Override
|
|
|
@TenantIgnore
|
|
@TenantIgnore
|
|
|
public List<SysTenantCommonVO> selectSysTenantList(SysTenantQueryDTO query) {
|
|
public List<SysTenantCommonVO> selectSysTenantList(SysTenantQueryDTO query) {
|
|
@@ -98,7 +104,10 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
public boolean updateSysTenantById(SysTenantAddDTO source) {
|
|
public boolean updateSysTenantById(SysTenantAddDTO source) {
|
|
|
validate();
|
|
validate();
|
|
|
validateSource(source);
|
|
validateSource(source);
|
|
|
- return tenantRepository.updateById(SysTenantMapper.INSTANCE.toPO(source)) != 0;
|
|
|
|
|
|
|
+ if (tenantRepository.updateById(SysTenantMapper.INSTANCE.toPO(source)) != 0) {
|
|
|
|
|
+ return Boolean.TRUE;
|
|
|
|
|
+ }
|
|
|
|
|
+ return Boolean.FALSE;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -111,7 +120,12 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
tenant.setInviteCode(inviteCode.getCode());
|
|
tenant.setInviteCode(inviteCode.getCode());
|
|
|
inviteCode.setStatus(1);
|
|
inviteCode.setStatus(1);
|
|
|
inviteCodeRepository.updateById(inviteCode);
|
|
inviteCodeRepository.updateById(inviteCode);
|
|
|
- return tenantRepository.insert(tenant) != 0;
|
|
|
|
|
|
|
+ if (tenantRepository.insert(tenant) != 0) {
|
|
|
|
|
+ //绑定admin用户
|
|
|
|
|
+ bindAdminUser(tenant.getContactMobile(),tenant.getId());
|
|
|
|
|
+ return Boolean.TRUE;
|
|
|
|
|
+ }
|
|
|
|
|
+ return Boolean.FALSE;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private List<SysUserPortalDTO> buildUserPortal(String userId, String portalId) {
|
|
private List<SysUserPortalDTO> buildUserPortal(String userId, String portalId) {
|
|
@@ -167,51 +181,22 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private SysPortalDTO buildPortal(String portalId) {
|
|
|
|
|
- SysPortalDTO org = new SysPortalDTO();
|
|
|
|
|
- org.setId(portalId);
|
|
|
|
|
- org.setCode("admin");
|
|
|
|
|
- org.setName("系统管理员工作台");
|
|
|
|
|
- org.setType(CreateEnum.sys.name());
|
|
|
|
|
- return org;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private SysOrgDTO buildOrg(String orgId, String tenantName) {
|
|
|
|
|
- SysOrgDTO org = new SysOrgDTO();
|
|
|
|
|
- org.setId(orgId);
|
|
|
|
|
- org.setParentId("0");
|
|
|
|
|
- org.setSort(1);
|
|
|
|
|
- org.setName(tenantName);
|
|
|
|
|
- org.setDisable(false);
|
|
|
|
|
- return org;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private SysRoleDTO buildRole(String roleId) {
|
|
|
|
|
- SysRoleDTO role = new SysRoleDTO();
|
|
|
|
|
- role.setId(roleId);
|
|
|
|
|
- role.setDataScope("1");
|
|
|
|
|
- role.setCode("admin");
|
|
|
|
|
- role.setName("超级管理员");
|
|
|
|
|
- role.setRemark("系统角色");
|
|
|
|
|
- role.setDisable(false);
|
|
|
|
|
- role.setSort(1);
|
|
|
|
|
- role.setType(CreateEnum.sys.name());
|
|
|
|
|
- return role;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private SysUserDTO buildUser(String userId, String portalId, String roleId, String orgId, String username, String password, String tenantName) {
|
|
|
|
|
- SysUserDTO user = new SysUserDTO();
|
|
|
|
|
- user.setId(userId);
|
|
|
|
|
- user.setOrgId(orgId);
|
|
|
|
|
- user.setPortalIds(Collections.singleton(portalId));
|
|
|
|
|
- user.setUsername(username);
|
|
|
|
|
- user.setPassword(password);
|
|
|
|
|
- user.setNickname(tenantName);
|
|
|
|
|
- user.setRoleIds(Collections.singleton(roleId));
|
|
|
|
|
- user.setStatus(UserStatusEnum.normal.getValue());
|
|
|
|
|
- return user;
|
|
|
|
|
|
|
+ private void bindAdminUser(String phone,String tenantId){
|
|
|
|
|
+ if(StrUtil.isEmpty(phone)){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ SysUserPO sysUserPO = userRepository.selectOne(new LambdaQueryWrapper<SysUserPO>()
|
|
|
|
|
+ .eq(SysUserPO::getUsername, phone)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if(ObjectUtil.isNull(sysUserPO)){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ SysUserTenantPO userTenant = new SysUserTenantPO();
|
|
|
|
|
+ userTenant.setTenantId(tenantId);
|
|
|
|
|
+ userTenant.setUserId(sysUserPO.getId());
|
|
|
|
|
+ userTenant.setStatus(UserStatusEnum.normal.getValue());
|
|
|
|
|
+ userTenantRepository.insert(userTenant);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
private void validate() {
|
|
private void validate() {
|
|
|
if (!Boolean.TRUE.equals(tenantEnable)) {
|
|
if (!Boolean.TRUE.equals(tenantEnable)) {
|
|
|
throw new UnsupportedOperationException("多租户功能已关闭");
|
|
throw new UnsupportedOperationException("多租户功能已关闭");
|