Commit 4974c17c by 宋祥

1.定时清理zip文件

parent 49e55a63
package com.baosight.hggp.core.tools;
import com.baosight.hggp.core.constant.OSConstant;
import com.baosight.hggp.util.DateUtils;
import com.baosight.hggp.util.FileUtils;
import java.io.File;
import java.time.LocalDate;
import lombok.extern.slf4j.Slf4j;
/**
* @author:songx
* @date:2024/10/12,10:27
*/
@Slf4j
public class FileTools {
/**
* 清理ZIP文件
*/
public static void clearZip() {
File zipFolder = new File(OSConstant.ZIP_DIR);
File[] zipFolderFiles = zipFolder.listFiles();
if (zipFolderFiles.length == 0) {
log.warn("清理ZIP文件:无有效的文件");
}
for (File zipFolderFile : zipFolderFiles) {
String folderName = zipFolderFile.getName();
// 当天以前的文件夹全部删除
if (LocalDate.parse(folderName, DateUtils.SHORT_DATE).isBefore(LocalDate.now())) {
FileUtils.deleteFiles(zipFolderFile);
}
}
log.info("清理ZIP文件成功!!!");
}
}
...@@ -7,6 +7,7 @@ import com.baosight.hggp.core.constant.CommonConstant; ...@@ -7,6 +7,7 @@ import com.baosight.hggp.core.constant.CommonConstant;
import com.baosight.hggp.core.dao.DaoUtils; import com.baosight.hggp.core.dao.DaoUtils;
import com.baosight.hggp.core.enums.OrgTypeEnum; import com.baosight.hggp.core.enums.OrgTypeEnum;
import com.baosight.hggp.core.security.UserSessionUtils; import com.baosight.hggp.core.security.UserSessionUtils;
import com.baosight.hggp.core.tools.FileTools;
import com.baosight.hggp.core.tools.Iplat4jTools; import com.baosight.hggp.core.tools.Iplat4jTools;
import com.baosight.hggp.core.utils.Iplat4jUtils; import com.baosight.hggp.core.utils.Iplat4jUtils;
import com.baosight.hggp.hg.constant.HGConstant; import com.baosight.hggp.hg.constant.HGConstant;
...@@ -578,4 +579,19 @@ public class ServiceHGWD001 extends ServiceEPBase { ...@@ -578,4 +579,19 @@ public class ServiceHGWD001 extends ServiceEPBase {
return inInfo; return inInfo;
} }
/**
* 清理下载的文件
*
* @param inInfo
* @return
*/
public EiInfo clearDownload(EiInfo inInfo) {
try {
FileTools.clearZip();
} catch (Exception e) {
LogUtils.setMsg(inInfo, e, "清理下载的文件失败");
}
return inInfo;
}
} }
package com.baosight.hggp.job; package com.baosight.hggp.job;
import com.baosight.hggp.core.constant.OSConstant; import com.baosight.hggp.core.constant.OSConstant;
import com.baosight.hggp.core.tools.FileTools;
import com.baosight.hggp.util.DateUtil; import com.baosight.hggp.util.DateUtil;
import com.baosight.hggp.util.DateUtils; import com.baosight.hggp.util.DateUtils;
import com.baosight.hggp.util.FileUtils; import com.baosight.hggp.util.FileUtils;
...@@ -29,19 +30,7 @@ public class ClearZipJob { ...@@ -29,19 +30,7 @@ public class ClearZipJob {
@Scheduled(cron = "0 45 0/3 * * ? ") @Scheduled(cron = "0 45 0/3 * * ? ")
public void clearZipFile() { public void clearZipFile() {
try { try {
File zipFolder = new File(OSConstant.ZIP_DIR); FileTools.clearZip();
File[] zipFolderFiles = zipFolder.listFiles();
if (zipFolderFiles.length == 0) {
log.warn("清理ZIP文件:无有效的文件");
}
for (File zipFolderFile : zipFolderFiles) {
String folderName = zipFolderFile.getName();
// 当天以前的文件夹全部删除
if (LocalDate.parse(folderName, DateUtils.SHORT_DATE).isBefore(LocalDate.now())) {
FileUtils.deleteFiles(zipFolderFile);
}
}
log.info("清理ZIP文件成功!!!");
} catch (Exception e) { } catch (Exception e) {
log.error("清理ZIP文件失败:{}", e.getMessage(), e); log.error("清理ZIP文件失败:{}", e.getMessage(), e);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment