init
This commit is contained in:
@@ -42,6 +42,11 @@ public class SysTenant extends BaseEntity {
|
||||
*/
|
||||
private String contactPhone;
|
||||
|
||||
/**
|
||||
* 前缀
|
||||
*/
|
||||
private String prefix;
|
||||
|
||||
/**
|
||||
* 企业名称
|
||||
*/
|
||||
|
||||
@@ -159,6 +159,11 @@ public class SysUser extends TenantEntity {
|
||||
@TableField(exist = false)
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 前缀
|
||||
*/
|
||||
private String prefix;
|
||||
|
||||
public SysUser(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
@@ -52,9 +52,10 @@ public class SysTenantBo extends BaseEntity {
|
||||
/**
|
||||
* 用户名(创建系统用户)
|
||||
*/
|
||||
@NotBlank(message = "用户名不能为空", groups = { AddGroup.class })
|
||||
private String username;
|
||||
|
||||
// @NotBlank(message = "用户名不能为空", groups = { AddGroup.class })
|
||||
// private String username;
|
||||
@NotBlank(message = "用户名前缀不能为空", groups = {AddGroup.class})
|
||||
private String prefix;
|
||||
/**
|
||||
* 密码(创建系统用户)
|
||||
*/
|
||||
|
||||
@@ -99,6 +99,8 @@ public class SysTenantVo implements Serializable {
|
||||
@ExcelProperty(value = "用户数量")
|
||||
private Long accountCount;
|
||||
|
||||
private String prefix;
|
||||
|
||||
/**
|
||||
* 租户状态(0正常 1停用)
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.ruoyi.system.event;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AddTenantEvent {
|
||||
private String tenantId;
|
||||
}
|
||||
@@ -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