package com.ym.mec.biz.event.listener;

import com.ym.mec.biz.event.TenantConfigChangeEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
public class TenantConfigListener implements ApplicationListener<TenantConfigChangeEvent> {

//    @Autowired
//    private SysTenantConfigService sysTenantConfigService;
//    @Autowired
//    private TenantInfoService tenantInfoService;

    @Override
    public void onApplicationEvent(TenantConfigChangeEvent event) {
//        if(event.getTenantId() != null){
//            TenantInfo tenantInfo = tenantInfoService.getById(event.getTenantId());
//            if(tenantInfo != null){
//                ConcurrentHashMap<Integer, ConcurrentHashMap<String, String>> allTenantConfig = sysTenantConfigService.getAllTenantConfig();
//                allTenantConfig.put(tenantInfo.getId(),sysTenantConfigService.queryAllMap(tenantInfo.getId()));
//                sysTenantConfigService.setTenantConfig(allTenantConfig);
//            }
//        }else {
//            List<TenantInfo> tenantInfos = tenantInfoService.list(new QueryWrapper<TenantInfo>().eq("state_",1));
//            if(tenantInfos != null && tenantInfos.size() > 0){
//                ConcurrentHashMap<Integer,ConcurrentHashMap<String,String>> tenantConfig = new ConcurrentHashMap<>(tenantInfos.size());
//                for (TenantInfo tenantInfo : tenantInfos) {
//                    tenantConfig.put(tenantInfo.getId(),sysTenantConfigService.queryAllMap(tenantInfo.getId()));
//                }
//                sysTenantConfigService.setTenantConfig(tenantConfig);
//            }
//        }
    }
}
