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;
|
}
|
}
|
}
|