From ccc0a99d6894844d83d751b924cfebe74da7826c Mon Sep 17 00:00:00 2001 From: ‘sxh’ <1632740646@qq.com> Date: 星期四, 15 六月 2023 11:20:43 +0800 Subject: [PATCH] 同步主线的代码,保持一致性 --- src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java | 111 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 98 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java index 880b697..45405f7 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java @@ -1,15 +1,17 @@ package com.genersoft.iot.vmp.service.impl; -import com.genersoft.iot.vmp.common.StreamInfo; +import com.genersoft.iot.vmp.common.InviteInfo; +import com.genersoft.iot.vmp.common.InviteSessionType; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; import com.genersoft.iot.vmp.service.IDeviceChannelService; +import com.genersoft.iot.vmp.service.IInviteStreamService; 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.utils.DateUtil; -import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo; +import com.genersoft.iot.vmp.vmanager.bean.ResourceBaseInfo; import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,6 +21,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; /** * @author lin @@ -32,6 +35,9 @@ private IRedisCatchStorage redisCatchStorage; @Autowired + private IInviteStreamService inviteStreamService; + + @Autowired private DeviceChannelMapper channelMapper; @Autowired @@ -43,6 +49,8 @@ if (device == null) { device = deviceMapper.getDeviceByDeviceId(deviceChannel.getDeviceId()); } + + if ("WGS84".equals(device.getGeoCoordSys())) { deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude()); @@ -75,9 +83,10 @@ public void updateChannel(String deviceId, DeviceChannel channel) { String channelId = channel.getChannelId(); channel.setDeviceId(deviceId); - StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId); - if (streamInfo != null) { - channel.setStreamId(streamInfo.getStream()); +// StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId); + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId); + if (inviteInfo != null && inviteInfo.getStreamInfo() != null) { + channel.setStreamId(inviteInfo.getStreamInfo().getStream()); } String now = DateUtil.getNow(); channel.setUpdateTime(now); @@ -103,9 +112,9 @@ if (channelList.size() == 0) { for (DeviceChannel channel : channels) { channel.setDeviceId(deviceId); - StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channel.getChannelId()); - if (streamInfo != null) { - channel.setStreamId(streamInfo.getStream()); + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channel.getChannelId()); + if (inviteInfo != null && inviteInfo.getStreamInfo() != null) { + channel.setStreamId(inviteInfo.getStreamInfo().getStream()); } String now = DateUtil.getNow(); channel.setUpdateTime(now); @@ -119,9 +128,9 @@ } for (DeviceChannel channel : channels) { channel.setDeviceId(deviceId); - StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channel.getChannelId()); - if (streamInfo != null) { - channel.setStreamId(streamInfo.getStream()); + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channel.getChannelId()); + if (inviteInfo != null && inviteInfo.getStreamInfo() != null) { + channel.setStreamId(inviteInfo.getStreamInfo().getStream()); } String now = DateUtil.getNow(); channel.setUpdateTime(now); @@ -166,8 +175,12 @@ } @Override - public ResourceBaceInfo getOverview() { - return channelMapper.getOverview(); + public ResourceBaseInfo getOverview() { + + int online = channelMapper.getOnlineCount(); + int total = channelMapper.getAllChannelCount(); + + return new ResourceBaseInfo(total, online); } @@ -176,5 +189,77 @@ return channelMapper.queryChannelListInAll(null, null, null, platformId, null); } + @Override + public boolean updateAllGps(Device device) { + List<DeviceChannel> deviceChannels = channelMapper.getChannelsWithoutTransform(device.getDeviceId()); + List<DeviceChannel> result = new CopyOnWriteArrayList<>(); + if (deviceChannels.size() == 0) { + return true; + } + String now = DateUtil.getNow(); + deviceChannels.parallelStream().forEach(deviceChannel -> { + deviceChannel.setUpdateTime(now); + result.add(updateGps(deviceChannel, device)); + }); + int limitCount = 300; + if (result.size() > limitCount) { + for (int i = 0; i < result.size(); i += limitCount) { + int toIndex = i + limitCount; + if (i + limitCount > result.size()) { + toIndex = result.size(); + } + channelMapper.batchUpdate(result.subList(i, toIndex)); + } + }else { + channelMapper.batchUpdate(result); + } + return true; + } + + @Override + public List<Device> getDeviceByChannelId(String channelId) { + + return channelMapper.getDeviceByChannelId(channelId); + } + + @Override + public int deleteChannels(List<DeviceChannel> deleteChannelList) { + return channelMapper.batchDel(deleteChannelList); + } + + @Override + public int channelsOnline(List<DeviceChannel> channels) { + return channelMapper.batchOnline(channels); + } + + @Override + public int channelsOffline(List<DeviceChannel> channels) { + return channelMapper.batchOffline(channels); + } + + @Override + public DeviceChannel getOne(String deviceId, String channelId){ + return channelMapper.queryChannel(deviceId, channelId); + } + + @Override + public void batchUpdateChannel(List<DeviceChannel> channels) { + channelMapper.batchUpdate(channels); + for (DeviceChannel channel : channels) { + if (channel.getParentId() != null) { + channelMapper.updateChannelSubCount(channel.getDeviceId(), channel.getParentId()); + } + } + } + + @Override + public void batchAddChannel(List<DeviceChannel> channels) { + channelMapper.batchAdd(channels); + for (DeviceChannel channel : channels) { + if (channel.getParentId() != null) { + channelMapper.updateChannelSubCount(channel.getDeviceId(), channel.getParentId()); + } + } + } } -- Gitblit v1.8.0