| | |
| | | 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; |
| | |
| | | public class ArdChannelServiceImpl implements IArdChannelService { |
| | | @Resource |
| | | private ArdChannelMapper ardChannelMapper; |
| | | |
| | | @Resource |
| | | private CameraSDKFactory cameraSDKFactory; |
| | | @Resource |
| | | private IVtduService vtduService; |
| | | /** |
| | | * 查询通道管理 |
| | | * |
| | |
| | | return ardChannelMapper.deleteArdChannelByDeviceId(deviceId); |
| | | } |
| | | |
| | | //求两个对象List的交集 |
| | | @Override |
| | | public List<ArdChannel> sameList(List<ArdChannel> oldArrayList, List<ArdChannel> newArrayList) { |
| | | List<ArdChannel> resultList = newArrayList.stream() |
| | | .filter(item -> oldArrayList.stream().map(e -> e.getChanNo()) |
| | | .collect(Collectors.toList()).contains(item.getChanNo())) |
| | | .collect(Collectors.toList()); |
| | | return resultList; |
| | | } |
| | | 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)); |
| | | |
| | | //求两个对象List的差集 |
| | | @Override |
| | | public List<ArdChannel> diffList(List<ArdChannel> firstArrayList, List<ArdChannel> secondArrayList) { |
| | | List<ArdChannel> resultList = firstArrayList.stream() |
| | | .filter(item -> !secondArrayList.stream().map(e -> e.getChanNo()).collect(Collectors.toList()).contains(item.getChanNo())) |
| | | .collect(Collectors.toList()); |
| | | return resultList; |
| | | } |
| | | // 需要更新的数据 |
| | | 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); |
| | | }); |
| | | |
| | | @Override |
| | | public void asyncChannel(List<ArdChannel> oldArrayList, List<ArdChannel> newArrayList) { |
| | | //需要更新的数据,参数顺序注意 |
| | | sameList(oldArrayList, newArrayList).stream().forEach(ardChannel -> { |
| | | updateArdChannel(ardChannel); |
| | | }); |
| | | //需要删除的数据 |
| | | diffList(oldArrayList, newArrayList).stream().forEach(ardChannel -> { |
| | | deleteArdChannelById(ardChannel.getId()); |
| | | }); |
| | | //需要新增的数据 |
| | | diffList(newArrayList, oldArrayList).stream().forEach(ardChannel -> { |
| | | insertArdChannel(ardChannel); |
| | | }); |
| | | // 需要删除的数据 |
| | | 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); |
| | | }); |
| | | } |
| | | } |