Commit e361f14a9687cb6bf4018b5efdedb4f658755a7b
Committed by
GitHub
Merge pull request #58 from lawrencehj/wvp-28181-2.0
同步主线Alarm处理功能
Showing
1 changed file
with
89 additions
and
41 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
| @@ -4,55 +4,53 @@ import java.io.ByteArrayInputStream; | @@ -4,55 +4,53 @@ import java.io.ByteArrayInputStream; | ||
| 4 | import java.text.ParseException; | 4 | import java.text.ParseException; |
| 5 | import java.util.*; | 5 | import java.util.*; |
| 6 | 6 | ||
| 7 | +import javax.sip.header.FromHeader; | ||
| 7 | import javax.sip.InvalidArgumentException; | 8 | import javax.sip.InvalidArgumentException; |
| 8 | import javax.sip.RequestEvent; | 9 | import javax.sip.RequestEvent; |
| 9 | import javax.sip.SipException; | 10 | import javax.sip.SipException; |
| 10 | -import javax.sip.header.FromHeader; | ||
| 11 | import javax.sip.message.Request; | 11 | import javax.sip.message.Request; |
| 12 | import javax.sip.message.Response; | 12 | import javax.sip.message.Response; |
| 13 | 13 | ||
| 14 | import com.alibaba.fastjson.JSONObject; | 14 | import com.alibaba.fastjson.JSONObject; |
| 15 | +import com.genersoft.iot.vmp.common.StreamInfo; | ||
| 16 | +import com.genersoft.iot.vmp.common.VideoManagerConstants; | ||
| 15 | import com.genersoft.iot.vmp.conf.UserSetup; | 17 | import com.genersoft.iot.vmp.conf.UserSetup; |
| 16 | import com.genersoft.iot.vmp.gb28181.bean.*; | 18 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 19 | +import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | ||
| 20 | +import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | ||
| 17 | import com.genersoft.iot.vmp.gb28181.transmit.callback.CheckForAllRecordsThread; | 21 | import com.genersoft.iot.vmp.gb28181.transmit.callback.CheckForAllRecordsThread; |
| 22 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | ||
| 23 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | ||
| 24 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | ||
| 18 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; | 25 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; |
| 26 | +import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor; | ||
| 27 | +import com.genersoft.iot.vmp.gb28181.utils.DateUtil; | ||
| 19 | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; | 28 | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; |
| 29 | +import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; | ||
| 20 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 30 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 31 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | ||
| 21 | import com.genersoft.iot.vmp.utils.GpsUtil; | 32 | import com.genersoft.iot.vmp.utils.GpsUtil; |
| 22 | import com.genersoft.iot.vmp.utils.SpringBeanFactory; | 33 | import com.genersoft.iot.vmp.utils.SpringBeanFactory; |
| 34 | +import com.genersoft.iot.vmp.utils.redis.RedisUtil; | ||
| 23 | import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce; | 35 | import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce; |
| 36 | + | ||
| 24 | import gov.nist.javax.sip.address.AddressImpl; | 37 | import gov.nist.javax.sip.address.AddressImpl; |
| 25 | import gov.nist.javax.sip.address.SipUri; | 38 | import gov.nist.javax.sip.address.SipUri; |
| 39 | + | ||
| 26 | import org.dom4j.Document; | 40 | import org.dom4j.Document; |
| 27 | import org.dom4j.DocumentException; | 41 | import org.dom4j.DocumentException; |
| 28 | import org.dom4j.Element; | 42 | import org.dom4j.Element; |
| 29 | import org.dom4j.io.SAXReader; | 43 | import org.dom4j.io.SAXReader; |
| 30 | import org.slf4j.Logger; | 44 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; | 45 | import org.slf4j.LoggerFactory; |
| 32 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 33 | - | ||
| 34 | -import com.genersoft.iot.vmp.common.VideoManagerConstants; | ||
| 35 | -import com.genersoft.iot.vmp.gb28181.bean.Device; | ||
| 36 | -import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | ||
| 37 | -import com.genersoft.iot.vmp.gb28181.bean.RecordInfo; | ||
| 38 | -import com.genersoft.iot.vmp.gb28181.bean.RecordItem; | ||
| 39 | -import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | ||
| 40 | -import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | ||
| 41 | -import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | ||
| 42 | -import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | ||
| 43 | -import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | ||
| 44 | -import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor; | ||
| 45 | -import com.genersoft.iot.vmp.gb28181.utils.DateUtil; | ||
| 46 | -import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; | ||
| 47 | -import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | ||
| 48 | -import com.genersoft.iot.vmp.utils.redis.RedisUtil; | ||
| 49 | import org.springframework.util.StringUtils; | 46 | import org.springframework.util.StringUtils; |
| 50 | -import com.genersoft.iot.vmp.common.StreamInfo; | 47 | + |
| 51 | /** | 48 | /** |
| 52 | * @Description:MESSAGE请求处理器 | 49 | * @Description:MESSAGE请求处理器 |
| 53 | * @author: swwheihei | 50 | * @author: swwheihei |
| 54 | * @date: 2020年5月3日 下午5:32:41 | 51 | * @date: 2020年5月3日 下午5:32:41 |
| 55 | */ | 52 | */ |
| 53 | +@SuppressWarnings(value={"unchecked", "rawtypes"}) | ||
| 56 | public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | 54 | public class MessageRequestProcessor extends SIPRequestAbstractProcessor { |
| 57 | 55 | ||
| 58 | public static volatile List<String> threadNameList = new ArrayList(); | 56 | public static volatile List<String> threadNameList = new ArrayList(); |
| @@ -517,15 +515,15 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -517,15 +515,15 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 517 | deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port"))); | 515 | deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port"))); |
| 518 | } | 516 | } |
| 519 | deviceChannel.setPassword(XmlUtil.getText(itemDevice, "Password")); | 517 | deviceChannel.setPassword(XmlUtil.getText(itemDevice, "Password")); |
| 520 | - if (XmlUtil.getText(itemDevice, "Longitude") == null || XmlUtil.getText(itemDevice, "Longitude") == "") { | ||
| 521 | - deviceChannel.setLongitude(0.00); | ||
| 522 | - } else { | 518 | + if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Longitude"))) { |
| 523 | deviceChannel.setLongitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Longitude"))); | 519 | deviceChannel.setLongitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Longitude"))); |
| 524 | - } | ||
| 525 | - if (XmlUtil.getText(itemDevice, "Latitude") == null || XmlUtil.getText(itemDevice, "Latitude") == "") { | ||
| 526 | - deviceChannel.setLatitude(0.00); | ||
| 527 | } else { | 520 | } else { |
| 521 | + deviceChannel.setLongitude(0.00); | ||
| 522 | + } | ||
| 523 | + if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Latitude"))) { | ||
| 528 | deviceChannel.setLatitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Latitude"))); | 524 | deviceChannel.setLatitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Latitude"))); |
| 525 | + } else { | ||
| 526 | + deviceChannel.setLatitude(0.00); | ||
| 529 | } | 527 | } |
| 530 | if (XmlUtil.getText(itemDevice, "PTZType") == null || XmlUtil.getText(itemDevice, "PTZType") == "") { | 528 | if (XmlUtil.getText(itemDevice, "PTZType") == null || XmlUtil.getText(itemDevice, "PTZType") == "") { |
| 531 | deviceChannel.setPTZType(0); | 529 | deviceChannel.setPTZType(0); |
| @@ -563,26 +561,72 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -563,26 +561,72 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 563 | Element rootElement = getRootElement(evt); | 561 | Element rootElement = getRootElement(evt); |
| 564 | Element deviceIdElement = rootElement.element("DeviceID"); | 562 | Element deviceIdElement = rootElement.element("DeviceID"); |
| 565 | String deviceId = deviceIdElement.getText().toString(); | 563 | String deviceId = deviceIdElement.getText().toString(); |
| 564 | + // 回复200 OK | ||
| 565 | + responseAck(evt); | ||
| 566 | 566 | ||
| 567 | Device device = storager.queryVideoDevice(deviceId); | 567 | Device device = storager.queryVideoDevice(deviceId); |
| 568 | if (device == null) { | 568 | if (device == null) { |
| 569 | - // TODO 也可能是通道 | ||
| 570 | - // storager.queryChannel(deviceId) | ||
| 571 | return; | 569 | return; |
| 572 | } | 570 | } |
| 573 | - device.setName(XmlUtil.getText(rootElement, "DeviceName")); | ||
| 574 | - device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer")); | ||
| 575 | - device.setModel(XmlUtil.getText(rootElement, "Model")); | ||
| 576 | - device.setFirmware(XmlUtil.getText(rootElement, "Firmware")); | ||
| 577 | - if (StringUtils.isEmpty(device.getStreamMode())) { | ||
| 578 | - device.setStreamMode("UDP"); | ||
| 579 | - } | ||
| 580 | - storager.updateDevice(device); | ||
| 581 | - //cmder.catalogQuery(device, null); | ||
| 582 | - // 回复200 OK | ||
| 583 | - responseAck(evt); | ||
| 584 | - if (offLineDetector.isOnline(deviceId)) { | ||
| 585 | - publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE); | 571 | + |
| 572 | + if (rootElement.getName().equals("Notify")) { // 处理报警通知 | ||
| 573 | + DeviceAlarm deviceAlarm = new DeviceAlarm(); | ||
| 574 | + deviceAlarm.setDeviceId(deviceId); | ||
| 575 | + deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority")); | ||
| 576 | + deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod")); | ||
| 577 | + deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime")); | ||
| 578 | + if (XmlUtil.getText(rootElement, "AlarmDescription") == null) { | ||
| 579 | + deviceAlarm.setAlarmDescription(""); | ||
| 580 | + } else { | ||
| 581 | + deviceAlarm.setAlarmDescription(XmlUtil.getText(rootElement, "AlarmDescription")); | ||
| 582 | + } | ||
| 583 | + if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Longitude"))) { | ||
| 584 | + deviceAlarm.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude"))); | ||
| 585 | + } else { | ||
| 586 | + deviceAlarm.setLongitude(0.00); | ||
| 587 | + } | ||
| 588 | + if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Latitude"))) { | ||
| 589 | + deviceAlarm.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude"))); | ||
| 590 | + } else { | ||
| 591 | + deviceAlarm.setLatitude(0.00); | ||
| 592 | + } | ||
| 593 | + | ||
| 594 | + if (!XmlUtil.isEmpty(deviceAlarm.getAlarmMethod())) { | ||
| 595 | + if ( deviceAlarm.getAlarmMethod().equals("4")) { | ||
| 596 | + MobilePosition mobilePosition = new MobilePosition(); | ||
| 597 | + mobilePosition.setDeviceId(deviceAlarm.getDeviceId()); | ||
| 598 | + mobilePosition.setTime(deviceAlarm.getAlarmTime()); | ||
| 599 | + mobilePosition.setLongitude(deviceAlarm.getLongitude()); | ||
| 600 | + mobilePosition.setLatitude(deviceAlarm.getLatitude()); | ||
| 601 | + mobilePosition.setReportSource("GPS Alarm"); | ||
| 602 | + BaiduPoint bp = new BaiduPoint(); | ||
| 603 | + bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude())); | ||
| 604 | + logger.info("百度坐标:" + bp.getBdLng() + ", " + bp.getBdLat()); | ||
| 605 | + mobilePosition.setGeodeticSystem("BD-09"); | ||
| 606 | + mobilePosition.setCnLng(bp.getBdLng()); | ||
| 607 | + mobilePosition.setCnLat(bp.getBdLat()); | ||
| 608 | + if (!userSetup.getSavePositionHistory()) { | ||
| 609 | + storager.clearMobilePositionsByDeviceId(deviceId); | ||
| 610 | + } | ||
| 611 | + storager.insertMobilePosition(mobilePosition); | ||
| 612 | + } | ||
| 613 | + } | ||
| 614 | + // TODO: 需要实现存储报警信息、报警分类 | ||
| 615 | + | ||
| 616 | + if (offLineDetector.isOnline(deviceId)) { | ||
| 617 | + publisher.deviceAlarmEventPublish(deviceAlarm); | ||
| 618 | + } | ||
| 619 | + } else if (rootElement.getName().equals("Response")) { // 处理报警查询响应 | ||
| 620 | + JSONObject json = new JSONObject(); | ||
| 621 | + XmlUtil.node2Json(rootElement, json); | ||
| 622 | + if (logger.isDebugEnabled()) { | ||
| 623 | + logger.debug(json.toJSONString()); | ||
| 624 | + } | ||
| 625 | + RequestMessage msg = new RequestMessage(); | ||
| 626 | + msg.setDeviceId(deviceId); | ||
| 627 | + msg.setType(DeferredResultHolder.CALLBACK_CMD_ALARM); | ||
| 628 | + msg.setData(json); | ||
| 629 | + deferredResultHolder.invokeResult(msg); | ||
| 586 | } | 630 | } |
| 587 | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { | 631 | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { |
| 588 | // } catch (DocumentException e) { | 632 | // } catch (DocumentException e) { |
| @@ -734,7 +778,11 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -734,7 +778,11 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 734 | } | 778 | } |
| 735 | } | 779 | } |
| 736 | 780 | ||
| 737 | - | 781 | + /** |
| 782 | + * 收到MediaStatus消息处理 | ||
| 783 | + * | ||
| 784 | + * @param evt | ||
| 785 | + */ | ||
| 738 | private void processMessageMediaStatus(RequestEvent evt){ | 786 | private void processMessageMediaStatus(RequestEvent evt){ |
| 739 | try { | 787 | try { |
| 740 | // 回复200 OK | 788 | // 回复200 OK |