package com.reptileclient.jlifeapp.schedule;


import com.reptileclient.jlifeapp.service.DownLoadEmailDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import java.io.IOException;
import java.text.ParseException;

@Slf4j
@Async
@Component
public class DownLoadEmailDataTask {

    @Autowired
    private DownLoadEmailDataService downLoadEmailDataService;
//    @Scheduled(cron = "0 30 18 * * ?")
    //修改成监听到邮件后自动下载
    public void runTask() {
        log.info("开始下载邮件内容");
        try {
            downLoadEmailDataService.downLoad();
        } catch (MessagingException | IOException | ParseException e) {
            throw new RuntimeException(e);
        }
        log.info("结束下载邮件内容");

    }
}
