From 08b6a55a3a111aaee9842999b85afa60b6d61dc3 Mon Sep 17 00:00:00 2001
From: houzhongjian <houzhongyi@126.com>
Date: 星期四, 14 十一月 2024 15:29:38 +0800
Subject: [PATCH] 大华及海康摄像头截图功能开发

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/video/service/impl/CameraServiceImpl.java |   44 +++++++++++++++++++++++++++++++++-----------
 1 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/video/service/impl/CameraServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/video/service/impl/CameraServiceImpl.java
index 5084c84..cd8f26a 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/video/service/impl/CameraServiceImpl.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/video/service/impl/CameraServiceImpl.java
@@ -10,8 +10,7 @@
 import com.iailab.framework.web.core.util.WebFrameworkUtils;
 import com.iailab.module.data.mq.consumer.ImageMessage;
 import com.iailab.module.data.video.controller.admin.camera.vo.CameraPageReqVO;
-import com.iailab.module.data.video.dahua.DHConfiguration;
-import com.iailab.module.data.video.dahua.DHSavePath;
+import com.iailab.module.data.video.config.VideoConfiguration;
 import com.iailab.module.data.video.dao.CameraDao;
 import com.iailab.module.data.video.dao.ImageDao;
 import com.iailab.module.data.video.dto.CameraDTO;
@@ -21,6 +20,7 @@
 import com.iailab.module.data.video.service.CameraService;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -36,6 +36,9 @@
  */
 @Service
 public class CameraServiceImpl extends BaseServiceImpl<CameraDao, CameraEntity> implements CameraService {
+
+    @Value("${video.capture-dir}")
+    public String captureDir;
 
     @Resource
     private CameraDao cameraDao;
@@ -94,20 +97,40 @@
     public void dealCapture(Map<String, String> params) {
         Calendar calendar = Calendar.getInstance();
         calendar.set(Calendar.MILLISECOND, 0);
-        calendar.set(Calendar.SECOND, 0);
         Date captureDate = calendar.getTime();
         CameraDTO devCamera = getByCode(params.get("cmdSerial"));
         String strFileName = params.get("strFileName");
+        String brand = params.get("brand");
+        String capturePath = "";
+        String routingKey = "";
+        switch (brand) {
+            case "DH":
+                capturePath = VideoConfiguration.staticDhCapturePath;
+                routingKey = ImageMessage.DAHUA_ROUTING_KEY;
+                break;
+            case "HK":
+                capturePath = VideoConfiguration.staticHkCapturePath;
+                routingKey = ImageMessage.HIKVISION_ROUTING_KEY;
+                break;
+        }
         String imagePath = strFileName.replace("\\", "/");
-        String imageUrl = imagePath.replace(DHConfiguration.staticCapturePath, "");
+        String imageUrl = imagePath.replace(capturePath, "");
         ImageEntity image = new ImageEntity();
         image.setCameraId(devCamera.getId());
         image.setImagePath(imagePath);
-        image.setImageUrl("/Capture/" + imageUrl);
+        image.setImageUrl(capturePath.replace(captureDir, "") + imageUrl);
         image.setCreateDate(captureDate);
         imageDao.insert(image);
         //存入rabbitmq消息队列,等待模型处理
-        sendRabbitMQMessage(image);
+        sendRabbitMQMessage(image, routingKey);
+    }
+
+    @Override
+    public void setStatus(String id, Integer status) {
+        CameraEntity cameraEntity = new CameraEntity();
+        cameraEntity.setId(id);
+        cameraEntity.setStatus(status);
+        baseDao.updateById(cameraEntity);
     }
 
     private QueryWrapper<CameraEntity> getWrapper(CameraPageReqVO cameraPageReqVO){
@@ -136,8 +159,8 @@
 
     @Override
     @DSTransactional(rollbackFor = Exception.class)
-    public void delete(String[] ids) {
-        baseDao.deleteBatchIds(Arrays.asList(ids));
+    public void delete(String id) {
+        baseDao.deleteById(id);
     }
 
     @Override
@@ -151,14 +174,13 @@
     }
 
     // 发送rabbitMQ消息
-    private void sendRabbitMQMessage(ImageEntity image) {
+    private void sendRabbitMQMessage(ImageEntity image, String routingKey) {
         String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
         ImageMessage imageMessage = new ImageMessage();
         imageMessage.setMessageId(image.getId());
         imageMessage.setCreateTime(createTime);
         imageMessage.setImageDTO(BeanUtils.toBean(image, ImageDTO.class));
-        rabbitTemplate.convertAndSend(ImageMessage.EXCHANGE, ImageMessage.DAHUA_ROUTING_KEY, imageMessage);
-        rabbitTemplate.convertAndSend(ImageMessage.EXCHANGE, ImageMessage.HIKVISION_ROUTING_KEY, imageMessage);
+        rabbitTemplate.convertAndSend(ImageMessage.EXCHANGE, routingKey, imageMessage);
     }
 
 }
\ No newline at end of file

--
Gitblit v1.9.3