| | |
| | | |
| | | import java.util.*; |
| | | |
| | | import com.genersoft.iot.vmp.common.PageResult; |
| | | import com.genersoft.iot.vmp.common.StreamInfo; |
| | | import com.genersoft.iot.vmp.conf.MediaServerConfig; |
| | | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| | | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| | | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; |
| | | import com.genersoft.iot.vmp.storager.dao.DeviceMapper; |
| | | import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; |
| | | import com.genersoft.iot.vmp.storager.dao.PatformChannelMapper; |
| | | import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| | | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| | | import com.genersoft.iot.vmp.utils.redis.RedisUtil; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * @Description:视频设备数据存储-jdbc实现 |
| | |
| | | |
| | | @Autowired |
| | | private DeviceChannelMapper deviceChannelMapper; |
| | | |
| | | @Autowired |
| | | private ParentPlatformMapper platformMapper; |
| | | |
| | | @Autowired |
| | | private IRedisCatchStorage redisCatchStorage; |
| | | |
| | | @Autowired |
| | | private PatformChannelMapper patformChannelMapper; |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | * @return true:创建成功 false:创建失败 |
| | | */ |
| | | @Override |
| | | public boolean create(Device device) { |
| | | public synchronized boolean create(Device device) { |
| | | return deviceMapper.add(device) > 0; |
| | | } |
| | | |
| | |
| | | * @return true:更新成功 false:更新失败 |
| | | */ |
| | | @Override |
| | | public boolean updateDevice(Device device) { |
| | | // if (deviceMap.get(device.getDeviceId()) == null) { |
| | | // deviceMap.put(device.getDeviceId(), new HashMap<String, HashSet<String>>()); |
| | | // } |
| | | // 更新device中的通道数量 |
| | | // device.setChannelCount(deviceMap.get(device.getDeviceId()).size()); |
| | | int result = deviceMapper.update(device); |
| | | // 存储device |
| | | return result > 0; |
| | | |
| | | public synchronized boolean updateDevice(Device device) { |
| | | Device deviceByDeviceId = deviceMapper.getDeviceByDeviceId(device.getDeviceId()); |
| | | if (deviceByDeviceId == null) { |
| | | return deviceMapper.add(device) > 0; |
| | | }else { |
| | | return deviceMapper.update(device) > 0; |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void updateChannel(String deviceId, DeviceChannel channel) { |
| | | public synchronized void updateChannel(String deviceId, DeviceChannel channel) { |
| | | String channelId = channel.getChannelId(); |
| | | channel.setDeviceId(deviceId); |
| | | deviceChannelMapper.update(channel); |
| | | DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId); |
| | | if (deviceChannel == null) { |
| | | deviceChannelMapper.add(channel); |
| | | }else { |
| | | deviceChannelMapper.update(channel); |
| | | } |
| | | } |
| | | |
| | | // HashMap<String, HashSet<String>> channelMap = deviceMap.get(deviceId); |
| | | // if (channelMap == null) return; |
| | | // // 作为父设备, 确定自己的子节点数 |
| | | // if (channelMap.get(channelId) == null) { |
| | | // channelMap.put(channelId, new HashSet<String>()); |
| | | // }else if (channelMap.get(channelId).size() > 0) { |
| | | // channel.setSubCount(channelMap.get(channelId).size()); |
| | | // } |
| | | // |
| | | // // 存储通道 |
| | | // redis.set(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + |
| | | // "_" + channel.getChannelId() + |
| | | // "_" + (channel.getStatus() == 1 ? "on":"off") + |
| | | // "_" + (channelMap.get(channelId).size() > 0)+ |
| | | // "_" + (StringUtils.isEmpty(channel.getParentId())?null:channel.getParentId()), |
| | | // channel); |
| | | // // 更新device中的通道数量 |
| | | // Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); |
| | | // device.setChannelCount(deviceMap.get(deviceId).size()); |
| | | // redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); |
| | | // |
| | | // |
| | | // // 如果有父设备,更新父设备内子节点数 |
| | | // String parentId = channel.getParentId(); |
| | | // if (!StringUtils.isEmpty(parentId) && !parentId.equals(deviceId)) { |
| | | // |
| | | // if (channelMap.get(parentId) == null) { |
| | | // channelMap.put(parentId, new HashSet<String>()); |
| | | // } |
| | | // channelMap.get(parentId).add(channelId); |
| | | // |
| | | // DeviceChannel deviceChannel = queryChannel(deviceId, parentId); |
| | | // if (deviceChannel != null) { |
| | | // deviceChannel.setSubCount(channelMap.get(parentId).size()); |
| | | // redis.set(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + |
| | | // "_" + deviceChannel.getChannelId() + |
| | | // "_" + (deviceChannel.getStatus() == 1 ? "on":"off") + |
| | | // "_" + (channelMap.get(deviceChannel.getChannelId()).size() > 0)+ |
| | | // "_" + (StringUtils.isEmpty(deviceChannel.getParentId())?null:deviceChannel.getParentId()), |
| | | // deviceChannel); |
| | | // |
| | | // } |
| | | // } |
| | | @Override |
| | | public void startPlay(String deviceId, String channelId, String streamId) { |
| | | deviceChannelMapper.startPlay(deviceId, channelId, streamId); |
| | | } |
| | | |
| | | @Override |
| | | public void stopPlay(String deviceId, String channelId) { |
| | | deviceChannelMapper.stopPlay(deviceId, channelId); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PageResult queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, String online, int page, int count) { |
| | | public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, int page, int count) { |
| | | // 获取到所有正在播放的流 |
| | | List<DeviceChannel> result = new ArrayList<>(); |
| | | PageResult pageResult = new PageResult<DeviceChannel>(); |
| | | |
| | | deviceChannelMapper.queryChannelsByDeviceId(deviceId); |
| | | // String queryContent = "*"; |
| | | // if (!StringUtils.isEmpty(query)) queryContent = String.format("*%S*",query); |
| | | // String queryHasSubChannel = "*"; |
| | | // if (hasSubChannel != null) queryHasSubChannel = hasSubChannel?"true":"false"; |
| | | // String queryOnline = "*"; |
| | | // if (!StringUtils.isEmpty(online)) queryOnline = online; |
| | | // String queryStr = VideoManagerConstants.CACHEKEY_PREFIX + deviceId + |
| | | // "_" + queryContent + // 搜索编号和名称 |
| | | // "_" + queryOnline + // 搜索是否在线 |
| | | // "_" + queryHasSubChannel + // 搜索是否含有子节点 |
| | | // "_" + "*"; |
| | | // List<Object> deviceChannelList = redis.scan(queryStr); |
| | | // //对查询结果排序,避免出现通道排列顺序乱序的情况 |
| | | // Collections.sort(deviceChannelList,new Comparator<Object>(){ |
| | | // @Override |
| | | // public int compare(Object o1, Object o2) { |
| | | // return o1.toString().compareToIgnoreCase(o2.toString()); |
| | | // } |
| | | // }); |
| | | // pageResult.setPage(page); |
| | | // pageResult.setCount(count); |
| | | // pageResult.setTotal(deviceChannelList.size()); |
| | | // int maxCount = (page + 1 ) * count; |
| | | // if (deviceChannelList != null && deviceChannelList.size() > 0 ) { |
| | | // for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { |
| | | // DeviceChannel deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(i)); |
| | | // StreamInfo streamInfo = stringStreamInfoMap.get(deviceId + "_" + deviceChannel.getChannelId()); |
| | | // deviceChannel.setPlay(streamInfo != null); |
| | | // if (streamInfo != null) deviceChannel.setStreamId(streamInfo.getStreamId()); |
| | | // result.add(deviceChannel); |
| | | // } |
| | | // pageResult.setData(result); |
| | | // } |
| | | |
| | | return pageResult; |
| | | PageHelper.startPage(page, count); |
| | | List<DeviceChannel> all = deviceChannelMapper.queryChannelsByDeviceId(deviceId, null, query, hasSubChannel, online); |
| | | return new PageInfo<>(all); |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) { |
| | | // List<DeviceChannel> result = new ArrayList<>(); |
| | | //// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); |
| | | // List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); |
| | | // |
| | | // if (deviceChannelList != null && deviceChannelList.size() > 0 ) { |
| | | // for (int i = 0; i < deviceChannelList.size(); i++) { |
| | | // result.add((DeviceChannel)redis.get((String) deviceChannelList.get(i))); |
| | | // } |
| | | // } |
| | | return deviceChannelMapper.queryChannelsByDeviceId(deviceId); |
| | | return deviceChannelMapper.queryChannelsByDeviceId(deviceId, null,null, null, null); |
| | | } |
| | | |
| | | @Override |
| | | public PageResult querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, String online, int page, int count) { |
| | | |
| | | deviceChannelMapper.queryChannelsByDeviceId(deviceId, parentChannelId); |
| | | |
| | | // List<DeviceChannel> allDeviceChannels = new ArrayList<>(); |
| | | // String queryContent = "*"; |
| | | // if (!StringUtils.isEmpty(query)) queryContent = String.format("*%S*",query); |
| | | // String queryHasSubChannel = "*"; |
| | | // if (hasSubChannel != null) queryHasSubChannel = hasSubChannel?"true":"false"; |
| | | // String queryOnline = "*"; |
| | | // if (!StringUtils.isEmpty(online)) queryOnline = online; |
| | | // String queryStr = VideoManagerConstants.CACHEKEY_PREFIX + deviceId + |
| | | // "_" + queryContent + // 搜索编号和名称 |
| | | // "_" + queryOnline + // 搜索是否在线 |
| | | // "_" + queryHasSubChannel + // 搜索是否含有子节点 |
| | | // "_" + parentChannelId; |
| | | // |
| | | //// List<Object> deviceChannelList = redis.keys(queryStr); |
| | | // List<Object> deviceChannelList = redis.scan(queryStr); |
| | | // |
| | | // if (deviceChannelList != null && deviceChannelList.size() > 0 ) { |
| | | // for (int i = 0; i < deviceChannelList.size(); i++) { |
| | | // DeviceChannel deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(i)); |
| | | // if (deviceChannel.getParentId() != null && deviceChannel.getParentId().equals(parentChannelId)) { |
| | | // allDeviceChannels.add(deviceChannel); |
| | | // } |
| | | // } |
| | | // } |
| | | // int maxCount = (page + 1 ) * count; |
| | | PageResult pageResult = new PageResult<DeviceChannel>(); |
| | | // pageResult.setPage(page); |
| | | // pageResult.setCount(count); |
| | | // pageResult.setTotal(allDeviceChannels.size()); |
| | | // |
| | | // if (allDeviceChannels.size() > 0) { |
| | | // pageResult.setData(allDeviceChannels.subList( |
| | | // page * count, pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() |
| | | // )); |
| | | // } |
| | | return pageResult; |
| | | } |
| | | |
| | | public List<DeviceChannel> querySubChannels(String deviceId, String parentChannelId) { |
| | | List<DeviceChannel> allDeviceChannels = new ArrayList<>(); |
| | | // List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); |
| | | // List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); |
| | | // |
| | | // if (deviceChannelList != null && deviceChannelList.size() > 0 ) { |
| | | // for (int i = 0; i < deviceChannelList.size(); i++) { |
| | | // DeviceChannel deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(i)); |
| | | // if (deviceChannel.getParentId() != null && deviceChannel.getParentId().equals(parentChannelId)) { |
| | | // allDeviceChannels.add(deviceChannel); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | return allDeviceChannels; |
| | | public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, String online, int page, int count) { |
| | | PageHelper.startPage(page, count); |
| | | List<DeviceChannel> all = deviceChannelMapper.queryChannelsByDeviceId(deviceId, parentChannelId, null, null, null); |
| | | return new PageInfo<>(all); |
| | | } |
| | | |
| | | @Override |
| | | public DeviceChannel queryChannel(String deviceId, String channelId) { |
| | | DeviceChannel deviceChannel = null; |
| | | return deviceChannelMapper.queryChannel(deviceId, channelId); |
| | | //// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + |
| | | // List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + |
| | | // "_" + channelId + "*"); |
| | | // if (deviceChannelList != null && deviceChannelList.size() > 0 ) { |
| | | // deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(0)); |
| | | // } |
| | | // return deviceChannel; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取多个设备 |
| | | * |
| | | * @param deviceIds 设备ID数组 |
| | | * @return List<Device> 设备对象数组 |
| | | * @param page 当前页数 |
| | | * @param count 每页数量 |
| | | * @return PageInfo<Device> 分页设备对象数组 |
| | | */ |
| | | @Override |
| | | public PageResult<Device> queryVideoDeviceList(String[] deviceIds, int page, int count) { |
| | | List<Device> devices = new ArrayList<>(); |
| | | PageResult pageResult = new PageResult<Device>(); |
| | | // pageResult.setPage(page); |
| | | // pageResult.setCount(count); |
| | | // Device device = null; |
| | | // |
| | | // if (deviceIds == null || deviceIds.length == 0) { |
| | | // |
| | | //// List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); |
| | | // List<Object> deviceIdList = redis.scan(VideoManagerConstants.DEVICE_PREFIX+"*"); |
| | | // pageResult.setTotal(deviceIdList.size()); |
| | | // int maxCount = (page + 1)* count; |
| | | // for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { |
| | | // // devices.add((Device)redis.get((String)deviceIdList.get(i))); |
| | | // device =(Device)redis.get((String)deviceIdList.get(i)); |
| | | // if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ |
| | | // // outline(device.getDeviceId()); |
| | | // } |
| | | // devices.add(device); |
| | | // } |
| | | // } else { |
| | | // for (int i = 0; i < deviceIds.length; i++) { |
| | | // // devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i])); |
| | | // device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i]); |
| | | // if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ |
| | | // // outline(device.getDeviceId()); |
| | | // } |
| | | // devices.add(device); |
| | | // } |
| | | // } |
| | | // pageResult.setData(devices); |
| | | return pageResult; |
| | | public PageInfo<Device> queryVideoDeviceList(int page, int count) { |
| | | PageHelper.startPage(page, count); |
| | | List<Device> all = deviceMapper.getDevices(); |
| | | return new PageInfo<>(all); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public List<Device> queryVideoDeviceList() { |
| | | |
| | | // if (deviceIds == null || deviceIds.length == 0) { |
| | | //// List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); |
| | | // List<Object> deviceIdList = redis.scan(VideoManagerConstants.DEVICE_PREFIX+"*"); |
| | | // for (int i = 0; i < deviceIdList.size(); i++) { |
| | | // device =(Device)redis.get((String)deviceIdList.get(i)); |
| | | // if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ |
| | | // outline(device.getDeviceId()); |
| | | // } |
| | | // devices.add(device); |
| | | // } |
| | | // } else { |
| | | // for (int i = 0; i < deviceIds.length; i++) { |
| | | // device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i]); |
| | | // if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ |
| | | // outline(device.getDeviceId()); |
| | | // } |
| | | // devices.add(device); |
| | | // } |
| | | // } |
| | | |
| | | List<Device> deviceList = deviceMapper.getDevices(); |
| | | return deviceList; |
| | |
| | | * @return true:更新成功 false:更新失败 |
| | | */ |
| | | @Override |
| | | public boolean online(String deviceId) { |
| | | public synchronized boolean online(String deviceId) { |
| | | Device device = deviceMapper.getDeviceByDeviceId(deviceId); |
| | | device.setOnline(1); |
| | | System.out.println("更新设备在线"); |
| | | if (device == null) { |
| | | return false; |
| | | } |
| | | return deviceMapper.update(device) > 0; |
| | | } |
| | | |
| | |
| | | * @return true:更新成功 false:更新失败 |
| | | */ |
| | | @Override |
| | | public boolean outline(String deviceId) { |
| | | // Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); |
| | | // if (device == null) return false; |
| | | // device.setOnline(0); |
| | | // return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); |
| | | |
| | | public synchronized boolean outline(String deviceId) { |
| | | Device device = deviceMapper.getDeviceByDeviceId(deviceId); |
| | | device.setOnline(0); |
| | | System.out.println("更新设备离线"); |
| | | return deviceMapper.update(device) > 0; |
| | | } |
| | | |
| | |
| | | int result = deviceChannelMapper.cleanChannelsByDeviceId(deviceId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean addParentPlatform(ParentPlatform parentPlatform) { |
| | | int result = platformMapper.addParentPlatform(parentPlatform); |
| | | return result > 0; |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateParentPlatform(ParentPlatform parentPlatform) { |
| | | int result = 0; |
| | | ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId()); // .getDeviceGBId()); |
| | | if ( platformMapper.getParentPlatById(parentPlatform.getServerGBId()) == null) { |
| | | result = platformMapper.addParentPlatform(parentPlatform); |
| | | |
| | | if (parentPlatformCatch == null) { |
| | | parentPlatformCatch = new ParentPlatformCatch(); |
| | | parentPlatformCatch.setParentPlatform(parentPlatform); |
| | | parentPlatformCatch.setId(parentPlatform.getServerGBId()); |
| | | } |
| | | }else { |
| | | result = platformMapper.updateParentPlatform(parentPlatform); |
| | | } |
| | | // 更新缓存 |
| | | parentPlatformCatch.setParentPlatform(parentPlatform); |
| | | redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch); |
| | | return result > 0; |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public boolean deleteParentPlatform(ParentPlatform parentPlatform) { |
| | | int result = platformMapper.delParentPlatform(parentPlatform); |
| | | // 删除关联的通道 |
| | | patformChannelMapper.cleanChannelForGB(parentPlatform.getDeviceGBId()); |
| | | return result > 0; |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<ParentPlatform> queryParentPlatformList(int page, int count) { |
| | | PageHelper.startPage(page, count); |
| | | List<ParentPlatform> all = platformMapper.getParentPlatformList(); |
| | | return new PageInfo<>(all); |
| | | } |
| | | |
| | | @Override |
| | | public ParentPlatform queryParentPlatById(String platformGbId) { |
| | | return platformMapper.getParentPlatById(platformGbId); |
| | | } |
| | | |
| | | @Override |
| | | public List<ParentPlatform> queryEnableParentPlatformList(boolean enable) { |
| | | return platformMapper.getEnableParentPlatformList(enable); |
| | | } |
| | | |
| | | @Override |
| | | public void outlineForAllParentPlatform() { |
| | | platformMapper.outlineForAllParentPlatform(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public PageInfo<ChannelReduce> queryAllChannelList(int page, int count, String query, Boolean online, |
| | | Boolean channelType, String platformId, Boolean inPlatform) { |
| | | PageHelper.startPage(page, count); |
| | | List<ChannelReduce> all = deviceChannelMapper.queryChannelListInAll(query, online, channelType, platformId, inPlatform); |
| | | return new PageInfo<>(all); |
| | | } |
| | | |
| | | @Override |
| | | public List<ChannelReduce> queryChannelListInParentPlatform(String platformId) { |
| | | |
| | | return deviceChannelMapper.queryChannelListInAll(null, null, null, platformId, true); |
| | | } |
| | | |
| | | @Override |
| | | public int updateChannelForGB(String platformId, List<ChannelReduce> channelReduces) { |
| | | |
| | | Map<String, ChannelReduce> deviceAndChannels = new HashMap<>(); |
| | | for (ChannelReduce channelReduce : channelReduces) { |
| | | deviceAndChannels.put(channelReduce.getDeviceId() + "_" + channelReduce.getChannelId(), channelReduce); |
| | | } |
| | | List<String> deviceAndChannelList = new ArrayList<>(deviceAndChannels.keySet()); |
| | | // 查询当前已经存在的 |
| | | List<String> relatedPlatformchannels = patformChannelMapper.findChannelRelatedPlatform(platformId, deviceAndChannelList); |
| | | if (relatedPlatformchannels != null) { |
| | | deviceAndChannelList.removeAll(relatedPlatformchannels); |
| | | } |
| | | for (String relatedPlatformchannel : relatedPlatformchannels) { |
| | | deviceAndChannels.remove(relatedPlatformchannel); |
| | | } |
| | | List<ChannelReduce> channelReducesToAdd = new ArrayList<>(deviceAndChannels.values()); |
| | | // 对剩下的数据进行存储 |
| | | int result = 0; |
| | | if (channelReducesToAdd.size() > 0) { |
| | | result = patformChannelMapper.addChannels(platformId, channelReducesToAdd); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public int delChannelForGB(String platformId, List<ChannelReduce> channelReduces) { |
| | | |
| | | int result = patformChannelMapper.delChannelForGB(platformId, channelReduces); |
| | | |
| | | return result; |
| | | } |
| | | } |