From 4a293865ac437a812eea8800cc0b04314efbd210 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期二, 24 十月 2023 10:06:24 +0800
Subject: [PATCH] 异步登录增加延迟时间避免接口频繁 修改大华通道数量获取
---
ard-work/src/main/java/com/ruoyi/device/camera/service/impl/CameraSdkServiceImpl.java | 5
ard-work/src/main/java/com/ruoyi/device/dhsdk/module/ConfigModule.java | 19 ++--
ard-work/src/main/java/com/ruoyi/device/dhsdk/module/LoginModule.java | 10 +-
ard-work/src/main/java/com/ruoyi/utils/forest/MediaClient.java | 2
ard-work/src/main/java/com/ruoyi/media/service/impl/VtduServiceImpl.java | 2
ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java | 5 +
ard-work/src/main/java/com/ruoyi/device/camera/service/impl/AsyncLogin.java | 5 +
ard-work/src/main/java/com/ruoyi/device/dhsdk/service/impl/DhClientServiceImpl.java | 127 ++++++++++++++++---------------
ard-work/src/main/java/com/ruoyi/inspect/service/impl/ArdVideoInspectTaskServiceImpl.java | 1
ard-work/src/main/java/com/ruoyi/device/camera/controller/CameraSdkController.java | 6 -
10 files changed, 95 insertions(+), 87 deletions(-)
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 65c6d73..6165144 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,12 +64,6 @@
private IArdCamerasService ardCamerasService;
-// //鍒濆鐧诲綍鎵�鏈夌浉鏈�
-// @PostConstruct
-// public void initLoginAll() {
-// cameraSdkService.loginAll();
-// }
-
@RequestMapping("/preview")
private String preview() {
return "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
index ed8f337..c6ce8c1 100644
--- 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
@@ -1,5 +1,6 @@
package com.ruoyi.device.camera.service.impl;
+import com.ruoyi.common.utils.Threads;
import com.ruoyi.device.camera.domain.ArdCameras;
import com.ruoyi.device.dhsdk.service.IDhClientService;
import com.ruoyi.device.hiksdk.service.IHikClientService;
@@ -10,7 +11,7 @@
import javax.annotation.Resource;
/**
- * @ClassName test
+ * @ClassName 寮傛鐧诲綍
* @Description:
* @Author 鍒樿嫃涔�
* @Date 2023/10/23 21:39
@@ -26,11 +27,13 @@
@Async
public void hikLogin(ArdCameras ardCameras) {
+ Threads.sleep(200);
hikClientService.login(ardCameras);
}
@Async
public void dhLogin(ArdCameras ardCameras) {
+ Threads.sleep(200);
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 6203512..2e4f73d 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
@@ -69,10 +69,11 @@
if (ardCamera != null) {
String factory = ardCamera.getFactory();
if (factory.equals("1")) {
- hikClientService.login(ardCamera);
+ asyncLogin.hikLogin(ardCamera);
result = true;
} else if (factory.equals("2")) {
- result = dhClientService.login(ardCamera);
+ asyncLogin.dhLogin(ardCamera);
+ result = true;
}
}
} catch (Exception ex) {
diff --git a/ard-work/src/main/java/com/ruoyi/device/dhsdk/module/ConfigModule.java b/ard-work/src/main/java/com/ruoyi/device/dhsdk/module/ConfigModule.java
index 9d9d17a..587adef 100644
--- a/ard-work/src/main/java/com/ruoyi/device/dhsdk/module/ConfigModule.java
+++ b/ard-work/src/main/java/com/ruoyi/device/dhsdk/module/ConfigModule.java
@@ -69,11 +69,11 @@
cmdObject.read();
result = true;
} else {
- log.error("Parse " + strCmd + " Config Failed!" + ToolKits.getErrorCodePrint());
+ log.error("Parse [" + strCmd + "] Config Failed!" + ToolKits.getErrorCodePrint());
result = false;
}
} else {
- log.error("Get %s Config Failed!Last Error = %s\n", strCmd, getErrorCodePrint());
+ log.error("Get [" + strCmd + "] Config Failed!Last Error = " + getErrorCodePrint());
result = false;
}
@@ -90,25 +90,27 @@
if (bRet) {
cmdObject.read();
} else {
- log.error("Get %s Config Failed!Last Error = %s\n", strCmd, getErrorCodePrint());
+ log.error("Get ["+strCmd+"] Config Failed!Last Error = " + getErrorCodePrint());
result = false;
}
return result;
}
+
// 鑾峰彇閰嶇疆
- public static boolean GetConfig(NetSDKLib.LLong hLoginHandle, int nChn,int type,Structure cmdObject) {
+ public static boolean GetConfig(NetSDKLib.LLong hLoginHandle, int nChn, int type, Structure cmdObject) {
boolean result = false;
// 鑾峰彇
cmdObject.write();
if (netsdk.CLIENT_GetConfig(hLoginHandle, type, nChn, cmdObject.getPointer(), cmdObject.size(), 4000, null)) {
cmdObject.read();
- result=true;
+ result = true;
} else {
log.error("GetConfig Failed!" + getErrorCodePrint());
- result=false;
+ result = false;
}
return result;
}
+
/**
* 璁剧疆鍗曚釜閰嶇疆
*
@@ -131,11 +133,12 @@
if (netsdk.CLIENT_SetNewDevConfig(hLoginHandle, strCmd, nChn, szBuffer, nBufferLen, error, restart, 3000)) {
result = true;
} else {
- log.error("Set %s Config Failed! Last Error = %s\n", strCmd, getErrorCodePrint());
+ log.error("Set [" + strCmd + "] Config Failed! Last Error = " + getErrorCodePrint());
+
result = false;
}
} else {
- log.error("Packet " + strCmd + " Config Failed!" + getErrorCodePrint());
+ log.error("Parse [" + strCmd + "] Config Failed!" + ToolKits.getErrorCodePrint());
result = false;
}
diff --git a/ard-work/src/main/java/com/ruoyi/device/dhsdk/module/LoginModule.java b/ard-work/src/main/java/com/ruoyi/device/dhsdk/module/LoginModule.java
index 3ff2550..73e5d65 100644
--- a/ard-work/src/main/java/com/ruoyi/device/dhsdk/module/LoginModule.java
+++ b/ard-work/src/main/java/com/ruoyi/device/dhsdk/module/LoginModule.java
@@ -18,7 +18,7 @@
public static NetSDKLib netsdk = NetSDKLib.NETSDK_INSTANCE;
// 璁惧淇℃伅
- public static NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex();
+ // public static NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex();
// 鐧婚檰鍙ユ焺
public static LLong m_hLoginHandle = new LLong(0);//
@@ -66,7 +66,6 @@
int tryTimes = 1; //鐧诲綍鏃跺皾璇曞缓绔嬮摼鎺�1娆�
netsdk.CLIENT_SetConnectTime(waitTime, tryTimes);
-
// 璁剧疆鏇村缃戠粶鍙傛暟锛孨ET_PARAM鐨刵Waittime锛宯ConnectTryNum鎴愬憳涓嶤LIENT_SetConnectTime
// 鎺ュ彛璁剧疆鐨勭櫥褰曡澶囪秴鏃舵椂闂村拰灏濊瘯娆℃暟鎰忎箟鐩稿悓,鍙��
NetSDKLib.NET_PARAM netParam = new NetSDKLib.NET_PARAM();
@@ -102,7 +101,7 @@
* 鐧诲綍璁惧
* \endif
*/
- public static LLong login(String m_strIp, int m_nPort, String m_strUser, String m_strPassword) {
+ public static LLong login(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, NetSDKLib.NET_DEVICEINFO_Ex lpDeviceInfo) {
IntByReference nError = new IntByReference(0);
//鍏ュ弬
NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY pstInParam = new NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY();
@@ -111,9 +110,8 @@
pstInParam.szPassword = m_strPassword.getBytes();
pstInParam.szUserName = m_strUser.getBytes();
//鍑哄弬
- NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY pstOutParam = new NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY();
- pstOutParam.stuDeviceInfo = m_stDeviceInfo;
- LLong m_hLoginHandle = netsdk.CLIENT_LoginEx2(m_strIp, m_nPort, m_strUser, m_strPassword, 0, null, m_stDeviceInfo, nError);
+ //NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY pstOutParam = new NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY();
+ LLong m_hLoginHandle = netsdk.CLIENT_LoginEx2(m_strIp, m_nPort, m_strUser, m_strPassword, 0, null, lpDeviceInfo, nError);
//m_hLoginHandle=netsdk.CLIENT_LoginWithHighLevelSecurity(pstInParam, pstOutParam);
if (m_hLoginHandle.longValue() == 0) {
log.debug("Login Device[%s] Port[%d]Failed. %s\n", m_strIp, m_nPort, getErrorCodePrint());
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 4fcaf12..1a41ec9 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
@@ -74,7 +74,8 @@
@Override
public Boolean login(ArdCameras camera) {
LoginModule.init(disConnect, haveReConnect);
- LLong loginId = LoginModule.login(camera.getIp(), camera.getPort(), camera.getUsername(), camera.getPassword());
+ NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex();
+ LLong loginId = LoginModule.login(camera.getIp(), camera.getPort(), camera.getUsername(), camera.getPassword(), m_stDeviceInfo);
if (loginId.longValue() > 0) {
//log.debug(camera.getIp() + ":" + camera.getPort() + "鐧诲綍鎴愬姛");
if (GlobalVariable.loginMap.containsKey(camera.getId())) {
@@ -83,13 +84,14 @@
//鍒犻櫎绠$悊閫氶亾
ardChannelService.deleteArdChannelByDeviceId(camera.getId());
camera.setState("1");
- camera.setChanNum(LoginModule.m_stDeviceInfo.byChanNum);
+ camera.setChanNum(m_stDeviceInfo.byChanNum);
camera.setStartDChan(1);
camera.setLoginId((int) loginId.longValue());
ardCamerasService.updateArdCameras(camera);
GlobalVariable.loginMap.put(camera.getId(), loginId);
+
//鑾峰彇鏈�鏂伴�氶亾
- for (int i = 1; i < LoginModule.m_stDeviceInfo.byChanNum + 1; i++) {
+ for (int i = 1; i < m_stDeviceInfo.byChanNum + 1; i++) {
ArdChannel channel = new ArdChannel();
AV_CFG_ChannelName av_cfg_channelName = new AV_CFG_ChannelName();
boolean b = ConfigModule.GetNewDevConfig(loginId, i - 1, CFG_CMD_CHANNELTITLE, av_cfg_channelName);
@@ -115,7 +117,6 @@
if (vtdu != null) {
vtduService.deleteVtduByName(name);
}
-
//娣诲姞鍒版祦濯掍綋
CameraCmd cmd = new CameraCmd(camera.getId(), channel.getChanNo());
Map<String, Object> videoCompressionCfg = getVideoCompressionCfg(cmd);
@@ -792,62 +793,66 @@
@Override
public Map<String, Object> getVideoCompressionCfg(CameraCmd cmd) {
Map<String, Object> map = new HashMap<>();
- String cameraId = cmd.getCameraId();
- Integer chanNo = cmd.getChanNo();
- if (!GlobalVariable.loginMap.containsKey(cameraId)) {
- return null;
- }
- LLong loginId = (LLong) GlobalVariable.loginMap.get(cameraId);
- CFG_ENCODE_INFO cfg_encode_info = new CFG_ENCODE_INFO();
- cfg_encode_info.nChannelID = chanNo - 1;
- boolean b = ConfigModule.GetNewDevConfig(loginId, chanNo - 1, CFG_CMD_ENCODE, cfg_encode_info);
- if (b) {
- int emCompression = cfg_encode_info.stuMainStream[0].stuVideoFormat.emCompression;//瑙嗛鏍煎紡
- String videoEncType = "";
- switch (emCompression) {
- case 0:
- videoEncType = "MPEG4";
- break;
- case 1:
- videoEncType = "MS-MPEG4";
- break;
- case 2:
- videoEncType = "MPEG2";
- break;
- case 3:
- videoEncType = "MPEG1";
- break;
- case 4:
- videoEncType = "H.263";
- break;
- case 5:
- videoEncType = "MJPG";
- break;
- case 6:
- videoEncType = "FCC-MPEG4";
- break;
- case 7:
- videoEncType = "鏍囧噯h264";
- break;
- case 8:
- videoEncType = "鏍囧噯h265";
- break;
- case 9:
- videoEncType = "SVAC";
- break;
- default:
- videoEncType = "鏈煡";
- break;
+ try {
+ String cameraId = cmd.getCameraId();
+ Integer chanNo = cmd.getChanNo();
+ if (!GlobalVariable.loginMap.containsKey(cameraId)) {
+ return null;
}
- int nBitRate = cfg_encode_info.stuMainStream[0].stuVideoFormat.nBitRate;
- int nWidth = cfg_encode_info.stuMainStream[0].stuVideoFormat.nWidth;
- int nHeight = cfg_encode_info.stuMainStream[0].stuVideoFormat.nHeight;
- String resolution = nWidth + "*" + nHeight;
- float nFrameRate = cfg_encode_info.stuMainStream[0].stuVideoFormat.nFrameRate;
- map.put("resolution", resolution);//鍒嗚鲸鐜�
- map.put("videoBitrate", String.valueOf(nBitRate));//姣旂壒鐜�
- map.put("videoEncType", videoEncType);//缂栫爜
- map.put("nFrameRate", String.valueOf(nFrameRate));//甯х巼
+ LLong loginId = (LLong) GlobalVariable.loginMap.get(cameraId);
+ CFG_ENCODE_INFO cfg_encode_info = new CFG_ENCODE_INFO();
+ cfg_encode_info.nChannelID = chanNo - 1;
+ boolean b = ConfigModule.GetNewDevConfig(loginId, chanNo - 1, CFG_CMD_ENCODE, cfg_encode_info);
+ if (b) {
+ int emCompression = cfg_encode_info.stuMainStream[0].stuVideoFormat.emCompression;//瑙嗛鏍煎紡
+ String videoEncType = "";
+ switch (emCompression) {
+ case 0:
+ videoEncType = "MPEG4";
+ break;
+ case 1:
+ videoEncType = "MS-MPEG4";
+ break;
+ case 2:
+ videoEncType = "MPEG2";
+ break;
+ case 3:
+ videoEncType = "MPEG1";
+ break;
+ case 4:
+ videoEncType = "H.263";
+ break;
+ case 5:
+ videoEncType = "MJPG";
+ break;
+ case 6:
+ videoEncType = "FCC-MPEG4";
+ break;
+ case 7:
+ videoEncType = "鏍囧噯h264";
+ break;
+ case 8:
+ videoEncType = "鏍囧噯h265";
+ break;
+ case 9:
+ videoEncType = "SVAC";
+ break;
+ default:
+ videoEncType = "鏈煡";
+ break;
+ }
+ int nBitRate = cfg_encode_info.stuMainStream[0].stuVideoFormat.nBitRate;
+ int nWidth = cfg_encode_info.stuMainStream[0].stuVideoFormat.nWidth;
+ int nHeight = cfg_encode_info.stuMainStream[0].stuVideoFormat.nHeight;
+ String resolution = nWidth + "*" + nHeight;
+ float nFrameRate = cfg_encode_info.stuMainStream[0].stuVideoFormat.nFrameRate;
+ map.put("resolution", resolution);//鍒嗚鲸鐜�
+ map.put("videoBitrate", String.valueOf(nBitRate));//姣旂壒鐜�
+ map.put("videoEncType", videoEncType);//缂栫爜
+ map.put("nFrameRate", String.valueOf(nFrameRate));//甯х巼
+ }
+ } catch (Exception ex) {
+ log.error("鍙栫爜娴佸帇缂╁弬鏁板紓甯�:" + ex.getMessage());
}
return map;
}
@@ -881,7 +886,7 @@
// 璁惧鏂嚎鍥炶皟: 褰撹澶囧嚭鐜版柇绾挎椂锛孲DK浼氳皟鐢ㄨ鍑芥暟
private static class DisConnect implements NetSDKLib.fDisConnect {
public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) {
- log.warn("Device["+pchDVRIP+"] Port["+nDVRPort+"] DisConnect!");
+ log.warn("Device[" + pchDVRIP + "] Port[" + nDVRPort + "] DisConnect!");
}
}
@@ -889,7 +894,7 @@
private static class HaveReConnect implements NetSDKLib.fHaveReConnect {
@Override
public void invoke(LLong lLoginID, String pchDVRIP, int nDVRPort, Pointer dwUser) {
- log.warn("ReConnect Device["+pchDVRIP+"] Port["+nDVRPort+"]");
+ log.warn("ReConnect Device[" + pchDVRIP + "] Port[" + nDVRPort + "]");
}
}
diff --git a/ard-work/src/main/java/com/ruoyi/inspect/service/impl/ArdVideoInspectTaskServiceImpl.java b/ard-work/src/main/java/com/ruoyi/inspect/service/impl/ArdVideoInspectTaskServiceImpl.java
index 88f2431..49757d6 100644
--- a/ard-work/src/main/java/com/ruoyi/inspect/service/impl/ArdVideoInspectTaskServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/inspect/service/impl/ArdVideoInspectTaskServiceImpl.java
@@ -184,6 +184,7 @@
for (ArdVideoInspectTaskStep ardVideoInspectTaskStep : ardVideoInspectTaskStepList) {
if (ardVideoInspectTaskStep.getId() == null) {
//鏂扮殑姝ラ,娣诲姞
+ ardVideoInspectTaskStep.setId(IdUtils.simpleUUID());
ardVideoInspectTaskStepMapper.insertArdVideoInspectTaskStep(ardVideoInspectTaskStep);
} else {
//宸叉湁姝ラ,鏇存柊
diff --git a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java
index 946ea51..81be80e 100644
--- a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java
@@ -463,7 +463,10 @@
for (Items item : items) {
nameList.add(item.getName());
}
- } catch (ForestRuntimeException ex) {
+ }catch (ForestNetworkException ex) {
+ log.error("鑾峰彇娴佸獟浣搉ame鍒楄〃寮傚父锛�"+ex.getMessage());
+ }
+ catch (ForestRuntimeException ex) {
log.error("鑾峰彇娴佸獟浣搉ame鍒楄〃寮傚父锛�"+ex.getMessage());
}
return nameList;
diff --git a/ard-work/src/main/java/com/ruoyi/media/service/impl/VtduServiceImpl.java b/ard-work/src/main/java/com/ruoyi/media/service/impl/VtduServiceImpl.java
index ee991af..b75ba69 100644
--- a/ard-work/src/main/java/com/ruoyi/media/service/impl/VtduServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/media/service/impl/VtduServiceImpl.java
@@ -117,8 +117,8 @@
*/
@Override
public int deleteVtduByName(String name) {
- log.debug("娴佸獟浣撱��" + name + "銆戦�氶亾鍒犻櫎");
mediaService.removePath(name);
+ log.debug("娴佸獟浣撱��" + name + "銆戦�氶亾鍒犻櫎");
return vtduMapper.deleteVtduByName(name);
}
diff --git a/ard-work/src/main/java/com/ruoyi/utils/forest/MediaClient.java b/ard-work/src/main/java/com/ruoyi/utils/forest/MediaClient.java
index 392e2fc..b5266a7 100644
--- a/ard-work/src/main/java/com/ruoyi/utils/forest/MediaClient.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/forest/MediaClient.java
@@ -17,7 +17,7 @@
/**
* 澧炲姞璺緞
*/
- @Post(url = "/config/paths/add/{name}")
+ @Post(url = "/config/paths/add/{name}",async = true)
public String addPath(@Var("name") String name, @JSONBody Conf body);
/**
--
Gitblit v1.9.3