Browse Source

fix: 海康/大华调转预置位、测温、抓拍的登录句柄统一管理,解决登录上限问题

master
yinhuaiwei 2 months ago
parent
commit
56955ef26b
7 changed files with 128 additions and 74 deletions
  1. +25
    -4
      src/main/java/com/inspect/nvr/controller/IvsCameraController.java
  2. +1
    -1
      src/main/java/com/inspect/nvr/hikVision/utils/jna/HikVisionUtils.java
  3. +0
    -1
      src/main/java/com/inspect/nvr/service/HikCaptureService.java
  4. +4
    -0
      src/main/java/com/inspect/nvr/service/IvsCameraService.java
  5. +5
    -24
      src/main/java/com/inspect/nvr/service/impl/DahuaServiceImpl.java
  6. +12
    -14
      src/main/java/com/inspect/nvr/service/impl/HikVisionServiceImpl.java
  7. +81
    -30
      src/main/java/com/inspect/nvr/service/impl/IvsCameraServiceImpl.java

+ 25
- 4
src/main/java/com/inspect/nvr/controller/IvsCameraController.java View File

@ -1,6 +1,6 @@
package com.inspect.nvr.controller; package com.inspect.nvr.controller;
import com.inspect.nvr.domain.Infrared.TemperatureData;
import com.inspect.nvr.aop.TimeTrace;
import com.inspect.nvr.domain.device.*; import com.inspect.nvr.domain.device.*;
import com.inspect.nvr.service.IvsCameraService; import com.inspect.nvr.service.IvsCameraService;
import com.inspect.nvr.utils.StringUtils; import com.inspect.nvr.utils.StringUtils;
@ -11,8 +11,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;
@Slf4j @Slf4j
@RestController @RestController
@ -60,7 +58,12 @@ public class IvsCameraController {
.body(ivsCameraService.getSnapshotList(param)); .body(ivsCameraService.getSnapshotList(param));
} }
@GetMapping("/downloadfile")
/**
* @deprecated
* use {@link #capture} instead.
*/
@Deprecated
@GetMapping("/downloadfile_old")
public ResponseEntity<InputStreamResource> downloadFile(@RequestParam("filesessionid") String fileSessionId) { public ResponseEntity<InputStreamResource> downloadFile(@RequestParam("filesessionid") String fileSessionId) {
// synchronized (captureLock_pic) { // synchronized (captureLock_pic) {
log.info("Download File Get Stream, fileSessionId: {}", fileSessionId); log.info("Download File Get Stream, fileSessionId: {}", fileSessionId);
@ -89,4 +92,22 @@ public class IvsCameraController {
.body(new InputStreamResource(byteArrayInputStream)); .body(new InputStreamResource(byteArrayInputStream));
// } // }
} }
@TimeTrace
@GetMapping("/downloadfile")
public ResponseEntity<InputStreamResource> capture(@RequestParam("filesessionid") String fileSessionId) {
ByteArrayInputStream byteArrayInputStream = ivsCameraService.capture(fileSessionId);
return ResponseEntity.ok().body(new InputStreamResource(byteArrayInputStream));
}
@TimeTrace
@GetMapping("/digest")
public ResponseEntity<String> rtsp(@RequestParam("filesessionid") String fileSessionId) {
byte[] bytes = ivsCameraService.captureDigest(fileSessionId);
if (bytes == null || bytes.length == 0) {
return ResponseEntity.ok().body("Not OK");
}
return ResponseEntity.ok().body("OK");
}
} }

+ 1
- 1
src/main/java/com/inspect/nvr/hikVision/utils/jna/HikVisionUtils.java View File

@ -83,7 +83,7 @@ public class HikVisionUtils {
m_strLoginInfo.wPort = port; m_strLoginInfo.wPort = port;
m_strLoginInfo.bUseAsynLogin = false; //是否异步登录0- 1- m_strLoginInfo.bUseAsynLogin = false; //是否异步登录0- 1-
m_strLoginInfo.write(); m_strLoginInfo.write();
log.info("海康相机登录成功");
log.info("海康相机登录");
return m_strLoginInfo; return m_strLoginInfo;
} }


+ 0
- 1
src/main/java/com/inspect/nvr/service/HikCaptureService.java View File

@ -101,7 +101,6 @@ public class HikCaptureService extends BaseCaptureService {
/** /**
* 旧版抓图备用 * 旧版抓图备用
*/ */
@Deprecated
private byte[] captureJPEGPicture(NvrInfo nvrInfo, int channel, Path fullPath) throws Exception { private byte[] captureJPEGPicture(NvrInfo nvrInfo, int channel, Path fullPath) throws Exception {
int userId = hikLoginService.login(nvrInfo); int userId = hikLoginService.login(nvrInfo);
// 兼容 C/C++ 编写的本地库 C 语言用 \0 标记字符串结束 // 兼容 C/C++ 编写的本地库 C 语言用 \0 标记字符串结束


+ 4
- 0
src/main/java/com/inspect/nvr/service/IvsCameraService.java View File

@ -18,4 +18,8 @@ public interface IvsCameraService {
SnapshotInfoListResult getSnapshotList(SnapshotInfoListParam param); SnapshotInfoListResult getSnapshotList(SnapshotInfoListParam param);
ByteArrayInputStream downloadFile(String fileSessionId); ByteArrayInputStream downloadFile(String fileSessionId);
ByteArrayInputStream capture(String fileSessionId);
byte[] captureDigest(String fileSessionId);
} }

+ 5
- 24
src/main/java/com/inspect/nvr/service/impl/DahuaServiceImpl.java View File

@ -1,7 +1,5 @@
package com.inspect.nvr.service.impl; package com.inspect.nvr.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.inspect.nvr.daHuaCarme.callback.fSnapReceiveCB; import com.inspect.nvr.daHuaCarme.callback.fSnapReceiveCB;
import com.inspect.nvr.daHuaCarme.jna.NetSDKLib; import com.inspect.nvr.daHuaCarme.jna.NetSDKLib;
import com.inspect.nvr.daHuaCarme.jna.NetSDKLib.LLong; import com.inspect.nvr.daHuaCarme.jna.NetSDKLib.LLong;
@ -10,7 +8,7 @@ import com.inspect.nvr.daHuaCarme.utils.jna.DahuaUtils;
import com.inspect.nvr.domain.Infrared.Camera; import com.inspect.nvr.domain.Infrared.Camera;
import com.inspect.nvr.domain.Infrared.NvrInfo; import com.inspect.nvr.domain.Infrared.NvrInfo;
import com.inspect.nvr.domain.Infrared.TemperatureData; import com.inspect.nvr.domain.Infrared.TemperatureData;
import com.inspect.nvr.hikVision.utils.AjaxResult;
import com.inspect.nvr.service.DahuaLoginService;
import com.inspect.nvr.service.DahuaService; import com.inspect.nvr.service.DahuaService;
import com.inspect.nvr.utils.StringUtils; import com.inspect.nvr.utils.StringUtils;
import com.inspect.nvr.utils.redis.RedisService; import com.inspect.nvr.utils.redis.RedisService;
@ -22,7 +20,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -33,8 +30,6 @@ import java.util.concurrent.TimeUnit;
@Slf4j @Slf4j
@Service @Service
public class DahuaServiceImpl implements DahuaService { public class DahuaServiceImpl implements DahuaService {
@Autowired @Autowired
private NetSDKLib dhNetSDK; private NetSDKLib dhNetSDK;
@Resource @Resource
@ -48,6 +43,8 @@ public class DahuaServiceImpl implements DahuaService {
private static final Object captureLock = new Object(); private static final Object captureLock = new Object();
@Value("${mode.delayTime:3000}") @Value("${mode.delayTime:3000}")
private int delayTime; private int delayTime;
@Autowired
private DahuaLoginService dahuaLoginService;
/** /**
* 登录大华设备 * 登录大华设备
@ -114,7 +111,7 @@ public class DahuaServiceImpl implements DahuaService {
nvrInfo.setServerPort(camera.getPort()); nvrInfo.setServerPort(camera.getPort());
nvrInfo.setAccount(camera.getUserName()); nvrInfo.setAccount(camera.getUserName());
nvrInfo.setPassword(camera.getPassword()); nvrInfo.setPassword(camera.getPassword());
m_hLoginHandle = login(nvrInfo);
m_hLoginHandle = dahuaLoginService.login(nvrInfo);
// m_hLoginHandle = new NetSDKLib.LLong((Long) redisService.redisTemplate.opsForValue().get(camera.getIp() + "_m_hLoginHandle")); // m_hLoginHandle = new NetSDKLib.LLong((Long) redisService.redisTemplate.opsForValue().get(camera.getIp() + "_m_hLoginHandle"));
if (StringUtils.isNull(m_hLoginHandle)) { if (StringUtils.isNull(m_hLoginHandle)) {
return null; return null;
@ -175,19 +172,9 @@ public class DahuaServiceImpl implements DahuaService {
netIn.stCondition.nPresetId, netIn.stCondition.nPresetId,
netIn.stCondition.nRuleId netIn.stCondition.nRuleId
); );
boolean b = dhNetSDK.CLIENT_Logout(m_hLoginHandle);
// if (b) {
// redisService.redisTemplate.opsForValue().getOperations().delete(camera.getIp() + "_m_hLoginHandle");
System.out.println("摄像机登出");
// }
return data; return data;
} }
System.out.println("大华-获取设备参数失败,错误码:" + ToolKits.getErrorCodePrint(dhNetSDK.CLIENT_GetLastError())); System.out.println("大华-获取设备参数失败,错误码:" + ToolKits.getErrorCodePrint(dhNetSDK.CLIENT_GetLastError()));
boolean b = dhNetSDK.CLIENT_Logout(m_hLoginHandle);
// if (b) {
// redisService.redisTemplate.opsForValue().getOperations().delete(camera.getIp() + "_m_hLoginHandle");
System.out.println("摄像机登出");
// }
return null; return null;
} }
@ -218,8 +205,7 @@ public class DahuaServiceImpl implements DahuaService {
nvrInfo.setServerPort(camera.getPort()); nvrInfo.setServerPort(camera.getPort());
nvrInfo.setAccount(camera.getUserName()); nvrInfo.setAccount(camera.getUserName());
nvrInfo.setPassword(camera.getPassword()); nvrInfo.setPassword(camera.getPassword());
m_hLoginHandle = login(nvrInfo);
// m_hLoginHandle = new NetSDKLib.LLong((Long) redisService.redisTemplate.opsForValue().get(camera.getIp() + "_m_hLoginHandle"));
m_hLoginHandle = dahuaLoginService.login(nvrInfo);
log.info("相机:m_hLoginHandle" + camera.getIp() + "m_hLoginHandle" + m_hLoginHandle); log.info("相机:m_hLoginHandle" + camera.getIp() + "m_hLoginHandle" + m_hLoginHandle);
// } // }
String ctr = "GOTO_PRESET"; String ctr = "GOTO_PRESET";
@ -234,11 +220,6 @@ public class DahuaServiceImpl implements DahuaService {
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
boolean bTemp = dhNetSDK.CLIENT_Logout(m_hLoginHandle);
// if (bTemp) {
// redisService.redisTemplate.opsForValue().getOperations().delete(camera.getIp() + "_m_hLoginHandle");
log.info("登出成功");
// }
return "0"; return "0";
} }


+ 12
- 14
src/main/java/com/inspect/nvr/service/impl/HikVisionServiceImpl.java View File

@ -18,6 +18,7 @@ import com.inspect.nvr.hikVision.utils.StringUtils;
import com.inspect.nvr.hikVision.utils.jna.HCNetSDK; import com.inspect.nvr.hikVision.utils.jna.HCNetSDK;
import com.inspect.nvr.hikVision.utils.jna.HikVisionUtils; import com.inspect.nvr.hikVision.utils.jna.HikVisionUtils;
import com.inspect.nvr.service.HikFRemoteConfigCallBack_imp; import com.inspect.nvr.service.HikFRemoteConfigCallBack_imp;
import com.inspect.nvr.service.HikLoginService;
import com.inspect.nvr.service.HikVisionService; import com.inspect.nvr.service.HikVisionService;
import com.inspect.nvr.tempCount.TempCount; import com.inspect.nvr.tempCount.TempCount;
import com.inspect.nvr.utils.DateUtils; import com.inspect.nvr.utils.DateUtils;
@ -118,6 +119,8 @@ public class HikVisionServiceImpl implements HikVisionService {
public AjaxResult login(NvrInfo nvrInfo) { public AjaxResult login(NvrInfo nvrInfo) {
return login_V40(nvrInfo); return login_V40(nvrInfo);
} }
@Autowired
private HikLoginService hikLoginService;
/** /**
@ -179,18 +182,13 @@ public class HikVisionServiceImpl implements HikVisionService {
log.info("实时测温入口================================================="); log.info("实时测温入口=================================================");
if (camera.getLUserID() != 0) { if (camera.getLUserID() != 0) {
log.info("海康摄像机登录 ip:{}", camera.getIp());
// 1. 登录设备
HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = HikVisionUtils.login_V40(camera.getIp(), (short) camera.getPort(), camera.getUserName(), camera.getPassword());
HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();
int lUserID = hcNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
if (lUserID == -1) {
int errorCode = hcNetSDK.NET_DVR_GetLastError();
String errorMsg = hcNetSDK.NET_DVR_GetErrorMsg(new IntByReference(errorCode));
log.error("登录设备失败,错误码为:{},错误信息为:{}", errorCode, errorMsg);
}
camera.setLUserID(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);
camera.setLUserID(userId);
} }
log.info("开始实时测温================================================="); log.info("开始实时测温=================================================");
@ -218,7 +216,7 @@ public class HikVisionServiceImpl implements HikVisionService {
int dwInBufferSize = cond.size(); int dwInBufferSize = cond.size();
result = hcNetSDK.NET_DVR_StartRemoteConfig( result = hcNetSDK.NET_DVR_StartRemoteConfig(
camera.getLUserID(), camera.getLUserID(),
hcNetSDK.NET_DVR_GET_REALTIME_THERMOMETRY,
HCNetSDK.NET_DVR_GET_REALTIME_THERMOMETRY,
lpInBuffer, lpInBuffer,
dwInBufferSize, dwInBufferSize,
new HikFRemoteConfigCallBack_imp() { new HikFRemoteConfigCallBack_imp() {
@ -264,7 +262,7 @@ public class HikVisionServiceImpl implements HikVisionService {
} }
temperatureData = temperatureFuture.get(); temperatureData = temperatureFuture.get();
} catch (Exception e) { } catch (Exception e) {
log.error("测温异常报错");
log.error("测温异常报错: {}", e.getMessage());
} finally { } finally {
log.info("关闭实时测温result值 {}", result); log.info("关闭实时测温result值 {}", result);
//关闭实时测温 //关闭实时测温


+ 81
- 30
src/main/java/com/inspect/nvr/service/impl/IvsCameraServiceImpl.java View File

@ -1,7 +1,6 @@
package com.inspect.nvr.service.impl; package com.inspect.nvr.service.impl;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.inspect.nvr.controller.CameraController; import com.inspect.nvr.controller.CameraController;
import com.inspect.nvr.domain.Infrared.Camera; import com.inspect.nvr.domain.Infrared.Camera;
import com.inspect.nvr.domain.Infrared.NvrInfo; 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.StringUtils;
import com.inspect.nvr.hikVision.utils.jna.HCNetSDK; import com.inspect.nvr.hikVision.utils.jna.HCNetSDK;
import com.inspect.nvr.hikVision.utils.jna.HikVisionUtils; 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.StringHexConverter;
import com.inspect.nvr.utils.redis.RedisService; import com.inspect.nvr.utils.redis.RedisService;
import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.IntByReference;
@ -32,38 +29,37 @@ import java.io.InputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; 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; import java.util.concurrent.TimeUnit;
@Slf4j @Slf4j
@Service @Service
public class IvsCameraServiceImpl implements IvsCameraService { public class IvsCameraServiceImpl implements IvsCameraService {
@Value("${test-mode:false}") @Value("${test-mode:false}")
private boolean testMode; private boolean testMode;
@Value("${mode.retryTimes:3}") @Value("${mode.retryTimes:3}")
private int retryTimes; private int retryTimes;
@Value("${mode.delayTime:3000}") @Value("${mode.delayTime:3000}")
private int delayTime; private int delayTime;
@Value("${mode.retryMode:0}") @Value("${mode.retryMode:0}")
private int retryMode; private int retryMode;
@Resource @Resource
private RedisService redisService; private RedisService redisService;
private Integer lUserID; private Integer lUserID;
@Autowired @Autowired
private HCNetSDK hcNetSDK; private HCNetSDK hcNetSDK;
@Autowired @Autowired
private DahuaService dahuaService; private DahuaService dahuaService;
@Autowired @Autowired
private CameraController cameraController; private CameraController cameraController;
@Autowired
private HikCaptureService hikCaptureService;
@Autowired
private DahuaCaptureService dhCaptureService;
@Autowired
private HikLoginService hikLoginService;
@Override @Override
public IvsPresetListView ptzPresetList(String cameraCode, String domainCode) { public IvsPresetListView ptzPresetList(String cameraCode, String domainCode) {
@ -147,20 +143,14 @@ public class IvsCameraServiceImpl implements IvsCameraService {
dahuaService.cameraControl(camera, 0, 0, 0); dahuaService.cameraControl(camera, 0, 0, 0);
} else { } 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) { if (!gotoPreset) {
log.error("海康-获取设备预置位跳转设备参数失败,错误码:" + hcNetSDK.NET_DVR_GetLastError()); log.error("海康-获取设备预置位跳转设备参数失败,错误码:" + hcNetSDK.NET_DVR_GetLastError());
} else { } else {
@ -334,13 +324,11 @@ public class IvsCameraServiceImpl implements IvsCameraService {
return null; return null;
} }
public byte[] loadDefaultImage() throws IOException { public byte[] loadDefaultImage() throws IOException {
ClassPathResource imgFile = new ClassPathResource("images/infrared_default.jpg"); ClassPathResource imgFile = new ClassPathResource("images/infrared_default.jpg");
return StreamUtils.copyToByteArray(imgFile.getInputStream()); return StreamUtils.copyToByteArray(imgFile.getInputStream());
} }
public AjaxResult login_V40(NvrInfo nvrInfo) { public AjaxResult login_V40(NvrInfo nvrInfo) {
log.info("nvrIP: " + nvrInfo.getNvrIp() + "serverPort: " + nvrInfo.getServerPort() + "account: " + nvrInfo.getAccount() + "password: " + nvrInfo.getPassword()); 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());//设备登录信息 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()))); 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;
}
}
}

Loading…
Cancel
Save