/// <summary> /// 一天一天删除文件 /// </summary> /// <param name="days"></param> /// <param name="sdp"></param> private void DeleteFileByDay(List <string> days, MediaServerStreamInfo mediaInfo) { foreach (var day in days) { var deleteList = ORMHelper.Db.Select <RecordFile>() .Where(x => x.RecordDate.Equals(day)) .Where(x => x.Deleted.Equals(false)) .Where(x => x.MainId.Equals(mediaInfo.Stream)) .ToList(); if (deleteList != null && deleteList.Count > 0) { var deleteFileList = deleteList.Select(x => x.Id).ToList(); ORMHelper.Db.Update <RecordFile>().Set(x => x.UpdateTime, DateTime.Now) .Set(x => x.Deleted, true) .Where(x => x.RecordDate.Equals(day)) .Where(x => x.MainId.Equals(mediaInfo.Stream)).ExecuteAffrows(); MediaServerService.DeleteRecordFileList(deleteFileList, out _); Logger.Info( $"[{Common.LoggerHead}]->删除一天录制文件->{mediaInfo.MediaServerId}->{mediaInfo.Stream}->{day}"); } Thread.Sleep(100); } }
/// <summary> /// 文件一个一个删除 /// </summary> /// <param name="videoSize"></param> /// <param name="sdp"></param> private void deleteFileOneByOne(decimal videoSize, MediaServerStreamInfo mediaInfo, RecordPlan plan) { ReqGetRecordFileList req = new ReqGetRecordFileList(); req.MainId = mediaInfo.Stream; req.MediaServerId = mediaInfo.MediaServerId; req.Deleted = false; req.OrderBy = new List <OrderByStruct>(); req.OrderBy.Add(new OrderByStruct() { FieldName = "starttime", OrderByDir = OrderByDir.ASC, }); req.PageIndex = 1; req.PageSize = 100; long deleteSize = 0; while (videoSize - deleteSize > plan.LimitSpace) { var recordFileList = MediaServerService.GetRecordFileList(req, out ResponseStruct rs); if (!rs.Code.Equals(ErrorNumber.None)) { break; } if (recordFileList != null && recordFileList.RecordFileList != null && recordFileList.RecordFileList.Count > 0) { foreach (var ret in recordFileList.RecordFileList) { if (ret != null) { if (MediaServerService.DeleteRecordFile(ret.Id, out rs)) { deleteSize += (long)ret.FileSize !; Logger.Info( $"[{Common.LoggerHead}]->删除一个录制文件->{mediaInfo.MediaServerId}->{mediaInfo.Stream}->DBId:{ret.Id}->FilePath:{ret.VideoPath}"); } Thread.Sleep(20); } if ((videoSize - deleteSize) < plan.LimitSpace) { break; } } } } }