From afa8fc57084c423218c6816b710dfb2f0b87ea89 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期四, 14 十一月 2024 15:55:48 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/video/service/impl/CameraServiceImpl.java |   54 +++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 41 insertions(+), 13 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 a79ee68..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,7 +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.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;
@@ -20,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;
@@ -35,6 +36,9 @@
  */
 @Service
 public class CameraServiceImpl extends BaseServiceImpl<CameraDao, CameraEntity> implements CameraService {
+
+    @Value("${video.capture-dir}")
+    public String captureDir;
 
     @Resource
     private CameraDao cameraDao;
@@ -93,26 +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(DHSavePath.capturePath, "");
+        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消息队列,等待模型处理
-        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.ROUTING_KEY, imageMessage);
-//        rabbitTemplate.convertAndSend("topic.image", imageMap);
+        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){
@@ -141,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
@@ -155,4 +173,14 @@
         return baseDao.selectCount(queryWrapper);
     }
 
+    // 发送rabbitMQ消息
+    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, routingKey, imageMessage);
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.3