| | |
| | | |
| | | import java.util.*; |
| | | |
| | | import com.genersoft.iot.vmp.common.StreamInfo; |
| | | import com.genersoft.iot.vmp.gb28181.bean.*; |
| | | import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | |
| | | import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | @SuppressWarnings("rawtypes") |
| | | @Component |
| | | public class VideoManagerStoragerImpl implements IVideoManagerStorager { |
| | | |
| | | private Logger logger = LoggerFactory.getLogger(VideoManagerStoragerImpl.class); |
| | | |
| | | @Autowired |
| | | DataSourceTransactionManager dataSourceTransactionManager; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private GbStreamMapper gbStreamMapper; |
| | | |
| | | @Autowired |
| | | private VideoStreamSessionManager streamSession; |
| | | |
| | | |
| | | /** |
| | |
| | | public synchronized void updateChannel(String deviceId, DeviceChannel channel) { |
| | | String channelId = channel.getChannelId(); |
| | | channel.setDeviceId(deviceId); |
| | | channel.setStreamId(streamSession.getStreamId(deviceId, channel.getChannelId())); |
| | | DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId); |
| | | if (deviceChannel == null) { |
| | | deviceChannelMapper.add(channel); |
| | |
| | | */ |
| | | @Override |
| | | public boolean delete(String deviceId) { |
| | | int result = deviceMapper.del(deviceId); |
| | | |
| | | return result > 0; |
| | | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| | | boolean result = false; |
| | | try { |
| | | if (platformChannelMapper.delChannelForDeviceId(deviceId) <0 // 删除与国标平台的关联 |
| | | || deviceChannelMapper.cleanChannelsByDeviceId(deviceId) < 0 // 删除他的通道 |
| | | || deviceMapper.del(deviceId) < 0 // 移除设备信息 |
| | | ) { |
| | | //事务回滚 |
| | | dataSourceTransactionManager.rollback(transactionStatus); |
| | | } |
| | | result = true; |
| | | dataSourceTransactionManager.commit(transactionStatus); //手动提交 |
| | | }catch (Exception e) { |
| | | dataSourceTransactionManager.rollback(transactionStatus); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | |
| | | return false; |
| | | } |
| | | device.setOnline(1); |
| | | System.out.println("更新设备在线"); |
| | | logger.info("更新设备在线: " + deviceId); |
| | | return deviceMapper.update(device) > 0; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public synchronized boolean outline(String deviceId) { |
| | | System.out.println("更新设备离线: " + deviceId); |
| | | logger.info("更新设备离线: " + deviceId); |
| | | Device device = deviceMapper.getDeviceByDeviceId(deviceId); |
| | | if (device == null) return false; |
| | | device.setOnline(0); |
| | | return deviceMapper.update(device) > 0; |
| | | } |
| | | |
| | | /** |
| | | * 更新所有设备离线 |
| | | * |
| | | * @return true:更新成功 false:更新失败 |
| | | */ |
| | | @Override |
| | | public synchronized boolean outlineForAll() { |
| | | logger.info("更新所有设备离线"); |
| | | int result = deviceMapper.outlineForAll(); |
| | | return result > 0; |
| | | } |
| | | |
| | | /** |
| | |
| | | public boolean updateParentPlatform(ParentPlatform parentPlatform) { |
| | | int result = 0; |
| | | ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId()); // .getDeviceGBId()); |
| | | if ( platformMapper.getParentPlatById(parentPlatform.getServerGBId()) == null) { |
| | | if (parentPlatform.getId() == null ) { |
| | | result = platformMapper.addParentPlatform(parentPlatform); |
| | | |
| | | if (parentPlatformCatch == null) { |
| | | parentPlatformCatch = new ParentPlatformCatch(); |
| | | parentPlatformCatch.setParentPlatform(parentPlatform); |
| | | parentPlatformCatch.setId(parentPlatform.getServerGBId()); |
| | | } |
| | | }else { |
| | | if (parentPlatformCatch == null) { // serverGBId 已变化 |
| | | ParentPlatform parentPlatById = platformMapper.getParentPlatById(parentPlatform.getId()); |
| | | // 使用旧的查出缓存ID |
| | | parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatById.getServerGBId()); |
| | | parentPlatformCatch.setId(parentPlatform.getServerGBId()); |
| | | redisCatchStorage.delPlatformCatchInfo(parentPlatById.getServerGBId()); |
| | | } |
| | | result = platformMapper.updateParentPlatform(parentPlatform); |
| | | } |
| | | // 更新缓存 |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ParentPlatform queryParentPlatById(String platformGbId) { |
| | | return platformMapper.getParentPlatById(platformGbId); |
| | | public ParentPlatform queryParentPlatByServerGBId(String platformGbId) { |
| | | return platformMapper.getParentPlatByServerGBId(platformGbId); |
| | | } |
| | | |
| | | @Override |
| | |
| | | dataSourceTransactionManager.commit(transactionStatus); //手动提交 |
| | | result = true; |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | dataSourceTransactionManager.rollback(transactionStatus); |
| | | } |
| | | return result; |
| | |
| | | @Override |
| | | public void updateMediaList(List<StreamPushItem> streamPushItems) { |
| | | if (streamPushItems == null || streamPushItems.size() == 0) return; |
| | | System.out.printf("updateMediaList: " + streamPushItems.size()); |
| | | logger.info("updateMediaList: " + streamPushItems.size()); |
| | | streamPushMapper.addAll(streamPushItems); |
| | | // TODO 待优化 |
| | | for (int i = 0; i < streamPushItems.size(); i++) { |
| | |
| | | public void mediaOutline(String app, String streamId) { |
| | | gbStreamMapper.setStatus(app, streamId, false); |
| | | } |
| | | |
| | | @Override |
| | | public void updateParentPlatformStatus(String platformGbID, boolean online) { |
| | | platformMapper.updateParentPlatformStatus(platformGbID, online); |
| | | } |
| | | } |