From 8cba63642fcff122907bd7d7a8d7d822555d34ca Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期一, 22 四月 2024 20:29:36 +0800 Subject: [PATCH] 优化notify消息处理 --- src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java | 76 +++++++++++++++++++++++++++----------- 1 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java old mode 100644 new mode 100755 index e2aee4a..c80cc88 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java @@ -2,6 +2,7 @@ import com.genersoft.iot.vmp.conf.CivilCodeFileConf; import com.genersoft.iot.vmp.conf.DynamicTask; +import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; @@ -12,6 +13,7 @@ import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; import com.genersoft.iot.vmp.service.IDeviceChannelService; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; +import com.genersoft.iot.vmp.utils.DateUtil; import org.dom4j.DocumentException; import org.dom4j.Element; import org.slf4j.Logger; @@ -63,6 +65,9 @@ @Autowired private CivilCodeFileConf civilCodeFileConf; + @Autowired + private SipConfig sipConfig; + private final static String talkKey = "notify-request-for-catalog-task"; public void process(RequestEvent evt) { @@ -91,10 +96,6 @@ // 閬嶅巻DeviceList while (deviceListIterator.hasNext()) { Element itemDevice = deviceListIterator.next(); - Element channelDeviceElement = itemDevice.element("DeviceID"); - if (channelDeviceElement == null) { - continue; - } Element eventElement = itemDevice.element("Event"); String event; if (eventElement == null) { @@ -103,8 +104,14 @@ }else { event = eventElement.getText().toUpperCase(); } - DeviceChannel channel = XmlUtil.channelContentHandler(itemDevice, device, event, civilCodeFileConf); - + DeviceChannel channel = XmlUtil.channelContentHandler(itemDevice, device, event); + if (channel == null) { + logger.info("[鏀跺埌鐩綍璁㈤槄]锛氫絾鏄В鏋愬け璐� {}", new String(evt.getRequest().getRawContent())); + continue; + } + if (channel.getParentId() != null && channel.getParentId().equals(sipConfig.getId())) { + channel.setParentId(null); + } channel.setDeviceId(device.getDeviceId()); logger.info("[鏀跺埌鐩綍璁㈤槄]锛歿}/{}", device.getDeviceId(), channel.getChannelId()); switch (event) { @@ -175,6 +182,7 @@ // 鍒ゆ柇姝ら�氶亾鏄惁瀛樺湪 DeviceChannel deviceChannel = deviceChannelService.getOne(deviceId, channel.getChannelId()); if (deviceChannel != null) { + logger.info("[澧炲姞閫氶亾] 宸插瓨鍦紝涓嶅彂閫侀�氱煡鍙洿鏂帮紝璁惧: {}, 閫氶亾 {}", device.getDeviceId(), channel.getChannelId()); channel.setId(deviceChannel.getId()); updateChannelMap.put(channel.getChannelId(), channel); if (updateChannelMap.keySet().size() > 300) { @@ -212,6 +220,7 @@ DeviceChannel deviceChannelForUpdate = deviceChannelService.getOne(deviceId, channel.getChannelId()); if (deviceChannelForUpdate != null) { channel.setId(deviceChannelForUpdate.getId()); + channel.setUpdateTime(DateUtil.getNow()); updateChannelMap.put(channel.getChannelId(), channel); if (updateChannelMap.keySet().size() > 300) { executeSaveForUpdate(); @@ -234,11 +243,11 @@ // 杞彂鍙樺寲淇℃伅 eventPublisher.catalogEventPublish(null, channel, event); - if (updateChannelMap.keySet().size() > 0 - || addChannelMap.keySet().size() > 0 - || updateChannelOnlineList.size() > 0 - || updateChannelOfflineList.size() > 0 - || deleteChannelList.size() > 0) { + if (!updateChannelMap.keySet().isEmpty() + || !addChannelMap.keySet().isEmpty() + || !updateChannelOnlineList.isEmpty() + || !updateChannelOfflineList.isEmpty() + || !deleteChannelList.isEmpty()) { if (!dynamicTask.contains(talkKey)) { dynamicTask.startDelay(talkKey, this::executeSave, 1000); @@ -251,26 +260,49 @@ } } + // TODO 鍚屼竴涓�氶亾濡傛灉鍏堝彂閫佹洿鏂板啀鍙戦�佺绾垮彲鑳芥棤娉曟甯哥绾� private void executeSave(){ - System.out.println("瀹氭椂瀛樺偍鏁版嵁"); - executeSaveForUpdate(); - executeSaveForDelete(); - executeSaveForOnline(); - executeSaveForOffline(); + try { + executeSaveForAdd(); + } catch (Exception e) { + logger.error("[瀛樺偍鏀跺埌鐨勫鍔犻�氶亾] 寮傚父锛� ", e ); + } + try { + executeSaveForOnline(); + } catch (Exception e) { + logger.error("[瀛樺偍鏀跺埌鐨勯�氶亾涓婄嚎] 寮傚父锛� ", e ); + } + try { + executeSaveForOffline(); + } catch (Exception e) { + logger.error("[瀛樺偍鏀跺埌鐨勯�氶亾绂荤嚎] 寮傚父锛� ", e ); + } + try { + executeSaveForUpdate(); + } catch (Exception e) { + logger.error("[瀛樺偍鏀跺埌鐨勬洿鏂伴�氶亾] 寮傚父锛� ", e ); + } + try { + executeSaveForDelete(); + } catch (Exception e) { + logger.error("[瀛樺偍鏀跺埌鐨勫垹闄ら�氶亾] 寮傚父锛� ", e ); + } + dynamicTask.stop(talkKey); } private void executeSaveForUpdate(){ - if (updateChannelMap.values().size() > 0) { + if (!updateChannelMap.values().isEmpty()) { + logger.info("[瀛樺偍鏀跺埌鐨勬洿鏂伴�氶亾], 鏁伴噺锛� {}", updateChannelMap.size()); ArrayList<DeviceChannel> deviceChannels = new ArrayList<>(updateChannelMap.values()); - updateChannelMap.clear(); deviceChannelService.batchUpdateChannel(deviceChannels); + updateChannelMap.clear(); } } private void executeSaveForAdd(){ - if (addChannelMap.values().size() > 0) { + if (!addChannelMap.values().isEmpty()) { ArrayList<DeviceChannel> deviceChannels = new ArrayList<>(addChannelMap.values()); addChannelMap.clear(); deviceChannelService.batchAddChannel(deviceChannels); @@ -278,21 +310,21 @@ } private void executeSaveForDelete(){ - if (deleteChannelList.size() > 0) { + if (!deleteChannelList.isEmpty()) { deviceChannelService.deleteChannels(deleteChannelList); deleteChannelList.clear(); } } private void executeSaveForOnline(){ - if (updateChannelOnlineList.size() > 0) { + if (!updateChannelOnlineList.isEmpty()) { deviceChannelService.channelsOnline(updateChannelOnlineList); updateChannelOnlineList.clear(); } } private void executeSaveForOffline(){ - if (updateChannelOfflineList.size() > 0) { + if (!updateChannelOfflineList.isEmpty()) { deviceChannelService.channelsOffline(updateChannelOfflineList); updateChannelOfflineList.clear(); } -- Gitblit v1.8.0