Commit b1a6640617756c261863842cba9735ed3809b4ca
1 parent
b7b35d9b
移除旧的录像文件过期处理任务
Showing
1 changed file
with
0 additions
and
69 deletions
src/main/java/top/panll/assist/config/TaskConfig.java deleted
100644 → 0
| 1 | -package top.panll.assist.config; | ||
| 2 | - | ||
| 3 | -import org.slf4j.Logger; | ||
| 4 | -import org.slf4j.LoggerFactory; | ||
| 5 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | -import org.springframework.context.annotation.Configuration; | ||
| 7 | -import org.springframework.scheduling.annotation.EnableScheduling; | ||
| 8 | -import org.springframework.scheduling.annotation.Scheduled; | ||
| 9 | -import org.springframework.stereotype.Component; | ||
| 10 | -import top.panll.assist.service.VideoFileService; | ||
| 11 | - | ||
| 12 | -import java.io.File; | ||
| 13 | -import java.text.ParseException; | ||
| 14 | -import java.text.SimpleDateFormat; | ||
| 15 | -import java.time.LocalDateTime; | ||
| 16 | -import java.util.Calendar; | ||
| 17 | -import java.util.Date; | ||
| 18 | -import java.util.List; | ||
| 19 | - | ||
| 20 | -@Component | ||
| 21 | -@EnableScheduling | ||
| 22 | -public class TaskConfig { | ||
| 23 | - | ||
| 24 | - private final static Logger logger = LoggerFactory.getLogger(TaskConfig.class); | ||
| 25 | - | ||
| 26 | - @Autowired | ||
| 27 | - private VideoFileService videoFileService; | ||
| 28 | - | ||
| 29 | - private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
| 30 | - | ||
| 31 | - @Scheduled(cron = "0 0 0 * * ?") | ||
| 32 | - private void configureTasks() { | ||
| 33 | - logger.info("录像过期自检任务执行"); | ||
| 34 | - List<File> appList = videoFileService.getAppList(false); | ||
| 35 | - Calendar calendar = Calendar.getInstance(); | ||
| 36 | - calendar.add(Calendar.DATE, - 7); | ||
| 37 | - Date monday = calendar.getTime(); | ||
| 38 | - if (appList != null && appList.size() > 0) { | ||
| 39 | - for (File appFile : appList) { | ||
| 40 | - List<File> streamList = videoFileService.getStreamList(appFile.getName(), false); | ||
| 41 | - if (streamList != null && streamList.size() > 0) { | ||
| 42 | - for (File streamFile : streamList) { | ||
| 43 | - File[] recordDateFileList = streamFile.listFiles(); | ||
| 44 | - if (recordDateFileList != null && recordDateFileList.length > 0) { | ||
| 45 | - for (File recordDateFile : recordDateFileList) { | ||
| 46 | - try { | ||
| 47 | - Date fileDaye = simpleDateFormat.parse(recordDateFile.getName()); | ||
| 48 | - if (fileDaye.before(monday)){ | ||
| 49 | - logger.debug("移除文件[{}]", recordDateFile.getAbsolutePath()); | ||
| 50 | - recordDateFile.delete(); | ||
| 51 | - } | ||
| 52 | - } catch (ParseException e) { | ||
| 53 | - logger.error("无法格式化[{}]为日期, 直接移除", recordDateFile.getName()); | ||
| 54 | - recordDateFile.delete(); | ||
| 55 | - } | ||
| 56 | - } | ||
| 57 | - } | ||
| 58 | - if (streamFile.listFiles().length == 0) { | ||
| 59 | - streamFile.delete(); | ||
| 60 | - } | ||
| 61 | - } | ||
| 62 | - } | ||
| 63 | - if (appFile.listFiles().length == 0) { | ||
| 64 | - appFile.delete(); | ||
| 65 | - } | ||
| 66 | - } | ||
| 67 | - } | ||
| 68 | - } | ||
| 69 | -} |