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业务层处理 * * @author ard * @date 2023-08-19 */ @Service public class ArdChannelServiceImpl implements IArdChannelService { @Resource private ArdChannelMapper ardChannelMapper; @Resource private CameraSDKFactory cameraSDKFactory; @Resource private IVtduService vtduService; /** * 查询通道管理 * * @param id 通道管理主键 * @return 通道管理 */ @Override public ArdChannel selectArdChannelById(String id) { return ardChannelMapper.selectArdChannelById(id); } /** * 查询通道管理列表 * * @param ardChannel 通道管理 * @return 通道管理 */ @Override public List selectArdChannelList(ArdChannel ardChannel) { return ardChannelMapper.selectArdChannelList(ardChannel); } /** * 新增通道管理 * * @param ardChannel 通道管理 * @return 结果 */ @Override public int insertArdChannel(ArdChannel ardChannel) { ardChannel.setId(IdUtils.simpleUUID()); return ardChannelMapper.insertArdChannel(ardChannel); } /** * 修改通道管理 * * @param ardChannel 通道管理 * @return 结果 */ @Override public int updateArdChannel(ArdChannel ardChannel) { return ardChannelMapper.updateArdChannel(ardChannel); } /** * 批量删除通道管理 * * @param ids 需要删除的通道管理主键 * @return 结果 */ @Override public int deleteArdChannelByIds(String[] ids) { return ardChannelMapper.deleteArdChannelByIds(ids); } /** * 删除通道管理信息 * * @param id 通道管理主键 * @return 结果 */ @Override public int deleteArdChannelById(String id) { return ardChannelMapper.deleteArdChannelById(id); } /** * 删除通道管理信息 * * @param deviceId 所属设备ID * @return 结果 */ @Override public int deleteArdChannelByDeviceId(String deviceId) { return ardChannelMapper.deleteArdChannelByDeviceId(deviceId); } @Override public void asyncChannel(ArdCameras ardCameras,List oldArrayList, List newArrayList) { // 将列表转换为映射以提高性能 Map oldMap = oldArrayList.stream() .collect(Collectors.toMap(ArdChannel::getChanNo, channel -> channel)); Map 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); }); } }