jiazx0107@163.com
2023-10-25 03e26beab1d9c382b685c26059e6dec274a0d7d4
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
125
126
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<String, GatewayRemoteService> remoteMap = new HashMap<>();
 
    public static Map<String, GatewaySyncGranService> syncGrain = new HashMap<>();
 
    public static Map<String, GatewaySyncIdCardService> syncIdCard = new HashMap<>();
 
    public static Map<String, GatewaySyncLedService> syncLed = new HashMap<>();
 
    public static Map<String, GatewaySyncLprService> syncLpr = new HashMap<>();
 
    public static Map<String, GatewaySyncWeightService> syncWeight = new HashMap<>();
 
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, GatewayRemoteService> serviceMap1 = applicationContext.getBeansOfType(GatewayRemoteService.class);
        for (String key : serviceMap1.keySet()) {
            remoteMap.put(serviceMap1.get(key).getProtocol(), serviceMap1.get(key));
        }
 
        Map<String, GatewaySyncGranService> serviceMap2 = applicationContext.getBeansOfType(GatewaySyncGranService.class);
        for (String key : serviceMap2.keySet()) {
            syncGrain.put(serviceMap2.get(key).getGrainProtocol(), serviceMap2.get(key));
        }
 
        Map<String, GatewaySyncIdCardService> serviceMap3 = applicationContext.getBeansOfType(GatewaySyncIdCardService.class);
        for (String key : serviceMap3.keySet()) {
            syncIdCard.put(serviceMap3.get(key).getIdCardProtocol(), serviceMap3.get(key));
        }
 
 
        Map<String, GatewaySyncLedService> serviceMap4 = applicationContext.getBeansOfType(GatewaySyncLedService.class);
        for (String key : serviceMap4.keySet()) {
            syncLed.put(serviceMap4.get(key).getLedProtocol(), serviceMap4.get(key));
        }
 
        Map<String, GatewaySyncLprService> serviceMap5 = applicationContext.getBeansOfType(GatewaySyncLprService.class);
        for (String key : serviceMap5.keySet()) {
            syncLpr.put(serviceMap5.get(key).getLprProtocol(), serviceMap5.get(key));
        }
 
        Map<String, GatewaySyncWeightService> serviceMap6 = applicationContext.getBeansOfType(GatewaySyncWeightService.class);
        for (String key : serviceMap6.keySet()) {
            syncWeight.put(serviceMap6.get(key).getWeightProtocol(), serviceMap6.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);
    }
 
}