Compare commits

..

1 Commits

Author SHA1 Message Date
WangXuewen
4c75e165d1
Pre Merge pull request !34 from WangXuewen/master 2025-05-11 14:00:53 +00:00
2 changed files with 69 additions and 67 deletions

View File

@ -120,83 +120,85 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
List<DeviceChannel> updateChannels = new ArrayList<>(); List<DeviceChannel> updateChannels = new ArrayList<>();
HashMap<String, DeviceChannel> channelsInStore = new HashMap<>(); HashMap<String, DeviceChannel> channelsInStore = new HashMap<>();
int result = 0; int result = 0;
List<DeviceChannel> channelList = channelMapper.queryChannelsByDeviceDbId(device.getId()); if (channels != null && !channels.isEmpty()) {
if (channelList.isEmpty()) { List<DeviceChannel> channelList = channelMapper.queryChannelsByDeviceDbId(device.getId());
for (DeviceChannel channel : channels) { if (channelList.isEmpty()) {
channel.setDataDeviceId(device.getId()); for (DeviceChannel channel : channels) {
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, channel.getId()); channel.setDataDeviceId(device.getId());
if (inviteInfo != null && inviteInfo.getStreamInfo() != null) { InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, channel.getId());
channel.setStreamId(inviteInfo.getStreamInfo().getStream()); if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
} channel.setStreamId(inviteInfo.getStreamInfo().getStream());
String now = DateUtil.getNow(); }
channel.setUpdateTime(now); String now = DateUtil.getNow();
channel.setCreateTime(now);
addChannels.add(channel);
}
}else {
for (DeviceChannel deviceChannel : channelList) {
channelsInStore.put(deviceChannel.getDataDeviceId() + deviceChannel.getDeviceId(), deviceChannel);
}
for (DeviceChannel channel : channels) {
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, channel.getId());
if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
channel.setStreamId(inviteInfo.getStreamInfo().getStream());
}
String now = DateUtil.getNow();
channel.setUpdateTime(now);
DeviceChannel deviceChannelInDb = channelsInStore.get(channel.getDataDeviceId() + channel.getDeviceId());
if ( deviceChannelInDb != null) {
channel.setId(deviceChannelInDb.getId());
channel.setUpdateTime(now); channel.setUpdateTime(now);
updateChannels.add(channel);
}else {
channel.setCreateTime(now); channel.setCreateTime(now);
channel.setUpdateTime(now);
addChannels.add(channel); addChannels.add(channel);
} }
}else {
for (DeviceChannel deviceChannel : channelList) {
channelsInStore.put(deviceChannel.getDataDeviceId() + deviceChannel.getDeviceId(), deviceChannel);
}
for (DeviceChannel channel : channels) {
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, channel.getId());
if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
channel.setStreamId(inviteInfo.getStreamInfo().getStream());
}
String now = DateUtil.getNow();
channel.setUpdateTime(now);
DeviceChannel deviceChannelInDb = channelsInStore.get(channel.getDataDeviceId() + channel.getDeviceId());
if ( deviceChannelInDb != null) {
channel.setId(deviceChannelInDb.getId());
channel.setUpdateTime(now);
updateChannels.add(channel);
}else {
channel.setCreateTime(now);
channel.setUpdateTime(now);
addChannels.add(channel);
}
}
} }
} Set<String> channelSet = new HashSet<>();
Set<String> channelSet = new HashSet<>(); // 滤重
// 滤重 List<DeviceChannel> addChannelList = new ArrayList<>();
List<DeviceChannel> addChannelList = new ArrayList<>(); List<DeviceChannel> updateChannelList = new ArrayList<>();
List<DeviceChannel> updateChannelList = new ArrayList<>(); addChannels.forEach(channel -> {
addChannels.forEach(channel -> { if (channelSet.add(channel.getDeviceId())) {
if (channelSet.add(channel.getDeviceId())) { addChannelList.add(channel);
addChannelList.add(channel); }
} });
}); channelSet.clear();
channelSet.clear(); updateChannels.forEach(channel -> {
updateChannels.forEach(channel -> { if (channelSet.add(channel.getDeviceId())) {
if (channelSet.add(channel.getDeviceId())) { updateChannelList.add(channel);
updateChannelList.add(channel); }
} });
});
int limitCount = 500; int limitCount = 500;
if (!addChannelList.isEmpty()) { if (!addChannelList.isEmpty()) {
if (addChannelList.size() > limitCount) { if (addChannelList.size() > limitCount) {
for (int i = 0; i < addChannelList.size(); i += limitCount) { for (int i = 0; i < addChannelList.size(); i += limitCount) {
int toIndex = i + limitCount; int toIndex = i + limitCount;
if (i + limitCount > addChannelList.size()) { if (i + limitCount > addChannelList.size()) {
toIndex = addChannelList.size(); toIndex = addChannelList.size();
}
result += channelMapper.batchAdd(addChannelList.subList(i, toIndex));
} }
result += channelMapper.batchAdd(addChannelList.subList(i, toIndex)); }else {
result += channelMapper.batchAdd(addChannelList);
} }
}else {
result += channelMapper.batchAdd(addChannelList);
} }
} if (!updateChannelList.isEmpty()) {
if (!updateChannelList.isEmpty()) { if (updateChannelList.size() > limitCount) {
if (updateChannelList.size() > limitCount) { for (int i = 0; i < updateChannelList.size(); i += limitCount) {
for (int i = 0; i < updateChannelList.size(); i += limitCount) { int toIndex = i + limitCount;
int toIndex = i + limitCount; if (i + limitCount > updateChannelList.size()) {
if (i + limitCount > updateChannelList.size()) { toIndex = updateChannelList.size();
toIndex = updateChannelList.size(); }
result += channelMapper.batchUpdate(updateChannelList.subList(i, toIndex));
} }
result += channelMapper.batchUpdate(updateChannelList.subList(i, toIndex)); }else {
result += channelMapper.batchUpdate(updateChannelList);
} }
}else {
result += channelMapper.batchUpdate(updateChannelList);
} }
} }
return result; return result;

View File

@ -60,7 +60,7 @@ export const constantRoutes = [
component: Layout, component: Layout,
redirect: '/live', redirect: '/live',
children: [{ children: [{
path: '', path: 'live',
name: 'Live', name: 'Live',
component: () => import('@/views/live/index'), component: () => import('@/views/live/index'),
meta: { title: '分屏监控', icon: 'live' } meta: { title: '分屏监控', icon: 'live' }