package org.jeecg.config.init;
|
|
import org.jeecg.common.constant.CommonCacheConstant;
|
import org.jeecg.common.util.RedisUtil;
|
import org.jeecg.modules.system.entity.SysTenant;
|
import org.jeecg.modules.system.service.ISysTenantService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
import org.springframework.context.ApplicationListener;
|
import org.springframework.stereotype.Component;
|
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
@Component
|
public class RedisInitListener implements ApplicationListener<ApplicationStartedEvent> {
|
@Autowired
|
private RedisUtil redisUtil;
|
@Autowired
|
private ISysTenantService sysTenantService;
|
|
@Override
|
public void onApplicationEvent(ApplicationStartedEvent event) {
|
//查询所有租户信息并缓存至redis
|
List<SysTenant> tenantList = sysTenantService.list();
|
//list转map
|
Map<String, Object> tenantMap = tenantList.stream()
|
.collect(Collectors.toMap(t -> String.valueOf(t.getId()), t -> (Object) t.getName(), (existingValue, newValue) -> existingValue));
|
redisUtil.hmset(CommonCacheConstant.SYS_CACHE_TENANT,tenantMap);
|
}
|
}
|