package com.zcxk.rmcp.web.factory;

import com.zcxk.rmcp.web.service.ReadRateService;
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 Andy
 * @version V1.0
 * @description: 抄表率处理
 * @date 2021/7/26
 **/
@Component
public class ReadRateFactory implements ApplicationContextAware {

    /**
     * 接口聚合
     */
    private static Map<Integer, ReadRateService> readRateMap;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, ReadRateService> acts = applicationContext.getBeansOfType(ReadRateService.class);
        readRateMap = new HashMap<>();
        acts.forEach((key, value) -> {
            readRateMap.put(value.getStatDays().getCode(),value);
        });
    }

    public <T extends ReadRateService> T getReadRateService(int code) {
        return (T)readRateMap.get(code);
    }

}
