package com.dxhy.sign.service.qsgz;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

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

@Service
public class RulesSenderProvider implements ApplicationContextAware {
    @Autowired
    private Map<String, RulesService> rulesServiceMap;

    public RulesService getEdiSenderByType(String ediType) {
        return rulesServiceMap.get(ediType);
    }
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, RulesService> beansOfType = applicationContext.getBeansOfType(RulesService.class);
        rulesServiceMap = new HashMap<String, RulesService>();
        for (RulesService rulesService : beansOfType.values()) {
            rulesServiceMap.put(rulesService.getEdiType(), rulesService);
        }
    }
}
