|
|
|
@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.util.FileSystemUtils;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
|
|
|
@ -22,7 +23,10 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.text.DateFormat;
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
@ -68,6 +72,44 @@ public class taskController {
|
|
|
|
|
PDFUtils.delAllFile(pdfErrorUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron="0 0 1 * * ?")//每天4点触发cron="0 0 4 * * ?"
|
|
|
|
|
public void taskPDF() throws IOException {
|
|
|
|
|
Date date1 = new Date();
|
|
|
|
|
Calendar calendar = Calendar.getInstance(); //得到日历
|
|
|
|
|
calendar.setTime(date1);//把当前时间赋给日历
|
|
|
|
|
calendar.add(calendar.DATE, -15); //设置为前15天
|
|
|
|
|
Date date2 = calendar.getTime();//获取15天前的时间
|
|
|
|
|
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
Date date;
|
|
|
|
|
//转换成时间戳
|
|
|
|
|
long t1 = date2.getTime();
|
|
|
|
|
try {
|
|
|
|
|
File f = new File("D:\\docus\\caCopy");
|
|
|
|
|
File[] files = f.listFiles();
|
|
|
|
|
for (int i = 0; i < files.length; i++) {
|
|
|
|
|
//获取文件路径
|
|
|
|
|
String filePath = files[i].getCanonicalPath();
|
|
|
|
|
//获取文件名,文件名为yyyy--mm--dd格式时间
|
|
|
|
|
String lastTime = files[i].getName();
|
|
|
|
|
//将lastTime时间转为long类型
|
|
|
|
|
try {
|
|
|
|
|
date = format.parse(lastTime);
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
Long timestamp = date.getTime();
|
|
|
|
|
if (timestamp < t1) {
|
|
|
|
|
//删除
|
|
|
|
|
FileSystemUtils.deleteRecursively(new File(filePath));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//@Scheduled(cron="0 0 3 * * ?")//每天3点触发0 0 3 * * ?
|
|
|
|
|
//@Scheduled(cron="${fixedDelay}")
|
|
|
|
|
public void task2() throws IOException {
|
|
|
|
|