From acdb4a206f64cc7b39cee05d77bbc4e98258c27b Mon Sep 17 00:00:00 2001
From: liusuyi <13324259@qq.com>
Date: 星期二, 24 十月 2023 21:50:48 +0800
Subject: [PATCH] 相机校验是否唯一
---
ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java | 13 ++++--
ard-work/src/main/java/com/ruoyi/device/camera/service/IArdCamerasService.java | 10 ++++
ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java | 9 ++--
ard-work/src/main/java/com/ruoyi/device/camera/mapper/ArdCamerasMapper.java | 14 +++++-
ard-work/src/main/java/com/ruoyi/media/controller/VtduController.java | 11 +++--
ruoyi-common/src/main/java/com/ruoyi/common/constant/CameraConstants.java | 15 +++++++
ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java | 24 +++++++++--
ard-work/src/main/resources/mapper/device/ArdCamerasMapper.xml | 3 +
8 files changed, 78 insertions(+), 21 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java b/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java
index afbee07..2ecbd0d 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java
@@ -4,21 +4,18 @@
import javax.servlet.http.HttpServletResponse;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import com.ruoyi.common.constant.CameraConstants;
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.camera.service.impl.CameraSdkServiceImpl;
import com.ruoyi.device.dhsdk.service.IDhClientService;
import com.ruoyi.device.hiksdk.service.IHikClientService;
-import com.ruoyi.device.hiksdk.service.impl.HikClientServiceImpl;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.inspect.service.IArdVideoInspectTaskService;
-import com.ruoyi.media.service.IVtduService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@@ -101,6 +98,10 @@
@Log(title = "鐩告満璁惧", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody ArdCameras camera) {
+ if (CameraConstants.NOT_UNIQUE.equals(ardCamerasService.checkCameraIpAndPortUnique(camera)))
+ {
+ return error("鏂板鐩告満'" + camera.getIp()+":"+camera.getPort() + "'澶辫触锛岀浉鏈哄凡瀛樺湪");
+ }
int i = ardCamerasService.insertArdCameras(camera);
if (i > 0) {
cameraSdkService.logout(camera.getId());
@@ -117,6 +118,10 @@
@Log(title = "鐩告満璁惧", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody ArdCameras camera) {
+ if (CameraConstants.NOT_UNIQUE.equals(ardCamerasService.checkCameraIpAndPortUnique(camera)))
+ {
+ return error("淇敼鐩告満'" + camera.getIp()+":"+camera.getPort() + "'澶辫触锛岀浉鏈哄凡瀛樺湪");
+ }
int i = ardCamerasService.updateArdCameras(camera);
if (i > 0) {
cameraSdkService.logout(camera.getId());
diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/mapper/ArdCamerasMapper.java b/ard-work/src/main/java/com/ruoyi/device/camera/mapper/ArdCamerasMapper.java
index 4f931ff..81e6a6d 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/mapper/ArdCamerasMapper.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/mapper/ArdCamerasMapper.java
@@ -1,11 +1,10 @@
package com.ruoyi.device.camera.mapper;
import java.util.List;
-
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.ruoyi.common.annotation.DataScope;
-import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.device.camera.domain.ArdCameras;
+import org.apache.ibatis.annotations.Param;
+
/**
* 鐩告満璁惧Mapper鎺ュ彛
@@ -77,4 +76,13 @@
* @return 閮ㄩ棬鍒楄〃
*/
public List<ArdCameras> selectArdCamerasByDeptId(Long deptId);
+
+ /**
+ * 鏍¢獙鐩告満鏄惁鍞竴
+ *
+ * @param ip 鐩告満ip
+ * @param port 鐩告満绔彛
+ * @return 鐩告満淇℃伅
+ */
+ public ArdCameras checkCameraIpAndPortUnique(@Param("ip") String ip, @Param("port")Integer port);
}
diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/service/IArdCamerasService.java b/ard-work/src/main/java/com/ruoyi/device/camera/service/IArdCamerasService.java
index c51ff05..b36ac59 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/service/IArdCamerasService.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/service/IArdCamerasService.java
@@ -1,6 +1,6 @@
package com.ruoyi.device.camera.service;
-import java.util.HashMap;
+
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -97,4 +97,12 @@
* 2023/8/17 13:56:36
*/
public List<ArdCameras> getNearCamerasWithPolygon(SchedulingParam param);
+
+ /**
+ * 鏍¢獙鐩告満鏄惁鍞竴
+ *
+ * @param camera 鐩告満
+ * @return 缁撴灉
+ */
+ public String checkCameraIpAndPortUnique(ArdCameras camera);
}
diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
index 99c36f5..1ef2e1a 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
@@ -4,17 +4,16 @@
import java.util.stream.Collectors;
import com.ruoyi.common.constant.CacheConstants;
+import com.ruoyi.common.constant.CameraConstants;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.device.camera.domain.CameraCmd;
import com.ruoyi.device.channel.domain.ArdChannel;
import com.ruoyi.device.channel.mapper.ArdChannelMapper;
-import com.ruoyi.device.hiksdk.service.IHikClientService;
-import com.ruoyi.media.domain.Vtdu;
-import com.ruoyi.media.service.IMediaService;
import com.ruoyi.media.service.IVtduService;
import com.ruoyi.scheduling.domian.SchedulingParam;
import com.ruoyi.utils.gis.GisUtil;
@@ -51,8 +50,6 @@
private ArdChannelMapper ardChannelMapper;
@Resource
private IVtduService vtduService;
- @Resource
- private IMediaService mediaService;
@PostConstruct
@@ -425,4 +422,21 @@
return null;
}
+ /**
+ * 鏍¢獙鐩告満鏄惁鍞竴
+ *
+ * @param camera 鐩告満
+ * @return 缁撴灉
+ */
+ @Override
+ public String checkCameraIpAndPortUnique(ArdCameras camera) {
+ String id = camera.getId();
+ String ip = camera.getIp();
+ Integer port = camera.getPort();
+ ArdCameras info = ardCamerasMapper.checkCameraIpAndPortUnique(ip, port);
+ if (StringUtils.isNotNull(info) && !info.getId().equals(id)) {
+ return CameraConstants.NOT_UNIQUE;
+ }
+ return CameraConstants.UNIQUE;
+ }
}
diff --git a/ard-work/src/main/java/com/ruoyi/media/controller/VtduController.java b/ard-work/src/main/java/com/ruoyi/media/controller/VtduController.java
index 34c87bd..1f8dd23 100644
--- a/ard-work/src/main/java/com/ruoyi/media/controller/VtduController.java
+++ b/ard-work/src/main/java/com/ruoyi/media/controller/VtduController.java
@@ -9,6 +9,7 @@
import com.ruoyi.device.camera.domain.CameraCmd;
import com.ruoyi.device.camera.service.ICameraSdkService;
import com.ruoyi.media.service.IMediaService;
+import com.ruoyi.media.service.impl.MediaServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -80,10 +81,12 @@
CameraCmd cmd = new CameraCmd(cameraId, chanNo);
Map<String, Object> videoCompressionCfg = cameraSdkService.getVideoCompressionCfg(cmd);
String videoEncType = (String) videoCompressionCfg.get("videoEncType");
- if (!videoEncType.equals("鏍囧噯h264")) {
- vtdu.setIsCode("1");
- } else {
- vtdu.setIsCode("0");
+ if (videoEncType != null) {
+ if (!videoEncType.equals("鏍囧噯h264")) {
+ vtdu.setIsCode("1");
+ } else {
+ vtdu.setIsCode("0");
+ }
}
//娴佸獟浣撲笉瀛樺湪鏂板锛屽瓨鍦ㄦ洿鏂�
if (!mediaService.checkNameExist(name)) {
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 b7242fd..694b3a5 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
@@ -35,7 +35,7 @@
@Slf4j(topic = "vtdu")
@Order(2)
public class MediaServiceImpl implements IMediaService, ApplicationRunner {
- private static List<String> mediaNameList = new ArrayList<>();
+ public static List<String> mediaNameList = new ArrayList<>();
@Resource
MediaClient mediaClient;
@@ -90,6 +90,7 @@
if (!checkNameExist(name)) {
mediaClient.addPath(name, conf);
+ mediaNameList.add(name);
}
map.put("rtspUrl", rtspUrl);
@@ -184,6 +185,7 @@
try {
if (checkNameExist(name)) {
mediaClient.removePath(name);
+ mediaNameList.remove(name);
}
} catch (ForestRuntimeException ex) {
log.error("绉婚櫎娴佸獟浣撳紓甯革細" + ex.getMessage());
@@ -473,20 +475,19 @@
*/
@Override
public List<String> getNameList() {
- List<String> nameList = new ArrayList<>();
try {
String paths = mediaClient.paths();
JsonsRoot jsonsRoot = JSONObject.parseObject(paths, JsonsRoot.class);
List<Items> items = jsonsRoot.getItems();
for (Items item : items) {
- nameList.add(item.getName());
+ mediaNameList.add(item.getName());
}
} catch (ForestNetworkException ex) {
log.error("鑾峰彇娴佸獟浣搉ame鍒楄〃寮傚父锛�" + ex.getMessage());
} catch (ForestRuntimeException ex) {
log.error("鑾峰彇娴佸獟浣搉ame鍒楄〃寮傚父锛�" + ex.getMessage());
}
- return nameList;
+ return mediaNameList;
}
/**
diff --git a/ard-work/src/main/resources/mapper/device/ArdCamerasMapper.xml b/ard-work/src/main/resources/mapper/device/ArdCamerasMapper.xml
index 3a13832..421252d 100644
--- a/ard-work/src/main/resources/mapper/device/ArdCamerasMapper.xml
+++ b/ard-work/src/main/resources/mapper/device/ArdCamerasMapper.xml
@@ -275,4 +275,7 @@
from ard_cameras
where dept_id = #{deptId}
</select>
+ <select id="checkCameraIpAndPortUnique" resultMap="ArdCamerasResult">
+ select * from ard_cameras where ip=#{ip} and port=#{port} limit 1
+ </select>
</mapper>
\ No newline at end of file
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/CameraConstants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/CameraConstants.java
new file mode 100644
index 0000000..e4ec245
--- /dev/null
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/CameraConstants.java
@@ -0,0 +1,15 @@
+package com.ruoyi.common.constant;
+
+/**
+ * 鐩告満甯搁噺淇℃伅
+ *
+ * @author ruoyi
+ */
+public class CameraConstants
+{
+
+ /** 鏍¢獙杩斿洖缁撴灉鐮� */
+ public final static String UNIQUE = "0";
+ public final static String NOT_UNIQUE = "1";
+
+}
--
Gitblit v1.9.3