package com.yeejoin.amos.boot.module.ugp.api.quartz;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;

import java.io.File;

@Component
@EnableScheduling
public class CylinderSchedulerJob {

    /**
     * 每天3点-删除图片
     */
    @Scheduled(cron = "${cylinder-early-warning-cron:0 0 3 * * ?}")
    public void clean() {
        dayReport(new File(new File("/home/yeejoin/ugp/minio-data/upload/common/ugp/qrcode").getAbsolutePath()));

    }


    public static void dayReport(File file) {
//        file.isAbsolute();
        if (!ValidationUtil.isEmpty(file.listFiles())) {
            for (File f : file.listFiles()) {
                //实现递归
                if (f.isDirectory()) {
                    dayReport(f);
                }
                //清理文件
                f.delete();
                System.out.println(f.getName() + "已清理!!!");
            }
        }
    }
//    public static void main(String[] args) {
//
//        dayReport(new File(new File("/home/yeejoin/ugp/minio-data/upload/common/ugp/qrcode").getAbsolutePath()));
//    }
}

