using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
using SCC.Interface;
using SCC.Common;
using SCC.Models;
namespace SCC.Crawler
{
///
/// 发送邮件的作业
///
public class SendEmailJob : IJob
{
private IEmail email = null;
private LogHelper log = null;
public SendEmailJob()
{
email = IOC.Resolve();
log = new LogHelper();
}
public void Execute(IJobExecutionContext context)
{
try
{
log.Info(typeof(SendEmailJob), "正在执行发送邮件作业!");
var mailConfig = ConfigHelper.GetConfigValue("MailTurnOn");
if (mailConfig)
{
List sendList = email.GetAllNeedSendEmail();
if (sendList.Count == 0) return;
var emailSubject = string.Format("{0}第{1}期等一共{2}条抓取失败日志", sendList[0].LotteryName, sendList[0].QiHao, sendList.Count);
StringBuilder emailBody = new StringBuilder();
emailBody.Append("抓取失败的彩种及期号列表:\r\n");
emailBody.Append("彩种 | 期号 | 开奖时间 |
");
foreach (var mail in sendList)
{
emailBody.Append(string.Format("{0} | {1} | {2} |
", mail.LotteryName, mail.QiHao, mail.OpenTime.ToString("yyyy-MM-dd HH:mm:ss")));
}
emailBody.Append("
");
if (CommonHelper.SendEmail(emailSubject, emailBody.ToString()))
{
email.UpdateEmailToSend(sendList);
log.Info(typeof(SendEmailJob), "今日发送邮件成功!");
}
}
}
catch (Exception ex)
{
log.Error(typeof(SendEmailJob), string.Format("发送邮件列表时发生错误,错误信息【{1}】", ex.Message));
}
}
}
}