panlinlin
2021-01-24 c1b3f2beb4b76e89d4938d2f7d5b31ff0f10220d
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
@@ -15,6 +15,8 @@
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce;
import gov.nist.javax.sip.address.AddressImpl;
import gov.nist.javax.sip.address.SipUri;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
@@ -166,10 +168,15 @@
         Element deviceIdElement = rootElement.element("DeviceID");
         String deviceId = deviceIdElement.getText();
         Element deviceListElement = rootElement.element("DeviceList");
         FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
         AddressImpl address = (AddressImpl) fromHeader.getAddress();
         SipUri uri = (SipUri) address.getURI();
         String platformId = uri.getUser();
         // if (deviceListElement == null) { // 存在DeviceList则为响应 catalog, 不存在DeviceList则为查询请求
         if (name == "Query") { // 区分是Response——查询响应,还是Query——查询请求
         if (name.equalsIgnoreCase("Query")) { // 区分是Response——查询响应,还是Query——查询请求
               // TODO 后续将代码拆分
            ParentPlatform parentPlatform = storager.queryParentPlatById(deviceId);
            ParentPlatform parentPlatform = storager.queryParentPlatById(platformId);
            if (parentPlatform == null) {
               response404Ack(evt);
               return;
@@ -179,9 +186,8 @@
               Element snElement = rootElement.element("SN");
               String sn = snElement.getText();
               FromHeader fromHeader = (FromHeader)evt.getRequest().getHeader(FromHeader.NAME);
               // 准备回复通道信息
               List<ChannelReduce> channelReduces = storager.queryChannelListInParentPlatform(parentPlatform.getDeviceGBId());
               List<ChannelReduce> channelReduces = storager.queryChannelListInParentPlatform(parentPlatform.getServerGBId());
               if (channelReduces.size() >0 ) {
                  for (ChannelReduce channelReduce : channelReduces) {
                     DeviceChannel deviceChannel = storager.queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId());
@@ -318,19 +324,41 @@
            // storager.queryChannel(deviceId)
            return;
         }
         device.setName(XmlUtil.getText(rootElement, "DeviceName"));
         device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer"));
         device.setModel(XmlUtil.getText(rootElement, "Model"));
         device.setFirmware(XmlUtil.getText(rootElement, "Firmware"));
         if (StringUtils.isEmpty(device.getStreamMode())) {
            device.setStreamMode("UDP");
         DeviceAlarm deviceAlarm = new DeviceAlarm();
         deviceAlarm.setDeviceId(deviceId);
         deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority"));
         deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod"));
         deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime"));
         if (XmlUtil.getText(rootElement, "AlarmDescription") == null) {
            deviceAlarm.setAlarmDescription("");
         } else {
            deviceAlarm.setAlarmDescription(XmlUtil.getText(rootElement, "AlarmDescription"));
         }
         storager.updateDevice(device);
         if (XmlUtil.getText(rootElement, "Longitude") == null || XmlUtil.getText(rootElement, "Longitude") == "") {
            deviceAlarm.setLongitude(0.00);
         } else {
            deviceAlarm.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
         }
         if (XmlUtil.getText(rootElement, "Latitude") == null || XmlUtil.getText(rootElement, "Latitude") =="") {
            deviceAlarm.setLatitude(0.00);
         } else {
            deviceAlarm.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
         }
         // device.setName(XmlUtil.getText(rootElement, "DeviceName"));
         // device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer"));
         // device.setModel(XmlUtil.getText(rootElement, "Model"));
         // device.setFirmware(XmlUtil.getText(rootElement, "Firmware"));
         // if (StringUtils.isEmpty(device.getStreamMode())) {
         //    device.setStreamMode("UDP");
         // }
         // storager.updateDevice(device);
         //cmder.catalogQuery(device, null);
         // 回复200 OK
         responseAck(evt);
         if (offLineDetector.isOnline(deviceId)) {
            publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE);
            publisher.deviceAlarmEventPublish(deviceAlarm);
         }
      } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
         // } catch (DocumentException e) {
@@ -499,7 +527,7 @@
   }
   /***
    * 回复200 OK
    * 回复404
    * @param evt
    * @throws SipException
    * @throws InvalidArgumentException