修改 report 时间 字段类型

This commit is contained in:
shikong 2024-03-28 09:45:20 +08:00
parent dda2d2fc07
commit d1829901bf
4 changed files with 15 additions and 26 deletions

View File

@ -1,14 +1,9 @@
package cn.skcks.docking.gb28181.wvp.dto.report; package cn.skcks.docking.gb28181.wvp.dto.report;
import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@ -26,23 +21,18 @@ public class ReportReq {
@Schema(description = "点播时长") @Schema(description = "点播时长")
private TimeRange timeRange; private TimeRange timeRange;
@DateTimeFormat(pattern= DatePattern.NORM_DATETIME_PATTERN)
@JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
@Schema(description = "日志记录时间") @Schema(description = "日志记录时间")
private Date logTime; private String logTime;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Data @Data
public static class TimeRange { public static class TimeRange {
@DateTimeFormat(pattern= DatePattern.NORM_DATETIME_PATTERN)
@JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
@Schema(description = "开始时间") @Schema(description = "开始时间")
private Date startTime; private String startTime;
@DateTimeFormat(pattern= DatePattern.NORM_DATETIME_PATTERN)
@JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
@Schema(description = "结束时间") @Schema(description = "结束时间")
private Date endTime; private String endTime;
} }
@Schema(description = "文件大小, 未知大小为 -1") @Schema(description = "文件大小, 未知大小为 -1")

View File

@ -27,7 +27,6 @@ import cn.skcks.docking.gb28181.service.ssrc.SsrcService;
import cn.skcks.docking.gb28181.wvp.config.MediaRtmpConfig; import cn.skcks.docking.gb28181.wvp.config.MediaRtmpConfig;
import cn.skcks.docking.gb28181.wvp.config.ProxySipConfig; import cn.skcks.docking.gb28181.wvp.config.ProxySipConfig;
import cn.skcks.docking.gb28181.wvp.config.WvpProxyConfig; import cn.skcks.docking.gb28181.wvp.config.WvpProxyConfig;
import cn.skcks.docking.gb28181.wvp.dto.report.ReportReq;
import cn.skcks.docking.gb28181.wvp.executor.DefaultVideoExecutor; import cn.skcks.docking.gb28181.wvp.executor.DefaultVideoExecutor;
import cn.skcks.docking.gb28181.wvp.orm.mybatis.dynamic.model.WvpProxyDevice; import cn.skcks.docking.gb28181.wvp.orm.mybatis.dynamic.model.WvpProxyDevice;
import cn.skcks.docking.gb28181.wvp.orm.mybatis.dynamic.model.WvpProxyDocking; import cn.skcks.docking.gb28181.wvp.orm.mybatis.dynamic.model.WvpProxyDocking;
@ -232,7 +231,7 @@ public class Gb28181DownloadService {
writeErrorToResponse(asyncResponse, JsonResponse.error("下载失败")); writeErrorToResponse(asyncResponse, JsonResponse.error("下载失败"));
} else if (wvpProxyConfig.getUseFfmpeg()) { } else if (wvpProxyConfig.getUseFfmpeg()) {
log.info("开始 ffmpeg 录制, deviceCode {}, startTime {}, endTime {}", deviceCode, DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime)); log.info("开始 ffmpeg 录制, deviceCode {}, startTime {}, endTime {}", deviceCode, DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime));
videoService.ffmpegRecord(request, asyncResponse, videoInfo.getUrl(), new ReportReq.TimeRange(startTime, endTime), DateUtil.between(startTime, endTime, DateUnit.SECOND), videoInfo.getDevice(), videoInfo.getCallId()); videoService.ffmpegRecord(request, asyncResponse, videoInfo.getUrl(), startTime, endTime, DateUtil.between(startTime, endTime, DateUnit.SECOND), videoInfo.getDevice(), videoInfo.getCallId());
DateTime end = DateUtil.date(); DateTime end = DateUtil.date();
asyncContext.complete(); asyncContext.complete();
log.info("下载总耗时: {}, deviceCode {}, startTime {}, endTime {}", DateUtil.between(start, end, DateUnit.SECOND), deviceCode, DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime)); log.info("下载总耗时: {}, deviceCode {}, startTime {}, endTime {}", DateUtil.between(start, end, DateUnit.SECOND), deviceCode, DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime));
@ -377,7 +376,7 @@ public class Gb28181DownloadService {
writeErrorToResponse(asyncResponse, JsonResponse.error("下载失败")); writeErrorToResponse(asyncResponse, JsonResponse.error("下载失败"));
} else if(wvpProxyConfig.getUseFfmpeg()){ } else if(wvpProxyConfig.getUseFfmpeg()){
log.info("开始 ffmpeg 录制, deviceCode {}, startTime {}, endTime {}", deviceCode, DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime)); log.info("开始 ffmpeg 录制, deviceCode {}, startTime {}, endTime {}", deviceCode, DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime));
videoService.ffmpegRecord(request, asyncResponse, videoInfo.getUrl(), new ReportReq.TimeRange(startTime, endTime), DateUtil.between(startTime, endTime, DateUnit.SECOND), videoInfo.getDevice(), videoInfo.getCallId()); videoService.ffmpegRecord(request, asyncResponse, videoInfo.getUrl(), startTime, endTime, DateUtil.between(startTime, endTime, DateUnit.SECOND), videoInfo.getDevice(), videoInfo.getCallId());
DateTime end = DateUtil.date(); DateTime end = DateUtil.date();
asyncContext.complete(); asyncContext.complete();
log.info("下载总耗时: {}, deviceCode {}, startTime {}, endTime {}", DateUtil.between(start, end, DateUnit.SECOND), deviceCode, DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime)); log.info("下载总耗时: {}, deviceCode {}, startTime {}, endTime {}", DateUtil.between(start, end, DateUnit.SECOND), deviceCode, DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime));

View File

@ -31,8 +31,8 @@ public class ReportService {
device.getDeviceCode(), device.getDeviceCode(),
device.getGbDeviceChannelId(), device.getGbDeviceChannelId(),
DateUtil.formatBetween(startTime, endTime, BetweenFormatter.Level.SECOND), DateUtil.formatBetween(startTime, endTime, BetweenFormatter.Level.SECOND),
new ReportReq.TimeRange(startTime, endTime), new ReportReq.TimeRange(DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime)),
DateUtil.date(), DateUtil.now(),
DataSizeUtil.format(fileSize)); DataSizeUtil.format(fileSize));
LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
reportConfig.getCustomHeaders().forEach(headers::add); reportConfig.getCustomHeaders().forEach(headers::add);

View File

@ -8,7 +8,6 @@ import cn.skcks.docking.gb28181.core.sip.utils.SipUtil;
import cn.skcks.docking.gb28181.wvp.config.FfmpegConfig; import cn.skcks.docking.gb28181.wvp.config.FfmpegConfig;
import cn.skcks.docking.gb28181.wvp.config.ProxySipConfig; import cn.skcks.docking.gb28181.wvp.config.ProxySipConfig;
import cn.skcks.docking.gb28181.wvp.config.WvpProxyConfig; import cn.skcks.docking.gb28181.wvp.config.WvpProxyConfig;
import cn.skcks.docking.gb28181.wvp.dto.report.ReportReq;
import cn.skcks.docking.gb28181.wvp.orm.mybatis.dynamic.model.WvpProxyDevice; import cn.skcks.docking.gb28181.wvp.orm.mybatis.dynamic.model.WvpProxyDevice;
import cn.skcks.docking.gb28181.wvp.orm.mybatis.dynamic.model.WvpProxyDocking; import cn.skcks.docking.gb28181.wvp.orm.mybatis.dynamic.model.WvpProxyDocking;
import cn.skcks.docking.gb28181.wvp.service.docking.DockingService; import cn.skcks.docking.gb28181.wvp.service.docking.DockingService;
@ -36,6 +35,7 @@ import org.bytedeco.javacv.FrameGrabber;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.*; import java.io.*;
import java.util.Date;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
@ -234,7 +234,7 @@ public class VideoService {
* @param time 录制时长 (单位: ) * @param time 录制时长 (单位: )
*/ */
@SneakyThrows @SneakyThrows
public void ffmpegRecord(HttpServletRequest request, ServletResponse response, String url, ReportReq.TimeRange timeRange, long time, WvpProxyDevice device, String callId){ public void ffmpegRecord(HttpServletRequest request, ServletResponse response, String url, Date startTime, Date endTime, long time, WvpProxyDevice device, String callId){
String tmpDir = ffmpegConfig.getTmpDir(); String tmpDir = ffmpegConfig.getTmpDir();
String fileName = callId + ".mp4"; String fileName = callId + ".mp4";
File file = new File(tmpDir, fileName); File file = new File(tmpDir, fileName);
@ -259,7 +259,7 @@ public class VideoService {
} }
} }
DateTime startTime = DateUtil.date(); DateTime start = DateUtil.date();
log.info("开始录制 {}", url); log.info("开始录制 {}", url);
ScheduledFuture<?> schedule = scheduledExecutorService.schedule(() -> { ScheduledFuture<?> schedule = scheduledExecutorService.schedule(() -> {
log.info("到达结束时间, 结束录制 {}", url); log.info("到达结束时间, 结束录制 {}", url);
@ -268,8 +268,8 @@ public class VideoService {
}, time + 60, TimeUnit.SECONDS); }, time + 60, TimeUnit.SECONDS);
executeResultHandler.waitFor(); executeResultHandler.waitFor();
schedule.cancel(true); schedule.cancel(true);
DateTime endTime = DateUtil.date(); DateTime end = DateUtil.date();
log.info("录制进程结束 {}, 录制耗时: {}", url, DateUtil.between(startTime,endTime, DateUnit.SECOND)); log.info("录制进程结束 {}, 录制耗时: {}", url, DateUtil.between(start,end, DateUnit.SECOND));
if(ffmpegConfig.getUseTmpFile()) { if(ffmpegConfig.getUseTmpFile()) {
ServletOutputStream servletOutputStream = response.getOutputStream(); ServletOutputStream servletOutputStream = response.getOutputStream();
@ -277,9 +277,9 @@ public class VideoService {
log.info("临时文件 {}(大小 {})", file.getAbsolutePath(), file.length()); log.info("临时文件 {}(大小 {})", file.getAbsolutePath(), file.length());
IoUtil.copy(new FileInputStream(file), servletOutputStream); IoUtil.copy(new FileInputStream(file), servletOutputStream);
response.flushBuffer(); response.flushBuffer();
reportService.report(request, device, timeRange.getStartTime(), timeRange.getEndTime(), file.length()); reportService.report(request, device, startTime, endTime, file.length());
} catch (Exception e){ } catch (Exception e){
reportService.report(request, device, timeRange.getStartTime(), timeRange.getEndTime(), -1); reportService.report(request, device, startTime, endTime, -1);
log.error("写入 http 响应异常: {}", e.getMessage()); log.error("写入 http 响应异常: {}", e.getMessage());
} finally { } finally {
System.gc(); System.gc();