From 2b1f7a47394363e95deb4dfa0f1c67d41e747f7f Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 01 二月 2023 10:56:40 +0800
Subject: [PATCH] Merge branch 'wvp-28181-2.0' into fix-269

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/RecordInfoQueryMessageHandler.java |  146 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 146 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/RecordInfoQueryMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/RecordInfoQueryMessageHandler.java
new file mode 100644
index 0000000..f3170a5
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/RecordInfoQueryMessageHandler.java
@@ -0,0 +1,146 @@
+package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query.cmd;
+
+import com.genersoft.iot.vmp.conf.SipConfig;
+import com.genersoft.iot.vmp.gb28181.bean.*;
+import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
+import com.genersoft.iot.vmp.gb28181.event.record.RecordEndEventListener;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
+import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
+import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
+import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query.QueryMessageHandler;
+import com.genersoft.iot.vmp.utils.DateUtil;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
+import com.genersoft.iot.vmp.storager.dao.dto.ChannelSourceInfo;
+import gov.nist.javax.sip.message.SIPRequest;
+import org.dom4j.Element;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.sip.InvalidArgumentException;
+import javax.sip.RequestEvent;
+import javax.sip.SipException;
+import javax.sip.message.Response;
+import java.text.ParseException;
+import java.util.List;
+
+@Component
+public class RecordInfoQueryMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler {
+
+    private Logger logger = LoggerFactory.getLogger(RecordInfoQueryMessageHandler.class);
+    private final String cmdType = "RecordInfo";
+
+    @Autowired
+    private QueryMessageHandler queryMessageHandler;
+
+    @Autowired
+    private IVideoManagerStorage storager;
+
+    @Autowired
+    private SIPCommanderFroPlatform cmderFroPlatform;
+
+    @Autowired
+    private SIPCommander commander;
+
+    @Autowired
+    private RecordEndEventListener recordEndEventListener;
+
+    @Autowired
+    private SipConfig config;
+
+    @Autowired
+    private EventPublisher publisher;
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        queryMessageHandler.addHandler(cmdType, this);
+    }
+
+    @Override
+    public void handForDevice(RequestEvent evt, Device device, Element element) {
+
+    }
+
+    @Override
+    public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) {
+
+        SIPRequest request = (SIPRequest) evt.getRequest();
+        Element snElement = rootElement.element("SN");
+        int sn = Integer.parseInt(snElement.getText());
+        Element deviceIDElement = rootElement.element("DeviceID");
+        String channelId = deviceIDElement.getText();
+        Element startTimeElement = rootElement.element("StartTime");
+        String startTime = null;
+        if (startTimeElement != null) {
+            startTime = startTimeElement.getText();
+        }
+        Element endTimeElement = rootElement.element("EndTime");
+        String endTime = null;
+        if (endTimeElement != null) {
+            endTime = endTimeElement.getText();
+        }
+        Element secrecyElement = rootElement.element("Secrecy");
+        int secrecy = 0;
+        if (secrecyElement != null) {
+            secrecy = Integer.parseInt(secrecyElement.getText().trim());
+        }
+        String type = "all";
+        Element typeElement = rootElement.element("Type");
+        if (typeElement != null) {
+            type =  typeElement.getText();
+        }
+        // 纭鏄洿鎾繕鏄浗鏍囷紝 鍥芥爣鐩存帴璇锋眰涓嬬骇锛岀洿鎾姹傚綍鍍忕鐞嗘湇鍔�
+        List<ChannelSourceInfo> channelSources = storager.getChannelSource(parentPlatform.getServerGBId(), channelId);
+
+        if (channelSources.get(0).getCount() > 0) { // 鍥芥爣
+            // 鍚戝浗鏍囪澶囪姹傚綍鍍忔暟鎹�
+            Device device = storager.queryVideoDeviceByPlatformIdAndChannelId(parentPlatform.getServerGBId(), channelId);
+            DeviceChannel deviceChannel = storager.queryChannelInParentPlatform(parentPlatform.getServerGBId(), channelId);
+            // 鎺ユ敹褰曞儚鏁版嵁
+            recordEndEventListener.addEndEventHandler(deviceChannel.getDeviceId(), channelId, (recordInfo)->{
+                try {
+                    cmderFroPlatform.recordInfo(deviceChannel, parentPlatform, request.getFromTag(), recordInfo);
+                } catch (SipException | InvalidArgumentException | ParseException e) {
+                    logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍥炲褰曞儚鏁版嵁: {}", e.getMessage());
+                }
+            });
+            try {
+                commander.recordInfoQuery(device, channelId, DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(startTime),
+                        DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(endTime), sn, secrecy, type, (eventResult -> {
+                            // 鍥炲200 OK
+                            try {
+                                responseAck(request, Response.OK);
+                            } catch (SipException | InvalidArgumentException | ParseException e) {
+                                logger.error("[鍛戒护鍙戦�佸け璐 褰曞儚鏌ヨ鍥炲: {}", e.getMessage());
+                            }
+                        }),(eventResult -> {
+                            // 鏌ヨ澶辫触
+                            try {
+                                responseAck(request, eventResult.statusCode, eventResult.msg);
+                            } catch (SipException | InvalidArgumentException | ParseException e) {
+                                logger.error("[鍛戒护鍙戦�佸け璐 褰曞儚鏌ヨ鍥炲: {}", e.getMessage());
+                            }
+                        }));
+            } catch (InvalidArgumentException | ParseException | SipException e) {
+                logger.error("[鍛戒护鍙戦�佸け璐 褰曞儚鏌ヨ: {}", e.getMessage());
+            }
+
+        }else if (channelSources.get(1).getCount() > 0) { // 鐩存挱娴�
+            // TODO
+            try {
+                responseAck(request, Response.NOT_IMPLEMENTED); // 鍥炲鏈疄鐜�
+            } catch (SipException | InvalidArgumentException | ParseException e) {
+                logger.error("[鍛戒护鍙戦�佸け璐 褰曞儚鏌ヨ: {}", e.getMessage());
+            }
+        }else { // 閿欒鐨勮姹�
+            try {
+                responseAck(request, Response.BAD_REQUEST);
+            } catch (SipException | InvalidArgumentException | ParseException e) {
+                logger.error("[鍛戒护鍙戦�佸け璐 褰曞儚鏌ヨ: {}", e.getMessage());
+            }
+        }
+    }
+}

--
Gitblit v1.8.0