fuliqi
2024-11-13 d8391959627eeba172c57763d1fb22f68256bbff
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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;
    public String HKUserName;
    public String HKPassword;
    public String DHUserName;
    public String DHPassword;
    public String YSUserName;
    public String YSPassword;
 
    public OSDCheckThread(TMonitor monitor, String HKUserName, String HKPassword, String DHUserName, String DHPassword, String YSUserName, String YSPassword) {
        this.monitor = monitor;
        this.HKUserName = HKUserName;
        this.HKPassword = HKPassword;
        this.DHUserName = DHUserName;
        this.DHPassword = DHPassword;
        this.YSUserName = YSUserName;
        this.YSPassword = YSPassword;
    }
 
    public TMonitor getMonitor() {
        return monitor;
    }
 
    public void setMonitor(TMonitor monitor) {
        this.monitor = monitor;
    }
 
    public String getHKUserName() {
        return HKUserName;
    }
 
    public void setHKUserName(String HKUserName) {
        this.HKUserName = HKUserName;
    }
 
    public String getHKPassword() {
        return HKPassword;
    }
 
    public void setHKPassword(String HKPassword) {
        this.HKPassword = HKPassword;
    }
 
    public String getDHUserName() {
        return DHUserName;
    }
 
    public void setDHUserName(String DHUserName) {
        this.DHUserName = DHUserName;
    }
 
    public String getDHPassword() {
        return DHPassword;
    }
 
    public void setDHPassword(String DHPassword) {
        this.DHPassword = DHPassword;
    }
 
    public String getYSUserName() {
        return YSUserName;
    }
 
    public void setYSUserName(String YSUserName) {
        this.YSUserName = YSUserName;
    }
 
    public String getYSPassword() {
        return YSPassword;
    }
 
    public void setYSPassword(String YSPassword) {
        this.YSPassword = YSPassword;
    }
 
    @Override
    public OSDResult call() throws Exception {
        if (DeviceType.HK.getType().equals(monitor.getDeviceType())) {
            //海康
            OSDResult osd = HKApi.getOsdByIP(monitor.getSerialNumber(),monitor.getIp(), HKUserName, HKPassword);
            OSDResult osdResult = checkSuccess(monitor, osd);
            if (osdResult!=null) {
                return osd;
            }else {
                return null;
            }
        } else if (DeviceType.DH.getType().equals(monitor.getDeviceType())) {
            //大华
            OSDResult osd = DHApi.getOsd(monitor.getSerialNumber(),monitor.getIp(), DHUserName, DHPassword);
            OSDResult osdResult = checkSuccess(monitor, osd);
            if (osdResult!=null) {
                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) {
                return osd;
            }else {
                return null;
            }
        }
        //未知品牌或者api调用失败,挨个执行所有api
        return tryAllApi(monitor);
    }
 
 
    private OSDResult tryAllApi(TMonitor monitor) {
        //尝试海康的api
        OSDResult hkosd = HKApi.getOsdByIP(monitor.getSerialNumber(),monitor.getIp(), HKUserName, HKPassword);
        if (hkosd != null) {
            hkosd.setSerialNumber(monitor.getSerialNumber());
            return hkosd;
        }
        //尝试大华的api
        OSDResult dhosd = DHApi.getOsd(monitor.getSerialNumber(),monitor.getIp(), DHUserName, DHPassword);
        if (dhosd != null) {
            dhosd.setSerialNumber(monitor.getSerialNumber());
            return dhosd;
        }
        //宇视api
        OSDResult ysosd = YSApi.getOsd(monitor.getIp(), YSUserName, YSPassword);
        if (ysosd != null) {
            ysosd.setSerialNumber(monitor.getSerialNumber());
            return ysosd;
        }
        return null;
    }
 
    private OSDResult checkSuccess(TMonitor monitor, OSDResult osd) {
        if (osd != null) {
            osd.setSerialNumber(monitor.getSerialNumber());
            return osd;
        } else {
            return null;
        }
    }
}