package com.whyc.schedule;
|
|
import com.whyc.factory.ThreadPoolExecutorFactory;
|
import com.whyc.pojo.Software;
|
import com.whyc.service.SoftwareService;
|
import com.whyc.util.DateUtil;
|
import com.whyc.util.MailUtil;
|
import com.whyc.util.ThreadLocalUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import javax.mail.MessagingException;
|
import java.util.Arrays;
|
import java.util.List;
|
|
/**
|
* 软件升级申请邮件推送定时任务
|
*/
|
@EnableScheduling
|
@Component
|
public class SoftwareMailSchedule {
|
|
@Autowired
|
private MailUtil mailUtil;
|
|
@Autowired
|
private SoftwareService softwareService;
|
|
/**数据4秒钟获取一次*/
|
@Scheduled(cron = "0/4 * * * * ? ")
|
public void sendMail(){
|
//查询需要发送邮件
|
List<Software> list = softwareService.getSendList();
|
String[] toArrStr = new String[]{"perryhsu@163.com"};
|
List toArr = Arrays.asList(toArrStr);
|
|
for (int i = 0; i < list.size(); i++){
|
Software software = list.get(i);
|
ThreadPoolExecutorFactory.getPoolExecutor().execute(() -> {
|
// 发送邮件
|
try {
|
mailUtil.sendMailBatch(toArr, "长城汽车-电池系统软件升级申请", "SN码:"+software.getSnCode()+"\n软件序列号:"+software.getSerialNumber()+"\n版本:"+software.getVersion()+"\n申请时间:"+ ThreadLocalUtil.format(software.getCreateTime(),1));
|
//更新邮件发送状态
|
softwareService.updateMailStatus(software.getId());
|
} catch (MessagingException e) {
|
throw new RuntimeException(e);
|
}
|
});
|
}
|
}
|
|
|
}
|