Browse Source

don't log for clearing virtualizer dir

sunyj 8 years ago
parent
commit
d3dec984a0

+ 3 - 3
src/main/java/com/uas/report/controller/PdfController.java

@@ -102,7 +102,7 @@ public class PdfController {
 			String pdfPath = r + "/"
 					+ fileService.generateFileName(u, pr, w, o, ExportType.PDF.getQualifier())
                     + "." + ExportType.PDF.getQualifier();
-			File file = new File(ReportUtils.getDocumentDir(), pdfPath);
+			File file = new File(ReportUtils.getDocumentsDir(), pdfPath);
 			FileUtils.write(file.getPath(), data);
 			result.put("path", "pdf/preview?p=" + pdfPath);
 			result.put("overload", false);
@@ -213,7 +213,7 @@ public class PdfController {
 		String pdfPath = r + "/"
 				+ fileService.generateFileName(u, pr, w, o, ExportType.PDF.getQualifier())
                 + "." + ExportType.PDF.getQualifier();
-		File file = new File(ReportUtils.getDocumentDir(), pdfPath);
+		File file = new File(ReportUtils.getDocumentsDir(), pdfPath);
 		String masterOfJrxml = printService.getMasterOfJrxml(u, r);
 		String jrxmlFilePath = fileService.getJrxmlFilePath(masterOfJrxml, r);
 		if (!fileService.isFileValid(file.getPath(), jrxmlFilePath)) {
@@ -238,7 +238,7 @@ public class PdfController {
 	@ResponseBody
 	public void preview(@RequestParam String p, HttpServletRequest request, HttpServletResponse response)
 			throws JRException, IOException, DocumentException, SQLException, IllegalStateException {
-		File file = new File(ReportUtils.getDocumentDir(), p);
+		File file = new File(ReportUtils.getDocumentsDir(), p);
 		if(!file.getName().toLowerCase().endsWith(".pdf")){
 			throw new IOException("并非 pdf 文件:" + p);
 		}

+ 2 - 2
src/main/java/com/uas/report/controller/PrintController.java

@@ -150,7 +150,7 @@ public class PrintController {
 		String filePath = reportName + "/"
 				+ fileService.generateFileName(userName, profile, whereCondition, otherParameters, exportFileType)
                 + "." + exportType.getQualifier();
-		File file = new File(ReportUtils.getDocumentDir(), filePath);
+		File file = new File(ReportUtils.getDocumentsDir(), filePath);
 		// 指定flush为true(强制刷新pdf、xls)
 		// 文件无效(不存在或过期),创建
 		if ((flush != null && flush)
@@ -207,7 +207,7 @@ public class PrintController {
         String pdfPath = reportName + "/"
                 + fileService.generateFileName(userName, profile, whereCondition, otherParameters, ExportType.PDF.getQualifier())
                 + "." + ExportType.PDF.getQualifier();
-        File file = new File(ReportUtils.getDocumentDir(), pdfPath);
+        File file = new File(ReportUtils.getDocumentsDir(), pdfPath);
         // 指定flush为true(强制刷新pdf)
 		// 文件无效(不存在或过期),重新创建pdf文件
 		if ((flush != null && flush)

+ 6 - 4
src/main/java/com/uas/report/service/impl/FileServiceImpl.java

@@ -592,17 +592,19 @@ public class FileServiceImpl implements FileService {
 		Executable command = new Executable() {
 			@Override
 			public String execute() {
-				FileUtils.delete(new File(ReportUtils.getGenerateDir()), new FileFilter() {
+				FileFilter fileFilter = new FileFilter() {
 					@Override
 					public boolean accept(File file) {
 						// 只删除已过期的文件(并且刚过期的文件本次不删除,以尽量避免打印耗时过长时,部分临时文件过期而被误删)
-                        long now = new Date().getTime();
-                        if (now - file.lastModified() - PDF_MAX_INVALID_INTERVAL > 0 && now - file.lastModified() - taskPeriod > 0) {
+						long now = new Date().getTime();
+						if (now - file.lastModified() - PDF_MAX_INVALID_INTERVAL > 0 && now - file.lastModified() - taskPeriod > 0) {
 							return true;
 						}
 						return false;
 					}
-				});
+				};
+				FileUtils.delete(new File(ReportUtils.getVirtualizerDir()), fileFilter, false);
+				FileUtils.delete(new File(ReportUtils.getDocumentsDir()), fileFilter, true);
 				return "success";
 			}
 		};

+ 3 - 10
src/main/java/com/uas/report/util/ReportUtils.java

@@ -53,25 +53,18 @@ public class ReportUtils {
 		return ContextUtils.getBean(FileService.class).getMasterPath("tmp");
 	}
 
-	/**
-	 * @return 存放 pdf、虚拟文件等文件的路径
-	 */
-	public static String getGenerateDir() {
-		return getTmpDir() + "/generate";
-	}
-
 	/**
 	 * @return 文件虚拟路径
 	 */
 	public static String getVirtualizerDir() {
-		return getGenerateDir() + "/virtualizer";
+		return getTmpDir() + "/virtualizer";
 	}
 
 	/**
 	 * @return pdf、excel 等文档路径
 	 */
-	public static String getDocumentDir() {
-		return getGenerateDir() + "/documents";
+	public static String getDocumentsDir() {
+		return getTmpDir() + "/documents";
 	}
 
 	/**