package com.fzzy.gateway.api; 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; /** * 接口封装 */ @Component public class GatewayRemoteManager implements ApplicationContextAware { public static Map remoteMap = new HashMap<>(); public static Map reportMap = new HashMap<>(); public static Map syncGrain = new HashMap<>(); public static Map syncIdCard = new HashMap<>(); public static Map syncLed = new HashMap<>(); public static Map syncLpr = new HashMap<>(); public static Map syncWeight = new HashMap<>(); public static Map testMap = new HashMap<>(); @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { Map serviceMap1 = applicationContext.getBeansOfType(GatewayRemoteService.class); for (String key : serviceMap1.keySet()) { remoteMap.put(serviceMap1.get(key).getProtocol(), serviceMap1.get(key)); } Map serviceMap2 = applicationContext.getBeansOfType(GatewaySyncGranService.class); for (String key : serviceMap2.keySet()) { syncGrain.put(serviceMap2.get(key).getGrainProtocol(), serviceMap2.get(key)); } Map serviceMap3 = applicationContext.getBeansOfType(GatewaySyncIdCardService.class); for (String key : serviceMap3.keySet()) { syncIdCard.put(serviceMap3.get(key).getIdCardProtocol(), serviceMap3.get(key)); } Map serviceMap4 = applicationContext.getBeansOfType(GatewaySyncLedService.class); for (String key : serviceMap4.keySet()) { syncLed.put(serviceMap4.get(key).getLedProtocol(), serviceMap4.get(key)); } Map serviceMap5 = applicationContext.getBeansOfType(GatewaySyncLprService.class); for (String key : serviceMap5.keySet()) { syncLpr.put(serviceMap5.get(key).getLprProtocol(), serviceMap5.get(key)); } Map serviceMap6 = applicationContext.getBeansOfType(GatewaySyncWeightService.class); for (String key : serviceMap6.keySet()) { syncWeight.put(serviceMap6.get(key).getWeightProtocol(), serviceMap6.get(key)); } Map serviceMap7 = applicationContext.getBeansOfType(GatewayDeviceReportService.class); for (String key : serviceMap7.keySet()) { reportMap.put(serviceMap7.get(key).getProtocol(), serviceMap7.get(key)); } Map serviceMap8 = applicationContext.getBeansOfType(GatewayDeviceTestService.class); for (String key : serviceMap8.keySet()) { testMap.put(serviceMap8.get(key).getProtocol(), serviceMap8.get(key)); } } /** * 根据实现协议获取当前实现方法 * * @param protocol * @return */ public GatewayRemoteService getRemoteService(String protocol) { return remoteMap.get(protocol); } /** * 根据实现协议获取当前实现方法 * * @param protocol * @return */ public GatewaySyncGranService getSyncGrainService(String protocol) { return syncGrain.get(protocol); } /** * 根据实现协议获取当前实现方法 * * @param protocol * @return */ public GatewaySyncIdCardService getSyncIdCardService(String protocol) { return syncIdCard.get(protocol); } /** * 根据实现协议获取当前实现方法 * * @param protocol * @return */ public GatewaySyncLedService getSyncLedService(String protocol) { return syncLed.get(protocol); } /** * 根据实现协议获取当前实现方法 * * @param protocol * @return */ public GatewaySyncLprService getSyncLprService(String protocol) { return syncLpr.get(protocol); } /** * 根据实现协议获取当前实现方法 * * @param protocol * @return */ public GatewaySyncWeightService getSyncWeightService(String protocol) { return syncWeight.get(protocol); } /** * 根据实现协议获取当前实现方法 * * @param protocol * @return */ public GatewayDeviceReportService getDeviceReportService(String protocol) { return reportMap.get(protocol); } /** * @param protocol * @return */ public GatewayDeviceTestService getGatewayTestService(String protocol) { return testMap.get(protocol); } }