liusuyi
2024-08-10 5b017324148ea92d96f9f16ade215463d6c712e5
ard-work/src/main/java/com/ruoyi/device/channel/service/impl/ArdChannelServiceImpl.java
@@ -1,13 +1,18 @@
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 org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.device.camera.domain.ArdCameras;
import com.ruoyi.media.service.IVtduService;
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 +22,10 @@
 */
@Service
public class ArdChannelServiceImpl implements IArdChannelService {
    @Autowired
    @Resource
    private ArdChannelMapper ardChannelMapper;
    @Resource
    private IVtduService vtduService;
    /**
     * 查询通道管理
     *
@@ -50,8 +56,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 +92,17 @@
    public int deleteArdChannelById(String id) {
        return ardChannelMapper.deleteArdChannelById(id);
    }
    /**
     * 清空通道
     *
     * @author 刘苏义
     * @date   2024/8/10 11:18
     */
    @Override
    public int clearArdChannel(){
        return ardChannelMapper.clearArdChannel();
    }
    /**
     * 删除通道管理信息
     *
@@ -96,4 +113,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);
                });
    }
}