From 985082d33930868c3cc1723f28fd9aaae9013a8f Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期三, 16 八月 2023 09:11:22 +0800 Subject: [PATCH] 添加缺少的内容 --- src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java | 101 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 99 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java old mode 100644 new mode 100755 index 580561b..f8c1ba1 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java @@ -24,23 +24,30 @@ import com.genersoft.iot.vmp.utils.JsonUtil; import com.genersoft.iot.vmp.utils.redis.RedisUtil; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; +import com.genersoft.iot.vmp.vmanager.bean.RecordFile; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Service; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; +import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import java.io.File; import java.time.LocalDateTime; import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; /** * 濯掍綋鏈嶅姟鍣ㄨ妭鐐圭鐞� @@ -104,6 +111,11 @@ @Autowired private RedisTemplate<Object, Object> redisTemplate; + @Qualifier("taskExecutor") + @Autowired + private ThreadPoolTaskExecutor taskExecutor; + + /** * 鍒濆鍖� @@ -149,7 +161,7 @@ } if (streamId == null) { - streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase(); + streamId = String.format("%08x", Long.parseLong(ssrc)).toUpperCase(); } int ssrcCheckParam = 0; if (ssrcCheck && tcpMode > 1) { @@ -158,7 +170,7 @@ } int rtpServerPort; if (mediaServerItem.isRtpEnable()) { - rtpServerPort = zlmServerFactory.createRTPServer(mediaServerItem, streamId, (ssrcCheck && tcpMode == 0)?Integer.parseInt(ssrc):0, port, reUsePort, tcpMode); + rtpServerPort = zlmServerFactory.createRTPServer(mediaServerItem, streamId, (ssrcCheck && tcpMode == 0) ? Long.parseLong(ssrc) : 0, port, reUsePort, tcpMode); } else { rtpServerPort = mediaServerItem.getRtpProxyPort(); } @@ -749,4 +761,89 @@ return result; } + @Override + public List<RecordFile> getRecords(String app, String stream, String startTime, String endTime, List<MediaServerItem> mediaServerItems) { + Assert.notNull(app, "app涓嶅瓨鍦�"); + Assert.notNull(stream, "stream涓嶅瓨鍦�"); + Assert.notNull(startTime, "startTime涓嶅瓨鍦�"); + Assert.notNull(endTime, "endTime涓嶅瓨鍦�"); + Assert.notEmpty(mediaServerItems, "娴佸獟浣撳垪琛ㄤ负绌�"); + + CompletableFuture[] completableFutures = new CompletableFuture[mediaServerItems.size()]; + for (int i = 0; i < mediaServerItems.size(); i++) { + completableFutures[i] = getRecordFilesForOne(app, stream, startTime, endTime, mediaServerItems.get(i)); + } + List<RecordFile> result = new ArrayList<>(); + for (int i = 0; i < completableFutures.length; i++) { + try { + List<RecordFile> list = (List<RecordFile>) completableFutures[i].get(); + if (!list.isEmpty()) { + for (int g = 0; g < list.size(); g++) { + list.get(g).setMediaServerId(mediaServerItems.get(i).getId()); + } + result.addAll(list); + } + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } + } + Comparator<RecordFile> comparator = Comparator.comparing(RecordFile::getFileName); + result.sort(comparator); + return result; + } + + @Override + public List<String> getRecordDates(String app, String stream, int year, int month, List<MediaServerItem> mediaServerItems) { + Assert.notNull(app, "app涓嶅瓨鍦�"); + Assert.notNull(stream, "stream涓嶅瓨鍦�"); + Assert.notEmpty(mediaServerItems, "娴佸獟浣撳垪琛ㄤ负绌�"); + CompletableFuture[] completableFutures = new CompletableFuture[mediaServerItems.size()]; + + for (int i = 0; i < mediaServerItems.size(); i++) { + completableFutures[i] = getRecordDatesForOne(app, stream, year, month, mediaServerItems.get(i)); + } + List<String> result = new ArrayList<>(); + CompletableFuture.allOf(completableFutures).join(); + for (CompletableFuture completableFuture : completableFutures) { + try { + List<String> list = (List<String>) completableFuture.get(); + result.addAll(list); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } + } + Collections.sort(result); + return result; + } + + @Async + public CompletableFuture<List<String>> getRecordDatesForOne(String app, String stream, int year, int month, MediaServerItem mediaServerItem) { + JSONObject fileListJson = assistRESTfulUtils.getDateList(mediaServerItem, app, stream, year, month); + if (fileListJson != null && !fileListJson.isEmpty()) { + if (fileListJson.getString("code") != null && fileListJson.getInteger("code") == 0) { + JSONArray data = fileListJson.getJSONArray("data"); + return CompletableFuture.completedFuture(data.toJavaList(String.class)); + } + } + return CompletableFuture.completedFuture(new ArrayList<>()); + } + + @Async + public CompletableFuture<List<RecordFile>> getRecordFilesForOne(String app, String stream, String startTime, String endTime, MediaServerItem mediaServerItem) { + JSONObject fileListJson = assistRESTfulUtils.getFileList(mediaServerItem, 1, 100000000, app, stream, startTime, endTime); + if (fileListJson != null && !fileListJson.isEmpty()) { + if (fileListJson.getString("code") != null && fileListJson.getInteger("code") == 0) { + JSONObject data = fileListJson.getJSONObject("data"); + JSONArray list = data.getJSONArray("list"); + if (list != null) { + return CompletableFuture.completedFuture(list.toJavaList(RecordFile.class)); + } + } + } + return CompletableFuture.completedFuture(new ArrayList<>()); + } } -- Gitblit v1.8.0