From 3591fc47eaa3e301252dc06d257d46bd3a45e120 Mon Sep 17 00:00:00 2001
From: liusuyi <13324259@qq.com>
Date: 星期一, 23 十月 2023 22:10:19 +0800
Subject: [PATCH] 相机sdk异步登录
---
ard-work/src/main/java/com/ruoyi/device/camera/service/impl/CameraSdkServiceImpl.java | 32 +++++++---
ard-work/src/main/java/com/ruoyi/alarm/config/AsyncConfiguration.java | 1
ard-work/src/main/java/com/ruoyi/device/dhsdk/service/IDhClientService.java | 4 -
ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java | 35 -----------
ard-work/src/main/java/com/ruoyi/device/camera/service/impl/AsyncLogin.java | 36 ++++++++++++
ard-work/src/main/java/com/ruoyi/device/dhsdk/service/impl/DhClientServiceImpl.java | 27 +--------
ard-work/src/main/java/com/ruoyi/device/camera/controller/CameraSdkController.java | 10 +-
ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java | 3 -
8 files changed, 68 insertions(+), 80 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/alarm/config/AsyncConfiguration.java b/ard-work/src/main/java/com/ruoyi/alarm/config/AsyncConfiguration.java
index f3b8be4..7549bcd 100644
--- a/ard-work/src/main/java/com/ruoyi/alarm/config/AsyncConfiguration.java
+++ b/ard-work/src/main/java/com/ruoyi/alarm/config/AsyncConfiguration.java
@@ -28,6 +28,7 @@
Integer keepAliveSeconds;
@Value("${ThreadPoolTask.queueCapacity}")
Integer queueCapacity;
+
@Bean("alarmExecutor")
public Executor alarmExecutor(){
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/controller/CameraSdkController.java b/ard-work/src/main/java/com/ruoyi/device/camera/controller/CameraSdkController.java
index fe7ff79..65c6d73 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/controller/CameraSdkController.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/controller/CameraSdkController.java
@@ -64,11 +64,11 @@
private IArdCamerasService ardCamerasService;
- //鍒濆鐧诲綍鎵�鏈夌浉鏈�
- @PostConstruct
- public void initLoginAll() {
- cameraSdkService.loginAll();
- }
+// //鍒濆鐧诲綍鎵�鏈夌浉鏈�
+// @PostConstruct
+// public void initLoginAll() {
+// cameraSdkService.loginAll();
+// }
@RequestMapping("/preview")
private String preview() {
diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/AsyncLogin.java b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/AsyncLogin.java
new file mode 100644
index 0000000..ed8f337
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/AsyncLogin.java
@@ -0,0 +1,36 @@
+package com.ruoyi.device.camera.service.impl;
+
+import com.ruoyi.device.camera.domain.ArdCameras;
+import com.ruoyi.device.dhsdk.service.IDhClientService;
+import com.ruoyi.device.hiksdk.service.IHikClientService;
+import org.hibernate.validator.internal.util.stereotypes.Lazy;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+/**
+ * @ClassName test
+ * @Description:
+ * @Author 鍒樿嫃涔�
+ * @Date 2023/10/23 21:39
+ * @Version 1.0
+ */
+@Service
+public class AsyncLogin {
+ @Resource
+ IHikClientService hikClientService;
+
+ @Resource
+ IDhClientService dhClientService;
+
+ @Async
+ public void hikLogin(ArdCameras ardCameras) {
+ hikClientService.login(ardCameras);
+ }
+
+ @Async
+ public void dhLogin(ArdCameras ardCameras) {
+ dhClientService.login(ardCameras);
+ }
+}
diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/CameraSdkServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/CameraSdkServiceImpl.java
index 6598897..6203512 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/CameraSdkServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/CameraSdkServiceImpl.java
@@ -3,29 +3,22 @@
import com.ruoyi.common.annotation.SdkOperate;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.redis.RedisCache;
-import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.device.camera.domain.ArdCameras;
import com.ruoyi.device.camera.domain.CameraCmd;
import com.ruoyi.device.camera.service.IArdCamerasService;
import com.ruoyi.device.camera.service.ICameraSdkService;
-import com.ruoyi.device.channel.domain.ArdChannel;
-import com.ruoyi.device.dhsdk.lib.NetSDKLib;
-import com.ruoyi.device.dhsdk.module.RealPlayModule;
import com.ruoyi.device.dhsdk.service.IDhClientService;
-import com.ruoyi.device.hiksdk.common.GlobalVariable;
import com.ruoyi.device.hiksdk.service.IHikClientService;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.stereotype.Service;
+import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
-import static com.ruoyi.device.dhsdk.lib.ToolKits.getErrorCodePrint;
-import static com.ruoyi.device.dhsdk.module.LoginModule.netsdk;
-import static com.ruoyi.device.hiksdk.sdk.HCNetSDK.NET_DVR_CHECK_USER_STATUS;
/**
@@ -45,12 +38,27 @@
IDhClientService dhClientService;
@Resource
RedisCache redisCache;
+ @Resource
+ AsyncLogin asyncLogin;
+
+
//鍒濆鍖朣DK
+ @PostConstruct
@Override
public void loginAll() {
- hikClientService.loginAll();//鐧诲綍鍏ㄩ儴娴峰悍鐩告満
- dhClientService.loginAll();//鐧诲綍鍏ㄩ儴澶у崕鐩告満
+ try {
+ List<ArdCameras> ardCameras = ardCamerasService.selectArdCamerasListNoDataScope(new ArdCameras());
+ for (ArdCameras camera : ardCameras) {
+ if ("1".equals(camera.getFactory())) {
+ asyncLogin.hikLogin(camera);
+ } else if ("2".equals(camera.getFactory())) {
+ asyncLogin.dhLogin(camera);
+ }
+ }
+ } catch (Exception ex) {
+ log.error("鍒濆鍖栫櫥褰曠浉鏈哄紓甯革細" + ex.getMessage());
+ }
}
//鐧诲綍
@@ -683,4 +691,6 @@
}
return map;
}
+
+
}
diff --git a/ard-work/src/main/java/com/ruoyi/device/dhsdk/service/IDhClientService.java b/ard-work/src/main/java/com/ruoyi/device/dhsdk/service/IDhClientService.java
index 8425ab9..f32f5ae 100644
--- a/ard-work/src/main/java/com/ruoyi/device/dhsdk/service/IDhClientService.java
+++ b/ard-work/src/main/java/com/ruoyi/device/dhsdk/service/IDhClientService.java
@@ -13,12 +13,8 @@
*/
public interface IDhClientService {
-
//鐧诲綍
Boolean login(ArdCameras ardCamera);
-
- //鐧诲綍鎵�鏈夌浉鏈�
- void loginAll();
//娉ㄩ攢
Boolean logout(String cameraId);
diff --git a/ard-work/src/main/java/com/ruoyi/device/dhsdk/service/impl/DhClientServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/dhsdk/service/impl/DhClientServiceImpl.java
index 80a104c..4fcaf12 100644
--- a/ard-work/src/main/java/com/ruoyi/device/dhsdk/service/impl/DhClientServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/device/dhsdk/service/impl/DhClientServiceImpl.java
@@ -18,6 +18,7 @@
import com.ruoyi.device.dhsdk.module.*;
import com.ruoyi.device.dhsdk.service.IDhClientService;
import com.ruoyi.device.hiksdk.common.GlobalVariable;
+import com.ruoyi.device.camera.service.impl.AsyncLogin;
import com.ruoyi.media.domain.Vtdu;
import com.ruoyi.media.service.IVtduService;
import com.ruoyi.utils.gis.GisUtil;
@@ -25,7 +26,6 @@
import com.sun.jna.Pointer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -59,31 +59,11 @@
@Value("${minio.endpoint}")
private String minioEndPoint;
+
// 璁惧鏂嚎閫氱煡鍥炶皟
private static DisConnect disConnect = new DisConnect();
// 缃戠粶杩炴帴鎭㈠
private static HaveReConnect haveReConnect = new HaveReConnect();
-
- /**
- * 鐧诲綍鎵�鏈夌浉鏈�
- * 鍒樿嫃涔�
- * 2023/10/17 8:28:13
- */
- @Override
- public void loginAll() {
- try {
- ArdCameras ardCamera = new ArdCameras();
- ardCamera.setFactory("2");//鑾峰彇澶у崕鐩告満
- List<ArdCameras> ardCameras = ardCamerasService.selectArdCamerasListNoDataScope(ardCamera);
- for (ArdCameras camera : ardCameras) {
- Thread.sleep(500);
- //鐧诲綍
- login(camera);
- }
- } catch (Exception ex) {
- log.error("鍒濆鍖栫櫥褰曠浉鏈哄紓甯革細" + ex.getMessage());
- }
- }
/**
@@ -207,6 +187,7 @@
* 2023/10/17 8:28:13
*/
@Override
+ @SdkOperate
public boolean pTZControl(CameraCmd cmd) {
String cameraId = cmd.getCameraId();
boolean enable = cmd.isEnable();
@@ -358,7 +339,6 @@
* @淇敼浜哄拰鍏跺畠淇℃伅 娉ㄦ剰淇话瑙掑害璐熷�奸渶瑕佸姞涓�360寰楀埌鐨勬鍊艰繘琛岃缃�
*/
@Override
- @SdkOperate
public boolean setZeroPtz(CameraCmd cmd) {
String cameraId = cmd.getCameraId();
Integer chanNo = cmd.getChanNo();
@@ -382,7 +362,6 @@
* @淇敼浜哄拰鍏跺畠淇℃伅
*/
@Override
- @SdkOperate
public String picCutCate(CameraCmd cmd) {
String cameraId = cmd.getCameraId();
Integer chanNo = cmd.getChanNo();
diff --git a/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java b/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java
index 9918a4a..443a3bb 100644
--- a/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java
+++ b/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java
@@ -22,9 +22,6 @@
//寮傛鐧诲綍
void asyncLogin(ArdCameras cameras);
- //鐧诲綍鎵�鏈夌浉鏈�
- void loginAll();
-
//娉ㄩ攢
boolean logout(String cameraId);
diff --git a/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java
index 9ebe065..bda9b3e 100644
--- a/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java
@@ -10,11 +10,10 @@
import com.ruoyi.device.camera.service.IArdCamerasService;
import com.ruoyi.device.channel.domain.ArdChannel;
import com.ruoyi.device.channel.service.IArdChannelService;
-import com.ruoyi.device.dhsdk.lib.LibraryLoad;
-import com.ruoyi.device.dhsdk.lib.NetSDKLib;
import com.ruoyi.device.hiksdk.common.GlobalVariable;
import com.ruoyi.device.camera.domain.ArdCameras;
import com.ruoyi.device.hiksdk.sdk.ExceptionCallBack;
+import com.ruoyi.device.camera.service.impl.AsyncLogin;
import com.ruoyi.media.domain.Vtdu;
import com.ruoyi.media.service.IVtduService;
import com.ruoyi.utils.gis.GisUtil;
@@ -22,13 +21,11 @@
import com.ruoyi.device.hiksdk.service.IHikClientService;
import com.ruoyi.device.hiksdk.sdk.LoginResultCallBack;
import com.ruoyi.utils.minio.MinioUtil;
-import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.Platform;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.Base64;
@@ -40,7 +37,6 @@
import java.util.*;
import java.util.concurrent.PriorityBlockingQueue;
-import static com.ruoyi.device.hiksdk.common.GlobalVariable.loginCameraMap;
import static com.ruoyi.device.hiksdk.sdk.HCNetSDK.*;
/**
@@ -243,28 +239,6 @@
}
- /**
- * @鎻忚堪 鐧诲綍鎵�鏈夌浉鏈�
- * @鍙傛暟 []
- * @杩斿洖鍊� void
- * @鍒涘缓浜� 鍒樿嫃涔�
- * @鍒涘缓鏃堕棿 2023/2/3 10:10
- * @淇敼浜哄拰鍏跺畠淇℃伅
- */
- @Override
- public void loginAll() {
- try {
- ArdCameras ardCamera = new ArdCameras();
- ardCamera.setFactory("1");
- List<ArdCameras> ardCameras = ardCamerasService.selectArdCamerasListNoDataScope(ardCamera);
- for (ArdCameras camera : ardCameras) {
- //鐧诲綍
- login(camera);
- }
- } catch (Exception ex) {
- log.error("鍒濆鍖栫櫥褰曠浉鏈哄紓甯革細" + ex.getMessage());
- }
- }
/**
* @鎻忚堪 娉ㄩ攢鐧诲綍
@@ -318,6 +292,7 @@
* @淇敼浜哄拰鍏跺畠淇℃伅
*/
@Override
+ @SdkOperate
public boolean pTZControlWithSpeed(CameraCmd cmd) {
String cameraId = cmd.getCameraId();
boolean enable = cmd.isEnable();
@@ -1068,7 +1043,6 @@
* @淇敼浜哄拰鍏跺畠淇℃伅
*/
@Override
- @SdkOperate
public boolean controlDefogcfg(CameraCmd cmd) {
String cameraId = cmd.getCameraId();
boolean enable = cmd.isEnable();
@@ -1114,7 +1088,6 @@
* @淇敼浜哄拰鍏跺畠淇℃伅
*/
@Override
- @SdkOperate
public boolean controlInfrarecfg(CameraCmd cmd) {
String cameraId = cmd.getCameraId();
boolean enable = cmd.isEnable();
@@ -1162,7 +1135,6 @@
* @淇敼浜哄拰鍏跺畠淇℃伅
*/
@Override
- @SdkOperate
public boolean controlFocusMode(CameraCmd cmd) {
String cameraId = cmd.getCameraId();
boolean enable = cmd.isEnable();
@@ -1235,7 +1207,6 @@
* @淇敼浜哄拰鍏跺畠淇℃伅
*/
@Override
- @SdkOperate
public boolean controlPTHeateRpwron(CameraCmd cmd) {
String cameraId = cmd.getCameraId();
boolean enable = cmd.isEnable();
@@ -1268,7 +1239,6 @@
* @淇敼浜哄拰鍏跺畠淇℃伅
*/
@Override
- @SdkOperate
public boolean controlCameraDeicing(CameraCmd cmd) {
String cameraId = cmd.getCameraId();
boolean enable = cmd.isEnable();
@@ -1349,7 +1319,6 @@
* @淇敼浜哄拰鍏跺畠淇℃伅
*/
@Override
- @SdkOperate
public String picCutCate(CameraCmd cmd) {
String cameraId = cmd.getCameraId();
Integer channelNum = cmd.getChanNo();
--
Gitblit v1.9.3