|
|
|
@ -1,7 +1,6 @@ |
|
|
|
package com.inspect.nvr.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.inspect.nvr.controller.CameraController; |
|
|
|
import com.inspect.nvr.domain.Infrared.Camera; |
|
|
|
import com.inspect.nvr.domain.Infrared.NvrInfo; |
|
|
|
@ -11,9 +10,7 @@ import com.inspect.nvr.hikVision.utils.AjaxResult; |
|
|
|
import com.inspect.nvr.hikVision.utils.StringUtils; |
|
|
|
import com.inspect.nvr.hikVision.utils.jna.HCNetSDK; |
|
|
|
import com.inspect.nvr.hikVision.utils.jna.HikVisionUtils; |
|
|
|
import com.inspect.nvr.service.DahuaService; |
|
|
|
import com.inspect.nvr.service.IvsCameraService; |
|
|
|
import com.inspect.nvr.utils.DateUtils; |
|
|
|
import com.inspect.nvr.service.*; |
|
|
|
import com.inspect.nvr.utils.StringHexConverter; |
|
|
|
import com.inspect.nvr.utils.redis.RedisService; |
|
|
|
import com.sun.jna.ptr.IntByReference; |
|
|
|
@ -32,38 +29,37 @@ import java.io.InputStream; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class IvsCameraServiceImpl implements IvsCameraService { |
|
|
|
|
|
|
|
@Value("${test-mode:false}") |
|
|
|
private boolean testMode; |
|
|
|
|
|
|
|
@Value("${mode.retryTimes:3}") |
|
|
|
private int retryTimes; |
|
|
|
|
|
|
|
@Value("${mode.delayTime:3000}") |
|
|
|
private int delayTime; |
|
|
|
|
|
|
|
@Value("${mode.retryMode:0}") |
|
|
|
private int retryMode; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private RedisService redisService; |
|
|
|
|
|
|
|
private Integer lUserID; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private HCNetSDK hcNetSDK; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private DahuaService dahuaService; |
|
|
|
@Autowired |
|
|
|
private CameraController cameraController; |
|
|
|
@Autowired |
|
|
|
private HikCaptureService hikCaptureService; |
|
|
|
@Autowired |
|
|
|
private DahuaCaptureService dhCaptureService; |
|
|
|
@Autowired |
|
|
|
private HikLoginService hikLoginService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public IvsPresetListView ptzPresetList(String cameraCode, String domainCode) { |
|
|
|
@ -147,20 +143,14 @@ public class IvsCameraServiceImpl implements IvsCameraService { |
|
|
|
dahuaService.cameraControl(camera, 0, 0, 0); |
|
|
|
} else { |
|
|
|
//海康预置位跳转 |
|
|
|
log.info("开始登录海康NVR 进行跳转预置位"); |
|
|
|
lUserID = (Integer) redisService.redisTemplate.opsForValue().get(camera.getIp() + "_userId"); |
|
|
|
if (ObjectUtil.isEmpty(lUserID)) { |
|
|
|
NvrInfo nvrInfo = new NvrInfo(); |
|
|
|
nvrInfo.setNvrIp(camera.getIp()); |
|
|
|
nvrInfo.setServerPort(camera.getPort()); |
|
|
|
nvrInfo.setAccount(camera.getUserName()); |
|
|
|
nvrInfo.setPassword(camera.getPassword()); |
|
|
|
login_V40(nvrInfo); |
|
|
|
lUserID = (Integer) redisService.redisTemplate.opsForValue().get(camera.getIp() + "_userId"); |
|
|
|
log.info("相机:lUserID" + camera.getIp() + "_userId" + lUserID); |
|
|
|
} |
|
|
|
NvrInfo nvrInfo = new NvrInfo(); |
|
|
|
nvrInfo.setNvrIp(camera.getIp()); |
|
|
|
nvrInfo.setServerPort(camera.getPort()); |
|
|
|
nvrInfo.setAccount(camera.getUserName()); |
|
|
|
nvrInfo.setPassword(camera.getPassword()); |
|
|
|
int userId = hikLoginService.login(nvrInfo); |
|
|
|
//参数:登录令牌,通道号,预置位跳转,跳转的预置位码 |
|
|
|
boolean gotoPreset = hcNetSDK.NET_DVR_PTZPreset_Other(lUserID, camera.getChannel(), HCNetSDK.GOTO_PRESET, camera.getPointNum()); |
|
|
|
boolean gotoPreset = hcNetSDK.NET_DVR_PTZPreset_Other(userId, camera.getChannel(), HCNetSDK.GOTO_PRESET, camera.getPointNum()); |
|
|
|
if (!gotoPreset) { |
|
|
|
log.error("海康-获取设备预置位跳转设备参数失败,错误码:" + hcNetSDK.NET_DVR_GetLastError()); |
|
|
|
} else { |
|
|
|
@ -334,13 +324,11 @@ public class IvsCameraServiceImpl implements IvsCameraService { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public byte[] loadDefaultImage() throws IOException { |
|
|
|
ClassPathResource imgFile = new ClassPathResource("images/infrared_default.jpg"); |
|
|
|
return StreamUtils.copyToByteArray(imgFile.getInputStream()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public AjaxResult login_V40(NvrInfo nvrInfo) { |
|
|
|
log.info("nvrIP: " + nvrInfo.getNvrIp() + "serverPort: " + nvrInfo.getServerPort() + "account: " + nvrInfo.getAccount() + "password: " + nvrInfo.getPassword()); |
|
|
|
HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = HikVisionUtils.login_V40(nvrInfo.getNvrIp(), nvrInfo.getServerPort().shortValue(), nvrInfo.getAccount(), nvrInfo.getPassword());//设备登录信息 |
|
|
|
@ -386,5 +374,68 @@ public class IvsCameraServiceImpl implements IvsCameraService { |
|
|
|
return AjaxResult.success(hcNetSDK.NET_DVR_GetErrorMsg(new IntByReference(hcNetSDK.NET_DVR_GetLastError()))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ByteArrayInputStream capture(String fileSessionId) { |
|
|
|
final String rawString = StringHexConverter.fromHex(fileSessionId); |
|
|
|
log.info("downloadImage hexString: {}, rawString: {}", fileSessionId, rawString); |
|
|
|
String[] cameraAddressInfos = rawString.split((":")); |
|
|
|
log.info("doCapture ip: {}, port: {}, channel: {}, pointName: {},cameraType: {}, username: {}, password: {}", cameraAddressInfos[0], cameraAddressInfos[1], cameraAddressInfos[2], cameraAddressInfos[3], cameraAddressInfos[4], cameraAddressInfos[5], cameraAddressInfos[6]); |
|
|
|
Camera camera = new Camera(); |
|
|
|
camera.setIp(cameraAddressInfos[0]); |
|
|
|
camera.setPort(Integer.parseInt(cameraAddressInfos[1])); |
|
|
|
camera.setChannel(Integer.parseInt(cameraAddressInfos[2])); |
|
|
|
camera.setPointNum(Integer.parseInt(cameraAddressInfos[3])); |
|
|
|
camera.setCameraType(Integer.parseInt(cameraAddressInfos[4])); |
|
|
|
camera.setUserName(cameraAddressInfos[5]); |
|
|
|
camera.setPassword(cameraAddressInfos[6]); |
|
|
|
|
|
|
|
NvrInfo nvrInfo = new NvrInfo(); |
|
|
|
nvrInfo.setNvrIp(camera.getIp()); |
|
|
|
nvrInfo.setServerPort(camera.getPort()); |
|
|
|
nvrInfo.setAccount(camera.getUserName()); |
|
|
|
nvrInfo.setPassword(camera.getPassword()); |
|
|
|
|
|
|
|
if (ObjectUtil.equals(camera.getCameraType(), 1)) { |
|
|
|
log.info("大华相机拍照"); |
|
|
|
byte[] bytes = dhCaptureService.capture(nvrInfo, camera.getChannel()); |
|
|
|
return new ByteArrayInputStream(bytes); |
|
|
|
} else { |
|
|
|
log.info("海康相机拍照"); |
|
|
|
byte[] bytes = hikCaptureService.capture(nvrInfo, camera.getChannel()); |
|
|
|
return new ByteArrayInputStream(bytes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public byte[] captureDigest(String fileSessionId) { |
|
|
|
final String rawString = StringHexConverter.fromHex(fileSessionId); |
|
|
|
log.info("downloadImage hexString: {}, rawString: {}", fileSessionId, rawString); |
|
|
|
String[] cameraAddressInfos = rawString.split((":")); |
|
|
|
log.info("doCapture ip: {}, port: {}, channel: {}, pointName: {},cameraType: {}, username: {}, password: {}", cameraAddressInfos[0], cameraAddressInfos[1], cameraAddressInfos[2], cameraAddressInfos[3], cameraAddressInfos[4], cameraAddressInfos[5], cameraAddressInfos[6]); |
|
|
|
Camera camera = new Camera(); |
|
|
|
camera.setIp(cameraAddressInfos[0]); |
|
|
|
camera.setPort(Integer.parseInt(cameraAddressInfos[1])); |
|
|
|
camera.setChannel(Integer.parseInt(cameraAddressInfos[2])); |
|
|
|
camera.setPointNum(Integer.parseInt(cameraAddressInfos[3])); |
|
|
|
camera.setCameraType(Integer.parseInt(cameraAddressInfos[4])); |
|
|
|
camera.setUserName(cameraAddressInfos[5]); |
|
|
|
camera.setPassword(cameraAddressInfos[6]); |
|
|
|
|
|
|
|
NvrInfo nvrInfo = new NvrInfo(); |
|
|
|
nvrInfo.setNvrIp(camera.getIp()); |
|
|
|
nvrInfo.setServerPort(camera.getPort()); |
|
|
|
nvrInfo.setAccount(camera.getUserName()); |
|
|
|
nvrInfo.setPassword(camera.getPassword()); |
|
|
|
|
|
|
|
if (ObjectUtil.equals(camera.getCameraType(), 1)) { |
|
|
|
log.info("大华相机拍照"); |
|
|
|
byte[] bytes = dhCaptureService.captureDigest(nvrInfo, camera.getChannel()); |
|
|
|
return bytes; |
|
|
|
} else { |
|
|
|
log.info("海康相机拍照"); |
|
|
|
byte[] bytes = hikCaptureService.captureDigest(nvrInfo, camera.getChannel()); |
|
|
|
return bytes; |
|
|
|
} |
|
|
|
} |
|
|
|
} |