优化通道更新逻辑

This commit is contained in:
648540858
2021-12-28 18:54:50 +08:00
parent 7241e0d2d2
commit 726963ba77
12 changed files with 14444 additions and 39 deletions

View File

@@ -55,7 +55,7 @@ public interface IVideoManagerStorager {
* @param deviceId 设备id
* @param channels 多个通道
*/
public void updateChannels(String deviceId, List<DeviceChannel> channels);
public int updateChannels(String deviceId, List<DeviceChannel> channels);
/**
* 开始播放
@@ -425,4 +425,10 @@ public interface IVideoManagerStorager {
*/
StreamProxyItem getStreamProxyByAppAndStream(String app, String streamId);
/**
* catlog查询结束后完全重写通道信息
* @param deviceId
* @param deviceChannelList
*/
boolean resetChannels(String deviceId, List<DeviceChannel> deviceChannelList);
}

View File

@@ -133,7 +133,7 @@ public interface DeviceChannelMapper {
"'${item.streamId}', ${item.longitude}, ${item.latitude},'${item.createTime}', '${item.updateTime}')" +
"</foreach> " +
"</script>")
void batchAdd(List<DeviceChannel> addChannels);
int batchAdd(List<DeviceChannel> addChannels);
@Update({"<script>" +
"<foreach collection='updateChannels' item='item' separator=';'>" +
@@ -167,7 +167,7 @@ public interface DeviceChannelMapper {
"WHERE deviceId=#{item.deviceId} AND channelId=#{item.channelId}"+
"</foreach>" +
"</script>"})
void batchUpdate(List<DeviceChannel> updateChannels);
int batchUpdate(List<DeviceChannel> updateChannels);
@Select(value = {" <script>" +
"SELECT * FROM ( "+

View File

@@ -156,7 +156,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
}
@Override
public void updateChannels(String deviceId, List<DeviceChannel> channels) {
public int updateChannels(String deviceId, List<DeviceChannel> channels) {
List<DeviceChannel> addChannels = new ArrayList<>();
List<DeviceChannel> updateChannels = new ArrayList<>();
HashMap<String, DeviceChannel> channelsInStore = new HashMap<>();
@@ -210,13 +210,47 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
if (i + limitCount > updateChannels.size()) {
toIndex = updateChannels.size();
}
deviceChannelMapper.batchAdd(updateChannels.subList(i, toIndex));
deviceChannelMapper.batchUpdate(updateChannels.subList(i, toIndex));
}
}else {
deviceChannelMapper.batchUpdate(updateChannels);
}
}
}
return addChannels.size() + updateChannels.size();
}
@Override
public boolean resetChannels(String deviceId, List<DeviceChannel> deviceChannelList) {
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
try {
int cleanChannelsResult = deviceChannelMapper.cleanChannelsByDeviceId(deviceId);
int limitCount = 300;
boolean result = cleanChannelsResult <0;
if (!result && deviceChannelList.size() > 0) {
if (deviceChannelList.size() > limitCount) {
for (int i = 0; i < deviceChannelList.size(); i += limitCount) {
int toIndex = i + limitCount;
if (i + limitCount > deviceChannelList.size()) {
toIndex = deviceChannelList.size();
}
result = result || deviceChannelMapper.batchAdd(deviceChannelList.subList(i, toIndex)) < 0;
}
}else {
result = result || deviceChannelMapper.batchAdd(deviceChannelList) < 0;
}
}
if (result) {
//事务回滚
dataSourceTransactionManager.rollback(transactionStatus);
}
dataSourceTransactionManager.commit(transactionStatus); //手动提交
return true;
}catch (Exception e) {
dataSourceTransactionManager.rollback(transactionStatus);
return false;
}
}
@Override
@@ -711,7 +745,6 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
if (streamProxyItems == null) {
platformGbStreamMapper.add(streamPushItem);
}
}
}
}