package com.ld.igds.timer.zcl; import com.ld.igds.timer.zcl.dto.InteGrainDto; import com.ld.igds.timer.zcl.service.InteGrainService; 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 chen */ @Component public class InteGrainManager implements ApplicationContextAware { private static Map serviceMap; @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { Map map = applicationContext .getBeansOfType(InteGrainService.class); serviceMap = new HashMap<>(); for (String key : map.keySet()) { serviceMap.put(map.get(key).getCompanyId(), map.get(key)); } } /** * 执行保存 * @param dto */ public void toSaveGrain(InteGrainDto dto){ InteGrainService service = serviceMap.get(dto.getCompanyId()); service.toSaveGrain(dto); } }