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
package com.ld.igds.camera;
 
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(ApiCameraManager.BEAN_ID)
public class ApiCameraManager implements ApplicationContextAware {
 
    public static final String BEAN_ID = "core.apiCameraManager";
 
 
    public static Map<String, ApiCameraService> remoteMap = new HashMap<>();
 
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
 
        Map<String, ApiCameraService> grainMap = applicationContext.getBeansOfType(ApiCameraService.class);
 
        for (String key : grainMap.keySet()) {
            remoteMap.put(grainMap.get(key).getPlayType(), grainMap.get(key));
        }
    }
 
 
    /**
     * 根据播放方式获取系统实现接口,如果接口没有实现,自动调用系统默认接口
     *
     * @param playType
     * @return
     */
    public ApiCameraService getApiCameraService(String playType) {
        ApiCameraService apiCameraService = remoteMap.get(playType);
        if (null == apiCameraService) {
            apiCameraService = remoteMap.get(CameraUtil.PLAY_TYPE_DEFAULT);
        }
        return apiCameraService;
    }
}