first commit
This commit is contained in:
@ -30,5 +30,9 @@
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-api-monitor</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-api-tenant</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -0,0 +1,60 @@
|
||||
package com.qiaoba.module.system.runner;
|
||||
|
||||
import com.qiaoba.api.tenant.entity.SysTenant;
|
||||
import com.qiaoba.api.tenant.entity.param.SysTenantParam;
|
||||
import com.qiaoba.api.tenant.service.SysTenantApiService;
|
||||
import com.qiaoba.api.tenant.utils.TenantUtil;
|
||||
import com.qiaoba.common.base.constants.TenantConstant;
|
||||
import com.qiaoba.common.base.context.BaseContext;
|
||||
import com.qiaoba.module.system.service.SysConfigService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 项目启动后同步-[系统配置]
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023-07-01 08:34:20
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class SyncDataToCacheRunner implements ApplicationRunner {
|
||||
|
||||
private final SysTenantApiService sysTenantApiService;
|
||||
private final SysConfigService sysConfigService;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
|
||||
// 查询主库中所有正常的租户列表
|
||||
List<SysTenant> sysTenantList;
|
||||
try {
|
||||
BaseContext.setTenantId(TenantConstant.DEFAULT_TENANT_ID);
|
||||
sysTenantList = sysTenantApiService.selectList(SysTenantParam.buildNormalSelectParam());
|
||||
} finally {
|
||||
BaseContext.clearTenantId();
|
||||
}
|
||||
|
||||
// 对租户类型进行分类
|
||||
for (SysTenant sysTenant : sysTenantList) {
|
||||
try {
|
||||
TenantUtil.setContext(sysTenant);
|
||||
sysConfigService.resetConfigCache();
|
||||
log.info("同步[系统配置]完成, 租户ID: {}", sysTenant.getTenantId());
|
||||
} catch (Exception e) {
|
||||
log.error("同步[系统配置]失败, 租户ID: {}, 错误原因: {}", sysTenant.getTenantId(), e.getMessage());
|
||||
} finally {
|
||||
BaseContext.clearAllHolder();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user