57 lines
2.0 KiB
C#
Raw Normal View History

2024-11-14 16:47:47 +08:00
using Infrastructure;
using Infrastructure.Attribute;
using Microsoft.Extensions.DependencyInjection;
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.System;
using DOAN.Service.MES.dev.IService;
using DOAN.Service.MES.mm.IService;
namespace DOAN.Tasks.TaskScheduler
{
[AppService(ServiceType = typeof(Job_MovSlow_Execute), ServiceLifetime = LifeTime.Scoped)]
public class Job_MovSlow_Execute : JobBase, IJob
{
private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private readonly IMmSlowMoveMaterialService MmSlowMoveMaterialService;
public Job_MovSlow_Execute(IMmSlowMoveMaterialService MmSlowMoveMaterialService)
{
this.MmSlowMoveMaterialService = MmSlowMoveMaterialService;
}
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);
// CopyNew 在多线程环境中,为每个线程或任务创建新的 SugarScope 实例以避免线程安全问题
var info = await DbScoped.SugarScope.CopyNew().Queryable<SysTasks>().FirstAsync(f => f.ID == trigger.JobName);
if (info == null)
{
throw new CustomException($"任务{trigger?.JobName}呆滞品任务调度请求执行失败,任务不存在");
}
2024-11-16 10:08:51 +08:00
bool result = MmSlowMoveMaterialService.GenerateShopFloorSluggishProducts(DateTime.Today.AddDays(-1), "任务调度");
2024-11-14 16:47:47 +08:00
logger.Info($"job任务【{info.Name}】设备管理调度请求执行结果=" + result);
}
}
}