From 2b0af3be14d3f8ac28a1cb031e21dc3a69146d2b Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期一, 25 三月 2024 17:59:09 +0800
Subject: [PATCH] 支持hook

---
 src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java |  219 ++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 170 insertions(+), 49 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java
index e2e4fe6..6c11159 100755
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java
@@ -1,17 +1,15 @@
 package com.genersoft.iot.vmp.vmanager.cloudRecord;
 
-import com.genersoft.iot.vmp.conf.DynamicTask;
-import com.genersoft.iot.vmp.conf.UserSetting;
+import com.alibaba.fastjson2.JSONArray;
 import com.genersoft.iot.vmp.conf.exception.ControllerException;
 import com.genersoft.iot.vmp.conf.security.JwtUtils;
-import com.genersoft.iot.vmp.media.zlm.SendRtpPortManager;
-import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory;
-import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
-import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
-import com.genersoft.iot.vmp.service.IMediaServerService;
+import com.genersoft.iot.vmp.media.zlm.dto.MediaServer;
+import com.genersoft.iot.vmp.service.ICloudRecordService;
+import com.genersoft.iot.vmp.media.service.IMediaServerService;
+import com.genersoft.iot.vmp.service.bean.CloudRecordItem;
+import com.genersoft.iot.vmp.service.bean.DownloadFileInfo;
 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
-import com.genersoft.iot.vmp.vmanager.bean.PageInfo;
-import com.genersoft.iot.vmp.vmanager.bean.RecordFile;
+import com.github.pagehelper.PageInfo;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@@ -20,9 +18,9 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.List;
@@ -34,28 +32,15 @@
 @RequestMapping("/api/cloud/record")
 public class CloudRecordController {
 
-    @Autowired
-    private ZLMServerFactory zlmServerFactory;
-
-    @Autowired
-    private SendRtpPortManager sendRtpPortManager;
 
     private final static Logger logger = LoggerFactory.getLogger(CloudRecordController.class);
 
     @Autowired
-    private ZlmHttpHookSubscribe hookSubscribe;
+    private ICloudRecordService cloudRecordService;
 
     @Autowired
     private IMediaServerService mediaServerService;
 
-    @Autowired
-    private UserSetting userSetting;
-
-    @Autowired
-    private DynamicTask dynamicTask;
-
-    @Autowired
-    private RedisTemplate<Object, Object> redisTemplate;
 
     @ResponseBody
     @GetMapping("/date/list")
@@ -66,8 +51,8 @@
     @Parameter(name = "month", description = "鏈堬紝缃┖鍒欐煡璇㈠綋鏈�", required = false)
     @Parameter(name = "mediaServerId", description = "娴佸獟浣揑D锛岀疆绌哄垯鏌ヨ鍏ㄩ儴", required = false)
     public List<String> openRtpServer(
-            @RequestParam String app,
-            @RequestParam String stream,
+            @RequestParam(required = true) String app,
+            @RequestParam(required = true) String stream,
             @RequestParam(required = false) int year,
             @RequestParam(required = false) int month,
             @RequestParam(required = false) String mediaServerId
@@ -82,66 +67,202 @@
         if (ObjectUtils.isEmpty(month)) {
             month = calendar.get(Calendar.MONTH) + 1;
         }
-        List<MediaServerItem> mediaServerItems;
+        List<MediaServer> mediaServerItems;
         if (!ObjectUtils.isEmpty(mediaServerId)) {
             mediaServerItems = new ArrayList<>();
-            MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
+            MediaServer mediaServerItem = mediaServerService.getOne(mediaServerId);
             if (mediaServerItem == null) {
                 throw new ControllerException(ErrorCode.ERROR100.getCode(), "鏈壘鍒版祦濯掍綋: " + mediaServerId);
             }
             mediaServerItems.add(mediaServerItem);
         } else {
-            mediaServerItems = mediaServerService.getAll();
+            mediaServerItems = mediaServerService.getAllOnlineList();
         }
         if (mediaServerItems.isEmpty()) {
             return new ArrayList<>();
         }
 
-        return mediaServerService.getRecordDates(app, stream, year, month, mediaServerItems);
+        return cloudRecordService.getDateList(app, stream, year, month, mediaServerItems);
     }
 
     @ResponseBody
     @GetMapping("/list")
     @Operation(summary = "鍒嗛〉鏌ヨ浜戠褰曞儚", security = @SecurityRequirement(name = JwtUtils.HEADER))
-    @Parameter(name = "app", description = "搴旂敤鍚�", required = true)
-    @Parameter(name = "stream", description = "娴両D", required = true)
-    @Parameter(name = "page", description = "褰撳墠椤�", required = false)
-    @Parameter(name = "count", description = "姣忛〉鏌ヨ鏁伴噺", required = false)
-    @Parameter(name = "startTime", description = "寮�濮嬫椂闂�(yyyy-MM-dd HH:mm:ss)", required = true)
-    @Parameter(name = "endTime", description = "缁撴潫鏃堕棿(yyyy-MM-dd HH:mm:ss)", required = true)
+    @Parameter(name = "query", description = "妫�绱㈠唴瀹�", required = false)
+    @Parameter(name = "app", description = "搴旂敤鍚�", required = false)
+    @Parameter(name = "stream", description = "娴両D", required = false)
+    @Parameter(name = "page", description = "褰撳墠椤�", required = true)
+    @Parameter(name = "count", description = "姣忛〉鏌ヨ鏁伴噺", required = true)
+    @Parameter(name = "startTime", description = "寮�濮嬫椂闂�(yyyy-MM-dd HH:mm:ss)", required = false)
+    @Parameter(name = "endTime", description = "缁撴潫鏃堕棿(yyyy-MM-dd HH:mm:ss)", required = false)
     @Parameter(name = "mediaServerId", description = "娴佸獟浣揑D锛岀疆绌哄垯鏌ヨ鍏ㄩ儴娴佸獟浣�", required = false)
-    public PageInfo<RecordFile> openRtpServer(
-            @RequestParam String app,
-            @RequestParam String stream,
+    public PageInfo<CloudRecordItem> openRtpServer(
+            @RequestParam(required = false)  String query,
+            @RequestParam(required = false)  String app,
+            @RequestParam(required = false)  String stream,
             @RequestParam int page,
             @RequestParam int count,
-            @RequestParam String startTime,
-            @RequestParam String endTime,
+            @RequestParam(required = false)  String startTime,
+            @RequestParam(required = false)  String endTime,
             @RequestParam(required = false) String mediaServerId
 
     ) {
         logger.info("[浜戠褰曞儚] 鏌ヨ app->{}, stream->{}, mediaServerId->{}, page->{}, count->{}, startTime->{}, endTime->{}",
                 app, stream, mediaServerId, page, count, startTime, endTime);
 
-        List<MediaServerItem> mediaServerItems;
+        List<MediaServer> mediaServerItems;
         if (!ObjectUtils.isEmpty(mediaServerId)) {
             mediaServerItems = new ArrayList<>();
-            MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
+            MediaServer mediaServerItem = mediaServerService.getOne(mediaServerId);
             if (mediaServerItem == null) {
                 throw new ControllerException(ErrorCode.ERROR100.getCode(), "鏈壘鍒版祦濯掍綋: " + mediaServerId);
             }
             mediaServerItems.add(mediaServerItem);
         } else {
-            mediaServerItems = mediaServerService.getAll();
+            mediaServerItems = mediaServerService.getAllOnlineList();
         }
         if (mediaServerItems.isEmpty()) {
-            return new PageInfo<>();
+            throw new ControllerException(ErrorCode.ERROR100.getCode(), "褰撳墠鏃犳祦濯掍綋");
         }
-        List<RecordFile> records = mediaServerService.getRecords(app, stream, startTime, endTime, mediaServerItems);
-        PageInfo<RecordFile> pageInfo = new PageInfo<>(records);
-        pageInfo.startPage(page, count);
-        return pageInfo;
+        if (query != null && ObjectUtils.isEmpty(query.trim())) {
+            query = null;
+        }
+        if (app != null && ObjectUtils.isEmpty(app.trim())) {
+            app = null;
+        }
+        if (stream != null && ObjectUtils.isEmpty(stream.trim())) {
+            stream = null;
+        }
+        if (startTime != null && ObjectUtils.isEmpty(startTime.trim())) {
+            startTime = null;
+        }
+        if (endTime != null && ObjectUtils.isEmpty(endTime.trim())) {
+            endTime = null;
+        }
+        return cloudRecordService.getList(page, count, query, app, stream, startTime, endTime, mediaServerItems);
     }
 
+    @ResponseBody
+    @GetMapping("/task/add")
+    @Operation(summary = "娣诲姞鍚堝苟浠诲姟")
+    @Parameter(name = "app", description = "搴旂敤鍚�", required = false)
+    @Parameter(name = "stream", description = "娴両D", required = false)
+    @Parameter(name = "mediaServerId", description = "娴佸獟浣揑D", required = false)
+    @Parameter(name = "startTime", description = "閴存潈ID", required = false)
+    @Parameter(name = "endTime", description = "閴存潈ID", required = false)
+    @Parameter(name = "callId", description = "閴存潈ID", required = false)
+    @Parameter(name = "remoteHost", description = "杩斿洖鍦板潃鏃剁殑杩滅▼鍦板潃", required = false)
+    public String addTask(
+            HttpServletRequest request,
+            @RequestParam(required = false) String app,
+            @RequestParam(required = false) String stream,
+            @RequestParam(required = false) String mediaServerId,
+            @RequestParam(required = false) String startTime,
+            @RequestParam(required = false) String endTime,
+            @RequestParam(required = false) String callId,
+            @RequestParam(required = false) String remoteHost
+    ){
+        MediaServer mediaServerItem;
+        if (mediaServerId == null) {
+            mediaServerItem = mediaServerService.getDefaultMediaServer();
+        }else {
+            mediaServerItem = mediaServerService.getOne(mediaServerId);
+        }
+        if (mediaServerItem == null) {
+            throw new ControllerException(ErrorCode.ERROR100.getCode(), "鏈壘鍒板彲鐢ㄧ殑娴佸獟浣�");
+        }else {
+            if (remoteHost == null) {
+                remoteHost = request.getScheme() + "://" + mediaServerItem.getIp() + ":" + mediaServerItem.getRecordAssistPort();
+            }
+        }
+        return cloudRecordService.addTask(app, stream, mediaServerItem, startTime, endTime, callId, remoteHost, mediaServerId != null);
+    }
 
+    @ResponseBody
+    @GetMapping("/task/list")
+    @Operation(summary = "鏌ヨ鍚堝苟浠诲姟")
+    @Parameter(name = "taskId", description = "浠诲姟Id", required = false)
+    @Parameter(name = "mediaServerId", description = "娴佸獟浣揑D", required = false)
+    @Parameter(name = "isEnd", description = "鏄惁缁撴潫", required = false)
+    public JSONArray queryTaskList(
+            HttpServletRequest request,
+            @RequestParam(required = false) String app,
+            @RequestParam(required = false) String stream,
+            @RequestParam(required = false) String callId,
+            @RequestParam(required = false) String taskId,
+            @RequestParam(required = false) String mediaServerId,
+            @RequestParam(required = false) Boolean isEnd
+    ){
+       if (ObjectUtils.isEmpty(mediaServerId)) {
+           mediaServerId = null;
+       }
+
+       return cloudRecordService.queryTask(app, stream, callId, taskId, mediaServerId, isEnd, request.getScheme());
+    }
+
+    @ResponseBody
+    @GetMapping("/collect/add")
+    @Operation(summary = "娣诲姞鏀惰棌")
+    @Parameter(name = "app", description = "搴旂敤鍚�", required = false)
+    @Parameter(name = "stream", description = "娴両D", required = false)
+    @Parameter(name = "mediaServerId", description = "娴佸獟浣揑D", required = false)
+    @Parameter(name = "startTime", description = "閴存潈ID", required = false)
+    @Parameter(name = "endTime", description = "閴存潈ID", required = false)
+    @Parameter(name = "callId", description = "閴存潈ID", required = false)
+    @Parameter(name = "recordId", description = "褰曞儚璁板綍鐨処D锛岀敤浜庣簿鍑嗘敹钘忎竴涓棰戞枃浠�", required = false)
+    public int addCollect(
+            @RequestParam(required = false) String app,
+            @RequestParam(required = false) String stream,
+            @RequestParam(required = false) String mediaServerId,
+            @RequestParam(required = false) String startTime,
+            @RequestParam(required = false) String endTime,
+            @RequestParam(required = false) String callId,
+            @RequestParam(required = false) Integer recordId
+    ){
+        logger.info("[浜戠褰曞儚] 娣诲姞鏀惰棌锛宎pp={}锛宻tream={},mediaServerId={},startTime={},endTime={},callId={},recordId={}",
+                app, stream, mediaServerId, startTime, endTime, callId, recordId);
+        if (recordId != null) {
+            return cloudRecordService.changeCollectById(recordId, true);
+        }else {
+            return cloudRecordService.changeCollect(true, app, stream, mediaServerId, startTime, endTime, callId);
+        }
+    }
+
+    @ResponseBody
+    @GetMapping("/collect/delete")
+    @Operation(summary = "绉婚櫎鏀惰棌")
+    @Parameter(name = "app", description = "搴旂敤鍚�", required = false)
+    @Parameter(name = "stream", description = "娴両D", required = false)
+    @Parameter(name = "mediaServerId", description = "娴佸獟浣揑D", required = false)
+    @Parameter(name = "startTime", description = "閴存潈ID", required = false)
+    @Parameter(name = "endTime", description = "閴存潈ID", required = false)
+    @Parameter(name = "callId", description = "閴存潈ID", required = false)
+    @Parameter(name = "recordId", description = "褰曞儚璁板綍鐨処D锛岀敤浜庣簿鍑嗙簿鍑嗙Щ闄や竴涓棰戞枃浠剁殑鏀惰棌", required = false)
+    public int deleteCollect(
+            @RequestParam(required = false) String app,
+            @RequestParam(required = false) String stream,
+            @RequestParam(required = false) String mediaServerId,
+            @RequestParam(required = false) String startTime,
+            @RequestParam(required = false) String endTime,
+            @RequestParam(required = false) String callId,
+            @RequestParam(required = false) Integer recordId
+    ){
+        logger.info("[浜戠褰曞儚] 绉婚櫎鏀惰棌锛宎pp={}锛宻tream={},mediaServerId={},startTime={},endTime={},callId={},recordId={}",
+                app, stream, mediaServerId, startTime, endTime, callId, recordId);
+        if (recordId != null) {
+            return cloudRecordService.changeCollectById(recordId, false);
+        }else {
+            return cloudRecordService.changeCollect(false, app, stream, mediaServerId, startTime, endTime, callId);
+        }
+    }
+
+    @ResponseBody
+    @GetMapping("/play/path")
+    @Operation(summary = "鑾峰彇鎾斁鍦板潃")
+    @Parameter(name = "recordId", description = "褰曞儚璁板綍鐨処D", required = true)
+    public DownloadFileInfo getPlayUrlPath(
+            @RequestParam(required = true) Integer recordId
+    ){
+        return cloudRecordService.getPlayUrlPath(recordId);
+    }
 }

--
Gitblit v1.8.0