|
|
@@ -36,7 +36,7 @@ import com.lowagie.text.pdf.PdfCopy;
|
|
|
import com.lowagie.text.pdf.PdfReader;
|
|
|
import com.uas.report.SpecialProperties;
|
|
|
import com.uas.report.core.exception.ReportException;
|
|
|
-import com.uas.report.schedule.model.DailyTaskInformation;
|
|
|
+import com.uas.report.schedule.model.TaskInformation;
|
|
|
import com.uas.report.schedule.service.Executable;
|
|
|
import com.uas.report.schedule.service.TaskService;
|
|
|
import com.uas.report.service.FileService;
|
|
|
@@ -54,6 +54,16 @@ public class FileServiceImpl implements FileService {
|
|
|
@Autowired
|
|
|
private TaskService taskService;
|
|
|
|
|
|
+ /**
|
|
|
+ * 第一次执行的延迟时间间隔为30秒
|
|
|
+ */
|
|
|
+ private static final long INITIAL_DELAY = 30 * 1000;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 产生的pdf的有效期(最高为10分钟)
|
|
|
+ */
|
|
|
+ private static final int PDF_MAX_INVALID_INTERVAL = 10 * 60 * 1000;
|
|
|
+
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
/**
|
|
|
@@ -421,8 +431,7 @@ public class FileServiceImpl implements FileService {
|
|
|
File jrxmlFile = new File(jrxmlFileAbsolutePath);
|
|
|
if (file.exists() && jrxmlFile.exists()) {
|
|
|
long interval = new Date().getTime() - file.lastModified();
|
|
|
- // 剩余的有效期(最高为10分钟)
|
|
|
- long validity = 10 * 60 * 1000 - interval;
|
|
|
+ long validity = PDF_MAX_INVALID_INTERVAL - interval;
|
|
|
// 有效期大于0并且比模板文件新
|
|
|
if (validity > 0 && file.lastModified() > jrxmlFile.lastModified()) {
|
|
|
logger.info(file.getName() + " will be expired after " + validity / 1000.0 + "s");
|
|
|
@@ -509,21 +518,30 @@ public class FileServiceImpl implements FileService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public DailyTaskInformation newDeleteGeneratedFilesDailyTask(Integer hour, Integer minute, Integer second) {
|
|
|
- if (hour == null || minute == null || second == null) {
|
|
|
+ public TaskInformation newDeleteGeneratedFilesTask(Integer taskPeriod) {
|
|
|
+ if (taskPeriod == null) {
|
|
|
throw new NullPointerException();
|
|
|
}
|
|
|
String title = "定时删除pdf等文件";
|
|
|
Executable command = new Executable() {
|
|
|
@Override
|
|
|
public String execute() {
|
|
|
- delete(ReportConstants.GENERATED_FILES_ABSOLUTE_PATH, true);
|
|
|
+ FileUtils.deleteDir(new File(ReportConstants.GENERATED_FILES_ABSOLUTE_PATH), new FileFilter() {
|
|
|
+ @Override
|
|
|
+ public boolean accept(File file) {
|
|
|
+ // 只删除已过期的文件
|
|
|
+ if (new Date().getTime() - file.lastModified() - PDF_MAX_INVALID_INTERVAL > 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
return "success";
|
|
|
}
|
|
|
};
|
|
|
- DailyTaskInformation dailyTaskInformation = new DailyTaskInformation(title, command, hour, minute, second);
|
|
|
- taskService.newTask(dailyTaskInformation);
|
|
|
- return dailyTaskInformation;
|
|
|
+ TaskInformation taskInformation = new TaskInformation(title, command, INITIAL_DELAY, taskPeriod);
|
|
|
+ taskService.newTask(taskInformation);
|
|
|
+ return taskInformation;
|
|
|
}
|
|
|
|
|
|
}
|