fuliqi
2024-09-17 e13b129c300d3eff2ba555d0c41bbccbaab1014a
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
package com.ycl.thread;
 
import com.ycl.api.DH.utils.DHApi;
import com.ycl.api.HK.HKApi;
import com.ycl.api.YS.YSApi;
import com.ycl.platform.domain.entity.TMonitor;
import com.ycl.platform.domain.result.OSDResult;
import enumeration.DeviceType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
 
import java.util.concurrent.Callable;
@Slf4j
public class OSDCheckThread implements Callable<OSDResult> {
    private TMonitor monitor;
    @Value("${HK.userName}")
    public String HKUserName;
    @Value("${HK.password}")
    public String HKPassword;
    @Value("${DH.userName}")
    public String DHUserName;
    @Value("${DH.password}")
    public String DHPassword;
    @Value("${YS.userName}")
    public String YSUserName;
    @Value("${YS.password}")
    public String YSPassword;
 
    public OSDCheckThread(TMonitor monitor) {
        this.monitor = monitor;
    }
 
    public TMonitor getMonitor() {
        return monitor;
    }
 
    public void setMonitor(TMonitor monitor) {
        this.monitor = monitor;
    }
 
    @Override
    public OSDResult call() throws Exception {
        if (DeviceType.HK.getType().equals(monitor.getDeviceType())) {
            //海康
            OSDResult osd = HKApi.getOsdByIP(monitor.getIp(), HKUserName, HKPassword);
            OSDResult osdResult = checkSuccess(monitor, osd);
            if (osdResult!=null) {
                log.info("海康调用成功" + osd);
                return osd;
            }else {
                return null;
            }
        } else if (DeviceType.DH.getType().equals(monitor.getDeviceType())) {
            //大华
            OSDResult osd = DHApi.getOsd(monitor.getIp(), DHUserName, DHPassword);
            OSDResult osdResult = checkSuccess(monitor, osd);
            if (osdResult!=null) {
                log.info("大华调用成功" + osd);
                return osd;
            }else {
                return null;
            }
        } else if (DeviceType.YS.getType().equals(monitor.getDeviceType())) {
            //宇视
            OSDResult osd = YSApi.getOsd(monitor.getIp(), YSUserName, YSPassword);
            OSDResult osdResult = checkSuccess(monitor, osd);
            if (osdResult!=null) {
                log.info("宇视调用成功" + osd);
                return osd;
            }else {
                return null;
            }
        }
        //未知品牌或者api调用失败,挨个执行所有api
        return tryAllApi(monitor);
    }
 
 
    private OSDResult tryAllApi(TMonitor monitor) {
        //尝试海康的api
        OSDResult hkosd = HKApi.getOsdByIP(monitor.getIp(), HKUserName, HKPassword);
        if (hkosd != null) {
            hkosd.setSerialNumber(monitor.getSerialNumber());
            log.info("海康调用成功" + hkosd);
            return hkosd;
        }
        //尝试大华的api
        OSDResult dhosd = DHApi.getOsd(monitor.getIp(), DHUserName, DHPassword);
        if (dhosd != null) {
            dhosd.setSerialNumber(monitor.getSerialNumber());
            log.info("大华调用成功" + dhosd);
            return dhosd;
        }
        //宇视api
        OSDResult ysosd = YSApi.getOsd(monitor.getIp(), YSUserName, YSPassword);
        if (ysosd != null) {
            ysosd.setSerialNumber(monitor.getSerialNumber());
            log.info("宇视调用成功" + ysosd);
            return ysosd;
        }
        return null;
    }
 
    private OSDResult checkSuccess(TMonitor monitor, OSDResult osd) {
        if (osd != null) {
            osd.setSerialNumber(monitor.getSerialNumber());
            return osd;
        } else {
            return null;
        }
    }
}