package com.sptg.gateway.service;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author WFT
 * @date 2020/5/28
 * description:
 */
@Component
public class ExcelServiceFactory implements ApplicationContextAware {

    private static Map<String, ExcelService> MAP;

    public ExcelService getService(String flag){
        return MAP.get(flag);
    }

    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        Map<String, ExcelService> beansMap = context.getBeansOfType(ExcelService.class);
        MAP = new HashMap<>(beansMap.size());
        beansMap.forEach((beanName,bean) -> MAP.put(bean.getFlag(),bean));
    }
}
