package com.fdkankan.platform.task;

import com.fdkankan.common.constant.ConstantFilePath;
import org.apache.tools.ant.util.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;

@Component
public class Schedule {
    public static final Logger log = LoggerFactory.getLogger("programLog");

    @Value("${environment}")
    private String environment;


    @Scheduled(cron = "0 0 4 * * ?")
    public void job1() {
        if("hq".equals(environment)){
            return;
        }
        log.warn("每天04:00开始执行定时任务：删除二维码");
        // 删除登录二维码
        String path = ConstantFilePath.LOGIN_QR_CODE_PATH;
        File file = new File(path);
        File[] files = file.listFiles();
        if (files != null && files.length > 0){
            for (File delFile : files){
                if (delFile.isFile()) FileUtils.delete(delFile);
            }
        }

        // 删除支付宝支付二维码
        path = ConstantFilePath.ALI_QRCODE_FOLDER;
        file = new File(path);
        files = file.listFiles();
        if (files != null && files.length > 0){
            for (File delFile : files){
                if (delFile.isFile()) FileUtils.delete(delFile);
            }
        }

        // 删除微信支付二维码
        path = ConstantFilePath.WEIXIN_QRCODE_FOLDER;
        file = new File(path);
        files = file.listFiles();
        if (files != null && files.length > 0){
            for (File delFile : files){
                if (delFile.isFile()) FileUtils.delete(delFile);
            }
        }
    }
}
