|
|
|
|
@ -24,11 +24,11 @@ public class CronTab {
|
|
|
|
|
|
|
|
|
|
private static LocalDateTime now;
|
|
|
|
|
|
|
|
|
|
//@Scheduled(cron = "0 0 0 * * ?")
|
|
|
|
|
@Scheduled(cron = "0 0/1 * * * *")
|
|
|
|
|
@Scheduled(cron = "0 0 0 * * ?")
|
|
|
|
|
//@Scheduled(cron = "0 0/1 * * * *")
|
|
|
|
|
public void file() {
|
|
|
|
|
log.info(" corn delete file");
|
|
|
|
|
now = LocalDateTime.now();
|
|
|
|
|
log.info(" corn delete file ,time:{}",now);
|
|
|
|
|
File dir = new File(configProperties.getSavePath().getMediaPath());
|
|
|
|
|
checkFileTime(dir,configProperties.getDeleteFileDays());
|
|
|
|
|
File dir2 = new File(configProperties.getSavePath().getMp4Path());
|
|
|
|
|
@ -36,7 +36,9 @@ public class CronTab {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void checkFileTime(File dir,int days) {
|
|
|
|
|
|
|
|
|
|
if(!dir.exists()){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (dir.isDirectory()) {
|
|
|
|
|
String[] children = dir.list();
|
|
|
|
|
if(children.length == 0){
|
|
|
|
|
@ -52,16 +54,19 @@ public class CronTab {
|
|
|
|
|
try {
|
|
|
|
|
Path path = dir.toPath();
|
|
|
|
|
attr = Files.readAttributes(path, BasicFileAttributes.class);
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
// 创建时间
|
|
|
|
|
Instant instant = attr.creationTime().toInstant();
|
|
|
|
|
LocalDateTime createTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
|
|
|
|
|
Duration duration = Duration.between(createTime,now);
|
|
|
|
|
if(days<=duration.toDays()){
|
|
|
|
|
log.info("delete path:{}",dir.getPath());
|
|
|
|
|
dir.delete();
|
|
|
|
|
if(attr != null){
|
|
|
|
|
// 创建时间
|
|
|
|
|
Instant instant = attr.creationTime().toInstant();
|
|
|
|
|
LocalDateTime createTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
|
|
|
|
|
Duration duration = Duration.between(createTime,now);
|
|
|
|
|
if(days<=duration.toDays()){
|
|
|
|
|
log.info("delete path:{}",dir.getPath());
|
|
|
|
|
dir.delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|