CZT
2023-11-27 c206acfaedc69c390fb67daa81bc686f58a212ef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.ld.igds.io;
 
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;
 
/**
 * 接口Api所有协议的协议类,根据不同的协议配置调用不同的协议实现
 *
 * @author jiazx
 */
@Component(RemoteManager.BEAN_ID)
public class RemoteManager implements ApplicationContextAware {
 
    public static final String BEAN_ID = "core.remoteManager";
 
    /**
     * 用于存放所有RemoteGrainService 接口的实现类
     */
    public static Map<String, RemoteGrainService> remoteGrainMap = new HashMap<>();
 
    public static Map<String, RemoteCommonService> remoteCommonMap = new HashMap<>();
 
    public static Map<String, RemoteControlService> remoteControlMap = new HashMap<>();
 
    public static Map<String, RemoteGasService> remoteGasMap = new HashMap<>();
 
    public static Map<String, RemotePestService> remotePestMap = new HashMap<>();
 
    @Override
    public void setApplicationContext(ApplicationContext applicationContext)
            throws BeansException {
        Map<String, RemoteGrainService> grainMap = applicationContext
                .getBeansOfType(RemoteGrainService.class);
 
        for (String key : grainMap.keySet()) {
            remoteGrainMap.put(grainMap.get(key).getProtocol(),
                    grainMap.get(key));
        }
 
        Map<String, RemoteCommonService> commonMap = applicationContext
                .getBeansOfType(RemoteCommonService.class);
        for (String key : commonMap.keySet()) {
            remoteCommonMap.put(commonMap.get(key).getProtocol(),
                    commonMap.get(key));
        }
 
        Map<String, RemoteControlService> controlMap = applicationContext
                .getBeansOfType(RemoteControlService.class);
 
        for (String key : controlMap.keySet()) {
            remoteControlMap.put(controlMap.get(key).getProtocol(),
                    controlMap.get(key));
        }
 
        Map<String, RemoteGasService> gasMap = applicationContext
                .getBeansOfType(RemoteGasService.class);
        for (String key : gasMap.keySet()) {
            remoteGasMap.put(gasMap.get(key).getProtocol(), gasMap.get(key));
        }
 
        Map<String, RemotePestService> pestMap = applicationContext
                .getBeansOfType(RemotePestService.class);
        for (String key : pestMap.keySet()) {
            remotePestMap.put(pestMap.get(key).getProtocol(), pestMap.get(key));
        }
 
    }
 
    /**
     * 根据协议获取协议实现接口
     *
     * @param protocol
     * @return
     */
    public RemoteGrainService getRemoteGrainService(String protocol) {
        return remoteGrainMap.get(protocol);
    }
 
    /**
     * 根据协议获取协议实现接口
     *
     * @param protocol
     * @return
     */
    public RemoteCommonService getRemoteCommonService(String protocol) {
        return remoteCommonMap.get(protocol);
    }
 
    /**
     * 根据协议获取协议实现接口
     *
     * @param protocol
     * @return
     */
    public RemoteGasService getRemoteGasService(String protocol) {
        return remoteGasMap.get(protocol);
    }
 
    /**
     * 根据协议获取协议实现接口
     *
     * @param protocol
     * @return
     */
    public RemoteControlService getRemoteControlService(String protocol) {
        return remoteControlMap.get(protocol);
    }
 
    /**
     * 根据协议获取协议实现接口
     *
     * @param protocol
     * @return
     */
    public RemotePestService getRemotePestService(String protocol) {
        return remotePestMap.get(protocol);
    }
 
}