Commit 319cdd215170391c7d88078703b7e102158f0b4d

Authored by 648540858
1 parent 138216c3

优化移动位置的时间

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 192 mobilePosition.setDeviceId(device.getDeviceId());
193 193 mobilePosition.setChannelId(channelId);
194 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 201 mobilePosition.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
197 202 mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
198 203 if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Speed"))) {
... ... @@ -237,7 +242,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
237 242  
238 243 // 发送redis消息。 通知位置信息的变化
239 244 JSONObject jsonObject = new JSONObject();
240   - jsonObject.put("time", time);
  245 + jsonObject.put("time", DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(mobilePosition.getTime()));
241 246 jsonObject.put("serial", deviceId);
242 247 jsonObject.put("code", channelId);
243 248 jsonObject.put("longitude", mobilePosition.getLongitude());
... ... @@ -339,7 +344,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
339 344 storager.updateChannelPosition(deviceChannel);
340 345 // 发送redis消息。 通知位置信息的变化
341 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 348 jsonObject.put("serial", deviceChannel.getDeviceId());
344 349 jsonObject.put("code", deviceChannel.getChannelId());
345 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 164  
165 165 // 发送redis消息。 通知位置信息的变化
166 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 168 jsonObject.put("serial", deviceChannel.getDeviceId());
169 169 jsonObject.put("code", deviceChannel.getChannelId());
170 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 7 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
8 8 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler;
9 9 import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
  10 +import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
10 11 import com.genersoft.iot.vmp.service.IDeviceChannelService;
11 12 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
12 13 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
... ... @@ -95,7 +96,12 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen
95 96 }
96 97 mobilePosition.setDeviceId(sipMsgInfo.getDevice().getDeviceId());
97 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 105 mobilePosition.setLongitude(Double.parseDouble(getText(rootElementAfterCharset, "Longitude")));
100 106 mobilePosition.setLatitude(Double.parseDouble(getText(rootElementAfterCharset, "Latitude")));
101 107 if (NumericUtil.isDouble(getText(rootElementAfterCharset, "Speed"))) {
... ... @@ -138,7 +144,7 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen
138 144  
139 145 // 发送redis消息。 通知位置信息的变化
140 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 148 jsonObject.put("serial", deviceChannel.getDeviceId());
143 149 jsonObject.put("code", deviceChannel.getChannelId());
144 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 12 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
13 13 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler;
14 14 import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
  15 +import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
15 16 import com.genersoft.iot.vmp.service.IDeviceChannelService;
16 17 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
17 18 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
... ... @@ -91,8 +92,11 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar
91 92 mobilePosition.setChannelId(getText(rootElement, "DeviceID"));
92 93 //兼容ISO 8601格式时间
93 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 100 mobilePosition.setLongitude(Double.parseDouble(getText(rootElement, "Longitude")));
97 101 mobilePosition.setLatitude(Double.parseDouble(getText(rootElement, "Latitude")));
98 102 if (NumericUtil.isDouble(getText(rootElement, "Speed"))) {
... ... @@ -141,7 +145,7 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar
141 145  
142 146 // 发送redis消息。 通知位置信息的变化
143 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 149 jsonObject.put("serial", deviceChannel.getDeviceId());
146 150 jsonObject.put("code", deviceChannel.getChannelId());
147 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 3 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
4 4 import com.genersoft.iot.vmp.gb28181.bean.Gb28181Sdp;
5 5 import com.genersoft.iot.vmp.gb28181.bean.RemoteAddressInfo;
  6 +import com.genersoft.iot.vmp.utils.DateUtil;
6 7 import com.genersoft.iot.vmp.utils.GitUtil;
7 8 import gov.nist.javax.sip.address.AddressImpl;
8 9 import gov.nist.javax.sip.address.SipUri;
9 10 import gov.nist.javax.sip.header.Subject;
10 11 import gov.nist.javax.sip.message.SIPRequest;
11 12 import org.apache.commons.lang3.RandomStringUtils;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
12 15 import org.springframework.util.ObjectUtils;
13 16  
14 17 import javax.sdp.SdpFactory;
... ... @@ -21,6 +24,8 @@ import javax.sip.header.Header;
21 24 import javax.sip.header.UserAgentHeader;
22 25 import javax.sip.message.Request;
23 26 import java.text.ParseException;
  27 +import java.time.LocalDateTime;
  28 +import java.time.format.DateTimeParseException;
24 29 import java.util.ArrayList;
25 30 import java.util.List;
26 31 import java.util.UUID;
... ... @@ -33,6 +38,8 @@ import java.util.UUID;
33 38 */
34 39 public class SipUtils {
35 40  
  41 + private final static Logger logger = LoggerFactory.getLogger(SipUtils.class);
  42 +
36 43 public static String getUserIdFromFromHeader(Request request) {
37 44 FromHeader fromHeader = (FromHeader)request.getHeader(FromHeader.NAME);
38 45 return getUserIdFromFromHeader(fromHeader);
... ... @@ -238,4 +245,23 @@ public class SipUtils {
238 245 }
239 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 }
... ...