Commit 418970eab27d313307d60fd4f2a187efcea260ff

Authored by panlinlin
2 parents 421c2f56 e361f14a

Merge remote-tracking branch 'origin/wvp-28181-2.0' into wvp-28181-2.0

src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
... ... @@ -4,55 +4,53 @@ import java.io.ByteArrayInputStream;
4 4 import java.text.ParseException;
5 5 import java.util.*;
6 6  
  7 +import javax.sip.header.FromHeader;
7 8 import javax.sip.InvalidArgumentException;
8 9 import javax.sip.RequestEvent;
9 10 import javax.sip.SipException;
10   -import javax.sip.header.FromHeader;
11 11 import javax.sip.message.Request;
12 12 import javax.sip.message.Response;
13 13  
14 14 import com.alibaba.fastjson.JSONObject;
  15 +import com.genersoft.iot.vmp.common.StreamInfo;
  16 +import com.genersoft.iot.vmp.common.VideoManagerConstants;
15 17 import com.genersoft.iot.vmp.conf.UserSetup;
16 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 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 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 28 import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
  29 +import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
20 30 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
  31 +import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
21 32 import com.genersoft.iot.vmp.utils.GpsUtil;
22 33 import com.genersoft.iot.vmp.utils.SpringBeanFactory;
  34 +import com.genersoft.iot.vmp.utils.redis.RedisUtil;
23 35 import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce;
  36 +
24 37 import gov.nist.javax.sip.address.AddressImpl;
25 38 import gov.nist.javax.sip.address.SipUri;
  39 +
26 40 import org.dom4j.Document;
27 41 import org.dom4j.DocumentException;
28 42 import org.dom4j.Element;
29 43 import org.dom4j.io.SAXReader;
30 44 import org.slf4j.Logger;
31 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 46 import org.springframework.util.StringUtils;
50   -import com.genersoft.iot.vmp.common.StreamInfo;
  47 +
51 48 /**
52 49 * @Description:MESSAGE请求处理器
53 50 * @author: swwheihei
54 51 * @date: 2020年5月3日 下午5:32:41
55 52 */
  53 +@SuppressWarnings(value={"unchecked", "rawtypes"})
56 54 public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
57 55  
58 56 public static volatile List<String> threadNameList = new ArrayList();
... ... @@ -517,15 +515,15 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
517 515 deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port")));
518 516 }
519 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 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 520 } else {
  521 + deviceChannel.setLongitude(0.00);
  522 + }
  523 + if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Latitude"))) {
528 524 deviceChannel.setLatitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Latitude")));
  525 + } else {
  526 + deviceChannel.setLatitude(0.00);
529 527 }
530 528 if (XmlUtil.getText(itemDevice, "PTZType") == null || XmlUtil.getText(itemDevice, "PTZType") == "") {
531 529 deviceChannel.setPTZType(0);
... ... @@ -563,26 +561,72 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
563 561 Element rootElement = getRootElement(evt);
564 562 Element deviceIdElement = rootElement.element("DeviceID");
565 563 String deviceId = deviceIdElement.getText().toString();
  564 + // 回复200 OK
  565 + responseAck(evt);
566 566  
567 567 Device device = storager.queryVideoDevice(deviceId);
568 568 if (device == null) {
569   - // TODO 也可能是通道
570   - // storager.queryChannel(deviceId)
571 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 631 } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
588 632 // } catch (DocumentException e) {
... ... @@ -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 786 private void processMessageMediaStatus(RequestEvent evt){
739 787 try {
740 788 // 回复200 OK
... ...