Commit 319cdd215170391c7d88078703b7e102158f0b4d
1 parent
138216c3
优化移动位置的时间
Showing
5 changed files
with
50 additions
and
9 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
| @@ -192,7 +192,12 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements | @@ -192,7 +192,12 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements | ||
| 192 | mobilePosition.setDeviceId(device.getDeviceId()); | 192 | mobilePosition.setDeviceId(device.getDeviceId()); |
| 193 | mobilePosition.setChannelId(channelId); | 193 | mobilePosition.setChannelId(channelId); |
| 194 | String time = XmlUtil.getText(rootElement, "Time"); | 194 | String time = XmlUtil.getText(rootElement, "Time"); |
| 195 | - mobilePosition.setTime(time); | 195 | + if (ObjectUtils.isEmpty(time)){ |
| 196 | + mobilePosition.setTime(DateUtil.getNow()); | ||
| 197 | + }else { | ||
| 198 | + mobilePosition.setTime(SipUtils.parseTime(time)); | ||
| 199 | + } | ||
| 200 | + | ||
| 196 | mobilePosition.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude"))); | 201 | mobilePosition.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude"))); |
| 197 | mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude"))); | 202 | mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude"))); |
| 198 | if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Speed"))) { | 203 | if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Speed"))) { |
| @@ -237,7 +242,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements | @@ -237,7 +242,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements | ||
| 237 | 242 | ||
| 238 | // 发送redis消息。 通知位置信息的变化 | 243 | // 发送redis消息。 通知位置信息的变化 |
| 239 | JSONObject jsonObject = new JSONObject(); | 244 | JSONObject jsonObject = new JSONObject(); |
| 240 | - jsonObject.put("time", time); | 245 | + jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime())); |
| 241 | jsonObject.put("serial", deviceId); | 246 | jsonObject.put("serial", deviceId); |
| 242 | jsonObject.put("code", channelId); | 247 | jsonObject.put("code", channelId); |
| 243 | jsonObject.put("longitude", mobilePosition.getLongitude()); | 248 | jsonObject.put("longitude", mobilePosition.getLongitude()); |
| @@ -339,7 +344,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements | @@ -339,7 +344,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements | ||
| 339 | storager.updateChannelPosition(deviceChannel); | 344 | storager.updateChannelPosition(deviceChannel); |
| 340 | // 发送redis消息。 通知位置信息的变化 | 345 | // 发送redis消息。 通知位置信息的变化 |
| 341 | JSONObject jsonObject = new JSONObject(); | 346 | JSONObject jsonObject = new JSONObject(); |
| 342 | - jsonObject.put("time", mobilePosition.getTime()); | 347 | + jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime())); |
| 343 | jsonObject.put("serial", deviceChannel.getDeviceId()); | 348 | jsonObject.put("serial", deviceChannel.getDeviceId()); |
| 344 | jsonObject.put("code", deviceChannel.getChannelId()); | 349 | jsonObject.put("code", deviceChannel.getChannelId()); |
| 345 | jsonObject.put("longitude", mobilePosition.getLongitude()); | 350 | jsonObject.put("longitude", mobilePosition.getLongitude()); |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
| @@ -164,7 +164,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme | @@ -164,7 +164,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme | ||
| 164 | 164 | ||
| 165 | // 发送redis消息。 通知位置信息的变化 | 165 | // 发送redis消息。 通知位置信息的变化 |
| 166 | JSONObject jsonObject = new JSONObject(); | 166 | JSONObject jsonObject = new JSONObject(); |
| 167 | - jsonObject.put("time", mobilePosition.getTime()); | 167 | + jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime())); |
| 168 | jsonObject.put("serial", deviceChannel.getDeviceId()); | 168 | jsonObject.put("serial", deviceChannel.getDeviceId()); |
| 169 | jsonObject.put("code", deviceChannel.getChannelId()); | 169 | jsonObject.put("code", deviceChannel.getChannelId()); |
| 170 | jsonObject.put("longitude", mobilePosition.getLongitude()); | 170 | jsonObject.put("longitude", mobilePosition.getLongitude()); |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java
| @@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorP | @@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorP | ||
| 7 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | 7 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; |
| 8 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler; | 8 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler; |
| 9 | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; | 9 | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; |
| 10 | +import com.genersoft.iot.vmp.gb28181.utils.SipUtils; | ||
| 10 | import com.genersoft.iot.vmp.service.IDeviceChannelService; | 11 | import com.genersoft.iot.vmp.service.IDeviceChannelService; |
| 11 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 12 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 12 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; | 13 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| @@ -95,7 +96,12 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen | @@ -95,7 +96,12 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen | ||
| 95 | } | 96 | } |
| 96 | mobilePosition.setDeviceId(sipMsgInfo.getDevice().getDeviceId()); | 97 | mobilePosition.setDeviceId(sipMsgInfo.getDevice().getDeviceId()); |
| 97 | mobilePosition.setChannelId(getText(rootElementAfterCharset, "DeviceID")); | 98 | mobilePosition.setChannelId(getText(rootElementAfterCharset, "DeviceID")); |
| 98 | - mobilePosition.setTime(getText(rootElementAfterCharset, "Time")); | 99 | + String time = getText(rootElementAfterCharset, "Time"); |
| 100 | + if (ObjectUtils.isEmpty(time)){ | ||
| 101 | + mobilePosition.setTime(DateUtil.getNow()); | ||
| 102 | + }else { | ||
| 103 | + mobilePosition.setTime(SipUtils.parseTime(time)); | ||
| 104 | + } | ||
| 99 | mobilePosition.setLongitude(Double.parseDouble(getText(rootElementAfterCharset, "Longitude"))); | 105 | mobilePosition.setLongitude(Double.parseDouble(getText(rootElementAfterCharset, "Longitude"))); |
| 100 | mobilePosition.setLatitude(Double.parseDouble(getText(rootElementAfterCharset, "Latitude"))); | 106 | mobilePosition.setLatitude(Double.parseDouble(getText(rootElementAfterCharset, "Latitude"))); |
| 101 | if (NumericUtil.isDouble(getText(rootElementAfterCharset, "Speed"))) { | 107 | if (NumericUtil.isDouble(getText(rootElementAfterCharset, "Speed"))) { |
| @@ -138,7 +144,7 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen | @@ -138,7 +144,7 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen | ||
| 138 | 144 | ||
| 139 | // 发送redis消息。 通知位置信息的变化 | 145 | // 发送redis消息。 通知位置信息的变化 |
| 140 | JSONObject jsonObject = new JSONObject(); | 146 | JSONObject jsonObject = new JSONObject(); |
| 141 | - jsonObject.put("time", mobilePosition.getTime()); | 147 | + jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime())); |
| 142 | jsonObject.put("serial", deviceChannel.getDeviceId()); | 148 | jsonObject.put("serial", deviceChannel.getDeviceId()); |
| 143 | jsonObject.put("code", deviceChannel.getChannelId()); | 149 | jsonObject.put("code", deviceChannel.getChannelId()); |
| 144 | jsonObject.put("longitude", mobilePosition.getLongitude()); | 150 | jsonObject.put("longitude", mobilePosition.getLongitude()); |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java
| @@ -12,6 +12,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorP | @@ -12,6 +12,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorP | ||
| 12 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | 12 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; |
| 13 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; | 13 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; |
| 14 | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; | 14 | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; |
| 15 | +import com.genersoft.iot.vmp.gb28181.utils.SipUtils; | ||
| 15 | import com.genersoft.iot.vmp.service.IDeviceChannelService; | 16 | import com.genersoft.iot.vmp.service.IDeviceChannelService; |
| 16 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 17 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 17 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; | 18 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| @@ -91,8 +92,11 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar | @@ -91,8 +92,11 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar | ||
| 91 | mobilePosition.setChannelId(getText(rootElement, "DeviceID")); | 92 | mobilePosition.setChannelId(getText(rootElement, "DeviceID")); |
| 92 | //兼容ISO 8601格式时间 | 93 | //兼容ISO 8601格式时间 |
| 93 | String time = getText(rootElement, "Time"); | 94 | String time = getText(rootElement, "Time"); |
| 94 | - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
| 95 | - mobilePosition.setTime(LocalDateTime.parse(time).format(formatter)); | 95 | + if (ObjectUtils.isEmpty(time)){ |
| 96 | + mobilePosition.setTime(DateUtil.getNow()); | ||
| 97 | + }else { | ||
| 98 | + mobilePosition.setTime(SipUtils.parseTime(time)); | ||
| 99 | + } | ||
| 96 | mobilePosition.setLongitude(Double.parseDouble(getText(rootElement, "Longitude"))); | 100 | mobilePosition.setLongitude(Double.parseDouble(getText(rootElement, "Longitude"))); |
| 97 | mobilePosition.setLatitude(Double.parseDouble(getText(rootElement, "Latitude"))); | 101 | mobilePosition.setLatitude(Double.parseDouble(getText(rootElement, "Latitude"))); |
| 98 | if (NumericUtil.isDouble(getText(rootElement, "Speed"))) { | 102 | if (NumericUtil.isDouble(getText(rootElement, "Speed"))) { |
| @@ -141,7 +145,7 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar | @@ -141,7 +145,7 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar | ||
| 141 | 145 | ||
| 142 | // 发送redis消息。 通知位置信息的变化 | 146 | // 发送redis消息。 通知位置信息的变化 |
| 143 | JSONObject jsonObject = new JSONObject(); | 147 | JSONObject jsonObject = new JSONObject(); |
| 144 | - jsonObject.put("time", mobilePosition.getTime()); | 148 | + jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime())); |
| 145 | jsonObject.put("serial", deviceChannel.getDeviceId()); | 149 | jsonObject.put("serial", deviceChannel.getDeviceId()); |
| 146 | jsonObject.put("code", deviceChannel.getChannelId()); | 150 | jsonObject.put("code", deviceChannel.getChannelId()); |
| 147 | jsonObject.put("longitude", mobilePosition.getLongitude()); | 151 | jsonObject.put("longitude", mobilePosition.getLongitude()); |
src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java
| @@ -3,12 +3,15 @@ package com.genersoft.iot.vmp.gb28181.utils; | @@ -3,12 +3,15 @@ package com.genersoft.iot.vmp.gb28181.utils; | ||
| 3 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | 3 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| 4 | import com.genersoft.iot.vmp.gb28181.bean.Gb28181Sdp; | 4 | import com.genersoft.iot.vmp.gb28181.bean.Gb28181Sdp; |
| 5 | import com.genersoft.iot.vmp.gb28181.bean.RemoteAddressInfo; | 5 | import com.genersoft.iot.vmp.gb28181.bean.RemoteAddressInfo; |
| 6 | +import com.genersoft.iot.vmp.utils.DateUtil; | ||
| 6 | import com.genersoft.iot.vmp.utils.GitUtil; | 7 | import com.genersoft.iot.vmp.utils.GitUtil; |
| 7 | import gov.nist.javax.sip.address.AddressImpl; | 8 | import gov.nist.javax.sip.address.AddressImpl; |
| 8 | import gov.nist.javax.sip.address.SipUri; | 9 | import gov.nist.javax.sip.address.SipUri; |
| 9 | import gov.nist.javax.sip.header.Subject; | 10 | import gov.nist.javax.sip.header.Subject; |
| 10 | import gov.nist.javax.sip.message.SIPRequest; | 11 | import gov.nist.javax.sip.message.SIPRequest; |
| 11 | import org.apache.commons.lang3.RandomStringUtils; | 12 | import org.apache.commons.lang3.RandomStringUtils; |
| 13 | +import org.slf4j.Logger; | ||
| 14 | +import org.slf4j.LoggerFactory; | ||
| 12 | import org.springframework.util.ObjectUtils; | 15 | import org.springframework.util.ObjectUtils; |
| 13 | 16 | ||
| 14 | import javax.sdp.SdpFactory; | 17 | import javax.sdp.SdpFactory; |
| @@ -21,6 +24,8 @@ import javax.sip.header.Header; | @@ -21,6 +24,8 @@ import javax.sip.header.Header; | ||
| 21 | import javax.sip.header.UserAgentHeader; | 24 | import javax.sip.header.UserAgentHeader; |
| 22 | import javax.sip.message.Request; | 25 | import javax.sip.message.Request; |
| 23 | import java.text.ParseException; | 26 | import java.text.ParseException; |
| 27 | +import java.time.LocalDateTime; | ||
| 28 | +import java.time.format.DateTimeParseException; | ||
| 24 | import java.util.ArrayList; | 29 | import java.util.ArrayList; |
| 25 | import java.util.List; | 30 | import java.util.List; |
| 26 | import java.util.UUID; | 31 | import java.util.UUID; |
| @@ -33,6 +38,8 @@ import java.util.UUID; | @@ -33,6 +38,8 @@ import java.util.UUID; | ||
| 33 | */ | 38 | */ |
| 34 | public class SipUtils { | 39 | public class SipUtils { |
| 35 | 40 | ||
| 41 | + private final static Logger logger = LoggerFactory.getLogger(SipUtils.class); | ||
| 42 | + | ||
| 36 | public static String getUserIdFromFromHeader(Request request) { | 43 | public static String getUserIdFromFromHeader(Request request) { |
| 37 | FromHeader fromHeader = (FromHeader)request.getHeader(FromHeader.NAME); | 44 | FromHeader fromHeader = (FromHeader)request.getHeader(FromHeader.NAME); |
| 38 | return getUserIdFromFromHeader(fromHeader); | 45 | return getUserIdFromFromHeader(fromHeader); |
| @@ -238,4 +245,23 @@ public class SipUtils { | @@ -238,4 +245,23 @@ public class SipUtils { | ||
| 238 | } | 245 | } |
| 239 | return null; | 246 | return null; |
| 240 | } | 247 | } |
| 248 | + | ||
| 249 | + public static String parseTime(String timeStr) { | ||
| 250 | + if (ObjectUtils.isEmpty(timeStr)){ | ||
| 251 | + return null; | ||
| 252 | + } | ||
| 253 | + System.out.println(timeStr); | ||
| 254 | + LocalDateTime localDateTime; | ||
| 255 | + try { | ||
| 256 | + localDateTime = LocalDateTime.parse(timeStr); | ||
| 257 | + }catch (DateTimeParseException e) { | ||
| 258 | + try { | ||
| 259 | + localDateTime = LocalDateTime.parse(timeStr, DateUtil.formatterISO8601); | ||
| 260 | + }catch (DateTimeParseException e2) { | ||
| 261 | + logger.error("[格式化时间] 无法格式化时间: {}", timeStr); | ||
| 262 | + return null; | ||
| 263 | + } | ||
| 264 | + } | ||
| 265 | + return localDateTime.format(DateUtil.formatterISO8601); | ||
| 266 | + } | ||
| 241 | } | 267 | } |