init
This commit is contained in:
@@ -19,6 +19,7 @@ import com.ruoyi.component.mybatis.core.page.TableDataInfo;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.domain.bo.SysTenantBo;
|
||||
import com.ruoyi.system.domain.vo.SysTenantVo;
|
||||
import com.ruoyi.system.event.AddTenantEvent;
|
||||
import com.ruoyi.system.mapper.*;
|
||||
import com.ruoyi.system.service.ISysTenantService;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -129,6 +130,10 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
||||
new LambdaQueryWrapper<SysTenant>().select(SysTenant::getTenantId));
|
||||
String tenantId = generateTenantId(tenantIds);
|
||||
add.setTenantId(tenantId);
|
||||
boolean exists = baseMapper.exists(Wrappers.lambdaQuery(SysTenant.class).eq(SysTenant::getPrefix, bo.getPrefix()));
|
||||
if(exists){
|
||||
throw new ServiceException("用户名前缀已经存在!");
|
||||
}
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (!flag) {
|
||||
throw new ServiceException("创建租户失败");
|
||||
@@ -152,12 +157,18 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
||||
roleDept.setRoleId(roleId);
|
||||
roleDept.setDeptId(deptId);
|
||||
roleDeptMapper.insert(roleDept);
|
||||
|
||||
String adminUsername = bo.getPrefix()+"_admin";
|
||||
// 检测用户是否存在
|
||||
SysUser sysUser = userMapper.selectUserByUserName(adminUsername);
|
||||
if(sysUser != null){
|
||||
throw new ServiceException("平台超管已经存在!");
|
||||
}
|
||||
// 创建系统用户
|
||||
SysUser user = new SysUser();
|
||||
user.setTenantId(tenantId);
|
||||
user.setUserName(bo.getUsername());
|
||||
user.setNickName(bo.getUsername());
|
||||
user.setPrefix(bo.getPrefix());
|
||||
user.setUserName(bo.getPrefix()+"_admin");
|
||||
user.setNickName("平台管理员");
|
||||
user.setPassword(BCrypt.hashpw(bo.getPassword()));
|
||||
user.setDeptId(deptId);
|
||||
userMapper.insert(user);
|
||||
@@ -196,6 +207,10 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
||||
config.setTenantId(tenantId);
|
||||
}
|
||||
// configMapper.insertBatch(sysConfigList);
|
||||
// 执行系统自定义的接口生成
|
||||
AddTenantEvent event = new AddTenantEvent();
|
||||
event.setTenantId(tenantId);
|
||||
SpringUtils.context().publishEvent(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user