mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-27 13:46:39 +08:00
add 增加 同步租户参数配置功能
This commit is contained in:
parent
dbcd8f58eb
commit
6036f8750b
@ -193,4 +193,19 @@ public class SysTenantController extends BaseController {
|
|||||||
return R.ok("同步租户字典成功");
|
return R.ok("同步租户字典成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步租户参数配置
|
||||||
|
*/
|
||||||
|
@SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY)
|
||||||
|
@Log(title = "租户管理", businessType = BusinessType.INSERT)
|
||||||
|
@Lock4j
|
||||||
|
@GetMapping("/syncTenantConfig")
|
||||||
|
public R<Void> syncTenantConfig() {
|
||||||
|
if (!TenantHelper.isEnable()) {
|
||||||
|
return R.fail("当前未开启租户模式");
|
||||||
|
}
|
||||||
|
tenantService.syncTenantConfig();
|
||||||
|
return R.ok("同步租户参数配置成功");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package org.dromara.system.service;
|
package org.dromara.system.service;
|
||||||
|
|
||||||
import org.dromara.system.domain.vo.SysTenantVo;
|
|
||||||
import org.dromara.system.domain.bo.SysTenantBo;
|
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
|
import org.dromara.system.domain.bo.SysTenantBo;
|
||||||
|
import org.dromara.system.domain.vo.SysTenantVo;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -84,4 +84,9 @@ public interface ISysTenantService {
|
|||||||
* 同步租户字典
|
* 同步租户字典
|
||||||
*/
|
*/
|
||||||
void syncTenantDict();
|
void syncTenantDict();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步租户参数配置
|
||||||
|
*/
|
||||||
|
void syncTenantConfig();
|
||||||
}
|
}
|
||||||
|
@ -508,4 +508,60 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步租户参数配置
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@Override
|
||||||
|
public void syncTenantConfig() {
|
||||||
|
// 查询超管 所有参数配置
|
||||||
|
List<SysConfig> configList = TenantHelper.ignore(() -> configMapper.selectList());
|
||||||
|
|
||||||
|
// 所有租户参数配置
|
||||||
|
Map<String, List<SysConfig>> configMap = StreamUtils.groupByKey(configList, TenantEntity::getTenantId);
|
||||||
|
|
||||||
|
// 默认租户字典类型列表
|
||||||
|
List<SysConfig> defaultConfigList = configMap.get(TenantConstants.DEFAULT_TENANT_ID);
|
||||||
|
|
||||||
|
// 获取所有租户编号
|
||||||
|
List<String> tenantIds = baseMapper.selectObjs(
|
||||||
|
new LambdaQueryWrapper<SysTenant>().select(SysTenant::getTenantId)
|
||||||
|
.eq(SysTenant::getStatus, SystemConstants.NORMAL), x -> {
|
||||||
|
return Convert.toStr(x);
|
||||||
|
});
|
||||||
|
// 待入库的字典类型和字典数据
|
||||||
|
List<SysConfig> saveConfigList = new ArrayList<>();
|
||||||
|
// 待同步的租户编号(用于清除对于租户的字典缓存)
|
||||||
|
Set<String> syncTenantIds = new HashSet<>();
|
||||||
|
// 循环所有租户,处理需要同步的数据
|
||||||
|
for (String tenantId : tenantIds) {
|
||||||
|
// 排除默认租户
|
||||||
|
if (TenantConstants.DEFAULT_TENANT_ID.equals(tenantId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 根据默认租户的字典类型进行数据同步
|
||||||
|
for (SysConfig config : defaultConfigList) {
|
||||||
|
// 获取当前租户的字典类型列表
|
||||||
|
List<String> typeList = StreamUtils.toList(configMap.get(tenantId), SysConfig::getConfigKey);
|
||||||
|
if (!typeList.contains(config.getConfigKey())) {
|
||||||
|
SysConfig type = BeanUtil.toBean(config, SysConfig.class);
|
||||||
|
type.setConfigId(null);
|
||||||
|
type.setTenantId(tenantId);
|
||||||
|
type.setCreateTime(null);
|
||||||
|
type.setUpdateTime(null);
|
||||||
|
syncTenantIds.add(tenantId);
|
||||||
|
saveConfigList.add(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TenantHelper.ignore(() -> {
|
||||||
|
if (CollUtil.isNotEmpty(saveConfigList)) {
|
||||||
|
configMapper.insertBatch(saveConfigList);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (String tenantId : syncTenantIds) {
|
||||||
|
TenantHelper.dynamic(tenantId, () -> CacheUtils.clear(CacheNames.SYS_CONFIG));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user