65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
using Infrastructure;
|
||
using Infrastructure.Attribute;
|
||
using Quartz;
|
||
using Quartz.Impl.Triggers;
|
||
using Quartz.Impl;
|
||
using SqlSugar.IOC;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using DOAN.Model.MES.dev;
|
||
using DOAN.Model.System;
|
||
using DOAN.Service.MES.andon.IService;
|
||
|
||
namespace DOAN.Tasks.TaskScheduler
|
||
{
|
||
/// <summary>
|
||
/// 超过一个小时就发送邮箱
|
||
/// </summary>
|
||
[AppService(ServiceType = typeof(Job_Email_send), ServiceLifetime = LifeTime.Scoped)]
|
||
public class Job_Email_send : JobBase, IJob
|
||
{
|
||
private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||
private readonly IAndonInteractionService _andonInteractionService;
|
||
public Job_Email_send(IAndonInteractionService andonInteractionService)
|
||
{
|
||
_andonInteractionService= andonInteractionService;
|
||
}
|
||
public async Task Execute(IJobExecutionContext context)
|
||
{
|
||
await ExecuteJob(context, async () => await Run(context));
|
||
}
|
||
public async Task Run(IJobExecutionContext context)
|
||
{
|
||
AbstractTrigger trigger = (context as JobExecutionContextImpl).Trigger as AbstractTrigger;
|
||
//var info = await tasksQzService.CopyNew().GetByIdAsync(trigger.JobName);
|
||
var info = await DbScoped.SugarScope.CopyNew().Queryable<SysTasks>().FirstAsync(f => f.ID == trigger.JobName);
|
||
if (info == null)
|
||
{
|
||
throw new CustomException($"任务{trigger?.JobName}_邮件发送定时调度请求执行失败,任务不存在");
|
||
}
|
||
|
||
string[] result = _andonInteractionService.MonitoringMails();
|
||
if (result!=null&&result.Length > 0)
|
||
{
|
||
foreach (string s in result)
|
||
{
|
||
logger.Info($"任务【{info.Name}】_邮件发送定时调度请求执行结果={s}\n");
|
||
}
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
logger.Info($"任务【{info.Name}】_邮件发送定时调度请求执行结果 没有数据\n");
|
||
}
|
||
|
||
|
||
}
|
||
|
||
}
|
||
|
||
}
|