干燥机配套车间生产管理系统/云平台服务端
baoshiwei
2024-12-11 7c585586e9bea943161676bd9d127e81123891c3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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);
    }
}