Commit 7360de7ff7570acfd3af46a87b49588170b4545a

Authored by 648540858
1 parent a3d583e3

录像事件保存时间为0时直接删除

src/main/java/top/panll/assist/controller/RecordController.java
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
5 import io.swagger.v3.oas.annotations.Operation; 5 import io.swagger.v3.oas.annotations.Operation;
6 import io.swagger.v3.oas.annotations.Parameter; 6 import io.swagger.v3.oas.annotations.Parameter;
7 import io.swagger.v3.oas.annotations.tags.Tag; 7 import io.swagger.v3.oas.annotations.tags.Tag;
  8 +import org.apache.commons.io.FileUtils;
8 import org.slf4j.Logger; 9 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory; 10 import org.slf4j.LoggerFactory;
10 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
@@ -344,10 +345,17 @@ public class RecordController { @@ -344,10 +345,17 @@ public class RecordController {
344 String app = json.getString("app"); 345 String app = json.getString("app");
345 String stream = json.getString("stream"); 346 String stream = json.getString("stream");
346 logger.debug("ZLM 录制完成,参数:" + file_path); 347 logger.debug("ZLM 录制完成,参数:" + file_path);
  348 +
347 if (file_path == null) { 349 if (file_path == null) {
348 return new ResponseEntity<String>(ret.toString(), HttpStatus.OK); 350 return new ResponseEntity<String>(ret.toString(), HttpStatus.OK);
349 } 351 }
350 - videoFileService.handFile(new File(file_path), app, stream); 352 + if (userSettings.getRecordDay() <= 0) {
  353 + logger.info("录像保存事件为{}天,直接删除: {}", userSettings.getRecordDay(), file_path);
  354 + FileUtils.deleteQuietly(new File(file_path));
  355 + }else {
  356 + videoFileService.handFile(new File(file_path), app, stream);
  357 + }
  358 +
351 359
352 return new ResponseEntity<String>(ret.toString(), HttpStatus.OK); 360 return new ResponseEntity<String>(ret.toString(), HttpStatus.OK);
353 } 361 }
src/main/java/top/panll/assist/service/FileManagerTimer.java
@@ -42,9 +42,12 @@ public class FileManagerTimer { @@ -42,9 +42,12 @@ public class FileManagerTimer {
42 int recordDay = userSettings.getRecordDay(); 42 int recordDay = userSettings.getRecordDay();
43 Date lastDate=new Date(); 43 Date lastDate=new Date();
44 Calendar lastCalendar = Calendar.getInstance(); 44 Calendar lastCalendar = Calendar.getInstance();
45 - lastCalendar.setTime(lastDate);  
46 - lastCalendar.add(Calendar.DAY_OF_MONTH, 0 - recordDay);  
47 - lastDate = lastCalendar.getTime(); 45 + if (recordDay > 0) {
  46 + lastCalendar.setTime(lastDate);
  47 + lastCalendar.add(Calendar.DAY_OF_MONTH, 0 - recordDay);
  48 + lastDate = lastCalendar.getTime();
  49 + }
  50 +
48 logger.info("[录像巡查]移除 {} 之前的文件", formatter.format(lastDate)); 51 logger.info("[录像巡查]移除 {} 之前的文件", formatter.format(lastDate));
49 File recordFileDir = new File(userSettings.getRecord()); 52 File recordFileDir = new File(userSettings.getRecord());
50 if (recordFileDir.canWrite()) { 53 if (recordFileDir.canWrite()) {
src/main/java/top/panll/assist/service/VideoFileService.java
@@ -162,7 +162,6 @@ public class VideoFileService { @@ -162,7 +162,6 @@ public class VideoFileService {
162 logger.debug("[处理文件] {}", file.getName()); 162 logger.debug("[处理文件] {}", file.getName());
163 } catch (IOException e) { 163 } catch (IOException e) {
164 logger.warn("文件可能以损坏[{}]", file.getAbsolutePath()); 164 logger.warn("文件可能以损坏[{}]", file.getAbsolutePath());
165 -// e.printStackTrace();  
166 } catch (ParseException e) { 165 } catch (ParseException e) {
167 logger.error("时间格式化失败", e.getMessage()); 166 logger.error("时间格式化失败", e.getMessage());
168 } 167 }