修复因为int自动装箱导致year和month为空时,接口报错

pull/1669/head
shaowei 2024-10-31 01:16:25 +08:00
parent 3ba473776f
commit 8384736c22
1 changed files with 30 additions and 108 deletions

View File

@ -3,9 +3,9 @@ package com.genersoft.iot.vmp.vmanager.cloudRecord;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.conf.security.JwtUtils; import com.genersoft.iot.vmp.conf.security.JwtUtils;
import com.genersoft.iot.vmp.gb28181.service.ICloudRecordService;
import com.genersoft.iot.vmp.media.bean.MediaServer; import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.media.service.IMediaServerService; import com.genersoft.iot.vmp.media.service.IMediaServerService;
import com.genersoft.iot.vmp.gb28181.service.ICloudRecordService;
import com.genersoft.iot.vmp.service.bean.CloudRecordItem; import com.genersoft.iot.vmp.service.bean.CloudRecordItem;
import com.genersoft.iot.vmp.service.bean.DownloadFileInfo; import com.genersoft.iot.vmp.service.bean.DownloadFileInfo;
import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.utils.DateUtil;
@ -55,16 +55,10 @@ public class CloudRecordController {
@Parameter(name = "year", description = "年,置空则查询当年", required = false) @Parameter(name = "year", description = "年,置空则查询当年", required = false)
@Parameter(name = "month", description = "月,置空则查询当月", required = false) @Parameter(name = "month", description = "月,置空则查询当月", required = false)
@Parameter(name = "mediaServerId", description = "流媒体ID置空则查询全部", required = false) @Parameter(name = "mediaServerId", description = "流媒体ID置空则查询全部", required = false)
public List<String> openRtpServer( public List<String> openRtpServer(@RequestParam(required = true) String app, @RequestParam(required = true) String stream, @RequestParam(required = false) Integer year, @RequestParam(required = false) Integer month, @RequestParam(required = false) String mediaServerId
@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
) { ) {
log.info("[云端录像] 查询存在云端录像的日期 app->{}, stream->{}, mediaServerId->{}, year->{}, month->{}", log.info("[云端录像] 查询存在云端录像的日期 app->{}, stream->{}, mediaServerId->{}, year->{}, month->{}", app, stream, mediaServerId, year, month);
app, stream, mediaServerId, year, month);
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
if (ObjectUtils.isEmpty(year)) { if (ObjectUtils.isEmpty(year)) {
year = calendar.get(Calendar.YEAR); year = calendar.get(Calendar.YEAR);
@ -102,20 +96,10 @@ public class CloudRecordController {
@Parameter(name = "endTime", 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 = "流媒体ID置空则查询全部流媒体", required = false) @Parameter(name = "mediaServerId", description = "流媒体ID置空则查询全部流媒体", required = false)
@Parameter(name = "callId", description = "每次录像的唯一标识,置空则查询全部流媒体", required = false) @Parameter(name = "callId", description = "每次录像的唯一标识,置空则查询全部流媒体", required = false)
public PageInfo<CloudRecordItem> openRtpServer( 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(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam(required = false) String mediaServerId, @RequestParam(required = false) String callId
@RequestParam(required = false) String query,
@RequestParam(required = false) String app,
@RequestParam(required = false) String stream,
@RequestParam int page,
@RequestParam int count,
@RequestParam(required = false) String startTime,
@RequestParam(required = false) String endTime,
@RequestParam(required = false) String mediaServerId,
@RequestParam(required = false) String callId
) { ) {
log.info("[云端录像] 查询 app->{}, stream->{}, mediaServerId->{}, page->{}, count->{}, startTime->{}, endTime->{}, callId->{}", log.info("[云端录像] 查询 app->{}, stream->{}, mediaServerId->{}, page->{}, count->{}, startTime->{}, endTime->{}, callId->{}", app, stream, mediaServerId, page, count, startTime, endTime, callId);
app, stream, mediaServerId, page, count, startTime, endTime, callId);
List<MediaServer> mediaServers; List<MediaServer> mediaServers;
if (!ObjectUtils.isEmpty(mediaServerId)) { if (!ObjectUtils.isEmpty(mediaServerId)) {
@ -162,25 +146,16 @@ public class CloudRecordController {
@Parameter(name = "endTime", description = "鉴权ID", required = false) @Parameter(name = "endTime", description = "鉴权ID", required = false)
@Parameter(name = "callId", description = "鉴权ID", required = false) @Parameter(name = "callId", description = "鉴权ID", required = false)
@Parameter(name = "remoteHost", description = "返回地址时的远程地址", required = false) @Parameter(name = "remoteHost", description = "返回地址时的远程地址", required = false)
public String addTask( 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) {
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 mediaServer; MediaServer mediaServer;
if (mediaServerId == null) { if (mediaServerId == null) {
mediaServer = mediaServerService.getDefaultMediaServer(); mediaServer = mediaServerService.getDefaultMediaServer();
}else { } else {
mediaServer = mediaServerService.getOne(mediaServerId); mediaServer = mediaServerService.getOne(mediaServerId);
} }
if (mediaServer == null) { if (mediaServer == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的流媒体"); throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的流媒体");
}else { } else {
if (remoteHost == null) { if (remoteHost == null) {
remoteHost = request.getScheme() + "://" + mediaServer.getIp() + ":" + mediaServer.getRecordAssistPort(); remoteHost = request.getScheme() + "://" + mediaServer.getIp() + ":" + mediaServer.getRecordAssistPort();
} }
@ -194,20 +169,12 @@ public class CloudRecordController {
@Parameter(name = "taskId", description = "任务Id", required = false) @Parameter(name = "taskId", description = "任务Id", required = false)
@Parameter(name = "mediaServerId", description = "流媒体ID", required = false) @Parameter(name = "mediaServerId", description = "流媒体ID", required = false)
@Parameter(name = "isEnd", description = "是否结束", required = false) @Parameter(name = "isEnd", description = "是否结束", required = false)
public JSONArray queryTaskList( 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) {
HttpServletRequest request, if (ObjectUtils.isEmpty(mediaServerId)) {
@RequestParam(required = false) String app, mediaServerId = null;
@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()); return cloudRecordService.queryTask(app, stream, callId, taskId, mediaServerId, isEnd, request.getScheme());
} }
@ResponseBody @ResponseBody
@ -220,20 +187,11 @@ public class CloudRecordController {
@Parameter(name = "endTime", description = "鉴权ID", required = false) @Parameter(name = "endTime", description = "鉴权ID", required = false)
@Parameter(name = "callId", description = "鉴权ID", required = false) @Parameter(name = "callId", description = "鉴权ID", required = false)
@Parameter(name = "recordId", description = "录像记录的ID用于精准收藏一个视频文件", required = false) @Parameter(name = "recordId", description = "录像记录的ID用于精准收藏一个视频文件", required = false)
public int addCollect( 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) {
@RequestParam(required = false) String app, log.info("[云端录像] 添加收藏app={}stream={},mediaServerId={},startTime={},endTime={},callId={},recordId={}", app, stream, mediaServerId, startTime, endTime, callId, recordId);
@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
){
log.info("[云端录像] 添加收藏app={}stream={},mediaServerId={},startTime={},endTime={},callId={},recordId={}",
app, stream, mediaServerId, startTime, endTime, callId, recordId);
if (recordId != null) { if (recordId != null) {
return cloudRecordService.changeCollectById(recordId, true); return cloudRecordService.changeCollectById(recordId, true);
}else { } else {
return cloudRecordService.changeCollect(true, app, stream, mediaServerId, startTime, endTime, callId); return cloudRecordService.changeCollect(true, app, stream, mediaServerId, startTime, endTime, callId);
} }
} }
@ -248,20 +206,11 @@ public class CloudRecordController {
@Parameter(name = "endTime", description = "鉴权ID", required = false) @Parameter(name = "endTime", description = "鉴权ID", required = false)
@Parameter(name = "callId", description = "鉴权ID", required = false) @Parameter(name = "callId", description = "鉴权ID", required = false)
@Parameter(name = "recordId", description = "录像记录的ID用于精准精准移除一个视频文件的收藏", required = false) @Parameter(name = "recordId", description = "录像记录的ID用于精准精准移除一个视频文件的收藏", required = false)
public int deleteCollect( 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) {
@RequestParam(required = false) String app, log.info("[云端录像] 移除收藏app={}stream={},mediaServerId={},startTime={},endTime={},callId={},recordId={}", app, stream, mediaServerId, startTime, endTime, callId, recordId);
@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
){
log.info("[云端录像] 移除收藏app={}stream={},mediaServerId={},startTime={},endTime={},callId={},recordId={}",
app, stream, mediaServerId, startTime, endTime, callId, recordId);
if (recordId != null) { if (recordId != null) {
return cloudRecordService.changeCollectById(recordId, false); return cloudRecordService.changeCollectById(recordId, false);
}else { } else {
return cloudRecordService.changeCollect(false, app, stream, mediaServerId, startTime, endTime, callId); return cloudRecordService.changeCollect(false, app, stream, mediaServerId, startTime, endTime, callId);
} }
} }
@ -270,9 +219,7 @@ public class CloudRecordController {
@GetMapping("/play/path") @GetMapping("/play/path")
@Operation(summary = "获取播放地址") @Operation(summary = "获取播放地址")
@Parameter(name = "recordId", description = "录像记录的ID", required = true) @Parameter(name = "recordId", description = "录像记录的ID", required = true)
public DownloadFileInfo getPlayUrlPath( public DownloadFileInfo getPlayUrlPath(@RequestParam(required = true) Integer recordId) {
@RequestParam(required = true) Integer recordId
){
return cloudRecordService.getPlayUrlPath(recordId); return cloudRecordService.getPlayUrlPath(recordId);
} }
@ -291,20 +238,10 @@ public class CloudRecordController {
*/ */
@ResponseBody @ResponseBody
@GetMapping("/zip") @GetMapping("/zip")
public void downloadZipFile( public void downloadZipFile(HttpServletResponse response, @RequestParam(required = false) String query, @RequestParam(required = false) String app, @RequestParam(required = false) String stream, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam(required = false) String mediaServerId, @RequestParam(required = false) String callId, @RequestParam(required = false) List<Integer> ids
HttpServletResponse response,
@RequestParam(required = false) String query,
@RequestParam(required = false) String app,
@RequestParam(required = false) String stream,
@RequestParam(required = false) String startTime,
@RequestParam(required = false) String endTime,
@RequestParam(required = false) String mediaServerId,
@RequestParam(required = false) String callId,
@RequestParam(required = false) List<Integer> ids
) { ) {
log.info("[下载指定录像文件的压缩包] 查询 app->{}, stream->{}, mediaServerId->{}, startTime->{}, endTime->{}, callId->{}", log.info("[下载指定录像文件的压缩包] 查询 app->{}, stream->{}, mediaServerId->{}, startTime->{}, endTime->{}, callId->{}", app, stream, mediaServerId, startTime, endTime, callId);
app, stream, mediaServerId, startTime, endTime, callId);
List<MediaServer> mediaServers; List<MediaServer> mediaServers;
if (!ObjectUtils.isEmpty(mediaServerId)) { if (!ObjectUtils.isEmpty(mediaServerId)) {
@ -339,7 +276,7 @@ public class CloudRecordController {
callId = null; callId = null;
} }
if (stream != null && callId != null) { if (stream != null && callId != null) {
response.addHeader( "Content-Disposition", "attachment;filename=" + stream + "_" + callId + ".zip" ); response.addHeader("Content-Disposition", "attachment;filename=" + stream + "_" + callId + ".zip");
} }
List<CloudRecordItem> cloudRecordItemList = cloudRecordService.getAllList(query, app, stream, startTime, endTime, mediaServers, callId, ids); List<CloudRecordItem> cloudRecordItemList = cloudRecordService.getAllList(query, app, stream, startTime, endTime, mediaServers, callId, ids);
if (ObjectUtils.isEmpty(cloudRecordItemList)) { if (ObjectUtils.isEmpty(cloudRecordItemList)) {
@ -354,9 +291,9 @@ public class CloudRecordController {
continue; continue;
} }
FileInputStream fis = new FileInputStream(cloudRecordItem.getFilePath()); FileInputStream fis = new FileInputStream(cloudRecordItem.getFilePath());
byte[] buf = new byte[2*1024]; byte[] buf = new byte[2 * 1024];
int len; int len;
while ((len = fis.read(buf)) != -1){ while ((len = fis.read(buf)) != -1) {
zos.write(buf, 0, len); zos.write(buf, 0, len);
} }
zos.closeEntry(); zos.closeEntry();
@ -364,8 +301,7 @@ public class CloudRecordController {
} }
zos.close(); zos.close();
} catch (IOException e) { } catch (IOException e) {
log.error("[下载指定录像文件的压缩包] 失败: 查询 app->{}, stream->{}, mediaServerId->{}, startTime->{}, endTime->{}, callId->{}", log.error("[下载指定录像文件的压缩包] 失败: 查询 app->{}, stream->{}, mediaServerId->{}, startTime->{}, endTime->{}, callId->{}", app, stream, mediaServerId, startTime, endTime, callId, e);
app, stream, mediaServerId, startTime, endTime, callId, e);
} }
} }
@ -392,22 +328,10 @@ public class CloudRecordController {
@Parameter(name = "endTime", 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 = "流媒体ID置空则查询全部流媒体", required = false) @Parameter(name = "mediaServerId", description = "流媒体ID置空则查询全部流媒体", required = false)
@Parameter(name = "callId", description = "每次录像的唯一标识,置空则查询全部流媒体", required = false) @Parameter(name = "callId", description = "每次录像的唯一标识,置空则查询全部流媒体", required = false)
public PageInfo<CloudRecordUrl> getListWithUrl( public PageInfo<CloudRecordUrl> getListWithUrl(HttpServletRequest request, @RequestParam(required = false) String query, @RequestParam(required = false) String app, @RequestParam(required = false) String stream, @RequestParam int page, @RequestParam int count, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam(required = false) String mediaServerId, @RequestParam(required = false) String callId, @RequestParam(required = false) String remoteHost
HttpServletRequest request,
@RequestParam(required = false) String query,
@RequestParam(required = false) String app,
@RequestParam(required = false) String stream,
@RequestParam int page,
@RequestParam int count,
@RequestParam(required = false) String startTime,
@RequestParam(required = false) String endTime,
@RequestParam(required = false) String mediaServerId,
@RequestParam(required = false) String callId,
@RequestParam(required = false) String remoteHost
) { ) {
log.info("[云端录像] 查询URL app->{}, stream->{}, mediaServerId->{}, page->{}, count->{}, startTime->{}, endTime->{}, callId->{}", log.info("[云端录像] 查询URL app->{}, stream->{}, mediaServerId->{}, page->{}, count->{}, startTime->{}, endTime->{}, callId->{}", app, stream, mediaServerId, page, count, startTime, endTime, callId);
app, stream, mediaServerId, page, count, startTime, endTime, callId);
List<MediaServer> mediaServers; List<MediaServer> mediaServers;
if (!ObjectUtils.isEmpty(mediaServerId)) { if (!ObjectUtils.isEmpty(mediaServerId)) {
@ -446,8 +370,7 @@ public class CloudRecordController {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到流媒体节点"); throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到流媒体节点");
} }
if (remoteHost == null) { if (remoteHost == null) {
remoteHost = request.getScheme() + "://" + request.getLocalAddr() + ":" + remoteHost = request.getScheme() + "://" + request.getLocalAddr() + ":" + (request.getScheme().equals("https") ? mediaServer.getHttpSSlPort() : mediaServer.getHttpPort());
(request.getScheme().equals("https")? mediaServer.getHttpSSlPort() : mediaServer.getHttpPort());
} }
PageInfo<CloudRecordItem> cloudRecordItemPageInfo = cloudRecordService.getList(page, count, query, app, stream, startTime, endTime, mediaServers, callId); PageInfo<CloudRecordItem> cloudRecordItemPageInfo = cloudRecordService.getList(page, count, query, app, stream, startTime, endTime, mediaServers, callId);
PageInfo<CloudRecordUrl> cloudRecordUrlPageInfo = new PageInfo<>(); PageInfo<CloudRecordUrl> cloudRecordUrlPageInfo = new PageInfo<>();
@ -474,8 +397,7 @@ public class CloudRecordController {
for (CloudRecordItem cloudRecordItem : cloudRecordItemList) { for (CloudRecordItem cloudRecordItem : cloudRecordItemList) {
CloudRecordUrl cloudRecordUrl = new CloudRecordUrl(); CloudRecordUrl cloudRecordUrl = new CloudRecordUrl();
cloudRecordUrl.setId(cloudRecordItem.getId()); cloudRecordUrl.setId(cloudRecordItem.getId());
cloudRecordUrl.setDownloadUrl(remoteHost + "/index/api/downloadFile?file_path=" + cloudRecordItem.getFilePath() cloudRecordUrl.setDownloadUrl(remoteHost + "/index/api/downloadFile?file_path=" + cloudRecordItem.getFilePath() + "&save_name=" + cloudRecordItem.getStream() + "_" + cloudRecordItem.getCallId() + "_" + DateUtil.timestampMsToUrlToyyyy_MM_dd_HH_mm_ss(cloudRecordItem.getStartTime()));
+ "&save_name=" + cloudRecordItem.getStream() + "_" + cloudRecordItem.getCallId() + "_" + DateUtil.timestampMsToUrlToyyyy_MM_dd_HH_mm_ss(cloudRecordItem.getStartTime()) );
cloudRecordUrl.setPlayUrl(remoteHost + "/index/api/downloadFile?file_path=" + cloudRecordItem.getFilePath()); cloudRecordUrl.setPlayUrl(remoteHost + "/index/api/downloadFile?file_path=" + cloudRecordItem.getFilePath());
cloudRecordUrlList.add(cloudRecordUrl); cloudRecordUrlList.add(cloudRecordUrl);
} }