| | |
| | | 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业务层处理 |
| | |
| | | */ |
| | | @Service |
| | | public class ArdChannelServiceImpl implements IArdChannelService { |
| | | @Autowired |
| | | @Resource |
| | | private ArdChannelMapper ardChannelMapper; |
| | | |
| | | @Resource |
| | | private IVtduService vtduService; |
| | | /** |
| | | * 查询通道管理 |
| | | * |
| | |
| | | */ |
| | | @Override |
| | | public int insertArdChannel(ArdChannel ardChannel) { |
| | | ardChannel.setId(IdUtils.simpleUUID()); |
| | | return ardChannelMapper.insertArdChannel(ardChannel); |
| | | ardChannel.setId(IdUtils.simpleUUID()); |
| | | return ardChannelMapper.insertArdChannel(ardChannel); |
| | | } |
| | | |
| | | /** |
| | |
| | | public int deleteArdChannelById(String id) { |
| | | return ardChannelMapper.deleteArdChannelById(id); |
| | | } |
| | | |
| | | /** |
| | | * 清空通道 |
| | | * |
| | | * @author 刘苏义 |
| | | * @date 2024/8/10 11:18 |
| | | */ |
| | | @Override |
| | | public int clearArdChannel(){ |
| | | return ardChannelMapper.clearArdChannel(); |
| | | } |
| | | /** |
| | | * 删除通道管理信息 |
| | | * |
| | |
| | | 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); |
| | | }); |
| | | } |
| | | } |