|
@@ -0,0 +1,54 @@
|
|
|
|
|
+package com.fdkankan.fusion.task;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.date.DateUnit;
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import com.fdkankan.fusion.common.util.DateUtils;
|
|
|
|
|
+import com.fdkankan.fusion.common.util.UploadToOssUtil;
|
|
|
|
|
+import com.fdkankan.fusion.config.CacheUtil;
|
|
|
|
|
+import com.fdkankan.fusion.response.FileInfoVo;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+public class TimeTaskService {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ UploadToOssUtil uploadToOssUtil;
|
|
|
|
|
+ @PostConstruct
|
|
|
|
|
+ public void init() {
|
|
|
|
|
+ delOssOffline();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Scheduled(cron = "0 0 0 * * ?")
|
|
|
|
|
+ public void scheduledTask() {
|
|
|
|
|
+ delOssOffline();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 定时删除oss中离线包文件
|
|
|
|
|
+ */
|
|
|
|
|
+ private void delOssOffline() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ List<String> list = uploadToOssUtil.listKeysFromAli("fusion/" + CacheUtil.environment + "/offline");
|
|
|
|
|
+ for (String key : list) {
|
|
|
|
|
+ FileInfoVo fileInfo = uploadToOssUtil.getFileInfo(key);
|
|
|
|
|
+ Long lastModified = fileInfo.getLastModified();
|
|
|
|
|
+ long between = DateUtil.between(new Date(lastModified), new Date(), DateUnit.DAY);
|
|
|
|
|
+ if(between >7){
|
|
|
|
|
+ log.info("删除文件->{},info:{}",key,lastModified);
|
|
|
|
|
+ uploadToOssUtil.delete(key);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ log.info("del-oss-offline-error:{}",e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+}
|