Commit b565523684b9c3c9f103d691db0dcf36022ab529
Committed by
GitHub
Merge pull request #403 from brewswang/wvp-28181-2.0
执法记录仪在更新目录数据的时候需要更新位置信息
Showing
1 changed file
with
82 additions
and
3 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java
| ... | ... | @@ -2,9 +2,8 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.respon |
| 2 | 2 | |
| 3 | 3 | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| 4 | 4 | import com.genersoft.iot.vmp.conf.SipConfig; |
| 5 | -import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 6 | -import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | |
| 7 | -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 5 | +import com.genersoft.iot.vmp.conf.UserSetup; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.bean.*; | |
| 8 | 7 | import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; |
| 9 | 8 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 10 | 9 | import com.genersoft.iot.vmp.gb28181.session.CatalogDataCatch; |
| ... | ... | @@ -15,7 +14,9 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessag |
| 15 | 14 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; |
| 16 | 15 | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; |
| 17 | 16 | import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; |
| 17 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | |
| 18 | 18 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 19 | +import com.genersoft.iot.vmp.utils.GpsUtil; | |
| 19 | 20 | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; |
| 20 | 21 | import org.dom4j.DocumentException; |
| 21 | 22 | import org.dom4j.Element; |
| ... | ... | @@ -24,6 +25,7 @@ import org.slf4j.LoggerFactory; |
| 24 | 25 | import org.springframework.beans.factory.InitializingBean; |
| 25 | 26 | import org.springframework.beans.factory.annotation.Autowired; |
| 26 | 27 | import org.springframework.stereotype.Component; |
| 28 | +import org.springframework.util.StringUtils; | |
| 27 | 29 | |
| 28 | 30 | import javax.sip.InvalidArgumentException; |
| 29 | 31 | import javax.sip.RequestEvent; |
| ... | ... | @@ -67,6 +69,13 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp |
| 67 | 69 | @Autowired |
| 68 | 70 | private EventPublisher publisher; |
| 69 | 71 | |
| 72 | + //by brewswang | |
| 73 | + @Autowired | |
| 74 | + private UserSetup userSetup; | |
| 75 | + | |
| 76 | + @Autowired | |
| 77 | + private IRedisCatchStorage redisCatchStorage; | |
| 78 | + | |
| 70 | 79 | @Override |
| 71 | 80 | public void afterPropertiesSet() throws Exception { |
| 72 | 81 | responseMessageHandler.addHandler(cmdType, this); |
| ... | ... | @@ -108,6 +117,11 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp |
| 108 | 117 | if (channelDeviceElement == null) { |
| 109 | 118 | continue; |
| 110 | 119 | } |
| 120 | + //by brewswang | |
| 121 | + if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Longitude"))) {//如果包含位置信息,就更新一下位置 | |
| 122 | + processNotifyMobilePosition(evt, itemDevice); | |
| 123 | + } | |
| 124 | + | |
| 111 | 125 | DeviceChannel deviceChannel = XmlUtil.channelContentHander(itemDevice); |
| 112 | 126 | deviceChannel.setDeviceId(device.getDeviceId()); |
| 113 | 127 | logger.debug("收到来自设备【{}】的通道: {}【{}】", device.getDeviceId(), deviceChannel.getName(), deviceChannel.getChannelId()); |
| ... | ... | @@ -154,4 +168,69 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp |
| 154 | 168 | public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) { |
| 155 | 169 | |
| 156 | 170 | } |
| 171 | + | |
| 172 | + /** | |
| 173 | + * 处理设备位置的更新 | |
| 174 | + * | |
| 175 | + * @param evt, itemDevice | |
| 176 | + */ | |
| 177 | + private void processNotifyMobilePosition(RequestEvent evt, Element itemDevice) { | |
| 178 | + try { | |
| 179 | + // 回复 200 OK | |
| 180 | + Element rootElement = getRootElement(evt); | |
| 181 | + MobilePosition mobilePosition = new MobilePosition(); | |
| 182 | + Element deviceIdElement = rootElement.element("DeviceID"); | |
| 183 | + String deviceId = deviceIdElement.getTextTrim().toString(); | |
| 184 | + Device device = redisCatchStorage.getDevice(deviceId); | |
| 185 | + if (device != null) { | |
| 186 | + if (!StringUtils.isEmpty(device.getName())) { | |
| 187 | + mobilePosition.setDeviceName(device.getName()); | |
| 188 | + } | |
| 189 | + } | |
| 190 | + mobilePosition.setDeviceId(XmlUtil.getText(rootElement, "DeviceID")); | |
| 191 | + | |
| 192 | + String time = XmlUtil.getText(itemDevice, "Time"); | |
| 193 | + if(time==null){ | |
| 194 | + time = XmlUtil.getText(itemDevice, "EndTime"); | |
| 195 | + } | |
| 196 | + mobilePosition.setTime(time); | |
| 197 | + String longitude = XmlUtil.getText(itemDevice, "Longitude"); | |
| 198 | + if(longitude!=null) { | |
| 199 | + mobilePosition.setLongitude(Double.parseDouble(longitude)); | |
| 200 | + } | |
| 201 | + String latitude = XmlUtil.getText(itemDevice, "Latitude"); | |
| 202 | + if(latitude!=null) { | |
| 203 | + mobilePosition.setLatitude(Double.parseDouble(latitude)); | |
| 204 | + } | |
| 205 | + if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Speed"))) { | |
| 206 | + mobilePosition.setSpeed(Double.parseDouble(XmlUtil.getText(itemDevice, "Speed"))); | |
| 207 | + } else { | |
| 208 | + mobilePosition.setSpeed(0.0); | |
| 209 | + } | |
| 210 | + if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Direction"))) { | |
| 211 | + mobilePosition.setDirection(Double.parseDouble(XmlUtil.getText(itemDevice, "Direction"))); | |
| 212 | + } else { | |
| 213 | + mobilePosition.setDirection(0.0); | |
| 214 | + } | |
| 215 | + if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Altitude"))) { | |
| 216 | + mobilePosition.setAltitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Altitude"))); | |
| 217 | + } else { | |
| 218 | + mobilePosition.setAltitude(0.0); | |
| 219 | + } | |
| 220 | + mobilePosition.setReportSource("Mobile Position"); | |
| 221 | + BaiduPoint bp = new BaiduPoint(); | |
| 222 | + bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude())); | |
| 223 | + logger.info("百度坐标:" + bp.getBdLng() + ", " + bp.getBdLat()); | |
| 224 | + mobilePosition.setGeodeticSystem("BD-09"); | |
| 225 | + mobilePosition.setCnLng(bp.getBdLng()); | |
| 226 | + mobilePosition.setCnLat(bp.getBdLat()); | |
| 227 | + if (!userSetup.getSavePositionHistory()) { | |
| 228 | + storager.clearMobilePositionsByDeviceId(deviceId); | |
| 229 | + } | |
| 230 | + storager.insertMobilePosition(mobilePosition); | |
| 231 | + responseAck(evt, Response.OK); | |
| 232 | + } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { | |
| 233 | + e.printStackTrace(); | |
| 234 | + } | |
| 235 | + } | |
| 157 | 236 | } | ... | ... |