From adc9b922c116463d626d8b7094933278ad89e6df Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 星期六, 20 七月 2024 13:10:25 +0800
Subject: [PATCH] 三一车辆车队查询bug修改提交

---
 ard-work/src/main/java/com/ruoyi/device/channel/service/impl/ArdChannelServiceImpl.java |   61 ++++++++++++++++++++++++++++--
 1 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/device/channel/service/impl/ArdChannelServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/channel/service/impl/ArdChannelServiceImpl.java
index 44ec3b3..c715669 100644
--- a/ard-work/src/main/java/com/ruoyi/device/channel/service/impl/ArdChannelServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/device/channel/service/impl/ArdChannelServiceImpl.java
@@ -1,13 +1,23 @@
 package com.ruoyi.device.channel.service.impl;
 
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 import com.ruoyi.common.utils.uuid.IdUtils;
+import com.ruoyi.device.camera.domain.ArdCameras;
+import com.ruoyi.device.camera.factory.CameraSDK;
+import com.ruoyi.device.camera.factory.CameraSDKFactory;
+import com.ruoyi.device.camera.mapper.ArdCamerasMapper;
+import com.ruoyi.media.mapper.VtduMapper;
+import com.ruoyi.media.service.IVtduService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.device.channel.mapper.ArdChannelMapper;
 import com.ruoyi.device.channel.domain.ArdChannel;
 import com.ruoyi.device.channel.service.IArdChannelService;
+
+import javax.annotation.Resource;
 
 /**
  * 閫氶亾绠$悊Service涓氬姟灞傚鐞�
@@ -17,9 +27,12 @@
  */
 @Service
 public class ArdChannelServiceImpl implements IArdChannelService {
-    @Autowired
+    @Resource
     private ArdChannelMapper ardChannelMapper;
-
+    @Resource
+    private CameraSDKFactory cameraSDKFactory;
+    @Resource
+    private IVtduService vtduService;
     /**
      * 鏌ヨ閫氶亾绠$悊
      *
@@ -50,8 +63,8 @@
      */
     @Override
     public int insertArdChannel(ArdChannel ardChannel) {
-                ardChannel.setId(IdUtils.simpleUUID());
-            return ardChannelMapper.insertArdChannel(ardChannel);
+        ardChannel.setId(IdUtils.simpleUUID());
+        return ardChannelMapper.insertArdChannel(ardChannel);
     }
 
     /**
@@ -86,6 +99,7 @@
     public int deleteArdChannelById(String id) {
         return ardChannelMapper.deleteArdChannelById(id);
     }
+
     /**
      * 鍒犻櫎閫氶亾绠$悊淇℃伅
      *
@@ -96,4 +110,41 @@
     public int deleteArdChannelByDeviceId(String deviceId) {
         return ardChannelMapper.deleteArdChannelByDeviceId(deviceId);
     }
-}
+
+    @Override
+    public void asyncChannel(ArdCameras ardCameras,List<ArdChannel> oldArrayList, List<ArdChannel> newArrayList) {
+        // 灏嗗垪琛ㄨ浆鎹负鏄犲皠浠ユ彁楂樻�ц兘
+        Map<Integer, ArdChannel> oldMap = oldArrayList.stream()
+                .collect(Collectors.toMap(ArdChannel::getChanNo, channel -> channel));
+        Map<Integer, ArdChannel> newMap = newArrayList.stream()
+                .collect(Collectors.toMap(ArdChannel::getChanNo, channel -> channel));
+
+        // 闇�瑕佹洿鏂扮殑鏁版嵁
+        newArrayList.stream()
+                .filter(channel -> {
+                    ArdChannel oldChannel = oldMap.get(channel.getChanNo());
+                    return oldChannel != null && !oldChannel.getName().equals(channel.getName());
+                })
+                .forEach(channel -> {
+                    ArdChannel oldChannel = oldMap.get(channel.getChanNo());
+                    channel.setId(oldChannel.getId());
+                    updateArdChannel(channel);
+                });
+
+        // 闇�瑕佸垹闄ょ殑鏁版嵁
+        oldArrayList.stream()
+                .filter(channel -> !newMap.containsKey(channel.getChanNo()))
+                .forEach(channel -> {
+                    deleteArdChannelById(channel.getId());
+                    vtduService.deleteVtduByName(channel.getDeviceId() + "_" + channel.getChanNo());
+                });
+
+        // 闇�瑕佹柊澧炵殑鏁版嵁
+        newArrayList.stream()
+                .filter(channel -> !oldMap.containsKey(channel.getChanNo()))
+                .forEach(channel -> {
+                    insertArdChannel(channel);
+                    vtduService.addChanToVtdu(ardCameras, channel);
+                });
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3