合并271 notify消息优化

This commit is contained in:
648540858
2024-09-26 14:46:08 +08:00
parent 394cf7ee4e
commit 249bdf69be
5 changed files with 103 additions and 64 deletions

View File

@@ -3,8 +3,8 @@ package com.genersoft.iot.vmp.gb28181.service;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaseInfo;
import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelReduce;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaseInfo;
import com.genersoft.iot.vmp.web.gb28181.dto.DeviceChannelExtend;
import com.github.pagehelper.PageInfo;
@@ -47,15 +47,7 @@ public interface IDeviceChannelService {
*/
int deleteChannelsForNotify(List<DeviceChannel> deleteChannelList);
/**
* 批量上线
*/
int channelsOnlineForNotify(List<DeviceChannel> channels);
/**
* 批量下线
*/
int channelsOfflineForNotify(List<DeviceChannel> channels);
int updateChannelsStatus(List<DeviceChannel> channels);
/**
* 获取一个通道

View File

@@ -193,13 +193,45 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
}
@Override
public int deleteChannelsForNotify(List<DeviceChannel> deleteChannelList) {
return channelMapper.batchDelForNotify(deleteChannelList);
@Transactional
public int deleteChannelsForNotify(List<DeviceChannel> channels) {
int limitCount = 1000;
int result = 0;
if (!channels.isEmpty()) {
if (channels.size() > limitCount) {
for (int i = 0; i < channels.size(); i += limitCount) {
int toIndex = i + limitCount;
if (i + limitCount > channels.size()) {
toIndex = channels.size();
}
result += channelMapper.batchDel(channels.subList(i, toIndex));
}
}else {
result += channelMapper.batchDel(channels);
}
}
return result;
}
@Transactional
@Override
public int channelsOnlineForNotify(List<DeviceChannel> channels) {
return channelMapper.batchOnlineForNotify(channels);
public int updateChannelsStatus(List<DeviceChannel> channels) {
int limitCount = 1000;
int result = 0;
if (!channels.isEmpty()) {
if (channels.size() > limitCount) {
for (int i = 0; i < channels.size(); i += limitCount) {
int toIndex = i + limitCount;
if (i + limitCount > channels.size()) {
toIndex = channels.size();
}
result += channelMapper.batchUpdateStatus(channels.subList(i, toIndex));
}
}else {
result += channelMapper.batchUpdateStatus(channels);
}
}
return result;
}
@Override
@@ -207,12 +239,6 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
channelMapper.online(channel.getId());
}
@Override
public int channelsOfflineForNotify(List<DeviceChannel> channels) {
return channelMapper.batchOfflineForNotify(channels);
}
@Override
public void offline(DeviceChannel channel) {
channelMapper.offline(channel.getId());
@@ -242,6 +268,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
}
@Override
@Transactional
public synchronized void batchUpdateChannelForNotify(List<DeviceChannel> channels) {
String now = DateUtil.getNow();
for (DeviceChannel channel : channels) {
@@ -264,8 +291,27 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
}
@Override
@Transactional
public void batchAddChannel(List<DeviceChannel> channels) {
channelMapper.batchAdd(channels);
String now = DateUtil.getNow();
for (DeviceChannel channel : channels) {
channel.setUpdateTime(now);
channel.setCreateTime(now);
}
int limitCount = 1000;
if (!channels.isEmpty()) {
if (channels.size() > limitCount) {
for (int i = 0; i < channels.size(); i += limitCount) {
int toIndex = i + limitCount;
if (i + limitCount > channels.size()) {
toIndex = channels.size();
}
channelMapper.batchAdd(channels.subList(i, toIndex));
}
}else {
channelMapper.batchAdd(channels);
}
}
for (DeviceChannel channel : channels) {
if (channel.getParentId() != null) {
channelMapper.updateChannelSubCount(channel.getDeviceDbId(), channel.getParentId());