优化预置位查询

结构优化
648540858 2023-12-21 15:31:28 +08:00
parent 35fd5eee63
commit 974e822f84
2 changed files with 22 additions and 15 deletions

View File

@ -129,17 +129,21 @@ public class PresetDataCatch {
for (Integer sn : keys) { for (Integer sn : keys) {
PresetData presetData = data.get(sn); PresetData presetData = data.get(sn);
String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + sn; String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + sn;
if ( presetData.getLastTime().isBefore(instantBefore5S)) { if ( presetData.getLastTime().isBefore(instantBefore5S) && !presetData.getStatus().equals(DataStatus.end) ) {
logger.info("[预置位接收等待超时] 直接返回已经收到的数据, {}/{}", presetData.getPresetItems().size(), presetData.getTotal()); logger.info("[预置位接收等待超时] 直接返回已经收到的数据, {}/{}", presetData.getPresetItems().size(), presetData.getTotal());
// 超过五秒收不到消息任务超时, 只更新这一部分数据, 收到数据与声明的总数一致,则重置通道数据,数据不全则只对收到的数据做更新操作 // 超过五秒收不到消息任务超时, 只更新这一部分数据, 收到数据与声明的总数一致,则重置通道数据,数据不全则只对收到的数据做更新操作
if (presetData.getStatus().equals(DataStatus.runIng)) { if (presetData.getStatus().equals(DataStatus.runIng)) {
RequestMessage requestMessage = new RequestMessage();
requestMessage.setKey(key);
requestMessage.setData(presetData.getPresetItems().values());
deferredResultHolder.invokeAllResult(requestMessage);
String errorMsg = "更新成功,共" + presetData.getTotal() + "条,已更新" + presetData.getPresetItems().size() + "条"; String errorMsg = "更新成功,共" + presetData.getTotal() + "条,已更新" + presetData.getPresetItems().size() + "条";
presetData.setErrorMsg(errorMsg); presetData.setErrorMsg(errorMsg);
RequestMessage requestMessage = new RequestMessage();
requestMessage.setKey(key);
requestMessage.setId(sn + "");
if (!presetData.getPresetItems().isEmpty()) {
requestMessage.setData(presetData.getPresetItems().values());
}else {
requestMessage.setData(presetData.getErrorMsg());
}
deferredResultHolder.invokeResult(requestMessage);
}else if (presetData.getStatus().equals(DataStatus.ready)) { }else if (presetData.getStatus().equals(DataStatus.ready)) {
String errorMsg = "同步失败,等待回复超时"; String errorMsg = "同步失败,等待回复超时";
presetData.setErrorMsg(errorMsg); presetData.setErrorMsg(errorMsg);

View File

@ -125,9 +125,9 @@ 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<>();
Device device = deviceMapper.getDeviceByDeviceId(deviceId); Device device = deviceMapper.getDeviceByDeviceId(deviceId);
if (channels != null && channels.size() > 0) { if (channels != null && !channels.isEmpty()) {
List<DeviceChannel> channelList = channelMapper.queryChannels(deviceId, null, null, null, null,null); List<DeviceChannel> channelList = channelMapper.queryChannels(deviceId, null, null, null, null,null);
if (channelList.size() == 0) { if (channelList.isEmpty()) {
for (DeviceChannel channel : channels) { for (DeviceChannel channel : channels) {
channel.setDeviceId(deviceId); channel.setDeviceId(deviceId);
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channel.getChannelId()); InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channel.getChannelId());
@ -204,7 +204,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
public boolean updateAllGps(Device device) { public boolean updateAllGps(Device device) {
List<DeviceChannel> deviceChannels = channelMapper.getChannelsWithoutTransform(device.getDeviceId()); List<DeviceChannel> deviceChannels = channelMapper.getChannelsWithoutTransform(device.getDeviceId());
List<DeviceChannel> result = new CopyOnWriteArrayList<>(); List<DeviceChannel> result = new CopyOnWriteArrayList<>();
if (deviceChannels.size() == 0) { if (deviceChannels.isEmpty()) {
return true; return true;
} }
String now = DateUtil.getNow(); String now = DateUtil.getNow();
@ -348,7 +348,6 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
Map<String, Region> regionMap = regionMapper.getAllForMap(); Map<String, Region> regionMap = regionMapper.getAllForMap();
// 存储得到的所有行政区划, 后续检验civilCode是否已传输对应的行政区划数据从而确定是否需要自动创建节点。 // 存储得到的所有行政区划, 后续检验civilCode是否已传输对应的行政区划数据从而确定是否需要自动创建节点。
Set<String> civilCodeSet = new HashSet<>(); Set<String> civilCodeSet = new HashSet<>();
List<String> clearChannels = new ArrayList<>();
Set<String> gbIdSet = new HashSet<>(); Set<String> gbIdSet = new HashSet<>();
for (DeviceChannel deviceChannel : deviceChannelList) { for (DeviceChannel deviceChannel : deviceChannelList) {
@ -357,6 +356,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
logger.info("[目录查询]收到的数据存在重复: {}" , deviceChannel.getChannelId()); logger.info("[目录查询]收到的数据存在重复: {}" , deviceChannel.getChannelId());
continue; continue;
} }
civilCodeSet.add(deviceChannel.getCivilCode());
gbIdSet.add(deviceChannel.getChannelId()); gbIdSet.add(deviceChannel.getChannelId());
Gb28181CodeType channelIdType = SipUtils.getChannelIdType(deviceChannel.getChannelId()); Gb28181CodeType channelIdType = SipUtils.getChannelIdType(deviceChannel.getChannelId());
// 处理国标通道相关的判断 // 处理国标通道相关的判断
@ -579,14 +579,17 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
commonGbChannelService.batchDelete(allCommonChannelsForDelete); commonGbChannelService.batchDelete(allCommonChannelsForDelete);
} }
// addChannels 与 addCommonChannels 数量一致,这里使用同一个循环处理 // addChannels 与 addCommonChannels 数量一致,这里使用同一个循环处理
if (!addChannelList.isEmpty()) { if (!addCommonChannelList.isEmpty()) {
// 对于新增的部分需要先添加通用通道拿到ID后再添加国标通道 // 对于新增的部分需要先添加通用通道拿到ID后再添加国标通道
commonGbChannelService.batchAdd(addCommonChannelList); commonGbChannelService.batchAdd(addCommonChannelList);
for (int j = 0; j < addCommonChannelList.size(); j++) { Map<String, Integer> commonChannelDeviceAndIdMap = new HashMap<>();
addChannelList.get(j).setCommonGbChannelId(addCommonChannelList.get(j).getCommonGbId()); addCommonChannelList.stream().forEach(commonGbChannel ->{
} commonChannelDeviceAndIdMap.put(commonGbChannel.getCommonGbDeviceID(), commonGbChannel.getCommonGbId());
});
addChannelList.stream().forEach(channel ->{
channel.setCommonGbChannelId(commonChannelDeviceAndIdMap.get(channel.getChannelId()));
});
addChannelHandler(addChannelList); addChannelHandler(addChannelList);
} }
if (!updateChannelList.isEmpty()) { if (!updateChannelList.isEmpty()) {
commonGbChannelService.batchUpdate(updateCommonChannelList); commonGbChannelService.batchUpdate(updateCommonChannelList);