使用zlm原生接口删除录像文件
parent
4ef1277c16
commit
75fccfaf17
|
@ -3,8 +3,10 @@ package com.genersoft.iot.vmp.conf;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils;
|
import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils;
|
||||||
|
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||||
|
import com.genersoft.iot.vmp.service.bean.CloudRecordItem;
|
||||||
import com.genersoft.iot.vmp.storager.dao.CloudRecordServiceMapper;
|
import com.genersoft.iot.vmp.storager.dao.CloudRecordServiceMapper;
|
||||||
import com.genersoft.iot.vmp.vmanager.cloudRecord.CloudRecordController;
|
import com.genersoft.iot.vmp.vmanager.cloudRecord.CloudRecordController;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -13,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -33,12 +36,13 @@ public class CloudRecordTimer {
|
||||||
private CloudRecordServiceMapper cloudRecordServiceMapper;
|
private CloudRecordServiceMapper cloudRecordServiceMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AssistRESTfulUtils assistRESTfulUtils;
|
private ZLMRESTfulUtils zlmresTfulUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时查询待删除的录像文件
|
* 定时查询待删除的录像文件
|
||||||
*/
|
*/
|
||||||
@Scheduled(cron = "0 0 0 * * ?") //每天的0点执行
|
@Scheduled(cron = "0 0 0 * * ?") //每天的0点执行
|
||||||
|
// @Scheduled(fixedRate = 5000)
|
||||||
public void execute(){
|
public void execute(){
|
||||||
logger.info("[录像文件定时清理] 开始清理过期录像文件");
|
logger.info("[录像文件定时清理] 开始清理过期录像文件");
|
||||||
// 获取配置了assist的流媒体节点
|
// 获取配置了assist的流媒体节点
|
||||||
|
@ -55,18 +59,29 @@ public class CloudRecordTimer {
|
||||||
// 获取保存的最后截至日期,因为每个节点都有一个日期,也就是支持每个节点设置不同的保存日期,
|
// 获取保存的最后截至日期,因为每个节点都有一个日期,也就是支持每个节点设置不同的保存日期,
|
||||||
lastCalendar.add(Calendar.DAY_OF_MONTH, -mediaServerItem.getRecordDate());
|
lastCalendar.add(Calendar.DAY_OF_MONTH, -mediaServerItem.getRecordDate());
|
||||||
Long lastDate = lastCalendar.getTimeInMillis();
|
Long lastDate = lastCalendar.getTimeInMillis();
|
||||||
|
|
||||||
// 获取到截至日期之前的录像文件列表,文件列表满足未被收藏和保持的。这两个字段目前共能一致,
|
// 获取到截至日期之前的录像文件列表,文件列表满足未被收藏和保持的。这两个字段目前共能一致,
|
||||||
// 为我自己业务系统相关的代码,大家使用的时候直接使用收藏(collect)这一个类型即可
|
// 为我自己业务系统相关的代码,大家使用的时候直接使用收藏(collect)这一个类型即可
|
||||||
List<String> filePathList = cloudRecordServiceMapper.queryRecordFilePathListForDelete(lastDate, mediaServerItem.getId());
|
List<CloudRecordItem> cloudRecordItemList = cloudRecordServiceMapper.queryRecordListForDelete(lastDate, mediaServerItem.getId());
|
||||||
if (filePathList.isEmpty()) {
|
if (cloudRecordItemList.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// 先调用assist删除磁盘文件,删除成功后再删除数据库记录
|
List<Integer> cloudRecordItemIdList = new ArrayList<>();
|
||||||
JSONObject jsonObject = assistRESTfulUtils.deleteFiles(mediaServerItem, filePathList);
|
for (CloudRecordItem cloudRecordItem : cloudRecordItemList) {
|
||||||
if (jsonObject != null && jsonObject.getInteger("code") == 0 && jsonObject.getInteger("data") > 0) {
|
String date = new File(cloudRecordItem.getFilePath()).getParentFile().getName();
|
||||||
result += jsonObject.getInteger("data");
|
JSONObject jsonObject = zlmresTfulUtils.deleteRecordDirectory(mediaServerItem, cloudRecordItem.getApp(),
|
||||||
cloudRecordServiceMapper.deleteByFileList(filePathList, mediaServerItem.getId());
|
cloudRecordItem.getStream(), date, cloudRecordItem.getFileName());
|
||||||
|
if (jsonObject.getInteger("code") == 0) {
|
||||||
|
cloudRecordItemIdList.add(cloudRecordItem.getId());
|
||||||
|
}else {
|
||||||
|
logger.warn("[录像文件定时清理] 删除磁盘文件错误: {}", jsonObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (cloudRecordItemIdList.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cloudRecordServiceMapper.deleteList(cloudRecordItemIdList, mediaServerItem.getId());
|
||||||
|
result += cloudRecordItemIdList.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.info("[录像文件定时清理] 共清理{}个过期录像文件", result);
|
logger.info("[录像文件定时清理] 共清理{}个过期录像文件", result);
|
||||||
|
|
|
@ -268,14 +268,4 @@ public class AssistRESTfulUtils {
|
||||||
|
|
||||||
return sendGet(mediaServerItem, "api/record/file/download/task/list", param, null);
|
return sendGet(mediaServerItem, "api/record/file/download/task/list", param, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject addCollect(MediaServerItem mediaServerItem, JSONObject jsonObject) {
|
|
||||||
return sendPost(mediaServerItem, "api/record/file/collection/add", jsonObject, null, 30);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JSONObject deleteFiles(MediaServerItem mediaServerItem, List<String> filePathList) {
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
jsonObject.put("filePathList", filePathList);
|
|
||||||
return sendPost(mediaServerItem, "api/record/file/delete", jsonObject, null, 15*60);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,6 @@ public class ZLMRESTfulUtils {
|
||||||
|
|
||||||
private OkHttpClient client;
|
private OkHttpClient client;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public interface RequestCallback{
|
public interface RequestCallback{
|
||||||
void run(JSONObject response);
|
void run(JSONObject response);
|
||||||
}
|
}
|
||||||
|
@ -398,4 +396,14 @@ public class ZLMRESTfulUtils {
|
||||||
param.put("stream_id", streamId);
|
param.put("stream_id", streamId);
|
||||||
return sendPost(mediaServerItem, "updateRtpServerSSRC",param, null);
|
return sendPost(mediaServerItem, "updateRtpServerSSRC",param, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JSONObject deleteRecordDirectory(MediaServerItem mediaServerItem, String app, String stream, String date, String fileName) {
|
||||||
|
Map<String, Object> param = new HashMap<>(1);
|
||||||
|
param.put("vhost", "__defaultVhost__");
|
||||||
|
param.put("app", app);
|
||||||
|
param.put("stream", stream);
|
||||||
|
param.put("period", date);
|
||||||
|
param.put("name", fileName);
|
||||||
|
return sendPost(mediaServerItem, "deleteRecordDirectory",param, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,25 +82,28 @@ public interface CloudRecordServiceMapper {
|
||||||
int updateCollectList(@Param("collect") boolean collect, List<CloudRecordItem> cloudRecordItemList);
|
int updateCollectList(@Param("collect") boolean collect, List<CloudRecordItem> cloudRecordItemList);
|
||||||
|
|
||||||
@Delete(" <script>" +
|
@Delete(" <script>" +
|
||||||
"delete from wvp_cloud_record where media_server_id=#{mediaServerId} file_path in " +
|
"delete from wvp_cloud_record where media_server_id=#{mediaServerId} and file_path in " +
|
||||||
" <foreach collection='filePathList' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
|
" <foreach collection='filePathList' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
|
||||||
" </script>")
|
" </script>")
|
||||||
void deleteByFileList(List<String> filePathList, @Param("mediaServerId") String mediaServerId);
|
void deleteByFileList(List<String> filePathList, @Param("mediaServerId") String mediaServerId);
|
||||||
|
|
||||||
|
|
||||||
@Select(" <script>" +
|
@Select(" <script>" +
|
||||||
"select file_path" +
|
"select *" +
|
||||||
" from wvp_cloud_record " +
|
" from wvp_cloud_record " +
|
||||||
" where collect = false " +
|
" where end_time <= #{endTimeStamp} and media_server_id = #{mediaServerId} " +
|
||||||
" <if test= 'endTimeStamp != null '> and start_time <= #{endTimeStamp}</if>" +
|
|
||||||
" <if test= 'callId != null '> and call_id = #{callId}</if>" +
|
|
||||||
" <if test= 'mediaServerId != null ' > and media_server_id = #{mediaServerId} </if>" +
|
|
||||||
" </script>")
|
" </script>")
|
||||||
List<String> queryRecordFilePathListForDelete(@Param("endTimeStamp")Long endTimeStamp, String mediaServerId);
|
List<CloudRecordItem> queryRecordListForDelete(@Param("endTimeStamp")Long endTimeStamp, String mediaServerId);
|
||||||
|
|
||||||
@Update(" <script>" +
|
@Update(" <script>" +
|
||||||
"update wvp_cloud_record set collect = #{collect} where id = #{recordId} " +
|
"update wvp_cloud_record set collect = #{collect} where id = #{recordId} " +
|
||||||
" </script>")
|
" </script>")
|
||||||
int changeCollectById(@Param("collect") boolean collect, @Param("recordId") Integer recordId);
|
int changeCollectById(@Param("collect") boolean collect, @Param("recordId") Integer recordId);
|
||||||
|
|
||||||
|
@Delete(" <script>" +
|
||||||
|
"delete from wvp_cloud_record where media_server_id=#{mediaServerId} and id in " +
|
||||||
|
" <foreach collection='cloudRecordItemIdList' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
|
||||||
|
" </script>")
|
||||||
|
int deleteList(List<Integer> cloudRecordItemIdList, @Param("mediaServerId") String mediaServerId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue