|
|
@@ -3,6 +3,7 @@ package org.dromara.system.service.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.crypto.digest.BCrypt;
|
|
|
@@ -22,6 +23,7 @@ import org.dromara.common.core.utils.StreamUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.platform.Platform;
|
|
|
import org.dromara.common.redis.utils.CacheUtils;
|
|
|
import org.dromara.common.tenant.core.TenantEntity;
|
|
|
import org.dromara.common.tenant.helper.TenantHelper;
|
|
|
@@ -58,6 +60,7 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
private final SysDictTypeMapper dictTypeMapper;
|
|
|
private final SysDictDataMapper dictDataMapper;
|
|
|
private final SysConfigMapper configMapper;
|
|
|
+ private final SysMenuMapper menuMapper;
|
|
|
|
|
|
@DubboReference(mock = "true")
|
|
|
private RemoteWorkflowService remoteWorkflowService;
|
|
|
@@ -124,14 +127,18 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
public Boolean insertByBo(SysTenantBo bo) {
|
|
|
SysTenant add = MapstructUtils.convert(bo, SysTenant.class);
|
|
|
|
|
|
+ // 直接先将用户ID创建好, 这样就可以避免插入完反过来又要更新管理员ID
|
|
|
+ long userId = IdUtil.getSnowflakeNextId();
|
|
|
+
|
|
|
// 获取所有租户编号
|
|
|
List<String> tenantIds = baseMapper.selectObjs(
|
|
|
new LambdaQueryWrapper<SysTenant>().select(SysTenant::getTenantId), x -> {return Convert.toStr(x);});
|
|
|
String tenantId = generateTenantId(tenantIds);
|
|
|
add.setTenantId(tenantId);
|
|
|
+ add.setAdmin(userId);
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (!flag) {
|
|
|
- throw new ServiceException("创建租户失败");
|
|
|
+ throw new ServiceException("创建品牌失败");
|
|
|
}
|
|
|
bo.setId(add.getId());
|
|
|
|
|
|
@@ -153,13 +160,16 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
roleDept.setDeptId(deptId);
|
|
|
roleDeptMapper.insert(roleDept);
|
|
|
|
|
|
- // 创建系统用户
|
|
|
+ // 创建系统用户(品牌商户的管理员)
|
|
|
SysUser user = new SysUser();
|
|
|
+ user.setUserId(userId);
|
|
|
user.setTenantId(tenantId);
|
|
|
user.setUserName(bo.getUsername());
|
|
|
user.setNickName(bo.getUsername());
|
|
|
+ user.setPhonenumber(bo.getContactPhone());
|
|
|
user.setPassword(BCrypt.hashpw(bo.getPassword()));
|
|
|
user.setDeptId(deptId);
|
|
|
+ user.setPlatformId(Platform.MERCHANT.getId());
|
|
|
userMapper.insert(user);
|
|
|
//新增系统用户后,默认当前用户为部门的负责人
|
|
|
SysDept sd = new SysDept();
|
|
|
@@ -173,47 +183,48 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
userRole.setRoleId(roleId);
|
|
|
userRoleMapper.insert(userRole);
|
|
|
|
|
|
- String defaultTenantId = TenantConstants.DEFAULT_TENANT_ID;
|
|
|
- List<SysDictType> dictTypeList = dictTypeMapper.selectList(
|
|
|
- new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getTenantId, defaultTenantId));
|
|
|
- List<SysDictData> dictDataList = dictDataMapper.selectList(
|
|
|
- new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getTenantId, defaultTenantId));
|
|
|
- for (SysDictType dictType : dictTypeList) {
|
|
|
- dictType.setDictId(null);
|
|
|
- dictType.setTenantId(tenantId);
|
|
|
- dictType.setCreateDept(null);
|
|
|
- dictType.setCreateBy(null);
|
|
|
- dictType.setCreateTime(null);
|
|
|
- dictType.setUpdateBy(null);
|
|
|
- dictType.setUpdateTime(null);
|
|
|
- }
|
|
|
- for (SysDictData dictData : dictDataList) {
|
|
|
- dictData.setDictCode(null);
|
|
|
- dictData.setTenantId(tenantId);
|
|
|
- dictData.setCreateDept(null);
|
|
|
- dictData.setCreateBy(null);
|
|
|
- dictData.setCreateTime(null);
|
|
|
- dictData.setUpdateBy(null);
|
|
|
- dictData.setUpdateTime(null);
|
|
|
- }
|
|
|
- dictTypeMapper.insertBatch(dictTypeList);
|
|
|
- dictDataMapper.insertBatch(dictDataList);
|
|
|
-
|
|
|
- List<SysConfig> sysConfigList = configMapper.selectList(
|
|
|
- new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getTenantId, defaultTenantId));
|
|
|
- for (SysConfig config : sysConfigList) {
|
|
|
- config.setConfigId(null);
|
|
|
- config.setTenantId(tenantId);
|
|
|
- config.setCreateDept(null);
|
|
|
- config.setCreateBy(null);
|
|
|
- config.setCreateTime(null);
|
|
|
- config.setUpdateBy(null);
|
|
|
- config.setUpdateTime(null);
|
|
|
- }
|
|
|
- configMapper.insertBatch(sysConfigList);
|
|
|
-
|
|
|
- // 新增租户流程定义
|
|
|
- remoteWorkflowService.syncDef(tenantId);
|
|
|
+ // FIXME 系统内字典和配置不进行租户隔离
|
|
|
+// String defaultTenantId = TenantConstants.DEFAULT_TENANT_ID;
|
|
|
+// List<SysDictType> dictTypeList = dictTypeMapper.selectList(
|
|
|
+// new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getTenantId, defaultTenantId));
|
|
|
+// List<SysDictData> dictDataList = dictDataMapper.selectList(
|
|
|
+// new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getTenantId, defaultTenantId));
|
|
|
+// for (SysDictType dictType : dictTypeList) {
|
|
|
+// dictType.setDictId(null);
|
|
|
+// dictType.setTenantId(tenantId);
|
|
|
+// dictType.setCreateDept(null);
|
|
|
+// dictType.setCreateBy(null);
|
|
|
+// dictType.setCreateTime(null);
|
|
|
+// dictType.setUpdateBy(null);
|
|
|
+// dictType.setUpdateTime(null);
|
|
|
+// }
|
|
|
+// for (SysDictData dictData : dictDataList) {
|
|
|
+// dictData.setDictCode(null);
|
|
|
+// dictData.setTenantId(tenantId);
|
|
|
+// dictData.setCreateDept(null);
|
|
|
+// dictData.setCreateBy(null);
|
|
|
+// dictData.setCreateTime(null);
|
|
|
+// dictData.setUpdateBy(null);
|
|
|
+// dictData.setUpdateTime(null);
|
|
|
+// }
|
|
|
+// dictTypeMapper.insertBatch(dictTypeList);
|
|
|
+// dictDataMapper.insertBatch(dictDataList);
|
|
|
+//
|
|
|
+// List<SysConfig> sysConfigList = configMapper.selectList(
|
|
|
+// new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getTenantId, defaultTenantId));
|
|
|
+// for (SysConfig config : sysConfigList) {
|
|
|
+// config.setConfigId(null);
|
|
|
+// config.setTenantId(tenantId);
|
|
|
+// config.setCreateDept(null);
|
|
|
+// config.setCreateBy(null);
|
|
|
+// config.setCreateTime(null);
|
|
|
+// config.setUpdateBy(null);
|
|
|
+// config.setUpdateTime(null);
|
|
|
+// }
|
|
|
+// configMapper.insertBatch(sysConfigList);
|
|
|
+//
|
|
|
+// // 新增租户流程定义
|
|
|
+// remoteWorkflowService.syncDef(tenantId);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -242,12 +253,15 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
*/
|
|
|
private Long createTenantRole(String tenantId, Long packageId) {
|
|
|
// 获取租户套餐
|
|
|
- SysTenantPackage tenantPackage = tenantPackageMapper.selectById(packageId);
|
|
|
- if (ObjectUtil.isNull(tenantPackage)) {
|
|
|
- throw new ServiceException("套餐不存在");
|
|
|
- }
|
|
|
+// SysTenantPackage tenantPackage = tenantPackageMapper.selectById(packageId);
|
|
|
+// if (ObjectUtil.isNull(tenantPackage)) {
|
|
|
+// throw new ServiceException("套餐不存在");
|
|
|
+// }
|
|
|
// 获取套餐菜单id
|
|
|
- List<Long> menuIds = StringUtils.splitTo(tenantPackage.getMenuIds(), Convert::toLong);
|
|
|
+// List<Long> menuIds = StringUtils.splitTo(tenantPackage.getMenuIds(), Convert::toLong);
|
|
|
+ List<Long> menuIds = menuMapper.selectList(
|
|
|
+ Wrappers.lambdaQuery(SysMenu.class).eq(SysMenu::getPlatformId, Platform.MERCHANT.getId())
|
|
|
+ ).stream().map(SysMenu::getMenuId).toList();
|
|
|
|
|
|
// 创建角色
|
|
|
SysRole role = new SysRole();
|
|
|
@@ -256,6 +270,7 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
role.setRoleKey(TenantConstants.TENANT_ADMIN_ROLE_KEY);
|
|
|
role.setRoleSort(1);
|
|
|
role.setStatus(SystemConstants.NORMAL);
|
|
|
+ role.setPlatformId(Platform.MERCHANT.getId());
|
|
|
roleMapper.insert(role);
|
|
|
Long roleId = role.getRoleId();
|
|
|
|
|
|
@@ -307,7 +322,7 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
@Override
|
|
|
public void checkTenantAllowed(String tenantId) {
|
|
|
if (ObjectUtil.isNotNull(tenantId) && TenantConstants.DEFAULT_TENANT_ID.equals(tenantId)) {
|
|
|
- throw new ServiceException("不允许操作管理租户");
|
|
|
+ throw new ServiceException("不允许操作管理商户");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -320,7 +335,7 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|
|
if (isValid) {
|
|
|
// 做一些业务上的校验,判断是否需要校验
|
|
|
if (ids.contains(TenantConstants.SUPER_ADMIN_ID)) {
|
|
|
- throw new ServiceException("超管租户不能删除");
|
|
|
+ throw new ServiceException("超管商户不能删除");
|
|
|
}
|
|
|
}
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|