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