| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package com.fdkankan.fusion.task;
- import cn.hutool.core.date.DateUnit;
- import cn.hutool.core.date.DateUtil;
- import com.fdkankan.fyun.face.FYunFileServiceInterface;
- import com.fdkankan.fyun.util.FileInfoVo;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Service;
- import java.util.Date;
- import java.util.List;
- @Service
- @Slf4j
- public class TimeTaskService {
- @Autowired
- FYunFileServiceInterface fYunFileServiceInterface;
- @Value("${spring.profiles.active}")
- private String environment;
- @Scheduled(cron = "0 0 0 * * ?")
- public void scheduledTask() {
- delOssOffline();
- }
- /**
- * 定时删除oss中离线包文件
- */
- private void delOssOffline() {
- String path = "fusion/" +environment+ "/offline";
- log.info("开始执行清除离线包:{}",path);
- try {
- List<String> list = fYunFileServiceInterface.listRemoteFiles(path);
- for (String key : list) {
- FileInfoVo fileInfo = fYunFileServiceInterface.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);
- fYunFileServiceInterface.deleteFile(key);
- }
- }
- }catch (Exception e){
- log.info("del-oss-offline-error:{}",e);
- }
- }
- }
|